@@ -35,6 +35,7 @@ import (
35
35
"github.com/transparency-dev/static-ct/internal/testdata"
36
36
"github.com/transparency-dev/static-ct/internal/testonly/storage/posix"
37
37
"github.com/transparency-dev/static-ct/internal/types/rfc6962"
38
+ "github.com/transparency-dev/static-ct/internal/types/staticct"
38
39
"github.com/transparency-dev/static-ct/internal/x509util"
39
40
"github.com/transparency-dev/static-ct/storage"
40
41
"github.com/transparency-dev/static-ct/storage/bbolt"
@@ -429,10 +430,11 @@ func TestAddChainWhitespace(t *testing.T) {
429
430
430
431
func TestAddChain (t * testing.T ) {
431
432
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
436
438
}{
437
439
{
438
440
descr : "leaf-only" ,
@@ -445,14 +447,28 @@ func TestAddChain(t *testing.T) {
445
447
want : http .StatusBadRequest ,
446
448
},
447
449
{
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 ,
451
454
},
452
455
{
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 ,
456
472
},
457
473
}
458
474
@@ -489,21 +505,27 @@ func TestAddChain(t *testing.T) {
489
505
if got , want := hex .EncodeToString (gotRsp .Signature ), "040300067369676e6564" ; got != want {
490
506
t .Errorf ("resp.Signature=%s; want %s" , got , want )
491
507
}
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
+ }
492
515
// TODO(phboneff): read from the log and compare values
493
516
// 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
496
517
}
497
518
})
498
519
}
499
520
}
500
521
501
522
func TestAddPreChain (t * testing.T ) {
502
523
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
507
529
}{
508
530
{
509
531
descr : "leaf-signed-by-different" ,
@@ -516,19 +538,28 @@ func TestAddPreChain(t *testing.T) {
516
538
want : http .StatusBadRequest ,
517
539
},
518
540
{
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 ,
522
545
},
523
546
{
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 ,
527
551
},
528
552
{
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 ,
532
563
},
533
564
}
534
565
@@ -565,10 +596,15 @@ func TestAddPreChain(t *testing.T) {
565
596
if got , want := hex .EncodeToString (gotRsp .Signature ), "040300067369676e6564" ; got != want {
566
597
t .Errorf ("resp.Signature=%s; want %s" , got , want )
567
598
}
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
+ }
568
606
// TODO(phboneff): read from the log and compare values
569
607
// 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
572
608
}
573
609
})
574
610
}
0 commit comments