@@ -48,9 +48,11 @@ const (
48
48
49
49
var (
50
50
// Fake Swift credentials map
51
- fakeSecretData = map [string ][]byte {
52
- "REGISTRY_STORAGE_SWIFT_USERNAME" : []byte (username ),
53
- "REGISTRY_STORAGE_SWIFT_PASSWORD" : []byte (password ),
51
+ fakeUserPassSecretData = map [string ][]byte {
52
+ "REGISTRY_STORAGE_SWIFT_USERNAME" : []byte (username ),
53
+ "REGISTRY_STORAGE_SWIFT_PASSWORD" : []byte (password ),
54
+ }
55
+ fakeAppCredsSecretData = map [string ][]byte {
54
56
"REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALID" : []byte (applicationCredentialID ),
55
57
"REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALNAME" : []byte (applicationCredentialName ),
56
58
"REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALSECRET" : []byte (applicationCredentialSecret ),
@@ -63,12 +65,41 @@ type MockSecretNamespaceLister interface {
63
65
Get (string ) (* corev1.Secret , error )
64
66
List (selector labels.Selector ) ([]* corev1.Secret , error )
65
67
}
68
+
69
+ type MockUPIAppCredsSecretNamespaceLister struct {}
70
+
71
+ func (m MockUPIAppCredsSecretNamespaceLister ) Get (name string ) (* corev1.Secret , error ) {
72
+ if name == upiSecretName {
73
+ return & corev1.Secret {
74
+ Data : fakeAppCredsSecretData ,
75
+ }, nil
76
+ }
77
+
78
+ return nil , & k8serrors.StatusError {
79
+ ErrStatus : metav1.Status {
80
+ Status : metav1 .StatusFailure ,
81
+ Code : http .StatusNotFound ,
82
+ Reason : metav1 .StatusReasonNotFound ,
83
+ Details : & metav1.StatusDetails {},
84
+ Message : fmt .Sprintf ("No secret with name %v was found" , name ),
85
+ },
86
+ }
87
+ }
88
+
89
+ func (m MockUPIAppCredsSecretNamespaceLister ) List (selector labels.Selector ) ([]* corev1.Secret , error ) {
90
+ return []* corev1.Secret {
91
+ {
92
+ Data : fakeAppCredsSecretData ,
93
+ },
94
+ }, nil
95
+ }
96
+
66
97
type MockUPISecretNamespaceLister struct {}
67
98
68
99
func (m MockUPISecretNamespaceLister ) Get (name string ) (* corev1.Secret , error ) {
69
100
if name == upiSecretName {
70
101
return & corev1.Secret {
71
- Data : fakeSecretData ,
102
+ Data : fakeUserPassSecretData ,
72
103
}, nil
73
104
}
74
105
@@ -86,7 +117,7 @@ func (m MockUPISecretNamespaceLister) Get(name string) (*corev1.Secret, error) {
86
117
func (m MockUPISecretNamespaceLister ) List (selector labels.Selector ) ([]* corev1.Secret , error ) {
87
118
return []* corev1.Secret {
88
119
{
89
- Data : fakeSecretData ,
120
+ Data : fakeUserPassSecretData ,
90
121
},
91
122
}, nil
92
123
}
@@ -542,7 +573,7 @@ func TestSwiftStorageExistsNativeSecret(t *testing.T) {
542
573
th .AssertEquals (t , true , res )
543
574
}
544
575
545
- func TestSwiftSecrets (t * testing.T ) {
576
+ func TestSwiftSecretsAppCreds (t * testing.T ) {
546
577
config := imageregistryv1.ImageRegistryConfigStorageSwift {
547
578
AuthURL : "http://localhost:5000/v3" ,
548
579
Container : container ,
@@ -551,7 +582,7 @@ func TestSwiftSecrets(t *testing.T) {
551
582
}
552
583
d := driver {
553
584
Listers : & regopclient.StorageListers {
554
- Secrets : MockUPISecretNamespaceLister {},
585
+ Secrets : MockUPIAppCredsSecretNamespaceLister {},
555
586
Infrastructures : fakeInfrastructureLister (cloudName ),
556
587
OpenShiftConfig : MockConfigMapNamespaceLister {},
557
588
},
@@ -562,8 +593,8 @@ func TestSwiftSecrets(t *testing.T) {
562
593
res , err := configenv .SecretData ()
563
594
th .AssertNoErr (t , err )
564
595
th .AssertEquals (t , 5 , len (res ))
565
- th .AssertEquals (t , username , res ["REGISTRY_STORAGE_SWIFT_USERNAME" ])
566
- th .AssertEquals (t , password , res ["REGISTRY_STORAGE_SWIFT_PASSWORD" ])
596
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_USERNAME" ])
597
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_PASSWORD" ])
567
598
th .AssertEquals (t , applicationCredentialID , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALID" ])
568
599
th .AssertEquals (t , applicationCredentialName , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALNAME" ])
569
600
th .AssertEquals (t , applicationCredentialSecret , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALSECRET" ])
@@ -586,13 +617,11 @@ func TestSwiftSecrets(t *testing.T) {
586
617
auth:
587
618
auth_url: "http://localhost:5000/v3"
588
619
project_name: ` + tenant + `
589
- username: ` + username + `
590
- password: ` + password + `
591
620
application_credential_id: ` + applicationCredentialID + `
592
621
application_credential_name: ` + applicationCredentialName + `
593
622
application_credential_secret: ` + applicationCredentialSecret + `
594
623
domain_name: ` + domain + `
595
- region_name: RegionOne` )
624
+ region_name: RegionOne` )
596
625
597
626
fakeCloudsYAML = map [string ][]byte {
598
627
cloudSecretKey : fakeCloudsYAMLData ,
@@ -602,13 +631,77 @@ func TestSwiftSecrets(t *testing.T) {
602
631
res , err = configenv .SecretData ()
603
632
th .AssertNoErr (t , err )
604
633
th .AssertEquals (t , 5 , len (res ))
605
- th .AssertEquals (t , username , res ["REGISTRY_STORAGE_SWIFT_USERNAME" ])
606
- th .AssertEquals (t , password , res ["REGISTRY_STORAGE_SWIFT_PASSWORD" ])
634
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_USERNAME" ])
635
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_PASSWORD" ])
607
636
th .AssertEquals (t , applicationCredentialID , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALID" ])
608
637
th .AssertEquals (t , applicationCredentialName , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALNAME" ])
609
638
th .AssertEquals (t , applicationCredentialSecret , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALSECRET" ])
610
639
}
611
640
641
+ func TestSwiftSecretsUserPass (t * testing.T ) {
642
+ config := imageregistryv1.ImageRegistryConfigStorageSwift {
643
+ AuthURL : "http://localhost:5000/v3" ,
644
+ Container : container ,
645
+ Domain : domain ,
646
+ Tenant : tenant ,
647
+ }
648
+ d := driver {
649
+ Listers : & regopclient.StorageListers {
650
+ Secrets : MockUPISecretNamespaceLister {},
651
+ Infrastructures : fakeInfrastructureLister (cloudName ),
652
+ OpenShiftConfig : MockConfigMapNamespaceLister {},
653
+ },
654
+ Config : & config ,
655
+ }
656
+ configenv , err := d .ConfigEnv ()
657
+ th .AssertNoErr (t , err )
658
+ res , err := configenv .SecretData ()
659
+ th .AssertNoErr (t , err )
660
+ th .AssertEquals (t , 5 , len (res ))
661
+ th .AssertEquals (t , username , res ["REGISTRY_STORAGE_SWIFT_USERNAME" ])
662
+ th .AssertEquals (t , password , res ["REGISTRY_STORAGE_SWIFT_PASSWORD" ])
663
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALID" ])
664
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALNAME" ])
665
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALSECRET" ])
666
+
667
+ config = imageregistryv1.ImageRegistryConfigStorageSwift {
668
+ Container : container ,
669
+ }
670
+ // Support any cloud name provided by platform status
671
+ customCloud := "myCloud"
672
+ d = driver {
673
+ Listers : & regopclient.StorageListers {
674
+ Secrets : MockIPISecretNamespaceLister {},
675
+ Infrastructures : fakeInfrastructureLister (customCloud ),
676
+ OpenShiftConfig : MockConfigMapNamespaceLister {},
677
+ },
678
+ Config : & config ,
679
+ }
680
+ fakeCloudsYAMLData := []byte (`clouds:
681
+ ` + customCloud + `:
682
+ auth:
683
+ auth_url: "http://localhost:5000/v3"
684
+ project_name: ` + tenant + `
685
+ username: ` + username + `
686
+ password: ` + password + `
687
+ domain_name: ` + domain + `
688
+ region_name: RegionOne` )
689
+
690
+ fakeCloudsYAML = map [string ][]byte {
691
+ cloudSecretKey : fakeCloudsYAMLData ,
692
+ }
693
+ configenv , err = d .ConfigEnv ()
694
+ th .AssertNoErr (t , err )
695
+ res , err = configenv .SecretData ()
696
+ th .AssertNoErr (t , err )
697
+ th .AssertEquals (t , 5 , len (res ))
698
+ th .AssertEquals (t , username , res ["REGISTRY_STORAGE_SWIFT_USERNAME" ])
699
+ th .AssertEquals (t , password , res ["REGISTRY_STORAGE_SWIFT_PASSWORD" ])
700
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALID" ])
701
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALNAME" ])
702
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALSECRET" ])
703
+ }
704
+
612
705
func TestSwiftCreateStorageCloudConfig (t * testing.T ) {
613
706
th .SetupHTTP ()
614
707
defer th .TeardownHTTP ()
0 commit comments