...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ctfe
16
17 import (
18 "testing"
19
20 "github.com/google/certificate-transparency-go/trillian/ctfe/testonly"
21 "github.com/google/certificate-transparency-go/x509"
22 "github.com/google/certificate-transparency-go/x509util"
23 )
24
25 func mustDePEM(t *testing.T, pem string) *x509.Certificate {
26 t.Helper()
27 c, err := x509util.CertificateFromPEM([]byte(pem))
28 if x509.IsFatal(err) {
29 t.Fatalf("Failed to parse PEM: %v", err)
30 }
31 return c
32 }
33
34 func TestQuotaUserForCert(t *testing.T) {
35 for _, test := range []struct {
36 desc string
37 cert *x509.Certificate
38 want string
39 }{
40 {
41 desc: "cacert",
42 cert: mustDePEM(t, testonly.CACertPEM),
43 want: "@intermediate O=Certificate Transparency CA,L=Erw Wen,ST=Wales,C=GB 02adddca08",
44 },
45 {
46 desc: "intermediate",
47 cert: mustDePEM(t, testonly.FakeIntermediateCertPEM),
48 want: "@intermediate CN=FakeIntermediateAuthority,OU=Eng,O=Google,L=London,ST=London,C=GB 6e62e56f67",
49 },
50 } {
51 t.Run(test.desc, func(t *testing.T) {
52 if got := QuotaUserForCert(test.cert); got != test.want {
53 t.Fatalf("QuotaUserForCert() = %q, want %q", got, test.want)
54 }
55 })
56 }
57 }
58
View as plain text