@@ -21,6 +21,10 @@ import (
21
21
"fmt"
22
22
"reflect"
23
23
"testing"
24
+
25
+ utilfeature "k8s.io/apiserver/pkg/util/feature"
26
+ featuregatetesting "k8s.io/component-base/featuregate/testing"
27
+ "k8s.io/kubernetes/pkg/features"
24
28
)
25
29
26
30
func TestURLsMatch (t * testing.T ) {
@@ -222,7 +226,7 @@ func TestDockerKeyringForGlob(t *testing.T) {
222
226
if cfg , err := ReadDockerConfigFileFromBytes ([]byte (sampleDockerConfig )); err != nil {
223
227
t .Errorf ("Error processing json blob %q, %v" , sampleDockerConfig , err )
224
228
} else {
225
- keyring .Add (cfg )
229
+ keyring .Add (nil , cfg )
226
230
}
227
231
228
232
creds , ok := keyring .Lookup (test .targetURL + "/foo/bar" )
@@ -290,7 +294,7 @@ func TestKeyringMiss(t *testing.T) {
290
294
if cfg , err := ReadDockerConfigFileFromBytes ([]byte (sampleDockerConfig )); err != nil {
291
295
t .Errorf ("Error processing json blob %q, %v" , sampleDockerConfig , err )
292
296
} else {
293
- keyring .Add (cfg )
297
+ keyring .Add (nil , cfg )
294
298
}
295
299
296
300
_ , ok := keyring .Lookup (test .lookupURL + "/foo/bar" )
@@ -318,7 +322,7 @@ func TestKeyringMissWithDockerHubCredentials(t *testing.T) {
318
322
if cfg , err := ReadDockerConfigFileFromBytes ([]byte (sampleDockerConfig )); err != nil {
319
323
t .Errorf ("Error processing json blob %q, %v" , sampleDockerConfig , err )
320
324
} else {
321
- keyring .Add (cfg )
325
+ keyring .Add (nil , cfg )
322
326
}
323
327
324
328
val , ok := keyring .Lookup ("world.mesos.org/foo/bar" )
@@ -344,7 +348,7 @@ func TestKeyringHitWithUnqualifiedDockerHub(t *testing.T) {
344
348
if cfg , err := ReadDockerConfigFileFromBytes ([]byte (sampleDockerConfig )); err != nil {
345
349
t .Errorf ("Error processing json blob %q, %v" , sampleDockerConfig , err )
346
350
} else {
347
- keyring .Add (cfg )
351
+ keyring .Add (nil , cfg )
348
352
}
349
353
350
354
creds , ok := keyring .Lookup ("google/docker-registry" )
@@ -353,7 +357,7 @@ func TestKeyringHitWithUnqualifiedDockerHub(t *testing.T) {
353
357
return
354
358
}
355
359
if len (creds ) > 1 {
356
- t .Errorf ("Got more hits than expected: %s " , creds )
360
+ t .Errorf ("Got more hits than expected: %v " , creds )
357
361
}
358
362
val := creds [0 ]
359
363
@@ -385,7 +389,7 @@ func TestKeyringHitWithUnqualifiedLibraryDockerHub(t *testing.T) {
385
389
if cfg , err := ReadDockerConfigFileFromBytes ([]byte (sampleDockerConfig )); err != nil {
386
390
t .Errorf ("Error processing json blob %q, %v" , sampleDockerConfig , err )
387
391
} else {
388
- keyring .Add (cfg )
392
+ keyring .Add (nil , cfg )
389
393
}
390
394
391
395
creds , ok := keyring .Lookup ("jenkins" )
@@ -394,7 +398,7 @@ func TestKeyringHitWithUnqualifiedLibraryDockerHub(t *testing.T) {
394
398
return
395
399
}
396
400
if len (creds ) > 1 {
397
- t .Errorf ("Got more hits than expected: %s " , creds )
401
+ t .Errorf ("Got more hits than expected: %v " , creds )
398
402
}
399
403
val := creds [0 ]
400
404
@@ -426,7 +430,7 @@ func TestKeyringHitWithQualifiedDockerHub(t *testing.T) {
426
430
if cfg , err := ReadDockerConfigFileFromBytes ([]byte (sampleDockerConfig )); err != nil {
427
431
t .Errorf ("Error processing json blob %q, %v" , sampleDockerConfig , err )
428
432
} else {
429
- keyring .Add (cfg )
433
+ keyring .Add (nil , cfg )
430
434
}
431
435
432
436
creds , ok := keyring .Lookup (url + "/google/docker-registry" )
@@ -435,7 +439,7 @@ func TestKeyringHitWithQualifiedDockerHub(t *testing.T) {
435
439
return
436
440
}
437
441
if len (creds ) > 2 {
438
- t .Errorf ("Got more hits than expected: %s " , creds )
442
+ t .Errorf ("Got more hits than expected: %v " , creds )
439
443
}
440
444
val := creds [0 ]
441
445
@@ -498,20 +502,24 @@ func TestProvidersDockerKeyring(t *testing.T) {
498
502
}
499
503
500
504
func TestDockerKeyringLookup (t * testing.T ) {
505
+ // turn on the ensure secret pulled images feature to get the hashes with the creds
506
+ featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .KubeletEnsureSecretPulledImages , true )
501
507
ada := AuthConfig {
502
508
Username : "ada" ,
503
509
Password : "smash" , // Fake value for testing.
504
510
505
511
}
512
+ adaHash := "353258b53f5e9a57b059eab3f05312fc35bbeb874f08ce101e7bf0bf46977423"
506
513
507
514
grace := AuthConfig {
508
515
Username : "grace" ,
509
516
Password : "squash" , // Fake value for testing.
510
517
511
518
}
519
+ graceHash := "f949b3837a1eb733a951b6aeda0b3327c09ec50c917de9ca35818e8fbf567e29"
512
520
513
521
dk := & BasicDockerKeyring {}
514
- dk .Add (DockerConfig {
522
+ dk .Add (nil , DockerConfig {
515
523
"bar.example.com/pong" : DockerConfigEntry {
516
524
Username : grace .Username ,
517
525
Password : grace .Password ,
@@ -526,27 +534,27 @@ func TestDockerKeyringLookup(t *testing.T) {
526
534
527
535
tests := []struct {
528
536
image string
529
- match []AuthConfig
537
+ match []TrackedAuthConfig
530
538
ok bool
531
539
}{
532
540
// direct match
533
- {"bar.example.com" , []AuthConfig { ada }, true },
541
+ {"bar.example.com" , []TrackedAuthConfig {{ AuthConfig : ada , AuthConfigHash : adaHash } }, true },
534
542
535
543
// direct match deeper than other possible matches
536
- {"bar.example.com/pong" , []AuthConfig { grace , ada }, true },
544
+ {"bar.example.com/pong" , []TrackedAuthConfig {{ AuthConfig : grace , AuthConfigHash : graceHash }, { AuthConfig : ada , AuthConfigHash : adaHash } }, true },
537
545
538
546
// no direct match, deeper path ignored
539
- {"bar.example.com/ping" , []AuthConfig { ada }, true },
547
+ {"bar.example.com/ping" , []TrackedAuthConfig {{ AuthConfig : ada , AuthConfigHash : adaHash } }, true },
540
548
541
549
// match first part of path token
542
- {"bar.example.com/pongz" , []AuthConfig { grace , ada }, true },
550
+ {"bar.example.com/pongz" , []TrackedAuthConfig {{ AuthConfig : grace , AuthConfigHash : graceHash }, { AuthConfig : ada , AuthConfigHash : adaHash } }, true },
543
551
544
552
// match regardless of sub-path
545
- {"bar.example.com/pong/pang" , []AuthConfig { grace , ada }, true },
553
+ {"bar.example.com/pong/pang" , []TrackedAuthConfig {{ AuthConfig : grace , AuthConfigHash : graceHash }, { AuthConfig : ada , AuthConfigHash : adaHash } }, true },
546
554
547
555
// no host match
548
- {"example.com" , []AuthConfig {}, false },
549
- {"foo.example.com" , []AuthConfig {}, false },
556
+ {"example.com" , []TrackedAuthConfig {}, false },
557
+ {"foo.example.com" , []TrackedAuthConfig {}, false },
550
558
}
551
559
552
560
for i , tt := range tests {
@@ -565,14 +573,17 @@ func TestDockerKeyringLookup(t *testing.T) {
565
573
// by images that only match the hostname.
566
574
// NOTE: the above covers the case of a more specific match trumping just hostname.
567
575
func TestIssue3797 (t * testing.T ) {
576
+ // turn on the ensure secret pulled images feature to get the hashes with the creds
577
+ featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .KubeletEnsureSecretPulledImages , true )
568
578
rex := AuthConfig {
569
579
Username : "rex" ,
570
580
Password : "tiny arms" , // Fake value for testing.
571
581
572
582
}
583
+ rexHash := "899748fec74c8dd761845fca727f4249b05be275ff24026676fcd4351f656363"
573
584
574
585
dk := & BasicDockerKeyring {}
575
- dk .Add (DockerConfig {
586
+ dk .Add (nil , DockerConfig {
576
587
"https://quay.io/v1/" : DockerConfigEntry {
577
588
Username : rex .Username ,
578
589
Password : rex .Password ,
@@ -582,15 +593,15 @@ func TestIssue3797(t *testing.T) {
582
593
583
594
tests := []struct {
584
595
image string
585
- match []AuthConfig
596
+ match []TrackedAuthConfig
586
597
ok bool
587
598
}{
588
599
// direct match
589
- {"quay.io" , []AuthConfig { rex }, true },
600
+ {"quay.io" , []TrackedAuthConfig {{ AuthConfig : rex , AuthConfigHash : rexHash } }, true },
590
601
591
602
// partial matches
592
- {"quay.io/foo" , []AuthConfig { rex }, true },
593
- {"quay.io/foo/bar" , []AuthConfig { rex }, true },
603
+ {"quay.io/foo" , []TrackedAuthConfig {{ AuthConfig : rex , AuthConfigHash : rexHash } }, true },
604
+ {"quay.io/foo/bar" , []TrackedAuthConfig {{ AuthConfig : rex , AuthConfigHash : rexHash } }, true },
594
605
}
595
606
596
607
for i , tt := range tests {
0 commit comments