@@ -345,15 +345,10 @@ func TestCompleteForServiceAccount(t *testing.T) {
345
345
t .Fatalf ("Failed to encode private key: %v" , err )
346
346
}
347
347
348
- // create and start mock signer.
349
- socketPath := "@mock-external-jwt-signer.sock"
350
- mockSigner := v1alpha1testing .NewMockSigner (t , socketPath )
351
- defer mockSigner .CleanUp ()
352
-
353
348
testCases := []struct {
354
349
desc string
355
350
issuers []string
356
- signingEndpoint string
351
+ externalSigner bool
357
352
signingKeyFiles string
358
353
maxExpiration time.Duration
359
354
externalMaxExpirationSec int64
@@ -366,11 +361,11 @@ func TestCompleteForServiceAccount(t *testing.T) {
366
361
externalPublicKeyGetterPresent bool
367
362
}{
368
363
{
369
- desc : "no endpoint or key file" ,
364
+ desc : "endpoint and key file" ,
370
365
issuers : []string {
371
366
"iss" ,
372
367
},
373
- signingEndpoint : socketPath ,
368
+ externalSigner : true ,
374
369
signingKeyFiles : "private_key.pem" ,
375
370
maxExpiration : time .Second * 3600 ,
376
371
@@ -381,7 +376,7 @@ func TestCompleteForServiceAccount(t *testing.T) {
381
376
issuers : []string {
382
377
"iss" ,
383
378
},
384
- signingEndpoint : socketPath ,
379
+ externalSigner : true ,
385
380
signingKeyFiles : "private_key.pem" ,
386
381
maxExpiration : time .Second * 10 ,
387
382
@@ -392,7 +387,7 @@ func TestCompleteForServiceAccount(t *testing.T) {
392
387
issuers : []string {
393
388
"iss" ,
394
389
},
395
- signingEndpoint : "" ,
390
+ externalSigner : false ,
396
391
signingKeyFiles : "private_key.pem" ,
397
392
maxExpiration : time .Second * 3600 ,
398
393
@@ -405,7 +400,7 @@ func TestCompleteForServiceAccount(t *testing.T) {
405
400
issuers : []string {
406
401
"iss" ,
407
402
},
408
- signingEndpoint : socketPath ,
403
+ externalSigner : true ,
409
404
signingKeyFiles : "" ,
410
405
maxExpiration : 0 ,
411
406
externalMaxExpirationSec : 600 , // 10m
@@ -419,7 +414,7 @@ func TestCompleteForServiceAccount(t *testing.T) {
419
414
issuers : []string {
420
415
"iss" ,
421
416
},
422
- signingEndpoint : socketPath ,
417
+ externalSigner : true ,
423
418
signingKeyFiles : "" ,
424
419
maxExpiration : time .Second * 3600 ,
425
420
externalMaxExpirationSec : 600 , // 10m
@@ -431,7 +426,7 @@ func TestCompleteForServiceAccount(t *testing.T) {
431
426
issuers : []string {
432
427
"iss" ,
433
428
},
434
- signingEndpoint : socketPath ,
429
+ externalSigner : true ,
435
430
signingKeyFiles : "" ,
436
431
maxExpiration : 0 ,
437
432
externalMaxExpirationSec : 300 , // 5m
@@ -443,7 +438,7 @@ func TestCompleteForServiceAccount(t *testing.T) {
443
438
issuers : []string {
444
439
"iss" ,
445
440
},
446
- signingEndpoint : socketPath ,
441
+ externalSigner : true ,
447
442
signingKeyFiles : "" ,
448
443
maxExpiration : 0 ,
449
444
externalMaxExpirationSec : 900 , // 15m
@@ -456,7 +451,7 @@ func TestCompleteForServiceAccount(t *testing.T) {
456
451
issuers : []string {
457
452
"iss" ,
458
453
},
459
- signingEndpoint : socketPath ,
454
+ externalSigner : true ,
460
455
signingKeyFiles : "" ,
461
456
maxExpiration : 0 ,
462
457
externalMaxExpirationSec : 900 , // 15m
@@ -468,8 +463,20 @@ func TestCompleteForServiceAccount(t *testing.T) {
468
463
469
464
for _ , tc := range testCases {
470
465
t .Run (tc .desc , func (t * testing.T ) {
466
+
471
467
options := NewOptions ()
472
- options .ServiceAccountSigningEndpoint = tc .signingEndpoint
468
+ if tc .externalSigner {
469
+ // create and start mock signer.
470
+ socketPath := fmt .Sprintf ("@mock-external-jwt-signer-%d.sock" , time .Now ().Nanosecond ())
471
+ mockSigner := v1alpha1testing .NewMockSigner (t , socketPath )
472
+ defer mockSigner .CleanUp ()
473
+
474
+ mockSigner .MaxTokenExpirationSeconds = tc .externalMaxExpirationSec
475
+ mockSigner .MetadataError = tc .metadataError
476
+ mockSigner .FetchError = tc .fetchError
477
+
478
+ options .ServiceAccountSigningEndpoint = socketPath
479
+ }
473
480
options .ServiceAccountSigningKeyFile = tc .signingKeyFiles
474
481
options .Authentication = & kubeoptions.BuiltInAuthenticationOptions {
475
482
ServiceAccounts : & kubeoptions.ServiceAccountAuthenticationOptions {
@@ -478,16 +485,13 @@ func TestCompleteForServiceAccount(t *testing.T) {
478
485
},
479
486
}
480
487
481
- _ = mockSigner .Reset ()
482
- mockSigner .MaxTokenExpirationSeconds = tc .externalMaxExpirationSec
483
- mockSigner .MetadataError = tc .metadataError
484
- mockSigner .FetchError = tc .fetchError
485
-
486
488
co := completedOptions {
487
489
Options : * options ,
488
490
}
489
491
490
- err := options .completeServiceAccountOptions (context .Background (), & co )
492
+ ctx , cancel := context .WithCancel (context .Background ())
493
+ defer cancel ()
494
+ err := options .completeServiceAccountOptions (ctx , & co )
491
495
492
496
if tc .wantError != nil {
493
497
if err == nil || tc .wantError .Error () != err .Error () {
0 commit comments