Skip to content

Commit 9a777ac

Browse files
authored
Test that issuers are populated correctly (#241)
* test issuer storage * typo
1 parent bb0b3de commit 9a777ac

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

internal/scti/handlers_test.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"bufio"
1919
"bytes"
2020
"context"
21+
"crypto/sha256"
2122
"crypto/x509"
2223
"encoding/base64"
2324
"encoding/hex"
@@ -507,7 +508,7 @@ func TestAddChain(t *testing.T) {
507508
t.Errorf("http.Post(%s)=(%d,nil); want (%d,nil)", rfc6962.AddChainPath, got, want)
508509
}
509510
if test.want == http.StatusOK {
510-
unseqEntry, _ := parseChain(t, false, test.chain, log.chainValidationOpts.trustedRoots.RawCertificates()[0])
511+
unseqEntry, wantIssChain := parseChain(t, false, test.chain, log.chainValidationOpts.trustedRoots.RawCertificates()[0])
511512

512513
var gotRsp rfc6962.AddChainResponse
513514
if err := json.NewDecoder(resp.Body).Decode(&gotRsp); err != nil {
@@ -559,7 +560,20 @@ func TestAddChain(t *testing.T) {
559560
if diff := cmp.Diff(wantEntry, gotEntry); diff != "" {
560561
t.Errorf("Logged entry mismatch (-want +got):\n%s", diff)
561562
}
562-
// TODO(phbnf): check the issuer chain fingerprint
563+
564+
// Check that the issuers have been populated correctly.
565+
for _, wantIss := range wantIssChain[1:] {
566+
key := sha256.Sum256(wantIss.Raw)
567+
issPath := path.Join(dir, issDir, hex.EncodeToString(key[:]))
568+
gotIss, err := os.ReadFile(issPath)
569+
if err != nil {
570+
t.Errorf("Failed to read issuer at %q: %v", issPath, err)
571+
}
572+
if !bytes.Equal(gotIss, wantIss.Raw) {
573+
t.Errorf("Issuer mismatch: got %s, want %s", gotIss, wantIss.Raw)
574+
}
575+
}
576+
563577
// TODO(phbnf): check inclusion proof
564578
// TODO(phbnf): add a test with a backend write failure
565579
}
@@ -633,7 +647,7 @@ func TestAddPreChain(t *testing.T) {
633647
t.Errorf("http.Post(%s)=(%d,nil); want (%d,nil)", rfc6962.AddPreChainPath, got, want)
634648
}
635649
if test.want == http.StatusOK {
636-
unseqEntry, _ := parseChain(t, true, test.chain, log.chainValidationOpts.trustedRoots.RawCertificates()[0])
650+
unseqEntry, wantIssChain := parseChain(t, true, test.chain, log.chainValidationOpts.trustedRoots.RawCertificates()[0])
637651

638652
var gotRsp rfc6962.AddChainResponse
639653
if err := json.NewDecoder(resp.Body).Decode(&gotRsp); err != nil {
@@ -685,7 +699,20 @@ func TestAddPreChain(t *testing.T) {
685699
if diff := cmp.Diff(wantEntry, gotEntry); diff != "" {
686700
t.Errorf("Logged entry mismatch (-want +got):\n%s", diff)
687701
}
688-
// TODO(phbnf): check the issuer chain fingerprint
702+
703+
// Check that the issuers have been populated correctly.
704+
for _, wantIss := range wantIssChain[1:] {
705+
key := sha256.Sum256(wantIss.Raw)
706+
issPath := path.Join(dir, issDir, hex.EncodeToString(key[:]))
707+
gotIss, err := os.ReadFile(issPath)
708+
if err != nil {
709+
t.Errorf("Failed to read issuer at %q: %v", issPath, err)
710+
}
711+
if !bytes.Equal(gotIss, wantIss.Raw) {
712+
t.Errorf("Issuer mismatch: got %s, want %s", gotIss, wantIss.Raw)
713+
}
714+
}
715+
689716
// TODO(phbnf): check inclusion proof
690717
// TODO(phboneff): add a test with a backend write failure
691718
}

0 commit comments

Comments
 (0)