@@ -15,9 +15,15 @@ var certJSONResponse = `
15
15
"certificate": {
16
16
"id": "892071a0-bb95-49bc-8021-3afd67a210bf",
17
17
"name": "web-cert-01",
18
+ "dns_names": [
19
+ "somedomain.com",
20
+ "api.somedomain.com"
21
+ ],
18
22
"not_after": "2017-02-22T00:23:00Z",
19
23
"sha1_fingerprint": "dfcc9f57d86bf58e321c2c6c31c7a971be244ac7",
20
- "created_at": "2017-02-08T16:02:37Z"
24
+ "created_at": "2017-02-08T16:02:37Z",
25
+ "state": "verified",
26
+ "type": "custom"
21
27
}
22
28
}
23
29
`
@@ -27,17 +33,26 @@ var certsJSONResponse = `
27
33
"certificates": [
28
34
{
29
35
"id": "892071a0-bb95-49bc-8021-3afd67a210bf",
30
- "name": "web-cert-01",
36
+ "name": "web-cert-01",
37
+ "dns_names": [
38
+ "somedomain.com",
39
+ "api.somedomain.com"
40
+ ],
31
41
"not_after": "2017-02-22T00:23:00Z",
32
42
"sha1_fingerprint": "dfcc9f57d86bf58e321c2c6c31c7a971be244ac7",
33
- "created_at": "2017-02-08T16:02:37Z"
43
+ "created_at": "2017-02-08T16:02:37Z",
44
+ "state": "verified",
45
+ "type": "custom"
34
46
},
35
47
{
36
48
"id": "992071a0-bb95-49bc-8021-3afd67a210bf",
37
- "name": "web-cert-02",
49
+ "name": "web-cert-02",
50
+ "dns_names":["example.com"],
38
51
"not_after": "2017-02-22T00:23:00Z",
39
52
"sha1_fingerprint": "cfcc9f57d86bf58e321c2c6c31c7a971be244ac7",
40
- "created_at": "2017-02-08T16:02:37Z"
53
+ "created_at": "2017-02-08T16:02:37Z",
54
+ "state": "pending",
55
+ "type": "lets_encrypt"
41
56
}
42
57
],
43
58
"links": {},
@@ -67,9 +82,12 @@ func TestCertificates_Get(t *testing.T) {
67
82
expected := & Certificate {
68
83
ID : "892071a0-bb95-49bc-8021-3afd67a210bf" ,
69
84
Name : "web-cert-01" ,
85
+ DNSNames : []string {"somedomain.com" , "api.somedomain.com" },
70
86
NotAfter : "2017-02-22T00:23:00Z" ,
71
87
SHA1Fingerprint : "dfcc9f57d86bf58e321c2c6c31c7a971be244ac7" ,
72
88
Created : "2017-02-08T16:02:37Z" ,
89
+ State : "verified" ,
90
+ Type : "custom" ,
73
91
}
74
92
75
93
assert .Equal (t , expected , certificate )
@@ -95,61 +113,125 @@ func TestCertificates_List(t *testing.T) {
95
113
{
96
114
ID : "892071a0-bb95-49bc-8021-3afd67a210bf" ,
97
115
Name : "web-cert-01" ,
116
+ DNSNames : []string {"somedomain.com" , "api.somedomain.com" },
98
117
NotAfter : "2017-02-22T00:23:00Z" ,
99
118
SHA1Fingerprint : "dfcc9f57d86bf58e321c2c6c31c7a971be244ac7" ,
100
119
Created : "2017-02-08T16:02:37Z" ,
120
+ State : "verified" ,
121
+ Type : "custom" ,
101
122
},
102
123
{
103
124
ID : "992071a0-bb95-49bc-8021-3afd67a210bf" ,
104
125
Name : "web-cert-02" ,
126
+ DNSNames : []string {"example.com" },
105
127
NotAfter : "2017-02-22T00:23:00Z" ,
106
128
SHA1Fingerprint : "cfcc9f57d86bf58e321c2c6c31c7a971be244ac7" ,
107
129
Created : "2017-02-08T16:02:37Z" ,
130
+ State : "pending" ,
131
+ Type : "lets_encrypt" ,
108
132
},
109
133
}
110
134
111
135
assert .Equal (t , expected , certificates )
112
136
}
113
137
114
138
func TestCertificates_Create (t * testing.T ) {
115
- setup ()
116
- defer teardown ()
117
-
118
- createRequest := & CertificateRequest {
119
- Name : "web-cert-01" ,
120
- PrivateKey : "-----BEGIN PRIVATE KEY-----" ,
121
- LeafCertificate : "-----BEGIN CERTIFICATE-----" ,
122
- CertificateChain : "-----BEGIN CERTIFICATE-----" ,
139
+ tests := []struct {
140
+ desc string
141
+ createRequest * CertificateRequest
142
+ certJSONResponse string
143
+ expectedCertificate * Certificate
144
+ }{
145
+ {
146
+ desc : "creates custom certificate" ,
147
+ createRequest : & CertificateRequest {
148
+ Name : "web-cert-01" ,
149
+ PrivateKey : "-----BEGIN PRIVATE KEY-----" ,
150
+ LeafCertificate : "-----BEGIN CERTIFICATE-----" ,
151
+ CertificateChain : "-----BEGIN CERTIFICATE-----" ,
152
+ },
153
+ certJSONResponse : `{
154
+ "certificate": {
155
+ "id": "892071a0-bb95-49bc-8021-3afd67a210bf",
156
+ "name": "custom-cert",
157
+ "dns_names":[],
158
+ "not_after": "2017-02-22T00:23:00Z",
159
+ "sha1_fingerprint": "dfcc9f57d86bf58e321c2c6c31c7a971be244ac7",
160
+ "created_at": "2017-02-08T16:02:37Z",
161
+ "state": "verified",
162
+ "type": "custom"
163
+ }
164
+ }` ,
165
+ expectedCertificate : & Certificate {
166
+ ID : "892071a0-bb95-49bc-8021-3afd67a210bf" ,
167
+ Name : "custom-cert" ,
168
+ DNSNames : []string {},
169
+ NotAfter : "2017-02-22T00:23:00Z" ,
170
+ SHA1Fingerprint : "dfcc9f57d86bf58e321c2c6c31c7a971be244ac7" ,
171
+ Created : "2017-02-08T16:02:37Z" ,
172
+ State : "verified" ,
173
+ Type : "custom" ,
174
+ },
175
+ },
176
+ {
177
+ desc : "creates let's encrypt certificate" ,
178
+ createRequest : & CertificateRequest {
179
+ Name : "lets-encrypt-cert" ,
180
+ DNSNames : []string {"example.com" , "api.example.com" },
181
+ Type : "lets_encrypt" ,
182
+ },
183
+ certJSONResponse : `{
184
+ "certificate": {
185
+ "id": "91bce928-a983-4c97-a5ee-78c585bf798d",
186
+ "name": "lets-encrypt-cert",
187
+ "dns_names":["example.com", "api.example.com"],
188
+ "not_after": "2022-01-26T15:50:00Z",
189
+ "sha1_fingerprint": "2e3c2ba8016faf80f431700ff2865ef6dba30a81",
190
+ "created_at": "2017-08-23T20:42:46Z",
191
+ "state": "pending",
192
+ "type": "lets_encrypt"
193
+ }
194
+ }` ,
195
+ expectedCertificate : & Certificate {
196
+ ID : "91bce928-a983-4c97-a5ee-78c585bf798d" ,
197
+ Name : "lets-encrypt-cert" ,
198
+ DNSNames : []string {"example.com" , "api.example.com" },
199
+ NotAfter : "2022-01-26T15:50:00Z" ,
200
+ SHA1Fingerprint : "2e3c2ba8016faf80f431700ff2865ef6dba30a81" ,
201
+ Created : "2017-08-23T20:42:46Z" ,
202
+ State : "pending" ,
203
+ Type : "lets_encrypt" ,
204
+ },
205
+ },
123
206
}
124
207
125
- urlStr := "/v2/certificates"
126
- mux .HandleFunc (urlStr , func (w http.ResponseWriter , r * http.Request ) {
127
- v := new (CertificateRequest )
128
- err := json .NewDecoder (r .Body ).Decode (v )
129
- if err != nil {
130
- t .Fatal (err )
131
- }
208
+ for _ , test := range tests {
209
+ t .Run (test .desc , func (t * testing.T ) {
210
+ setup ()
211
+ defer teardown ()
132
212
133
- testMethod (t , r , http .MethodPost )
134
- assert .Equal (t , createRequest , v )
213
+ urlStr := "/v2/certificates"
214
+ mux .HandleFunc (urlStr , func (w http.ResponseWriter , r * http.Request ) {
215
+ v := new (CertificateRequest )
216
+ err := json .NewDecoder (r .Body ).Decode (v )
217
+ if err != nil {
218
+ t .Fatal (err )
219
+ }
135
220
136
- fmt . Fprint ( w , certJSONResponse )
137
- } )
221
+ testMethod ( t , r , http . MethodPost )
222
+ assert . Equal ( t , test . createRequest , v )
138
223
139
- certificate , _ , err := client .Certificates .Create (ctx , createRequest )
140
- if err != nil {
141
- t .Errorf ("Certificates.Create returned error: %v" , err )
142
- }
224
+ fmt .Fprint (w , test .certJSONResponse )
225
+ })
143
226
144
- expected := & Certificate {
145
- ID : "892071a0-bb95-49bc-8021-3afd67a210bf" ,
146
- Name : "web-cert-01" ,
147
- NotAfter : "2017-02-22T00:23:00Z" ,
148
- SHA1Fingerprint : "dfcc9f57d86bf58e321c2c6c31c7a971be244ac7" ,
149
- Created : "2017-02-08T16:02:37Z" ,
150
- }
227
+ certificate , _ , err := client .Certificates .Create (ctx , test .createRequest )
228
+ if err != nil {
229
+ t .Errorf ("Certificates.Create returned error: %v" , err )
230
+ }
151
231
152
- assert .Equal (t , expected , certificate )
232
+ assert .Equal (t , test .expectedCertificate , certificate )
233
+ })
234
+ }
153
235
}
154
236
155
237
func TestCertificates_Delete (t * testing.T ) {
0 commit comments