diff options
Diffstat (limited to 'vendor/github.com/DreamItGetIT/statuscake/ssl_test.go')
-rw-r--r-- | vendor/github.com/DreamItGetIT/statuscake/ssl_test.go | 343 |
1 files changed, 343 insertions, 0 deletions
diff --git a/vendor/github.com/DreamItGetIT/statuscake/ssl_test.go b/vendor/github.com/DreamItGetIT/statuscake/ssl_test.go new file mode 100644 index 0000000..48a961c --- /dev/null +++ b/vendor/github.com/DreamItGetIT/statuscake/ssl_test.go | |||
@@ -0,0 +1,343 @@ | |||
1 | package statuscake | ||
2 | |||
3 | import ( | ||
4 | "testing" | ||
5 | //"fmt" | ||
6 | "github.com/stretchr/testify/assert" | ||
7 | "github.com/stretchr/testify/require" | ||
8 | "net/url" | ||
9 | ) | ||
10 | |||
11 | func TestSsl_All(t *testing.T) { | ||
12 | assert := assert.New(t) | ||
13 | require := require.New(t) | ||
14 | |||
15 | c := &fakeAPIClient{ | ||
16 | fixture: "sslListAllOk.json", | ||
17 | } | ||
18 | tt := NewSsls(c) | ||
19 | ssls, err := tt.All() | ||
20 | require.Nil(err) | ||
21 | |||
22 | assert.Equal("/SSL", c.sentRequestPath) | ||
23 | assert.Equal("GET", c.sentRequestMethod) | ||
24 | assert.Nil(c.sentRequestValues) | ||
25 | assert.Len(ssls, 3) | ||
26 | mixed := make(map[string]string) | ||
27 | flags := make(map[string]bool) | ||
28 | flags["is_extended"] = false | ||
29 | flags["has_pfs"] = true | ||
30 | flags["is_broken"] = false | ||
31 | flags["is_expired"] = false | ||
32 | flags["is_missing"] = false | ||
33 | flags["is_revoked"] = false | ||
34 | flags["has_mixed"] = false | ||
35 | expectedTest := &Ssl{ | ||
36 | ID: "143615", | ||
37 | Checkrate: 2073600, | ||
38 | Paused: false, | ||
39 | Domain: "https://www.exemple.com", | ||
40 | IssuerCn: "Let's Encrypt Authority X3", | ||
41 | CertScore: "95", | ||
42 | CipherScore: "100", | ||
43 | CertStatus: "CERT_OK", | ||
44 | Cipher: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", | ||
45 | ValidFromUtc: "2019-05-28 01:22:00", | ||
46 | ValidUntilUtc: "2019-08-26 01:22:00", | ||
47 | MixedContent: []map[string]string{}, | ||
48 | Flags: flags, | ||
49 | ContactGroups: []string{}, | ||
50 | ContactGroupsC: "", | ||
51 | AlertAt: "7,18,2019", | ||
52 | LastReminder: 2019, | ||
53 | AlertReminder: true, | ||
54 | AlertExpiry: true, | ||
55 | AlertBroken: true, | ||
56 | AlertMixed: true, | ||
57 | LastUpdatedUtc: "2019-06-20 10:11:03", | ||
58 | } | ||
59 | assert.Equal(expectedTest, ssls[0]) | ||
60 | |||
61 | expectedTest.ID="143617" | ||
62 | expectedTest.LastUpdatedUtc="2019-06-20 10:23:20" | ||
63 | assert.Equal(expectedTest, ssls[2]) | ||
64 | |||
65 | expectedTest.ID="143616" | ||
66 | expectedTest.LastUpdatedUtc="2019-06-20 10:23:14" | ||
67 | mixed["type"]="img" | ||
68 | mixed["src"]="http://example.com/image.gif" | ||
69 | expectedTest.MixedContent=[]map[string]string{mixed} | ||
70 | expectedTest.ContactGroupsC="12,13,34" | ||
71 | expectedTest.ContactGroups=[]string{"12","13","34"} | ||
72 | assert.Equal(expectedTest, ssls[1]) | ||
73 | } | ||
74 | |||
75 | func TestSsls_Detail_OK(t *testing.T) { | ||
76 | assert := assert.New(t) | ||
77 | require := require.New(t) | ||
78 | |||
79 | c := &fakeAPIClient{ | ||
80 | fixture: "sslListAllOk.json", | ||
81 | } | ||
82 | tt := NewSsls(c) | ||
83 | |||
84 | ssl, err := tt.Detail("143616") | ||
85 | require.Nil(err) | ||
86 | assert.Equal("/SSL", c.sentRequestPath) | ||
87 | assert.Equal("GET", c.sentRequestMethod) | ||
88 | assert.Nil(c.sentRequestValues) | ||
89 | |||
90 | mixed := make(map[string]string) | ||
91 | flags := make(map[string]bool) | ||
92 | |||
93 | mixed["type"]="img" | ||
94 | mixed["src"]="http://example.com/image.gif" | ||
95 | |||
96 | flags["is_extended"] = false | ||
97 | flags["has_pfs"] = true | ||
98 | flags["is_broken"] = false | ||
99 | flags["is_expired"] = false | ||
100 | flags["is_missing"] = false | ||
101 | flags["is_revoked"] = false | ||
102 | flags["has_mixed"] = false | ||
103 | expectedTest := &Ssl{ | ||
104 | ID: "143616", | ||
105 | Checkrate: 2073600, | ||
106 | Paused: false, | ||
107 | Domain: "https://www.exemple.com", | ||
108 | IssuerCn: "Let's Encrypt Authority X3", | ||
109 | CertScore: "95", | ||
110 | CipherScore: "100", | ||
111 | CertStatus: "CERT_OK", | ||
112 | Cipher: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", | ||
113 | ValidFromUtc: "2019-05-28 01:22:00", | ||
114 | ValidUntilUtc: "2019-08-26 01:22:00", | ||
115 | MixedContent: []map[string]string{mixed}, | ||
116 | Flags: flags, | ||
117 | ContactGroups: []string{"12","13","34"}, | ||
118 | ContactGroupsC: "12,13,34", | ||
119 | AlertAt: "7,18,2019", | ||
120 | LastReminder: 2019, | ||
121 | AlertReminder: true, | ||
122 | AlertExpiry: true, | ||
123 | AlertBroken: true, | ||
124 | AlertMixed: true, | ||
125 | LastUpdatedUtc: "2019-06-20 10:23:14", | ||
126 | } | ||
127 | |||
128 | assert.Equal(expectedTest, ssl) | ||
129 | } | ||
130 | |||
131 | func TestSsls_CreatePartial_OK(t *testing.T) { | ||
132 | assert := assert.New(t) | ||
133 | require := require.New(t) | ||
134 | |||
135 | c := &fakeAPIClient{ | ||
136 | fixture: "sslCreateOk.json", | ||
137 | } | ||
138 | tt := NewSsls(c) | ||
139 | partial := &PartialSsl{ | ||
140 | Domain: "https://www.exemple.com", | ||
141 | Checkrate: "2073600", | ||
142 | ContactGroupsC: "", | ||
143 | AlertReminder: true, | ||
144 | AlertExpiry: true, | ||
145 | AlertBroken: true, | ||
146 | AlertMixed: true, | ||
147 | AlertAt: "7,18,2019", | ||
148 | } | ||
149 | expectedRes := &PartialSsl { | ||
150 | ID: 143616, | ||
151 | Domain: "https://www.exemple.com", | ||
152 | Checkrate: "2073600", | ||
153 | ContactGroupsC: "", | ||
154 | AlertReminder: true, | ||
155 | AlertExpiry: true, | ||
156 | AlertBroken: true, | ||
157 | AlertMixed: true, | ||
158 | AlertAt: "7,18,2019", | ||
159 | } | ||
160 | res, err := tt.CreatePartial(partial) | ||
161 | require.Nil(err) | ||
162 | assert.Equal("/SSL/Update", c.sentRequestPath) | ||
163 | assert.Equal("PUT", c.sentRequestMethod) | ||
164 | assert.Equal(c.sentRequestValues,url.Values(url.Values{"domain":[]string{"https://www.exemple.com"}, "checkrate":[]string{"2073600"}, "contact_groups":[]string{""}, "alert_at":[]string{"7,18,2019"}, "alert_expiry":[]string{"true"}, "alert_reminder":[]string{"true"}, "alert_broken":[]string{"true"}, "alert_mixed":[]string{"true"}})) | ||
165 | |||
166 | assert.Equal(expectedRes, res) | ||
167 | } | ||
168 | |||
169 | func TestSsls_UpdatePartial_OK(t *testing.T) { | ||
170 | assert := assert.New(t) | ||
171 | require := require.New(t) | ||
172 | |||
173 | c := &fakeAPIClient{ | ||
174 | fixture: "sslUpdateOk.json", | ||
175 | } | ||
176 | tt := NewSsls(c) | ||
177 | partial := &PartialSsl{ | ||
178 | ID: 143616, | ||
179 | Domain: "https://www.exemple.com", | ||
180 | Checkrate: "2073600", | ||
181 | ContactGroupsC: "", | ||
182 | AlertReminder: false, | ||
183 | AlertExpiry: true, | ||
184 | AlertBroken: true, | ||
185 | AlertMixed: true, | ||
186 | AlertAt: "7,18,2019", | ||
187 | } | ||
188 | expectedRes := &PartialSsl { | ||
189 | ID: 143616, | ||
190 | Domain: "https://www.exemple.com", | ||
191 | Checkrate: "2073600", | ||
192 | ContactGroupsC: "", | ||
193 | AlertReminder: false, | ||
194 | AlertExpiry: true, | ||
195 | AlertBroken: true, | ||
196 | AlertMixed: true, | ||
197 | AlertAt: "7,18,2019", | ||
198 | } | ||
199 | res, err := tt.UpdatePartial(partial) | ||
200 | require.Nil(err) | ||
201 | assert.Equal(expectedRes, res) | ||
202 | assert.Equal("/SSL/Update", c.sentRequestPath) | ||
203 | assert.Equal("PUT", c.sentRequestMethod) | ||
204 | assert.Equal(c.sentRequestValues,url.Values(url.Values{"id":[]string{"143616"},"domain":[]string{"https://www.exemple.com"}, "checkrate":[]string{"2073600"}, "contact_groups":[]string{""}, "alert_at":[]string{"7,18,2019"}, "alert_expiry":[]string{"true"}, "alert_reminder":[]string{"false"}, "alert_broken":[]string{"true"}, "alert_mixed":[]string{"true"}})) | ||
205 | } | ||
206 | |||
207 | func TestSsl_complete_OK(t *testing.T) { | ||
208 | assert := assert.New(t) | ||
209 | require := require.New(t) | ||
210 | |||
211 | c := &fakeAPIClient{ | ||
212 | fixture: "sslListAllOk.json", | ||
213 | } | ||
214 | tt := NewSsls(c) | ||
215 | |||
216 | partial := &PartialSsl { | ||
217 | ID: 143616, | ||
218 | Domain: "https://www.exemple.com", | ||
219 | Checkrate: "2073600", | ||
220 | ContactGroupsC: "12,13,34", | ||
221 | AlertReminder: true, | ||
222 | AlertExpiry: true, | ||
223 | AlertBroken: true, | ||
224 | AlertMixed: true, | ||
225 | AlertAt: "7,18,2019", | ||
226 | } | ||
227 | full, err := tt.completeSsl(partial) | ||
228 | require.Nil(err) | ||
229 | mixed := make(map[string]string) | ||
230 | flags := make(map[string]bool) | ||
231 | |||
232 | mixed["type"]="img" | ||
233 | mixed["src"]="http://example.com/image.gif" | ||
234 | |||
235 | flags["is_extended"] = false | ||
236 | flags["has_pfs"] = true | ||
237 | flags["is_broken"] = false | ||
238 | flags["is_expired"] = false | ||
239 | flags["is_missing"] = false | ||
240 | flags["is_revoked"] = false | ||
241 | flags["has_mixed"] = false | ||
242 | expectedTest := &Ssl{ | ||
243 | ID: "143616", | ||
244 | Checkrate: 2073600, | ||
245 | Paused: false, | ||
246 | Domain: "https://www.exemple.com", | ||
247 | IssuerCn: "Let's Encrypt Authority X3", | ||
248 | CertScore: "95", | ||
249 | CipherScore: "100", | ||
250 | CertStatus: "CERT_OK", | ||
251 | Cipher: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", | ||
252 | ValidFromUtc: "2019-05-28 01:22:00", | ||
253 | ValidUntilUtc: "2019-08-26 01:22:00", | ||
254 | MixedContent: []map[string]string{mixed}, | ||
255 | Flags: flags, | ||
256 | ContactGroups: []string{"12","13","34"}, | ||
257 | ContactGroupsC: "12,13,34", | ||
258 | AlertAt: "7,18,2019", | ||
259 | LastReminder: 2019, | ||
260 | AlertReminder: true, | ||
261 | AlertExpiry: true, | ||
262 | AlertBroken: true, | ||
263 | AlertMixed: true, | ||
264 | LastUpdatedUtc: "2019-06-20 10:23:14", | ||
265 | } | ||
266 | |||
267 | assert.Equal(expectedTest, full) | ||
268 | |||
269 | } | ||
270 | |||
271 | func TestSsl_partial_OK(t *testing.T) { | ||
272 | assert := assert.New(t) | ||
273 | require := require.New(t) | ||
274 | |||
275 | mixed := make(map[string]string) | ||
276 | flags := make(map[string]bool) | ||
277 | |||
278 | mixed["type"]="img" | ||
279 | mixed["src"]="http://example.com/image.gif" | ||
280 | |||
281 | flags["is_extended"] = false | ||
282 | flags["has_pfs"] = true | ||
283 | flags["is_broken"] = false | ||
284 | flags["is_expired"] = false | ||
285 | flags["is_missing"] = false | ||
286 | flags["is_revoked"] = false | ||
287 | flags["has_mixed"] = false | ||
288 | full := &Ssl{ | ||
289 | ID: "143616", | ||
290 | Checkrate: 2073600, | ||
291 | Paused: false, | ||
292 | Domain: "https://www.exemple.com", | ||
293 | IssuerCn: "Let's Encrypt Authority X3", | ||
294 | CertScore: "95", | ||
295 | CipherScore: "100", | ||
296 | CertStatus: "CERT_OK", | ||
297 | Cipher: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", | ||
298 | ValidFromUtc: "2019-05-28 01:22:00", | ||
299 | ValidUntilUtc: "2019-08-26 01:22:00", | ||
300 | MixedContent: []map[string]string{mixed}, | ||
301 | Flags: flags, | ||
302 | ContactGroups: []string{"12","13","34"}, | ||
303 | ContactGroupsC: "12,13,34", | ||
304 | AlertAt: "7,18,2019", | ||
305 | LastReminder: 2019, | ||
306 | AlertReminder: true, | ||
307 | AlertExpiry: true, | ||
308 | AlertBroken: true, | ||
309 | AlertMixed: true, | ||
310 | LastUpdatedUtc: "2019-06-20 10:23:14", | ||
311 | } | ||
312 | expectedTest:=&PartialSsl { | ||
313 | ID: 143616, | ||
314 | Domain: "https://www.exemple.com", | ||
315 | Checkrate: "2073600", | ||
316 | ContactGroupsC: "12,13,34", | ||
317 | AlertReminder: true, | ||
318 | AlertExpiry: true, | ||
319 | AlertBroken: true, | ||
320 | AlertMixed: true, | ||
321 | AlertAt: "7,18,2019", | ||
322 | } | ||
323 | partial,err:=Partial(full) | ||
324 | require.Nil(err) | ||
325 | assert.Equal(expectedTest, partial) | ||
326 | |||
327 | } | ||
328 | |||
329 | func TestSsls_Delete_OK(t *testing.T) { | ||
330 | assert := assert.New(t) | ||
331 | require := require.New(t) | ||
332 | |||
333 | c := &fakeAPIClient{ | ||
334 | fixture: "sslDeleteOk.json", | ||
335 | } | ||
336 | tt := NewSsls(c) | ||
337 | |||
338 | err := tt.Delete("143616") | ||
339 | require.Nil(err) | ||
340 | assert.Equal("/SSL/Update", c.sentRequestPath) | ||
341 | assert.Equal("DELETE", c.sentRequestMethod) | ||
342 | assert.Equal(c.sentRequestValues,url.Values(url.Values{"id":[]string{"143616"},},)) | ||
343 | } | ||