diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-02-17 19:58:27 +0100 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-02-17 19:58:27 +0100 |
commit | 238518951868db81cd3a004e5c3f0b99f8e82b06 (patch) | |
tree | 1df8e71e869272bc5324e7412eab9236276f3548 /reqres_test.go | |
parent | 72c8492ee1bd07d5960c9920e51b7addac11b806 (diff) |
added basic server-side cosigning (work in progress)
Diffstat (limited to 'reqres_test.go')
-rw-r--r-- | reqres_test.go | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/reqres_test.go b/reqres_test.go index fab0e29..ce0c7b6 100644 --- a/reqres_test.go +++ b/reqres_test.go @@ -7,9 +7,48 @@ import ( "testing" "net/http" - // "github.com/google/trillian" + + "github.com/system-transparency/stfe/namespace/testdata" ) +func TestNewAddCosignatureRequest(t *testing.T) { + lp := makeTestLogParameters(t, nil) + validSth := NewSignedTreeHeadV1(NewTreeHeadV1(makeTrillianLogRoot(t, testTimestamp, testTreeSize, testNodeHash)), testLogId, testSignature) + for _, table := range []struct { + description string + breq *bytes.Buffer + wantErr bool + }{ + // TODO: test cases for all errors + add wantBytes for valid cases + { + description: "invalid: unknown witness", + breq: mustMakeAddCosiBuffer(t, testdata.Ed25519Sk2, testdata.Ed25519Vk2, validSth), + wantErr: true, + }, + { + description: "invalid: bad signature", + breq: mustMakeAddCosiBuffer(t, testdata.Ed25519Sk, testdata.Ed25519Vk2, validSth), + wantErr: true, + }, + { + description: "valid", + breq: mustMakeAddCosiBuffer(t, testdata.Ed25519Sk, testdata.Ed25519Vk, validSth), + }, + } { + url := EndpointAddCosi.Path("http://example.com", lp.Prefix) + req, err := http.NewRequest("POST", url, table.breq) + if err != nil { + t.Fatalf("failed creating http request: %v", err) + } + req.Header.Set("Content-Type", "application/json") + + _, err = lp.newAddCosignatureRequest(req) + if got, want := err != nil, table.wantErr; got != want { + t.Errorf("got errror %v but wanted %v in test %q: %v", got, want, table.description, err) + } + } +} + // TODO: TestNewAddEntryRequest func TestNewAddEntryRequest(t *testing.T) { } |