File: certificate_service_test.go

package info (click to toggle)
golang-github-kong-go-kong 0.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 620 kB
  • sloc: sh: 18; makefile: 4
file content (416 lines) | stat: -rw-r--r-- 19,421 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
package kong

import (
	"testing"

	uuid "github.com/satori/go.uuid"
	"github.com/stret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IIP0bWCvxADflW9/hRZn7x
P7CeEpeGos4sg4/Ide7nOJl7ub7/4ho54AwL70pniZPmRpoRAgMBAAGjUDBOMB0G
A1UdDgQWBBTOQKJ21L/ciHTkRi1n7rRTInXJ4zAfBgNVHSMEGDAWgBTOQKJ21L/c
iHTkRi1n7rRTInXJ4zAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4ICAQB5
tZqWk0RyeAsCK6sX9tWZFAKFiQrVRGlhcW21nUdZn+jLruup27UontAML0mWHIVi
FUaok3BZ6qEMC0q6DAzfCN7Zmk/K7MeaHc0staCv8qj6XC/CAWgkx3k9WgDp72K1
lyp1hwW8I9tUMoM4C+6LFjp2959v/4mUnLz69atzdomVZiPf2HiUrBAb4eMOXntZ
E4tVyAG3A713QAsOXFMtz8LzlHOTUOPiWcyk92/XfBtsVTmFYpxOKSBrhHIXz+WV
6pKJ557iBpGbu5/CscT5+VN5CYAFxzw0LsRXgJoVqgM5XQS8zztCi8XK9kchpt2u
eULB8qUFnUHqewkBypxDDNQ/mOjY4K5dm9RwM6WUeAlVZGWWn0vHaToUN91f7usr
UfbR/OrU4lizCkznqNqH9IYIB11LSJngr/FMSymRKAQOUSUmqJCUlLvALKEColhW
Ti/feroXva50o6DojtMRBn5G2aTyfIqeiYHBdrBd6NQXKxNSd/qeR3sKRZ4kp6c8
+tCIfUQuN9no4J2cnYULhs2mwInqIny5AgOytXRfDxR61wUezV7OEfUAhhovmuwf
Nez1wdrqpD+3AI7Rv+GU/zCBOCoKl0LlqYchcWWEFgBHcmjgTvGI9yfhoDiezibT
StncqiK5F5CsWRrwQCpoNDkOAQE/l7QZgBzYrXw4vQ==
-----END CERTIFICATE-----`
)

func TestCertificatesService(T *testing.T) {
	assert := assert.New(T)

	client, err := NewTestClient(nil, nil)
	assert.Nil(err)
	assert.NotNil(client)

	certificate := &Certificate{
		Key:  String("foo"),
		Cert: String("bar"),
		SNIs: StringSlice("host1.com", "host2.com"),
	}

	createdCertificate, err := client.Certificates.Create(defaultCtx, certificate)
	assert.NotNil(err) // invalid cert and key
	assert.Nil(createdCertificate)

	certificate.Key = String(key1)
	certificate.Cert = String(cert1)
	createdCertificate, err = client.Certificates.Create(defaultCtx, certificate)
	assert.Nil(err)
	assert.NotNil(createdCertificate)

	certificate, err = client.Certificates.Get(defaultCtx, createdCertificate.ID)
	assert.Nil(err)
	assert.NotNil(certificate)
	assert.Equal(2, len(createdCertificate.SNIs))

	certificate.Key = String(key2)
	certificate.Cert = String(cert2)
	certificate, err = client.Certificates.Update(defaultCtx, certificate)
	assert.Nil(err)
	assert.NotNil(certificate)
	assert.Equal(key2, *certificate.Key)

	err = client.Certificates.Delete(defaultCtx, createdCertificate.ID)
	assert.Nil(err)

	// ID can be specified
	id := uuid.NewV4().String()
	certificate = &Certificate{
		Key:  String(key3),
		Cert: String(cert3),
		ID:   String(id),
	}

	createdCertificate, err = client.Certificates.Create(defaultCtx, certificate)
	assert.Nil(err)
	assert.NotNil(createdCertificate)
	assert.Equal(id, *createdCertificate.ID)

	err = client.Certificates.Delete(defaultCtx, createdCertificate.ID)
	assert.Nil(err)
}

func TestCertificateWithTags(T *testing.T) {
	runWhenKong(T, ">=1.1.0")
	assert := assert.New(T)

	client, err := NewTestClient(nil, nil)
	assert.Nil(err)
	assert.NotNil(client)

	certificate := &Certificate{
		Key:  String(key3),
		Cert: String(cert3),
		Tags: StringSlice("tag1", "tag2"),
	}

	createdCertificate, err := client.Certificates.Create(defaultCtx, certificate)
	assert.Nil(err)
	assert.NotNil(createdCertificate)
	assert.Equal(StringSlice("tag1", "tag2"), createdCertificate.Tags)

	err = client.Certificates.Delete(defaultCtx, createdCertificate.ID)
	assert.Nil(err)
}

func TestCertificateListEndpoint(T *testing.T) {
	assert := assert.New(T)

	client, err := NewTestClient(nil, nil)
	assert.Nil(err)
	assert.NotNil(client)

	// fixtures
	certificates := []*Certificate{
		{
			Cert: String(cert1),
			Key:  String(key1),
		},
		{
			Cert: String(cert2),
			Key:  String(key2),
		},
		{
			Cert: String(cert3),
			Key:  String(key3),
		},
	}

	// create fixturs
	for i := 0; i < len(certificates); i++ {
		certificate, err := client.Certificates.Create(defaultCtx, certificates[i])
		assert.Nil(err)
		assert.NotNil(certificate)
		certificates[i] = certificate
	}

	certificatesFromKong, next, err := client.Certificates.List(defaultCtx, nil)
	assert.Nil(err)
	assert.Nil(next)
	assert.NotNil(certificatesFromKong)
	assert.Equal(3, len(certificatesFromKong))

	// check if we see all certificates
	assert.True(compareCertificates(certificates, certificatesFromKong))

	// Test pagination
	certificatesFromKong = []*Certificate{}

	// first page
	page1, next, err := client.Certificates.List(defaultCtx, &ListOpt{Size: 1})
	assert.Nil(err)
	assert.NotNil(next)
	assert.NotNil(page1)
	assert.Equal(1, len(page1))
	certificatesFromKong = append(certificatesFromKong, page1...)

	// last page
	next.Size = 2
	page2, next, err := client.Certificates.List(defaultCtx, next)
	assert.Nil(err)
	assert.Nil(next)
	assert.NotNil(page2)
	assert.Equal(2, len(page2))
	certificatesFromKong = append(certificatesFromKong, page2...)

	assert.True(compareCertificates(certificates, certificatesFromKong))

	certificates, err = client.Certificates.ListAll(defaultCtx)
	assert.Nil(err)
	assert.NotNil(certificates)
	assert.Equal(3, len(certificates))

	for i := 0; i < len(certificates); i++ {
		assert.Nil(client.Certificates.Delete(defaultCtx, certificates[i].ID))
	}
}

func compareCertificates(expected, actual []*Certificate) bool {
	var expectedUsernames, actualUsernames []string
	for _, certificate := range expected {
		expectedUsernames = append(expectedUsernames, *certificate.Cert)
	}

	for _, certificate := range actual {
		actualUsernames = append(actualUsernames, *certificate.Cert)
	}

	return (compareSlices(expectedUsernames, actualUsernames))
}