@@ -69,112 +69,6 @@ func Test_mergeCloudConfig(t *testing.T) {
6969 args : []string {"--cloud-config-file-path" , "foo" },
7070 expectedErrMsg : "stat foo: no such file or directory" ,
7171 },
72- {
73- name : "AZURE_CLIENT_ID not set" ,
74- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , outputFile .Name ()},
75- expectedErrMsg : "azure_client_id should be set up" ,
76- },
77- {
78- name : "AZURE_CLIENT_SECRET not set" ,
79- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , outputFile .Name ()},
80- envVars : map [string ]string {"AZURE_CLIENT_ID" : "foo" },
81- expectedErrMsg : "azure_client_secret should be set up" ,
82- },
83- {
84- name : "input file content is not a valid json" ,
85- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , outputFile .Name ()},
86- envVars : map [string ]string {"AZURE_CLIENT_ID" : "foo" , "AZURE_CLIENT_SECRET" : "bar" },
87- fileContent : "{*&(&#@!}" ,
88- expectedErrMsg : "couldn't read cloud config from file: invalid character '*' looking for beginning of object key string" ,
89- },
90- {
91- name : "input file content is valid json, but format is unexpected" ,
92- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , outputFile .Name ()},
93- envVars : map [string ]string {"AZURE_CLIENT_ID" : "foo" , "AZURE_CLIENT_SECRET" : "bar" },
94- fileContent : "[1]" ,
95- expectedErrMsg : "couldn't read cloud config from file: json: cannot unmarshal array into Go value of type map[string]interface {}" ,
96- },
97- {
98- name : "all ok, file is empty json object" ,
99- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , outputFile .Name ()},
100- envVars : map [string ]string {"AZURE_CLIENT_ID" : "foo" , "AZURE_CLIENT_SECRET" : "bar" },
101- fileContent : "{}" ,
102- expectedContent : "{\" aadClientId\" :\" foo\" ,\" aadClientSecret\" :\" bar\" }" ,
103- },
104- {
105- name : "all ok, some content in json" ,
106- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , outputFile .Name ()},
107- envVars : map [string ]string {"AZURE_CLIENT_ID" : "foo" , "AZURE_CLIENT_SECRET" : "bar" },
108- fileContent : "{\" bar\" : \" baz\" }" ,
109- expectedContent : "{\" aadClientId\" :\" foo\" ,\" aadClientSecret\" :\" bar\" ,\" bar\" :\" baz\" }" ,
110- },
111- {
112- name : "all ok, client_id and client_secret overrides" ,
113- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , outputFile .Name ()},
114- envVars : map [string ]string {"AZURE_CLIENT_ID" : "foo" , "AZURE_CLIENT_SECRET" : "bar" },
115- fileContent : "{\" aadClientSecret\" :\" fizz\" ,\" aadClientId\" :\" baz\" }" ,
116- expectedContent : "{\" aadClientId\" :\" foo\" ,\" aadClientSecret\" :\" bar\" }" ,
117- },
118- {
119- name : "output file write error" ,
120- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , "/tmp" },
121- envVars : map [string ]string {"AZURE_CLIENT_ID" : "foo" , "AZURE_CLIENT_SECRET" : "bar" },
122- fileContent : "{}" ,
123- expectedErrMsg : "couldn't write prepared cloud config to file: open /tmp: is a directory" ,
124- },
125- {
126- name : "all ok, useManagedIdentityExtension not disabled" ,
127- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , outputFile .Name ()},
128- envVars : map [string ]string {"AZURE_CLIENT_ID" : "foo" , "AZURE_CLIENT_SECRET" : "bar" },
129- fileContent : "{\" aadClientSecret\" :\" fizz\" ,\" aadClientId\" :\" baz\" ,\" useManagedIdentityExtension\" :true}" ,
130- expectedContent : "{\" aadClientId\" :\" foo\" ,\" aadClientSecret\" :\" bar\" ,\" useManagedIdentityExtension\" :true}" ,
131- },
132- {
133- name : "all ok, useManagedIdentityExtension disabled" ,
134- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , outputFile .Name (), "--disable-identity-extension-auth" },
135- envVars : map [string ]string {"AZURE_CLIENT_ID" : "foo" , "AZURE_CLIENT_SECRET" : "bar" },
136- fileContent : "{\" aadClientSecret\" :\" fizz\" ,\" aadClientId\" :\" baz\" ,\" useManagedIdentityExtension\" :true}" ,
137- expectedContent : "{\" aadClientId\" :\" foo\" ,\" aadClientSecret\" :\" bar\" ,\" useManagedIdentityExtension\" :false}" ,
138- },
139- {
140- name : "all ok, invalid useManagedIdentityExtension value" ,
141- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , outputFile .Name (), "--disable-identity-extension-auth" },
142- envVars : map [string ]string {"AZURE_CLIENT_ID" : "foo" , "AZURE_CLIENT_SECRET" : "bar" },
143- fileContent : "{\" aadClientSecret\" :\" fizz\" ,\" aadClientId\" :\" baz\" ,\" useManagedIdentityExtension\" :\" true\" }" ,
144- expectedContent : "{\" aadClientId\" :\" foo\" ,\" aadClientSecret\" :\" bar\" ,\" useManagedIdentityExtension\" :false}" ,
145- },
146- {
147- name : "all ok, use workload identity while client secret is not present" ,
148- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , outputFile .Name (), "--disable-identity-extension-auth" , "--enable-azure-workload-identity=true" },
149- envVars : map [string ]string {"AZURE_TENANT_ID" : "bar" , "AZURE_CLIENT_ID" : "buzz" , "AZURE_FEDERATED_TOKEN_FILE" : "baz" },
150- fileContent : "{\" tenantId\" :\" foo\" ,\" aadClientId\" :\" fizz\" }" ,
151- expectedContent : "{\" aadClientId\" :\" buzz\" ,\" aadFederatedTokenFile\" :\" baz\" ,\" tenantId\" :\" bar\" ,\" useFederatedWorkloadIdentityExtension\" :true}" ,
152- },
153- {
154- name : "all ok, use workload identity while managed identity is not explicitly disabled" ,
155- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , outputFile .Name (), "--enable-azure-workload-identity=true" },
156- envVars : map [string ]string {"AZURE_TENANT_ID" : "bar" , "AZURE_CLIENT_ID" : "buzz" , "AZURE_FEDERATED_TOKEN_FILE" : "baz" },
157- fileContent : "{\" tenantId\" :\" foo\" ,\" aadClientId\" :\" fizz\" }" ,
158- expectedContent : "{\" aadClientId\" :\" buzz\" ,\" aadFederatedTokenFile\" :\" baz\" ,\" tenantId\" :\" bar\" ,\" useFederatedWorkloadIdentityExtension\" :true}" ,
159- },
160- {
161- name : "should fail, client secret is present while federated token file is present" ,
162- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , outputFile .Name (), "--disable-identity-extension-auth" , "--enable-azure-workload-identity=true" },
163- envVars : map [string ]string {"AZURE_TENANT_ID" : "baz" , "AZURE_CLIENT_ID" : "foo" , "AZURE_CLIENT_SECRET" : "bar" , "AZURE_FEDERATED_TOKEN_FILE" : "baz" },
164- expectedErrMsg : "azure_client_secret is set while workload identity is enabled using azure_federated_token_file, this should never happen.\n Please consider reporting a bug: https://issues.redhat.com" ,
165- },
166- {
167- name : "should fail, tenant id missing while federated token file is present" ,
168- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , outputFile .Name (), "--disable-identity-extension-auth" , "--enable-azure-workload-identity=true" },
169- envVars : map [string ]string {"AZURE_CLIENT_ID" : "buzz" , "AZURE_FEDERATED_TOKEN_FILE" : "baz" },
170- expectedErrMsg : "azure_tenant_id should be set up while workload identity is enabled using azure_federated_token_file, this should never happen.\n Please consider reporting a bug: https://issues.redhat.com" ,
171- },
172- {
173- name : "should fail, workload identity can't be enabled because federated token missing, expect secret provided" ,
174- args : []string {"--cloud-config-file-path" , inputFile .Name (), "--output-file-path" , outputFile .Name (), "--disable-identity-extension-auth" , "--enable-azure-workload-identity=true" },
175- envVars : map [string ]string {"AZURE_TENANT_ID" : "bar" , "AZURE_CLIENT_ID" : "buzz" },
176- expectedErrMsg : "azure_client_secret should be set up" ,
177- },
17872 }
17973
18074 for _ , tc := range testCases {
0 commit comments