aboutsummaryrefslogtreecommitdiff
path: root/reqres_test.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-11-25 14:29:15 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-11-25 14:29:15 +0100
commit6be4a0ae1a5a1b58d5660a94b522d34e5b610484 (patch)
tree8995d2a46139c3b5fd87b4fc3d6f9d4a9b658cad /reqres_test.go
parent1c003474d48c2ae5275d5445816156b42fdb9d77 (diff)
added get-entries response test
Diffstat (limited to 'reqres_test.go')
-rw-r--r--reqres_test.go61
1 files changed, 60 insertions, 1 deletions
diff --git a/reqres_test.go b/reqres_test.go
index 7d6b714..228904e 100644
--- a/reqres_test.go
+++ b/reqres_test.go
@@ -9,6 +9,7 @@ import (
"crypto/x509"
"net/http"
+ "github.com/google/trillian"
"github.com/system-transparency/stfe/testdata"
)
@@ -224,8 +225,66 @@ func TestNewGetConsistencyProofRequest(t *testing.T) {
}
}
-// TODO: TestNewGetEntryResponse
+func TestNewGetEntryResponse(t *testing.T) {
+ lp := makeTestLogParameters(t, nil)
+
+ var appendix Appendix
+ leaf, app := makeTestLeaf(t, testPackage, testdata.FirstPemChain, testdata.FirstPemChainKey)
+ if err := appendix.Unmarshal(app); err != nil {
+ t.Fatalf("must unmarshal appendix: %v", err)
+ }
+ if _, err := lp.newGetEntryResponse(leaf, app[1:]); err == nil {
+ t.Errorf("got no error invalid appendix")
+ }
+
+ // Valid response
+ rsp, err := lp.newGetEntryResponse(leaf, app)
+ if err != nil {
+ t.Errorf("got error %v but wanted none", err)
+ return
+ }
+ if got, want := rsp.Item, leaf; !bytes.Equal(got, want) {
+ t.Errorf("got leaf %X but wanted %X", got, want)
+ }
+ if got, want := rsp.Signature, appendix.Signature; !bytes.Equal(got, want) {
+ t.Errorf("got signature %X but wanted %X", got, want)
+ }
+ if got, want := rsp.SignatureScheme, appendix.SignatureScheme; got != want {
+ t.Errorf("got signature scheme %d but wanted %d", got, want)
+ }
+ if got, want := len(rsp.Chain), len(appendix.Chain); got != want {
+ t.Errorf("got chain length %d but wanted %d", got, want)
+ }
+ for i, n := 0, len(rsp.Chain); i < n; i++ {
+ if got, want := rsp.Chain[i], appendix.Chain[i].Data; !bytes.Equal(got, want) {
+ t.Errorf("got chain[%d]=%X but wanted %X", i, got, want)
+ }
+ }
+}
+
func TestNewGetEntriesResponse(t *testing.T) {
+ lp := makeTestLogParameters(t, nil)
+
+ // Invalid
+ leaf := makeTrillianQueueLeafResponse(t, testPackage, testdata.FirstPemChain, testdata.FirstPemChainKey, false).QueuedLeaf.Leaf
+ leaf.ExtraData = leaf.ExtraData[1:]
+ if _, err := lp.newGetEntriesResponse([]*trillian.LogLeaf{leaf}); err == nil {
+ t.Errorf("got no error for invalid appendix")
+ }
+
+ // Valid, including empty
+ for n, numEntries := 0, 5; n < numEntries; n++ {
+ leaves := make([]*trillian.LogLeaf, 0, n)
+ for i := 0; i < n; i++ {
+ leaves = append(leaves, makeTrillianQueueLeafResponse(t, []byte(fmt.Sprintf("%s-%d", testPackage, i)), testdata.FirstPemChain, testdata.FirstPemChainKey, false).QueuedLeaf.Leaf)
+ }
+ if rsp, err := lp.newGetEntriesResponse(leaves); err != nil {
+ t.Errorf("got error for %d valid leaves: %v", n, err)
+ } else if got, want := len(rsp), n; got != want {
+ t.Errorf("got %d leaves but wanted %d", got, want)
+ }
+ // note that we tested actual leaf contents in TestNewGetEntryResponse
+ }
}
func TestNewGetAnchorsResponse(t *testing.T) {