diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-01-27 19:59:47 +0100 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-01-27 19:59:47 +0100 |
commit | 0284a7460f03799452f4743a0032f2ae1564a3e8 (patch) | |
tree | f735b7d5aa39b476f008e1d19665354fa5e3d1d4 /reqres_test.go | |
parent | f5ad698cdb0fc9ecd8ad4c7b2cb7ec11ac0435ef (diff) |
started replacing x509 with namespace
Diffstat (limited to 'reqres_test.go')
-rw-r--r-- | reqres_test.go | 130 |
1 files changed, 65 insertions, 65 deletions
diff --git a/reqres_test.go b/reqres_test.go index 3574750..fab0e29 100644 --- a/reqres_test.go +++ b/reqres_test.go @@ -6,11 +6,8 @@ import ( "strconv" "testing" - "crypto/x509" "net/http" - - "github.com/google/trillian" - "github.com/system-transparency/stfe/x509util/testdata" + // "github.com/google/trillian" ) // TODO: TestNewAddEntryRequest @@ -228,78 +225,81 @@ func TestNewGetConsistencyProofRequest(t *testing.T) { } } +// TODO: refactor TestNewGetEntryResponse func TestNewGetEntryResponse(t *testing.T) { - lp := makeTestLogParameters(t, nil) + //lp := makeTestLogParameters(t, nil) - var appendix Appendix - leaf, app := makeTestLeaf(t, testPackage, testdata.RootChain, testdata.EndEntityPrivateKey) - 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") - } + //var appendix Appendix + //leaf, app := makeTestLeaf(t, testPackage, testdata.RootChain, testdata.EndEntityPrivateKey) + //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) - } - } + //// 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) + // } + //} } +// TODO: refactor TestNewGetEntriesResponse func TestNewGetEntriesResponse(t *testing.T) { - lp := makeTestLogParameters(t, nil) + //lp := makeTestLogParameters(t, nil) - // Invalid - leaf := makeTrillianQueueLeafResponse(t, testPackage, testdata.RootChain, testdata.EndEntityPrivateKey, 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") - } + //// Invalid + //leaf := makeTrillianQueueLeafResponse(t, testPackage, testdata.RootChain, testdata.EndEntityPrivateKey, 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.RootChain, testdata.EndEntityPrivateKey, 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 - } + //// 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.RootChain, testdata.EndEntityPrivateKey, 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 + //} } +// TODO: refactor TestNewGetAnchorsResponse func TestNewGetAnchorsResponse(t *testing.T) { - rawAnchors := makeTestLogParameters(t, nil).newGetAnchorsResponse() - if got, want := len(rawAnchors), testdata.NumTrustAnchors; got != want { - t.Errorf("got %d anchors but wanted %d", got, want) - } - for _, rawAnchor := range rawAnchors { - if _, err := x509.ParseCertificate(rawAnchor); err != nil { - t.Errorf("invalid trust anchor %X: %v", rawAnchor, err) - } - } + //rawAnchors := makeTestLogParameters(t, nil).newGetAnchorsResponse() + //if got, want := len(rawAnchors), testdata.NumTrustAnchors; got != want { + // t.Errorf("got %d anchors but wanted %d", got, want) + //} + //for _, rawAnchor := range rawAnchors { + // if _, err := x509.ParseCertificate(rawAnchor); err != nil { + // t.Errorf("invalid trust anchor %X: %v", rawAnchor, err) + // } + //} } func mustParseInt64(t *testing.T, num string) int64 { |