Skip to content

Test that issuers are populated correctly #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions internal/scti/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bufio"
"bytes"
"context"
"crypto/sha256"
"crypto/x509"
"encoding/base64"
"encoding/hex"
Expand Down Expand Up @@ -507,7 +508,7 @@ func TestAddChain(t *testing.T) {
t.Errorf("http.Post(%s)=(%d,nil); want (%d,nil)", rfc6962.AddChainPath, got, want)
}
if test.want == http.StatusOK {
unseqEntry, _ := parseChain(t, false, test.chain, log.chainValidationOpts.trustedRoots.RawCertificates()[0])
unseqEntry, wantIssChain := parseChain(t, false, test.chain, log.chainValidationOpts.trustedRoots.RawCertificates()[0])

var gotRsp rfc6962.AddChainResponse
if err := json.NewDecoder(resp.Body).Decode(&gotRsp); err != nil {
Expand Down Expand Up @@ -559,7 +560,20 @@ func TestAddChain(t *testing.T) {
if diff := cmp.Diff(wantEntry, gotEntry); diff != "" {
t.Errorf("Logged entry mismatch (-want +got):\n%s", diff)
}
// TODO(phbnf): check the issuer chain fingerprint

// Check that the issuers have been populated correctly.
for _, wantIss := range wantIssChain[1:] {
key := sha256.Sum256(wantIss.Raw)
issPath := path.Join(dir, issDir, hex.EncodeToString(key[:]))
gotIss, err := os.ReadFile(issPath)
if err != nil {
t.Errorf("Failed to read issuer at %q: %v", issPath, err)
}
if !bytes.Equal(gotIss, wantIss.Raw) {
t.Errorf("Issuer mismatch: got %s, want %s", gotIss, wantIss.Raw)
}
}

// TODO(phbnf): check inclusion proof
// TODO(phbnf): add a test with a backend write failure
}
Expand Down Expand Up @@ -633,7 +647,7 @@ func TestAddPreChain(t *testing.T) {
t.Errorf("http.Post(%s)=(%d,nil); want (%d,nil)", rfc6962.AddPreChainPath, got, want)
}
if test.want == http.StatusOK {
unseqEntry, _ := parseChain(t, true, test.chain, log.chainValidationOpts.trustedRoots.RawCertificates()[0])
unseqEntry, wantIssChain := parseChain(t, true, test.chain, log.chainValidationOpts.trustedRoots.RawCertificates()[0])

var gotRsp rfc6962.AddChainResponse
if err := json.NewDecoder(resp.Body).Decode(&gotRsp); err != nil {
Expand Down Expand Up @@ -685,7 +699,20 @@ func TestAddPreChain(t *testing.T) {
if diff := cmp.Diff(wantEntry, gotEntry); diff != "" {
t.Errorf("Logged entry mismatch (-want +got):\n%s", diff)
}
// TODO(phbnf): check the issuer chain fingerprint

// Check that the issuers have been populated correctly.
for _, wantIss := range wantIssChain[1:] {
key := sha256.Sum256(wantIss.Raw)
issPath := path.Join(dir, issDir, hex.EncodeToString(key[:]))
gotIss, err := os.ReadFile(issPath)
if err != nil {
t.Errorf("Failed to read issuer at %q: %v", issPath, err)
}
if !bytes.Equal(gotIss, wantIss.Raw) {
t.Errorf("Issuer mismatch: got %s, want %s", gotIss, wantIss.Raw)
}
}

// TODO(phbnf): check inclusion proof
// TODO(phboneff): add a test with a backend write failure
}
Expand Down
Loading