@@ -34,6 +34,7 @@ const (
34
34
applicationCredentialID = "myId"
35
35
applicationCredentialName = "myName"
36
36
applicationCredentialSecret = "mySecret"
37
+ TokenID = "myTokenID"
37
38
container = "registry"
38
39
domain = "Default"
39
40
tenant = "openshift-registry"
58
59
"REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALNAME" : []byte (applicationCredentialName ),
59
60
"REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALSECRET" : []byte (applicationCredentialSecret ),
60
61
}
62
+ fakeTokenSecretData = map [string ][]byte {
63
+ "REGISTRY_STORAGE_SWIFT_TOKENID" : []byte (TokenID ),
64
+ }
61
65
fakeCloudsYAML map [string ][]byte
62
66
fakeCloudProviderConfigMap map [string ]string
63
67
)
@@ -179,6 +183,34 @@ func (m MockConfigMapNamespaceLister) List(selector labels.Selector) ([]*corev1.
179
183
}, nil
180
184
}
181
185
186
+ type MockUPITokenSecretNamespaceLister struct {}
187
+
188
+ func (m MockUPITokenSecretNamespaceLister ) Get (name string ) (* corev1.Secret , error ) {
189
+ if name == upiSecretName {
190
+ return & corev1.Secret {
191
+ Data : fakeTokenSecretData ,
192
+ }, nil
193
+ }
194
+
195
+ return nil , & k8serrors.StatusError {
196
+ ErrStatus : metav1.Status {
197
+ Status : metav1 .StatusFailure ,
198
+ Code : http .StatusNotFound ,
199
+ Reason : metav1 .StatusReasonNotFound ,
200
+ Details : & metav1.StatusDetails {},
201
+ Message : fmt .Sprintf ("No secret with name %v was found" , name ),
202
+ },
203
+ }
204
+ }
205
+
206
+ func (m MockUPITokenSecretNamespaceLister ) List (selector labels.Selector ) ([]* corev1.Secret , error ) {
207
+ return []* corev1.Secret {
208
+ {
209
+ Data : fakeTokenSecretData ,
210
+ },
211
+ }, nil
212
+ }
213
+
182
214
func handleAuthentication (t * testing.T , endpointType string ) {
183
215
th .Mux .HandleFunc ("/v3/auth/tokens" , func (w http.ResponseWriter , r * http.Request ) {
184
216
th .TestMethod (t , r , "POST" )
@@ -593,9 +625,10 @@ func TestSwiftSecretsAppCreds(t *testing.T) {
593
625
th .AssertNoErr (t , err )
594
626
res , err := configenv .SecretData ()
595
627
th .AssertNoErr (t , err )
596
- th .AssertEquals (t , 5 , len (res ))
628
+ th .AssertEquals (t , 6 , len (res ))
597
629
th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_USERNAME" ])
598
630
th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_PASSWORD" ])
631
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_TOKENID" ])
599
632
th .AssertEquals (t , applicationCredentialID , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALID" ])
600
633
th .AssertEquals (t , applicationCredentialName , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALNAME" ])
601
634
th .AssertEquals (t , applicationCredentialSecret , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALSECRET" ])
@@ -631,9 +664,10 @@ func TestSwiftSecretsAppCreds(t *testing.T) {
631
664
th .AssertNoErr (t , err )
632
665
res , err = configenv .SecretData ()
633
666
th .AssertNoErr (t , err )
634
- th .AssertEquals (t , 5 , len (res ))
667
+ th .AssertEquals (t , 6 , len (res ))
635
668
th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_USERNAME" ])
636
669
th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_PASSWORD" ])
670
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_TOKENID" ])
637
671
th .AssertEquals (t , applicationCredentialID , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALID" ])
638
672
th .AssertEquals (t , applicationCredentialName , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALNAME" ])
639
673
th .AssertEquals (t , applicationCredentialSecret , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALSECRET" ])
@@ -658,9 +692,10 @@ func TestSwiftSecretsUserPass(t *testing.T) {
658
692
th .AssertNoErr (t , err )
659
693
res , err := configenv .SecretData ()
660
694
th .AssertNoErr (t , err )
661
- th .AssertEquals (t , 5 , len (res ))
695
+ th .AssertEquals (t , 6 , len (res ))
662
696
th .AssertEquals (t , username , res ["REGISTRY_STORAGE_SWIFT_USERNAME" ])
663
697
th .AssertEquals (t , password , res ["REGISTRY_STORAGE_SWIFT_PASSWORD" ])
698
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_TOKENID" ])
664
699
th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALID" ])
665
700
th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALNAME" ])
666
701
th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALSECRET" ])
@@ -695,9 +730,76 @@ func TestSwiftSecretsUserPass(t *testing.T) {
695
730
th .AssertNoErr (t , err )
696
731
res , err = configenv .SecretData ()
697
732
th .AssertNoErr (t , err )
698
- th .AssertEquals (t , 5 , len (res ))
733
+ th .AssertEquals (t , 6 , len (res ))
699
734
th .AssertEquals (t , username , res ["REGISTRY_STORAGE_SWIFT_USERNAME" ])
700
735
th .AssertEquals (t , password , res ["REGISTRY_STORAGE_SWIFT_PASSWORD" ])
736
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_TOKENID" ])
737
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALID" ])
738
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALNAME" ])
739
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALSECRET" ])
740
+ }
741
+
742
+ func TestSwiftSecretsToken (t * testing.T ) {
743
+ config := imageregistryv1.ImageRegistryConfigStorageSwift {
744
+ AuthURL : "http://localhost:5000/v3" ,
745
+ Container : container ,
746
+ Domain : domain ,
747
+ Tenant : tenant ,
748
+ }
749
+ d := driver {
750
+ Listers : & regopclient.StorageListers {
751
+ Secrets : MockUPITokenSecretNamespaceLister {},
752
+ Infrastructures : fakeInfrastructureLister (cloudName ),
753
+ OpenShiftConfig : MockConfigMapNamespaceLister {},
754
+ },
755
+ Config : & config ,
756
+ }
757
+ configenv , err := d .ConfigEnv ()
758
+ th .AssertNoErr (t , err )
759
+ res , err := configenv .SecretData ()
760
+ fmt .Println (res )
761
+ th .AssertNoErr (t , err )
762
+ th .AssertEquals (t , 6 , len (res ))
763
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_USERNAME" ])
764
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_PASSWORD" ])
765
+ th .AssertEquals (t , TokenID , res ["REGISTRY_STORAGE_SWIFT_TOKENID" ])
766
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALID" ])
767
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALNAME" ])
768
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALSECRET" ])
769
+
770
+ config = imageregistryv1.ImageRegistryConfigStorageSwift {
771
+ Container : container ,
772
+ }
773
+ // Support any cloud name provided by platform status
774
+ customCloud := "myCloud"
775
+ d = driver {
776
+ Listers : & regopclient.StorageListers {
777
+ Secrets : MockIPISecretNamespaceLister {},
778
+ Infrastructures : fakeInfrastructureLister (customCloud ),
779
+ OpenShiftConfig : MockConfigMapNamespaceLister {},
780
+ },
781
+ Config : & config ,
782
+ }
783
+ fakeCloudsYAMLData := []byte (`clouds:
784
+ ` + customCloud + `:
785
+ auth:
786
+ auth_url: "http://localhost:5000/v3"
787
+ project_name: ` + tenant + `
788
+ token: ` + TokenID + `
789
+ domain_name: ` + domain + `
790
+ region_name: RegionOne` )
791
+
792
+ fakeCloudsYAML = map [string ][]byte {
793
+ cloudSecretKey : fakeCloudsYAMLData ,
794
+ }
795
+ configenv , err = d .ConfigEnv ()
796
+ th .AssertNoErr (t , err )
797
+ res , err = configenv .SecretData ()
798
+ th .AssertNoErr (t , err )
799
+ th .AssertEquals (t , 6 , len (res ))
800
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_USERNAME" ])
801
+ th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_PASSWORD" ])
802
+ th .AssertEquals (t , TokenID , res ["REGISTRY_STORAGE_SWIFT_TOKENID" ])
701
803
th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALID" ])
702
804
th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALNAME" ])
703
805
th .AssertEquals (t , `""` , res ["REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALSECRET" ])
@@ -853,7 +955,6 @@ func TestSwiftConfigEnvCloudConfig(t *testing.T) {
853
955
d , _ := mockConfig (false , "http://localhost:5000/v3" , MockIPISecretNamespaceLister {}, false )
854
956
855
957
res , err := d .ConfigEnv ()
856
-
857
958
th .AssertNoErr (t , err )
858
959
th .AssertEquals (t , "REGISTRY_STORAGE" , res [0 ].Name )
859
960
th .AssertEquals (t , "swift" , res [0 ].Value )
@@ -865,20 +966,22 @@ func TestSwiftConfigEnvCloudConfig(t *testing.T) {
865
966
th .AssertEquals (t , true , res [3 ].Secret )
866
967
th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_PASSWORD" , res [4 ].Name )
867
968
th .AssertEquals (t , true , res [4 ].Secret )
868
- th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALID " , res [5 ].Name )
969
+ th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_TOKENID " , res [5 ].Name )
869
970
th .AssertEquals (t , true , res [5 ].Secret )
870
- th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALNAME " , res [6 ].Name )
971
+ th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALID " , res [6 ].Name )
871
972
th .AssertEquals (t , true , res [6 ].Secret )
872
- th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALSECRET " , res [7 ].Name )
973
+ th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALNAME " , res [7 ].Name )
873
974
th .AssertEquals (t , true , res [7 ].Secret )
874
- th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_AUTHVERSION" , res [8 ].Name )
875
- th .AssertEquals (t , 3 , res [8 ].Value )
876
- th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_DOMAIN" , res [9 ].Name )
877
- th .AssertEquals (t , domain , res [9 ].Value )
878
- th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_TENANT" , res [10 ].Name )
879
- th .AssertEquals (t , tenant , res [10 ].Value )
880
- th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_REGION" , res [11 ].Name )
881
- th .AssertEquals (t , "RegionOne" , res [11 ].Value )
975
+ th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_APPLICATIONCREDENTIALSECRET" , res [8 ].Name )
976
+ th .AssertEquals (t , true , res [8 ].Secret )
977
+ th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_AUTHVERSION" , res [9 ].Name )
978
+ th .AssertEquals (t , 3 , res [9 ].Value )
979
+ th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_DOMAIN" , res [10 ].Name )
980
+ th .AssertEquals (t , domain , res [10 ].Value )
981
+ th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_TENANT" , res [11 ].Name )
982
+ th .AssertEquals (t , tenant , res [11 ].Value )
983
+ th .AssertEquals (t , "REGISTRY_STORAGE_SWIFT_REGION" , res [12 ].Name )
984
+ th .AssertEquals (t , "RegionOne" , res [12 ].Value )
882
985
}
883
986
884
987
func TestSwiftEnsureAuthURLHasAPIVersion (t * testing.T ) {
0 commit comments