Skip to content

Commit f7a2ab6

Browse files
authored
Check the returned cert index in tests, and test deduplication behaviour (#237)
* check cert index and deduplication # Conflicts: # internal/scti/handlers_test.go # Conflicts: # internal/scti/handlers_test.go * address comments
1 parent afe9c88 commit f7a2ab6

File tree

1 file changed

+63
-27
lines changed

1 file changed

+63
-27
lines changed

internal/scti/handlers_test.go

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/transparency-dev/static-ct/internal/testdata"
3636
"github.com/transparency-dev/static-ct/internal/testonly/storage/posix"
3737
"github.com/transparency-dev/static-ct/internal/types/rfc6962"
38+
"github.com/transparency-dev/static-ct/internal/types/staticct"
3839
"github.com/transparency-dev/static-ct/internal/x509util"
3940
"github.com/transparency-dev/static-ct/storage"
4041
"github.com/transparency-dev/static-ct/storage/bbolt"
@@ -429,10 +430,11 @@ func TestAddChainWhitespace(t *testing.T) {
429430

430431
func TestAddChain(t *testing.T) {
431432
var tests = []struct {
432-
descr string
433-
chain []string
434-
want int
435-
err error
433+
descr string
434+
chain []string
435+
want int
436+
wantIdx uint64
437+
err error
436438
}{
437439
{
438440
descr: "leaf-only",
@@ -445,14 +447,28 @@ func TestAddChain(t *testing.T) {
445447
want: http.StatusBadRequest,
446448
},
447449
{
448-
descr: "success-without-root",
449-
chain: []string{testdata.CertFromIntermediate, testdata.IntermediateFromRoot},
450-
want: http.StatusOK,
450+
descr: "success",
451+
chain: []string{testdata.CertFromIntermediate, testdata.IntermediateFromRoot, testdata.CACertPEM},
452+
wantIdx: 0,
453+
want: http.StatusOK,
451454
},
452455
{
453-
descr: "success",
454-
chain: []string{testdata.CertFromIntermediate, testdata.IntermediateFromRoot, testdata.CACertPEM},
455-
want: http.StatusOK,
456+
descr: "success-duplicate",
457+
chain: []string{testdata.CertFromIntermediate, testdata.IntermediateFromRoot, testdata.CACertPEM},
458+
wantIdx: 0,
459+
want: http.StatusOK,
460+
},
461+
{
462+
descr: "success-not-duplicate",
463+
chain: []string{testdata.TestCertPEM, testdata.CACertPEM},
464+
wantIdx: 1,
465+
want: http.StatusOK,
466+
},
467+
{
468+
descr: "success-without-root",
469+
chain: []string{testdata.CertFromIntermediate, testdata.IntermediateFromRoot},
470+
wantIdx: 0,
471+
want: http.StatusOK,
456472
},
457473
}
458474

@@ -489,21 +505,27 @@ func TestAddChain(t *testing.T) {
489505
if got, want := hex.EncodeToString(gotRsp.Signature), "040300067369676e6564"; got != want {
490506
t.Errorf("resp.Signature=%s; want %s", got, want)
491507
}
508+
idx, err := staticct.ParseCTExtensions(gotRsp.Extensions)
509+
if err != nil {
510+
t.Errorf("Failed to parse extensions %q: %v", gotRsp.Extensions, err)
511+
}
512+
if got, want := idx, test.wantIdx; got != want {
513+
t.Errorf("resp.Extensions.Index=%d; want %d", got, want)
514+
}
492515
// TODO(phboneff): read from the log and compare values
493516
// TODO(phboneff): add a test with a backend write failure
494-
// TODO(phboneff): check that the index is in the SCT
495-
// TODO(phboneff): add duplicate tests
496517
}
497518
})
498519
}
499520
}
500521

501522
func TestAddPreChain(t *testing.T) {
502523
var tests = []struct {
503-
descr string
504-
chain []string
505-
want int
506-
err error
524+
descr string
525+
chain []string
526+
want int
527+
wantIdx uint64
528+
err error
507529
}{
508530
{
509531
descr: "leaf-signed-by-different",
@@ -516,19 +538,28 @@ func TestAddPreChain(t *testing.T) {
516538
want: http.StatusBadRequest,
517539
},
518540
{
519-
descr: "success",
520-
chain: []string{testdata.PrecertPEMValid, testdata.CACertPEM},
521-
want: http.StatusOK,
541+
descr: "success",
542+
chain: []string{testdata.PrecertPEMValid, testdata.CACertPEM},
543+
want: http.StatusOK,
544+
wantIdx: 0,
522545
},
523546
{
524-
descr: "success-with-intermediate",
525-
chain: []string{testdata.PreCertFromIntermediate, testdata.IntermediateFromRoot, testdata.CACertPEM},
526-
want: http.StatusOK,
547+
descr: "success-duplicate",
548+
chain: []string{testdata.PrecertPEMValid, testdata.CACertPEM},
549+
want: http.StatusOK,
550+
wantIdx: 0,
527551
},
528552
{
529-
descr: "success-without-root",
530-
chain: []string{testdata.PrecertPEMValid},
531-
want: http.StatusOK,
553+
descr: "success-with-intermediate",
554+
chain: []string{testdata.PreCertFromIntermediate, testdata.IntermediateFromRoot, testdata.CACertPEM},
555+
want: http.StatusOK,
556+
wantIdx: 1,
557+
},
558+
{
559+
descr: "success-without-root",
560+
chain: []string{testdata.PrecertPEMValid},
561+
want: http.StatusOK,
562+
wantIdx: 0,
532563
},
533564
}
534565

@@ -565,10 +596,15 @@ func TestAddPreChain(t *testing.T) {
565596
if got, want := hex.EncodeToString(gotRsp.Signature), "040300067369676e6564"; got != want {
566597
t.Errorf("resp.Signature=%s; want %s", got, want)
567598
}
599+
idx, err := staticct.ParseCTExtensions(gotRsp.Extensions)
600+
if err != nil {
601+
t.Errorf("Failed to parse extensions %q: %v", gotRsp.Extensions, err)
602+
}
603+
if got, want := idx, test.wantIdx; got != want {
604+
t.Errorf("resp.Extensions.Index=%d; want %d", got, want)
605+
}
568606
// TODO(phboneff): read from the log and compare values
569607
// TODO(phboneff): add a test with a backend write failure
570-
// TODO(phboneff): check that the index is in the SCT
571-
// TODO(phboneff): add duplicate tests
572608
}
573609
})
574610
}

0 commit comments

Comments
 (0)