From a67b1277a0ea25eef33fb89cce1b1252a9491544 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Wed, 25 Nov 2020 17:44:39 +0100 Subject: added NewCertPool tests --- x509util/x509util_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'x509util') diff --git a/x509util/x509util_test.go b/x509util/x509util_test.go index 8595360..4ef743c 100644 --- a/x509util/x509util_test.go +++ b/x509util/x509util_test.go @@ -1,8 +1,11 @@ package x509util import ( + "bytes" "fmt" "testing" + + "github.com/system-transparency/stfe/testdata" ) func TestNewEd25519PrivateKey(t *testing.T) { @@ -211,6 +214,24 @@ Vc510vi4dM8I+e/vcoBsmMQP } func TestNewCertPool(t *testing.T) { + for i, chain := range [][]byte{ + testdata.FirstPemChain, + testdata.SecondPemChain, + } { + list, err := NewCertificateList(chain) + if err != nil { + t.Fatalf("must parse chain: %v", err) + } + pool := NewCertPool(list) + if got, want := len(pool.Subjects()), len(list); got != want { + t.Errorf("got pool of size %d but wanted %d in test %d", got, want, i) + } + for j, got := range pool.Subjects() { + if want := list[j].RawSubject; !bytes.Equal(got, want) { + t.Errorf("got subject[%d]=%X but wanted %X in test %d", j, got, want, i) + } + } + } } func TestParseDerChain(t *testing.T) { -- cgit v1.2.3