1
2
3 package integration
4
5 import (
6 "crypto/ecdsa"
7 "crypto/elliptic"
8 "crypto/rand"
9 "fmt"
10 "os"
11 "strings"
12 "testing"
13
14 "github.com/letsencrypt/boulder/test"
15 )
16
17
18
19 func TestCommonNameInCSR(t *testing.T) {
20 t.Parallel()
21
22
23 client, err := makeClient("mailto:example@letsencrypt.org")
24 test.AssertNotError(t, err, "creating acme client")
25
26
27 key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
28 test.AssertNotError(t, err, "creating random cert key")
29
30
31 cn := random_domain()
32 san1 := random_domain()
33 san2 := random_domain()
34
35
36 ir, err := authAndIssue(client, key, []string{cn, san1, san2}, true)
37 test.AssertNotError(t, err, "failed to issue test cert")
38 cert := ir.certs[0]
39
40
41 test.AssertSliceContains(t, cert.DNSNames, cn)
42 test.AssertSliceContains(t, cert.DNSNames, san1)
43 test.AssertSliceContains(t, cert.DNSNames, san2)
44
45
46 test.AssertEquals(t, cert.Subject.CommonName, cn)
47 }
48
49
50
51 func TestFirstCSRSANHoistedToCN(t *testing.T) {
52 t.Parallel()
53
54
55 client, err := makeClient("mailto:example@letsencrypt.org")
56 test.AssertNotError(t, err, "creating acme client")
57
58
59 key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
60 test.AssertNotError(t, err, "creating random cert key")
61
62
63 san1 := "a" + random_domain()
64 san2 := "b" + random_domain()
65
66
67 ir, err := authAndIssue(client, key, []string{san2, san1}, false)
68 test.AssertNotError(t, err, "failed to issue test cert")
69 cert := ir.certs[0]
70
71
72 test.AssertEquals(t, cert.DNSNames[0], san1)
73 test.AssertEquals(t, cert.DNSNames[1], san2)
74
75
76 test.Assert(t, cert.Subject.CommonName == san2, "first SAN should have been hoisted")
77 }
78
79
80
81
82 func TestCommonNameSANsTooLong(t *testing.T) {
83 t.Parallel()
84
85
86 client, err := makeClient("mailto:example@letsencrypt.org")
87 test.AssertNotError(t, err, "creating acme client")
88
89
90 key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
91 test.AssertNotError(t, err, "creating random cert key")
92
93
94 san1 := fmt.Sprintf("thisdomainnameis.morethan64characterslong.forthesakeoftesting.%s", random_domain())
95 san2 := fmt.Sprintf("thisdomainnameis.morethan64characterslong.forthesakeoftesting.%s", random_domain())
96
97
98 ir, err := authAndIssue(client, key, []string{san1, san2}, false)
99
100
101 if !strings.Contains(os.Getenv("BOULDER_CONFIG_DIR"), "test/config-next") {
102 test.AssertError(t, err, "issuing cert with no CN")
103 return
104 }
105
106
107
108 test.AssertNotError(t, err, "failed to issue test cert")
109 cert := ir.certs[0]
110
111
112 test.AssertSliceContains(t, cert.DNSNames, san1)
113 test.AssertSliceContains(t, cert.DNSNames, san2)
114
115
116 test.AssertEquals(t, cert.Subject.CommonName, "")
117 }
118
View as plain text