@@ -25,14 +25,30 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
25
25
// OAuth mode.
26
26
fakeCredsPath := withFile (t , `{"user_id":"foo","user_secret":"bar","client_id": "baz","client_secret": "foobar","auth_server_domain":"bazbar"}` )
27
27
28
- t .Run ("period must be given with either --period/-p or period field in config" , func (t * testing.T ) {
28
+ // Usually, the namespace is guessed from the file
29
+ // /var/run/secrets/kubernetes.io/serviceaccount/namespace. But since we
30
+ // can't realistically set that file in tests, we pass the flag
31
+ // --install-namespace in all the tests.
32
+ t .Run ("--install-namespace must be provided if namespace file doesn't exist" , func (t * testing.T ) {
29
33
_ , _ , err := ValidateAndCombineConfig (discardLogs (),
30
34
withConfig (testutil .Undent (`
31
35
server: https://api.venafi.eu
32
36
organization_id: foo
33
37
cluster_id: bar
38
+ period: 5m
34
39
` )),
35
40
withCmdLineFlags ("--credentials-file" , fakeCredsPath ))
41
+ assert .EqualError (t , err , "1 error occurred:\n \t * could not guess which namespace the agent is running in: not running in cluster, please use --install-namespace to specify the namespace in which the agent is running\n \n " )
42
+ })
43
+
44
+ t .Run ("period must be given with either --period/-p or period field in config" , func (t * testing.T ) {
45
+ _ , _ , err := ValidateAndCombineConfig (discardLogs (),
46
+ withConfig (testutil .Undent (`
47
+ server: https://api.venafi.eu
48
+ organization_id: foo
49
+ cluster_id: bar
50
+ ` )),
51
+ withCmdLineFlags ("--credentials-file" , fakeCredsPath , "--install-namespace" , "venafi" ))
36
52
assert .EqualError (t , err , "1 error occurred:\n \t * period must be set using --period or -p, or using the 'period' field in the config file\n \n " )
37
53
38
54
})
@@ -44,12 +60,12 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
44
60
cluster_id: bar
45
61
` ))
46
62
47
- got , _ , err := ValidateAndCombineConfig (discardLogs (), given , withCmdLineFlags ("--period" , "5m" , "--credentials-file" , fakeCredsPath ))
63
+ got , _ , err := ValidateAndCombineConfig (discardLogs (), given , withCmdLineFlags ("--period" , "5m" , "--credentials-file" , fakeCredsPath , "--install-namespace" , "venafi" ))
48
64
49
65
require .NoError (t , err )
50
66
assert .Equal (t , 5 * time .Minute , got .Period )
51
67
52
- got , _ , err = ValidateAndCombineConfig (discardLogs (), given , withCmdLineFlags ("-p" , "3m" , "--credentials-file" , fakeCredsPath ))
68
+ got , _ , err = ValidateAndCombineConfig (discardLogs (), given , withCmdLineFlags ("-p" , "3m" , "--credentials-file" , fakeCredsPath , "--install-namespace" , "venafi" ))
53
69
require .NoError (t , err )
54
70
assert .Equal (t , 3 * time .Minute , got .Period )
55
71
})
@@ -62,7 +78,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
62
78
organization_id: foo
63
79
cluster_id: bar
64
80
` )),
65
- withCmdLineFlags ("--credentials-file" , fakeCredsPath ))
81
+ withCmdLineFlags ("--credentials-file" , fakeCredsPath , "--install-namespace" , "venafi" ))
66
82
require .NoError (t , err )
67
83
assert .Equal (t , 7 * time .Minute , got .Period )
68
84
})
@@ -76,7 +92,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
76
92
organization_id: foo
77
93
cluster_id: bar
78
94
` )),
79
- withCmdLineFlags ("--period" , "99m" , "--credentials-file" , fakeCredsPath ))
95
+ withCmdLineFlags ("--period" , "99m" , "--credentials-file" , fakeCredsPath , "--install-namespace" , "venafi" ))
80
96
require .NoError (t , err )
81
97
assert .Equal (t , testutil .Undent (`
82
98
Using the Jetstack Secure OAuth auth mode since --credentials-file was specified without --venafi-cloud.
@@ -92,7 +108,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
92
108
organization_id: foo
93
109
cluster_id: bar
94
110
` )),
95
- withCmdLineFlags ("--credentials-file" , fakeCredsPath ))
111
+ withCmdLineFlags ("--credentials-file" , fakeCredsPath , "--install-namespace" , "venafi" ))
96
112
require .NoError (t , err )
97
113
assert .Equal (t , "https://preflight.jetstack.io" , got .Server )
98
114
})
@@ -106,7 +122,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
106
122
venafi-cloud:
107
123
upload_path: /foo/bar
108
124
` )),
109
- withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath ))
125
+ withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath , "--install-namespace" , "venafi" ))
110
126
require .NoError (t , err )
111
127
assert .Equal (t , "https://api.venafi.cloud" , got .Server )
112
128
})
@@ -122,7 +138,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
122
138
- kind: dummy
123
139
name: dummy
124
140
` )),
125
- withCmdLineFlags ("--credentials-file" , fakeCredsPath ))
141
+ withCmdLineFlags ("--credentials-file" , fakeCredsPath , "--install-namespace" , "venafi" ))
126
142
assert .EqualError (t , gotErr , testutil .Undent (`
127
143
1 error occurred:
128
144
* server "something not a URL" is not a valid URL
@@ -137,7 +153,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
137
153
organization_id: "my_org"
138
154
cluster_id: "my_cluster"
139
155
` )),
140
- withCmdLineFlags ("--strict" , "--credentials-file" , fakeCredsPath ))
156
+ withCmdLineFlags ("--strict" , "--credentials-file" , fakeCredsPath , "--install-namespace" , "venafi" ))
141
157
require .NoError (t , gotErr )
142
158
assert .Equal (t , true , got .StrictMode )
143
159
})
@@ -182,7 +198,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
182
198
config:
183
199
always-fail: false
184
200
` )),
185
- withCmdLineFlags ("--credentials-file" , credsPath ),
201
+ withCmdLineFlags ("--credentials-file" , credsPath , "--install-namespace" , "venafi" ),
186
202
)
187
203
expect := CombinedConfig {
188
204
AuthMode : "Jetstack Secure OAuth" ,
@@ -196,6 +212,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
196
212
OrganizationID : "example" ,
197
213
EndpointPath : "api/v1/data" ,
198
214
BackoffMaxTime : 10 * time .Minute ,
215
+ InstallNS : "venafi" ,
199
216
}
200
217
require .NoError (t , err )
201
218
assert .Equal (t , expect , got )
@@ -221,7 +238,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
221
238
uploader_id: test-agent
222
239
upload_path: "/testing/path"
223
240
` )),
224
- withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath , "--backoff-max-time" , "99m" ),
241
+ withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath , "--backoff-max-time" , "99m" , "--install-namespace" , "venafi" ),
225
242
)
226
243
expect := CombinedConfig {
227
244
Server : "http://localhost:8080" ,
@@ -235,6 +252,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
235
252
AuthMode : VenafiCloudKeypair ,
236
253
ClusterID : "the cluster name" ,
237
254
BackoffMaxTime : 99 * time .Minute ,
255
+ InstallNS : "venafi" ,
238
256
}
239
257
require .NoError (t , err )
240
258
assert .Equal (t , expect , got )
@@ -251,7 +269,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
251
269
venafi-cloud:
252
270
upload_path: "/foo/bar"
253
271
` )),
254
- withCmdLineFlags ("--client-id" , "5bc7d07c-45da-11ef-a878-523f1e1d7de1" , "--private-key-path" , privKeyPath ),
272
+ withCmdLineFlags ("--client-id" , "5bc7d07c-45da-11ef-a878-523f1e1d7de1" , "--private-key-path" , privKeyPath , "--install-namespace" , "venafi" ),
255
273
)
256
274
require .NoError (t , err )
257
275
assert .Equal (t , VenafiCloudKeypair , got .AuthMode )
@@ -260,7 +278,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
260
278
261
279
t .Run ("jetstack-secure-oauth-auth: fail if organization_id or cluster_id is missing and --venafi-cloud not enabled" , func (t * testing.T ) {
262
280
credsPath := withFile (
t ,
`{"user_id":"[email protected] ","user_secret":"foo","client_id": "k3TrDbfLhCgnpAbOiiT2kIE1AbovKzjo","client_secret": "f39w_3KT9Vp0VhzcPzvh-uVbudzqCFmHER3Huj0dvHgJwVrjxsoOQPIw_1SDiCfa","auth_server_domain":"auth.jetstack.io"}` )
263
- _ , _ , err := ValidateAndCombineConfig (discardLogs (), withConfig ("" ), withCmdLineFlags ("--credentials-file" , credsPath ))
281
+ _ , _ , err := ValidateAndCombineConfig (discardLogs (), withConfig ("" ), withCmdLineFlags ("--credentials-file" , credsPath , "--install-namespace" , "venafi" ))
264
282
assert .EqualError (t , err , testutil .Undent (`
265
283
3 errors occurred:
266
284
* organization_id is required
@@ -278,7 +296,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
278
296
venafi-cloud:
279
297
upload_path: /foo/bar
280
298
` )),
281
- withCmdLineFlags ("--venafi-cloud" , "--period" , "1m" , "--client-id" , "test-client-id" , "--private-key-path" , path ))
299
+ withCmdLineFlags ("--venafi-cloud" , "--period" , "1m" , "--client-id" , "test-client-id" , "--private-key-path" , path , "--install-namespace" , "venafi" ))
282
300
require .NoError (t , err )
283
301
assert .IsType (t , & client.VenafiCloudClient {}, cl )
284
302
})
@@ -291,7 +309,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
291
309
venafi-cloud:
292
310
upload_path: /foo/bar
293
311
` )),
294
- withCmdLineFlags ("--venafi-cloud" , "--period" , "1m" , "--private-key-path" , path , "--client-id" , "test-client-id" ))
312
+ withCmdLineFlags ("--venafi-cloud" , "--period" , "1m" , "--private-key-path" , path , "--client-id" , "test-client-id" , "--install-namespace" , "venafi" ))
295
313
require .NoError (t , err )
296
314
assert .IsType (t , & client.VenafiCloudClient {}, cl )
297
315
})
@@ -304,7 +322,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
304
322
venafi-cloud:
305
323
upload_path: /foo/bar
306
324
` )),
307
- withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath , "--period" , "1m" ))
325
+ withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath , "--period" , "1m" , "--install-namespace" , "venafi" ))
308
326
require .NoError (t , err )
309
327
assert .IsType (t , & client.VenafiCloudClient {}, cl )
310
328
})
@@ -319,7 +337,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
319
337
uploader_id: test-agent
320
338
cluster_id: "the cluster name"
321
339
` )),
322
- withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath ))
340
+ withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath , "--install-namespace" , "venafi" ))
323
341
require .EqualError (t , err , "1 error occurred:\n \t * the venafi-cloud.upload_path field is required when using the Venafi Cloud Key Pair Service Account mode\n \n " )
324
342
})
325
343
@@ -335,9 +353,9 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
335
353
organization_id: foo
336
354
cluster_id: bar
337
355
` )),
338
- withCmdLineFlags ("--credentials-file" , path ))
356
+ withCmdLineFlags ("--credentials-file" , path , "--install-namespace" , "venafi" ))
339
357
require .NoError (t , err )
340
- assert .Equal (t , CombinedConfig {Server : "https://api.venafi.eu" , Period : time .Hour , OrganizationID : "foo" , ClusterID : "bar" , AuthMode : JetstackSecureOAuth , BackoffMaxTime : 10 * time .Minute }, got )
358
+ assert .Equal (t , CombinedConfig {Server : "https://api.venafi.eu" , Period : time .Hour , OrganizationID : "foo" , ClusterID : "bar" , AuthMode : JetstackSecureOAuth , BackoffMaxTime : 10 * time .Minute , InstallNS : "venafi" }, got )
341
359
assert .IsType (t , & client.OAuthClient {}, cl )
342
360
})
343
361
@@ -349,7 +367,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
349
367
organization_id: foo
350
368
cluster_id: bar
351
369
` )),
352
- withCmdLineFlags ("--credentials-file" , "credentials.json" ))
370
+ withCmdLineFlags ("--credentials-file" , "credentials.json" , "--install-namespace" , "venafi" ))
353
371
assert .EqualError (t , err , testutil .Undent (`
354
372
validating creds: failed loading config using the Jetstack Secure OAuth mode: 1 error occurred:
355
373
* credentials file: failed to load credentials from file credentials.json: open credentials.json: no such file or directory
@@ -367,7 +385,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
367
385
organization_id: foo
368
386
cluster_id: bar
369
387
` )),
370
- withCmdLineFlags ("--credentials-file" , credsPath ))
388
+ withCmdLineFlags ("--credentials-file" , credsPath , "--install-namespace" , "venafi" ))
371
389
assert .EqualError (t , err , testutil .Undent (`
372
390
validating creds: failed loading config using the Jetstack Secure OAuth mode: 2 errors occurred:
373
391
* credentials file: user_id cannot be empty
@@ -409,9 +427,9 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
409
427
venafi-cloud:
410
428
upload_path: /foo/bar
411
429
` )),
412
- withCmdLineFlags ("--client-id" , "5bc7d07c-45da-11ef-a878-523f1e1d7de1" , "--private-key-path" , path ))
430
+ withCmdLineFlags ("--client-id" , "5bc7d07c-45da-11ef-a878-523f1e1d7de1" , "--private-key-path" , path , "--install-namespace" , "venafi" ))
413
431
require .NoError (t , err )
414
- assert .Equal (t , CombinedConfig {Server : "https://api.venafi.eu" , Period : time .Hour , AuthMode : VenafiCloudKeypair , ClusterID : "the cluster name" , UploadPath : "/foo/bar" , BackoffMaxTime : 10 * time .Minute }, got )
432
+ assert .Equal (t , CombinedConfig {Server : "https://api.venafi.eu" , Period : time .Hour , AuthMode : VenafiCloudKeypair , ClusterID : "the cluster name" , UploadPath : "/foo/bar" , BackoffMaxTime : 10 * time .Minute , InstallNS : "venafi" }, got )
415
433
assert .IsType (t , & client.VenafiCloudClient {}, cl )
416
434
})
417
435
@@ -430,9 +448,9 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
430
448
venafi-cloud:
431
449
upload_path: /foo/bar
432
450
` )),
433
- withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath ))
451
+ withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath , "--install-namespace" , "venafi" ))
434
452
require .NoError (t , err )
435
- assert .Equal (t , CombinedConfig {Server : "https://api.venafi.eu" , Period : time .Hour , AuthMode : VenafiCloudKeypair , ClusterID : "the cluster name" , UploadPath : "/foo/bar" , BackoffMaxTime : 10 * time .Minute }, got )
453
+ assert .Equal (t , CombinedConfig {Server : "https://api.venafi.eu" , Period : time .Hour , AuthMode : VenafiCloudKeypair , ClusterID : "the cluster name" , UploadPath : "/foo/bar" , BackoffMaxTime : 10 * time .Minute , InstallNS : "venafi" }, got )
436
454
})
437
455
438
456
t .Run ("venafi-cloud-keypair-auth: venafi-cloud.upload_path field is required" , func (t * testing.T ) {
@@ -446,7 +464,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
446
464
venafi-cloud:
447
465
upload_path: "" # <-- Cannot be left empty
448
466
` )),
449
- withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath ))
467
+ withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath , "--install-namespace" , "venafi" ))
450
468
require .EqualError (t , err , testutil .Undent (`
451
469
1 error occurred:
452
470
* the venafi-cloud.upload_path field is required when using the Venafi Cloud Key Pair Service Account mode
@@ -463,7 +481,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
463
481
period: 1h
464
482
cluster_id: the cluster name
465
483
` )),
466
- withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath , "--private-key-path" , privKeyPath ))
484
+ withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath , "--private-key-path" , privKeyPath , "--install-namespace" , "venafi" ))
467
485
require .EqualError (t , err , testutil .Undent (`
468
486
1 error occurred:
469
487
* the venafi-cloud.upload_path field is required when using the Venafi Cloud Key Pair Service Account mode
@@ -483,7 +501,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
483
501
uploader_id: test-agent
484
502
upload_path: /testing/path
485
503
` )),
486
- withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath , "--private-key-path" , privKeyPath ))
504
+ withCmdLineFlags ("--venafi-cloud" , "--credentials-file" , credsPath , "--private-key-path" , privKeyPath , "--install-namespace" , "venafi" ))
487
505
require .EqualError (t , err , testutil .Undent (`
488
506
1 error occurred:
489
507
* cluster_id is required in Venafi Cloud Key Pair Service Account mode
@@ -514,23 +532,6 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
514
532
assert .IsType (t , & client.VenConnClient {}, cl )
515
533
})
516
534
517
- t .Run ("venafi-cloud-workload-identity-auth: namespace can't be read from disk" , func (t * testing.T ) {
518
- t .Setenv ("KUBECONFIG" , withFile (t , fakeKubeconfig ))
519
- got , _ , err := ValidateAndCombineConfig (discardLogs (),
520
- withConfig (testutil .Undent (`
521
- server: https://api.venafi.eu
522
- period: 1h
523
- ` )),
524
- withCmdLineFlags ("--venafi-connection" , "venafi-components" ))
525
- assert .EqualError (t , err , testutil .Undent (`
526
- 2 errors occurred:
527
- * cluster_id is required in Venafi Cloud VenafiConnection mode
528
- * could not guess which namespace the agent is running in: not running in cluster, please use --install-namespace to specify the namespace in which the agent is running
529
-
530
- ` ))
531
- assert .Equal (t , CombinedConfig {}, got )
532
- })
533
-
534
535
t .Run ("venafi-cloud-workload-identity-auth: warning about server, venafi-cloud.uploader_id, and venafi-cloud.upload_path being skipped" , func (t * testing.T ) {
535
536
t .Setenv ("KUBECONFIG" , withFile (t , fakeKubeconfig ))
536
537
log , gotLogs := recordLogs ()
@@ -595,11 +596,11 @@ func Test_ValidateAndCombineConfig_VenafiCloudKeyPair(t *testing.T) {
595
596
uploader_id: no
596
597
upload_path: /v1/tlspk/upload/clusterdata
597
598
` )),
598
- withCmdLineFlags ("--client-id" , "5bc7d07c-45da-11ef-a878-523f1e1d7de1" , "--private-key-path" , privKeyPath ),
599
+ withCmdLineFlags ("--client-id" , "5bc7d07c-45da-11ef-a878-523f1e1d7de1" , "--private-key-path" , privKeyPath , "--install-namespace" , "venafi" ),
599
600
)
601
+ require .NoError (t , err )
600
602
testutil .TrustCA (t , cl , cert )
601
603
assert .Equal (t , VenafiCloudKeypair , got .AuthMode )
602
- require .NoError (t , err )
603
604
604
605
err = cl .PostDataReadingsWithOptions (nil , client.Options {ClusterName : "test cluster name" })
605
606
require .NoError (t , err )
0 commit comments