From c05c22ddbc771e7713849cae40f9d91bfafa0503 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Thu, 25 Feb 2021 14:36:35 +0100 Subject: major refactor based on README.md and TODOs Updated types, improved units tests, isolated most test data to have it in one place, renamed and created new files to improve readability, and fixed a bunch of minor TODOs. --- sth_test.go | 364 +++++++++++++++++++++++++++--------------------------------- 1 file changed, 163 insertions(+), 201 deletions(-) (limited to 'sth_test.go') diff --git a/sth_test.go b/sth_test.go index e3350dd..e5914c6 100644 --- a/sth_test.go +++ b/sth_test.go @@ -10,8 +10,8 @@ import ( "github.com/golang/mock/gomock" cttestdata "github.com/google/certificate-transparency-go/trillian/testdata" "github.com/google/trillian" - "github.com/system-transparency/stfe/namespace" - "github.com/system-transparency/stfe/namespace/testdata" + "github.com/system-transparency/stfe/testdata" + "github.com/system-transparency/stfe/types" ) func TestNewActiveSthSource(t *testing.T) { @@ -21,28 +21,28 @@ func TestNewActiveSthSource(t *testing.T) { trsp *trillian.GetLatestSignedLogRootResponse terr error wantErr bool - wantCosi *StItem // current cosigned sth - wantStable *StItem // next stable sth that signatures are collected for + wantCosi *types.StItem // current cosigned sth + wantStable *types.StItem // next stable sth that signatures are collected for }{ { - description: "invalid trillian response", - signer: cttestdata.NewSignerWithFixedSig(nil, testSignature), + description: "invalid: no Trillian response", + signer: cttestdata.NewSignerWithFixedSig(nil, testdata.Signature), terr: fmt.Errorf("internal server error"), wantErr: true, }, { description: "valid", - signer: cttestdata.NewSignerWithFixedSig(nil, testSignature), - trsp: makeLatestSignedLogRootResponse(t, testTimestamp, testTreeSize, testNodeHash), - wantCosi: NewCosignedTreeHeadV1(NewSignedTreeHeadV1(NewTreeHeadV1(makeTrillianLogRoot(t, testTimestamp, testTreeSize, testNodeHash)), testLogId, testSignature).SignedTreeHeadV1, nil), - wantStable: NewCosignedTreeHeadV1(NewSignedTreeHeadV1(NewTreeHeadV1(makeTrillianLogRoot(t, testTimestamp, testTreeSize, testNodeHash)), testLogId, testSignature).SignedTreeHeadV1, nil), + signer: cttestdata.NewSignerWithFixedSig(nil, testdata.Signature), + trsp: testdata.DefaultTSlr(t), + wantCosi: testdata.DefaultCosth(t, testdata.Ed25519VkLog, nil), + wantStable: testdata.DefaultCosth(t, testdata.Ed25519VkLog, nil), }, } { func() { // run deferred functions at the end of each iteration - th := newTestHandler(t, table.signer, nil) - defer th.mockCtrl.Finish() - th.client.EXPECT().GetLatestSignedLogRoot(gomock.Any(), gomock.Any()).Return(table.trsp, table.terr) - source, err := NewActiveSthSource(th.client, th.instance.LogParameters) + ti := newTestInstance(t, table.signer) + defer ti.ctrl.Finish() + ti.client.EXPECT().GetLatestSignedLogRoot(gomock.Any(), gomock.Any()).Return(table.trsp, table.terr) + source, err := NewActiveSthSource(ti.client, ti.instance.LogParameters) if got, want := err != nil, table.wantErr; got != want { t.Errorf("got error %v but wanted %v in test %q: %v", got, want, table.description, err) } @@ -51,20 +51,20 @@ func TestNewActiveSthSource(t *testing.T) { } if got, want := source.currCosth, table.wantCosi; !reflect.DeepEqual(got, want) { - t.Errorf("got cosigned sth %v but wanted %v in test %q", got, want, table.description) + t.Errorf("got cosigned sth\n%v\n\tbut wanted\n%v\n\tin test %q", got, want, table.description) } if got, want := source.nextCosth, table.wantStable; !reflect.DeepEqual(got, want) { - t.Errorf("got stable sth %v but wanted %v in test %q", got, want, table.description) + t.Errorf("got stable sth\n%v\n\tbut wanted\n%v\n\tin test %q", got, want, table.description) } - cosignatureFrom := make(map[string]bool) - for _, wit := range table.wantStable.CosignedTreeHeadV1.SignatureV1 { - cosignatureFrom[wit.Namespace.String()] = true + cosignatureFrom := make(map[[types.NamespaceFingerprintSize]byte]bool) + for _, cosig := range table.wantStable.CosignedTreeHeadV1.Cosignatures { + cosignatureFrom[testdata.Fingerprint(t, &cosig.Namespace)] = true } if got, want := source.cosignatureFrom, cosignatureFrom; !reflect.DeepEqual(got, want) { if got == nil { - t.Errorf("got uninitialized witness map %v but wanted %v in test %q", nil, want, table.description) + t.Errorf("got uninitialized witness map\n%v\n\tbut wanted\n%v\n\tin test %q", nil, want, table.description) } else { - t.Errorf("got witness map %v but wanted %v in test %q", got, want, table.description) + t.Errorf("got witness map\n%v\n\t but wanted\n%v\n\tin test %q", got, want, table.description) } } }() @@ -78,32 +78,32 @@ func TestLatest(t *testing.T) { trsp *trillian.GetLatestSignedLogRootResponse terr error wantErr bool - wantRsp *StItem + wantRsp *types.StItem }{ { - description: "invalid trillian response", - signer: cttestdata.NewSignerWithFixedSig(nil, testSignature), + description: "invalid: no Trillian response", + signer: cttestdata.NewSignerWithFixedSig(nil, testdata.Signature), terr: fmt.Errorf("internal server error"), wantErr: true, }, { - description: "signature failure", + description: "invalid: no signature", signer: cttestdata.NewSignerWithErr(nil, fmt.Errorf("signing failed")), terr: fmt.Errorf("internal server error"), wantErr: true, }, { description: "valid", - signer: cttestdata.NewSignerWithFixedSig(nil, testSignature), - trsp: makeLatestSignedLogRootResponse(t, testTimestamp, testTreeSize, testNodeHash), - wantRsp: NewSignedTreeHeadV1(NewTreeHeadV1(makeTrillianLogRoot(t, testTimestamp, testTreeSize, testNodeHash)), testLogId, testSignature), + signer: cttestdata.NewSignerWithFixedSig(nil, testdata.Signature), + trsp: testdata.DefaultTSlr(t), + wantRsp: testdata.DefaultSth(t, testdata.Ed25519VkLog), }, } { func() { // run deferred functions at the end of each iteration - th := newTestHandler(t, table.signer, nil) - defer th.mockCtrl.Finish() - th.client.EXPECT().GetLatestSignedLogRoot(gomock.Any(), gomock.Any()).Return(table.trsp, table.terr) - sth, err := th.instance.SthSource.Latest(context.Background()) + ti := newTestInstance(t, table.signer) + defer ti.ctrl.Finish() + ti.client.EXPECT().GetLatestSignedLogRoot(gomock.Any(), gomock.Any()).Return(table.trsp, table.terr) + sth, err := ti.instance.SthSource.Latest(context.Background()) if got, want := err != nil, table.wantErr; got != want { t.Errorf("got error %v but wanted %v in test %q: %v", got, want, table.description, err) } @@ -111,30 +111,30 @@ func TestLatest(t *testing.T) { return } if got, want := sth, table.wantRsp; !reflect.DeepEqual(got, want) { - t.Errorf("got %v but wanted %v in test %q", got, want, table.description) + t.Errorf("got\n%v\n\tbut wanted\n%v\n\t in test %q", got, want, table.description) } }() } } func TestStable(t *testing.T) { - sth := NewSignedTreeHeadV1(NewTreeHeadV1(makeTrillianLogRoot(t, testTimestamp, testTreeSize, testNodeHash)), testLogId, testSignature) for _, table := range []struct { description string source SthSource - wantRsp *StItem + wantRsp *types.StItem wantErr bool }{ { - description: "no stable sth", + description: "invalid: no stable sth", source: &ActiveSthSource{}, wantErr: true, }, { description: "valid", source: &ActiveSthSource{ - nextCosth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil)}, - wantRsp: sth, + nextCosth: testdata.DefaultCosth(t, testdata.Ed25519VkLog, nil), + }, + wantRsp: testdata.DefaultSth(t, testdata.Ed25519VkLog), }, } { sth, err := table.source.Stable(context.Background()) @@ -145,43 +145,36 @@ func TestStable(t *testing.T) { continue } if got, want := sth, table.wantRsp; !reflect.DeepEqual(got, want) { - t.Errorf("got %v but wanted %v in test %q", got, want, table.description) + t.Errorf("got\n%v\n\t but wanted\n%v\n\t in test %q", got, want, table.description) } } } func TestCosigned(t *testing.T) { - sth := NewSignedTreeHeadV1(NewTreeHeadV1(makeTrillianLogRoot(t, testTimestamp, testTreeSize, testNodeHash)), testLogId, testSignature) - sigs := []SignatureV1{ - SignatureV1{ - Namespace: *mustNewNamespaceEd25519V1(t, testdata.Ed25519Vk), - Signature: testSignature, - }, - } for _, table := range []struct { description string source SthSource - wantRsp *StItem + wantRsp *types.StItem wantErr bool }{ { - description: "no cosigned sth: nil", + description: "invalid: no cosigned sth: nil", source: &ActiveSthSource{}, wantErr: true, }, { - description: "no cosigned sth: nil signatures", + description: "invalid: no cosigned sth: nil signatures", source: &ActiveSthSource{ - currCosth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil), + currCosth: testdata.DefaultCosth(t, testdata.Ed25519VkLog, nil), }, wantErr: true, }, { description: "valid", source: &ActiveSthSource{ - currCosth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, sigs), + currCosth: testdata.DefaultCosth(t, testdata.Ed25519VkLog, [][32]byte{testdata.Ed25519VkWitness}), }, - wantRsp: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, sigs), + wantRsp: testdata.DefaultCosth(t, testdata.Ed25519VkLog, [][32]byte{testdata.Ed25519VkWitness}), }, } { cosi, err := table.source.Cosigned(context.Background()) @@ -192,91 +185,58 @@ func TestCosigned(t *testing.T) { continue } if got, want := cosi, table.wantRsp; !reflect.DeepEqual(got, want) { - t.Errorf("got %v but wanted %v in test %q", got, want, table.description) + t.Errorf("got\n%v\n\tbut wanted\n%v\n\tin test %q", got, want, table.description) } } } func TestAddCosignature(t *testing.T) { - sth := NewSignedTreeHeadV1(NewTreeHeadV1(makeTrillianLogRoot(t, testTimestamp, testTreeSize, testNodeHash)), testLogId, testSignature) - wit1 := mustNewNamespaceEd25519V1(t, testdata.Ed25519Vk) - wit2 := mustNewNamespaceEd25519V1(t, testdata.Ed25519Vk2) for _, table := range []struct { description string source *ActiveSthSource - req *StItem - wantWit []*namespace.Namespace + req *types.StItem + wantWit []*types.Namespace wantErr bool }{ { description: "invalid: cosignature must target the stable sth", source: &ActiveSthSource{ - nextCosth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil), - cosignatureFrom: make(map[string]bool), + nextCosth: testdata.DefaultCosth(t, testdata.Ed25519VkLog, nil), + cosignatureFrom: make(map[[types.NamespaceFingerprintSize]byte]bool), }, - req: NewCosignedTreeHeadV1(NewSignedTreeHeadV1(NewTreeHeadV1(makeTrillianLogRoot(t, testTimestamp+1000000, testTreeSize, testNodeHash)), testLogId, testSignature).SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ - Namespace: *wit1, - Signature: testSignature, - }, - }), + req: testdata.DefaultCosth(t, testdata.Ed25519VkLog2, [][32]byte{testdata.Ed25519VkWitness}), wantErr: true, }, { description: "valid: adding duplicate into a pool of cosignatures", source: &ActiveSthSource{ - nextCosth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ - Namespace: *wit1, - Signature: testSignature, - }, - }), - cosignatureFrom: map[string]bool{ - wit1.String(): true, + nextCosth: testdata.DefaultCosth(t, testdata.Ed25519VkLog, [][32]byte{testdata.Ed25519VkWitness}), + cosignatureFrom: map[[types.NamespaceFingerprintSize]byte]bool{ + testdata.Fingerprint(t, testdata.NewNamespace(t, testdata.Ed25519VkWitness)): true, }, }, - req: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ - Namespace: *wit1, - Signature: testSignature, - }, - }), - wantWit: []*namespace.Namespace{wit1}, + req: testdata.DefaultCosth(t, testdata.Ed25519VkLog, [][32]byte{testdata.Ed25519VkWitness}), + wantWit: []*types.Namespace{testdata.NewNamespace(t, testdata.Ed25519VkWitness)}, }, { description: "valid: adding into an empty pool of cosignatures", source: &ActiveSthSource{ - nextCosth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil), - cosignatureFrom: make(map[string]bool), + nextCosth: testdata.DefaultCosth(t, testdata.Ed25519VkLog, nil), + cosignatureFrom: make(map[[types.NamespaceFingerprintSize]byte]bool), }, - req: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ - Namespace: *wit1, - Signature: testSignature, - }, - }), - wantWit: []*namespace.Namespace{wit1}, + req: testdata.DefaultCosth(t, testdata.Ed25519VkLog, [][32]byte{testdata.Ed25519VkWitness}), + wantWit: []*types.Namespace{testdata.NewNamespace(t, testdata.Ed25519VkWitness)}, }, { description: "valid: adding into a pool of cosignatures", source: &ActiveSthSource{ - nextCosth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ - Namespace: *wit1, - Signature: testSignature, - }, - }), - cosignatureFrom: map[string]bool{ - wit1.String(): true, + nextCosth: testdata.DefaultCosth(t, testdata.Ed25519VkLog, [][32]byte{testdata.Ed25519VkWitness}), + cosignatureFrom: map[[types.NamespaceFingerprintSize]byte]bool{ + testdata.Fingerprint(t, testdata.NewNamespace(t, testdata.Ed25519VkWitness)): true, }, }, - req: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ - Namespace: *wit2, - Signature: testSignature, - }, - }), - wantWit: []*namespace.Namespace{wit1, wit2}, + req: testdata.DefaultCosth(t, testdata.Ed25519VkLog, [][32]byte{testdata.Ed25519VkWitness2}), + wantWit: []*types.Namespace{testdata.NewNamespace(t, testdata.Ed25519VkWitness), testdata.NewNamespace(t, testdata.Ed25519VkWitness2)}, }, } { err := table.source.AddCosignature(context.Background(), table.req) @@ -288,23 +248,23 @@ func TestAddCosignature(t *testing.T) { } // Check that the next cosigned sth is updated - var sigs []SignatureV1 + var sigs []types.SignatureV1 for _, wit := range table.wantWit { - sigs = append(sigs, SignatureV1{ + sigs = append(sigs, types.SignatureV1{ Namespace: *wit, - Signature: testSignature, + Signature: testdata.Signature, }) } - if got, want := table.source.nextCosth, NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, sigs); !reflect.DeepEqual(got, want) { - t.Errorf("got %v but wanted %v in test %q", got, want, table.description) + if got, want := table.source.nextCosth, types.NewCosignedTreeHeadV1(testdata.DefaultSth(t, testdata.Ed25519VkLog).SignedTreeHeadV1, sigs); !reflect.DeepEqual(got, want) { + t.Errorf("got\n%v\n\tbut wanted\n%v\n\tin test %q", got, want, table.description) } // Check that the map tracking witness signatures is updated if got, want := len(table.source.cosignatureFrom), len(table.wantWit); got != want { t.Errorf("witness map got %d cosignatures but wanted %d in test %q", got, want, table.description) } else { for _, wit := range table.wantWit { - if _, ok := table.source.cosignatureFrom[wit.String()]; !ok { - t.Errorf("missing signature from witness %X in test %q", wit.String(), table.description) + if _, ok := table.source.cosignatureFrom[testdata.Fingerprint(t, wit)]; !ok { + t.Errorf("missing signature from witness %X in test %q", testdata.Fingerprint(t, wit), table.description) } } } @@ -312,199 +272,201 @@ func TestAddCosignature(t *testing.T) { } func TestRotate(t *testing.T) { - sth1 := NewSignedTreeHeadV1(NewTreeHeadV1(makeTrillianLogRoot(t, testTimestamp, testTreeSize, testNodeHash)), testLogId, testSignature) - sth2 := NewSignedTreeHeadV1(NewTreeHeadV1(makeTrillianLogRoot(t, testTimestamp+1000000, testTreeSize+1, testNodeHash)), testLogId, testSignature) - sth3 := NewSignedTreeHeadV1(NewTreeHeadV1(makeTrillianLogRoot(t, testTimestamp+2000000, testTreeSize+2, testNodeHash)), testLogId, testSignature) - wit1 := mustNewNamespaceEd25519V1(t, testdata.Ed25519Vk) - wit2 := mustNewNamespaceEd25519V1(t, testdata.Ed25519Vk2) - wit3 := mustNewNamespaceEd25519V1(t, testdata.Ed25519Vk3) + // distinct sths + sth1 := testdata.DefaultSth(t, testdata.Ed25519VkLog) + sth2 := testdata.DefaultSth(t, testdata.Ed25519VkLog2) + sth3 := testdata.DefaultSth(t, testdata.Ed25519VkLog3) + // distinct witnesses + wit1 := testdata.NewNamespace(t, testdata.Ed25519VkWitness) + wit2 := testdata.NewNamespace(t, testdata.Ed25519VkWitness2) + wit3 := testdata.NewNamespace(t, testdata.Ed25519VkWitness3) for _, table := range []struct { description string source *ActiveSthSource - fixedSth *StItem - wantCurrSth *StItem - wantNextSth *StItem - wantWit []*namespace.Namespace + fixedSth *types.StItem + wantCurrSth *types.StItem + wantNextSth *types.StItem + wantWit []*types.Namespace }{ { description: "not repeated cosigned and not repeated stable", source: &ActiveSthSource{ - currCosth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, nil), - nextCosth: NewCosignedTreeHeadV1(sth2.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ + currCosth: types.NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, nil), + nextCosth: types.NewCosignedTreeHeadV1(sth2.SignedTreeHeadV1, []types.SignatureV1{ + types.SignatureV1{ Namespace: *wit1, - Signature: testSignature, + Signature: testdata.Signature, }, }), - cosignatureFrom: map[string]bool{ - wit1.String(): true, + cosignatureFrom: map[[types.NamespaceFingerprintSize]byte]bool{ + testdata.Fingerprint(t, wit1): true, }, }, fixedSth: sth3, - wantCurrSth: NewCosignedTreeHeadV1(sth2.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ + wantCurrSth: types.NewCosignedTreeHeadV1(sth2.SignedTreeHeadV1, []types.SignatureV1{ + types.SignatureV1{ Namespace: *wit1, - Signature: testSignature, + Signature: testdata.Signature, }, }), - wantNextSth: NewCosignedTreeHeadV1(sth3.SignedTreeHeadV1, nil), + wantNextSth: types.NewCosignedTreeHeadV1(sth3.SignedTreeHeadV1, nil), wantWit: nil, // no cosignatures for the next stable sth yet }, { description: "not repeated cosigned and repeated stable", source: &ActiveSthSource{ - currCosth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, nil), - nextCosth: NewCosignedTreeHeadV1(sth2.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ + currCosth: types.NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, nil), + nextCosth: types.NewCosignedTreeHeadV1(sth2.SignedTreeHeadV1, []types.SignatureV1{ + types.SignatureV1{ Namespace: *wit1, - Signature: testSignature, + Signature: testdata.Signature, }, }), - cosignatureFrom: map[string]bool{ - wit1.String(): true, + cosignatureFrom: map[[types.NamespaceFingerprintSize]byte]bool{ + testdata.Fingerprint(t, wit1): true, }, }, fixedSth: sth2, - wantCurrSth: NewCosignedTreeHeadV1(sth2.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ + wantCurrSth: types.NewCosignedTreeHeadV1(sth2.SignedTreeHeadV1, []types.SignatureV1{ + types.SignatureV1{ Namespace: *wit1, - Signature: testSignature, + Signature: testdata.Signature, }, }), - wantNextSth: NewCosignedTreeHeadV1(sth2.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ + wantNextSth: types.NewCosignedTreeHeadV1(sth2.SignedTreeHeadV1, []types.SignatureV1{ + types.SignatureV1{ Namespace: *wit1, - Signature: testSignature, + Signature: testdata.Signature, }, }), - wantWit: []*namespace.Namespace{wit1}, + wantWit: []*types.Namespace{wit1}, }, { description: "repeated cosigned and not repeated stable", source: &ActiveSthSource{ - currCosth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ + currCosth: types.NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []types.SignatureV1{ + types.SignatureV1{ Namespace: *wit1, - Signature: testSignature, + Signature: testdata.Signature, }, - SignatureV1{ + types.SignatureV1{ Namespace: *wit2, - Signature: testSignature, + Signature: testdata.Signature, }, }), - nextCosth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ + nextCosth: types.NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []types.SignatureV1{ + types.SignatureV1{ Namespace: *wit2, - Signature: testSignature, + Signature: testdata.Signature, }, - SignatureV1{ + types.SignatureV1{ Namespace: *wit3, - Signature: testSignature, + Signature: testdata.Signature, }, }), - cosignatureFrom: map[string]bool{ - wit2.String(): true, - wit3.String(): true, + cosignatureFrom: map[[types.NamespaceFingerprintSize]byte]bool{ + testdata.Fingerprint(t, wit2): true, + testdata.Fingerprint(t, wit3): true, }, }, fixedSth: sth3, - wantCurrSth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ + wantCurrSth: types.NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []types.SignatureV1{ + types.SignatureV1{ Namespace: *wit2, - Signature: testSignature, + Signature: testdata.Signature, }, - SignatureV1{ + types.SignatureV1{ Namespace: *wit3, - Signature: testSignature, + Signature: testdata.Signature, }, - SignatureV1{ + types.SignatureV1{ Namespace: *wit1, - Signature: testSignature, + Signature: testdata.Signature, }, }), - wantNextSth: NewCosignedTreeHeadV1(sth3.SignedTreeHeadV1, nil), + wantNextSth: types.NewCosignedTreeHeadV1(sth3.SignedTreeHeadV1, nil), wantWit: nil, // no cosignatures for the next stable sth yet }, { description: "repeated cosigned and repeated stable", source: &ActiveSthSource{ - currCosth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ + currCosth: types.NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []types.SignatureV1{ + types.SignatureV1{ Namespace: *wit1, - Signature: testSignature, + Signature: testdata.Signature, }, - SignatureV1{ + types.SignatureV1{ Namespace: *wit2, - Signature: testSignature, + Signature: testdata.Signature, }, }), - nextCosth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ + nextCosth: types.NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []types.SignatureV1{ + types.SignatureV1{ Namespace: *wit2, - Signature: testSignature, + Signature: testdata.Signature, }, - SignatureV1{ + types.SignatureV1{ Namespace: *wit3, - Signature: testSignature, + Signature: testdata.Signature, }, }), - cosignatureFrom: map[string]bool{ - wit2.String(): true, - wit3.String(): true, + cosignatureFrom: map[[types.NamespaceFingerprintSize]byte]bool{ + testdata.Fingerprint(t, wit2): true, + testdata.Fingerprint(t, wit3): true, }, }, fixedSth: sth1, - wantCurrSth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ + wantCurrSth: types.NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []types.SignatureV1{ + types.SignatureV1{ Namespace: *wit2, - Signature: testSignature, + Signature: testdata.Signature, }, - SignatureV1{ + types.SignatureV1{ Namespace: *wit3, - Signature: testSignature, + Signature: testdata.Signature, }, - SignatureV1{ + types.SignatureV1{ Namespace: *wit1, - Signature: testSignature, + Signature: testdata.Signature, }, }), - wantNextSth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []SignatureV1{ - SignatureV1{ + wantNextSth: types.NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []types.SignatureV1{ + types.SignatureV1{ Namespace: *wit2, - Signature: testSignature, + Signature: testdata.Signature, }, - SignatureV1{ + types.SignatureV1{ Namespace: *wit3, - Signature: testSignature, + Signature: testdata.Signature, }, - SignatureV1{ + types.SignatureV1{ Namespace: *wit1, - Signature: testSignature, + Signature: testdata.Signature, }, }), - wantWit: []*namespace.Namespace{wit1, wit2, wit3}, + wantWit: []*types.Namespace{wit1, wit2, wit3}, }, } { table.source.rotate(table.fixedSth) if got, want := table.source.currCosth, table.wantCurrSth; !reflect.DeepEqual(got, want) { - t.Errorf("got currCosth %X but wanted %X in test %q", got, want, table.description) + t.Errorf("got currCosth\n%v\n\tbut wanted \n%v\n\tin test %q", got, want, table.description) } if got, want := table.source.nextCosth, table.wantNextSth; !reflect.DeepEqual(got, want) { - t.Errorf("got nextCosth %X but wanted %X in test %q", got, want, table.description) + t.Errorf("got nextCosth\n%v\n\tbut wanted\n%v\n\tin test %q", got, want, table.description) } if got, want := len(table.source.cosignatureFrom), len(table.wantWit); got != want { t.Errorf("witness map got %d cosignatures but wanted %d in test %q", got, want, table.description) } else { for _, wit := range table.wantWit { - if _, ok := table.source.cosignatureFrom[wit.String()]; !ok { - t.Errorf("missing signature from witness %X in test %q", wit.String(), table.description) + if _, ok := table.source.cosignatureFrom[testdata.Fingerprint(t, wit)]; !ok { + t.Errorf("missing signature from witness %X in test %q", testdata.Fingerprint(t, wit), table.description) } } } // check that adding cosignatures to stable will not effect cosigned sth - wantLen := len(table.source.currCosth.CosignedTreeHeadV1.SignatureV1) - table.source.nextCosth.CosignedTreeHeadV1.SignatureV1 = append(table.source.nextCosth.CosignedTreeHeadV1.SignatureV1, SignatureV1{Namespace: *wit1, Signature: testSignature}) - if gotLen := len(table.source.currCosth.CosignedTreeHeadV1.SignatureV1); gotLen != wantLen { + wantLen := len(table.source.currCosth.CosignedTreeHeadV1.Cosignatures) + table.source.nextCosth.CosignedTreeHeadV1.Cosignatures = append(table.source.nextCosth.CosignedTreeHeadV1.Cosignatures, types.SignatureV1{Namespace: *wit1, Signature: testdata.Signature}) + if gotLen := len(table.source.currCosth.CosignedTreeHeadV1.Cosignatures); gotLen != wantLen { t.Errorf("adding cosignatures to the stable sth modifies the fixated cosigned sth in test %q", table.description) } } -- cgit v1.2.3