@@ -104,6 +104,29 @@ public void credentialsProvider_propertyToUseDefaultIsSet_configuresDefaultAwsCr
104
104
.isEqualTo ("testSecretKey" );
105
105
}
106
106
107
+ @ Test
108
+ public void credentialsProvider_dashSeparatedPropertyToUseDefaultIsSet_configuresDefaultAwsCredentialsProvider_existAccessKeyAndSecretKey () {
109
+ // @checkstyle:on
110
+ this .context = new AnnotationConfigApplicationContext ();
111
+ this .context .register (ContextCredentialsAutoConfiguration .class );
112
+ TestPropertyValues
113
+ .of ("cloud.aws.credentials.access-key:testAccessKey" ,
114
+ "cloud.aws.credentials.secret-key:testSecretKey" ,
115
+ "cloud.aws.credentials.use-default-aws-credentials-chain:true" )
116
+ .applyTo (this .context );
117
+ this .context .refresh ();
118
+
119
+ AWSCredentialsProvider awsCredentialsProvider = this .context .getBean (
120
+ AmazonWebserviceClientConfigurationUtils .CREDENTIALS_PROVIDER_BEAN_NAME ,
121
+ AWSCredentialsProvider .class );
122
+ assertThat (awsCredentialsProvider ).isNotNull ();
123
+
124
+ assertThat (awsCredentialsProvider .getCredentials ().getAWSAccessKeyId ())
125
+ .isEqualTo ("testAccessKey" );
126
+ assertThat (awsCredentialsProvider .getCredentials ().getAWSSecretKey ())
127
+ .isEqualTo ("testSecretKey" );
128
+ }
129
+
107
130
@ Test
108
131
public void credentialsProvider_propertyToUseDefaultIsSet_configuresDefaultAwsCredentialsProvider () {
109
132
this .context = new AnnotationConfigApplicationContext ();
@@ -121,6 +144,23 @@ public void credentialsProvider_propertyToUseDefaultIsSet_configuresDefaultAwsCr
121
144
.isAssignableFrom (DefaultAWSCredentialsProviderChain .class )).isTrue ();
122
145
}
123
146
147
+ @ Test
148
+ public void credentialsProvider_dashSeparatedPropertyToUseDefaultIsSet_configuresDefaultAwsCredentialsProvider () {
149
+ this .context = new AnnotationConfigApplicationContext ();
150
+ this .context .register (ContextCredentialsAutoConfiguration .class );
151
+ TestPropertyValues .of ("cloud.aws.credentials.use-default-aws-credentials-chain:true" )
152
+ .applyTo (this .context );
153
+ this .context .refresh ();
154
+
155
+ AWSCredentialsProvider awsCredentialsProvider = this .context .getBean (
156
+ AmazonWebserviceClientConfigurationUtils .CREDENTIALS_PROVIDER_BEAN_NAME ,
157
+ AWSCredentialsProvider .class );
158
+ assertThat (awsCredentialsProvider ).isNotNull ();
159
+
160
+ assertThat (awsCredentialsProvider .getClass ()
161
+ .isAssignableFrom (DefaultAWSCredentialsProviderChain .class )).isTrue ();
162
+ }
163
+
124
164
// @checkstyle:off
125
165
@ Test
126
166
public void credentialsProvider_accessKeyAndSecretKeyConfigured_configuresStaticCredentialsProviderWithAccessAndSecretKey () {
@@ -152,6 +192,37 @@ public void credentialsProvider_accessKeyAndSecretKeyConfigured_configuresStatic
152
192
153
193
}
154
194
195
+ // @checkstyle:off
196
+ @ Test
197
+ public void credentialsProvider_dashSeparatedAccessKeyAndSecretKeyConfigured_configuresStaticCredentialsProviderWithAccessAndSecretKey () {
198
+ // @checkstyle:on
199
+ this .context = new AnnotationConfigApplicationContext ();
200
+ this .context .register (ContextCredentialsAutoConfiguration .class );
201
+ TestPropertyValues .of ("cloud.aws.credentials.access-key:foo" ,
202
+ "cloud.aws.credentials.secret-key:bar" ).applyTo (this .context );
203
+ this .context .refresh ();
204
+ AWSCredentialsProvider awsCredentialsProvider = this .context .getBean (
205
+ AmazonWebserviceClientConfigurationUtils .CREDENTIALS_PROVIDER_BEAN_NAME ,
206
+ AWSCredentialsProviderChain .class );
207
+ assertThat (awsCredentialsProvider ).isNotNull ();
208
+
209
+ @ SuppressWarnings ("unchecked" )
210
+ List <CredentialsProvider > credentialsProviders = (List <CredentialsProvider >) ReflectionTestUtils
211
+ .getField (awsCredentialsProvider , "credentialsProviders" );
212
+ assertThat (credentialsProviders .size ()).isEqualTo (2 );
213
+ assertThat (AWSStaticCredentialsProvider .class
214
+ .isInstance (credentialsProviders .get (0 ))).isTrue ();
215
+ assertThat (
216
+ ProfileCredentialsProvider .class .isInstance (credentialsProviders .get (1 )))
217
+ .isTrue ();
218
+
219
+ assertThat (awsCredentialsProvider .getCredentials ().getAWSAccessKeyId ())
220
+ .isEqualTo ("foo" );
221
+ assertThat (awsCredentialsProvider .getCredentials ().getAWSSecretKey ())
222
+ .isEqualTo ("bar" );
223
+
224
+ }
225
+
155
226
@ Test
156
227
public void credentialsProvider_instanceProfileConfigured_configuresInstanceProfileCredentialsProvider () {
157
228
this .context = new AnnotationConfigApplicationContext ();
@@ -175,6 +246,29 @@ public void credentialsProvider_instanceProfileConfigured_configuresInstanceProf
175
246
.isTrue ();
176
247
}
177
248
249
+ @ Test
250
+ public void credentialsProvider_dashSeparatedInstanceProfileConfigured_configuresInstanceProfileCredentialsProvider () {
251
+ this .context = new AnnotationConfigApplicationContext ();
252
+ this .context .register (ContextCredentialsAutoConfiguration .class );
253
+ TestPropertyValues .of ("cloud.aws.credentials.instance-profile" )
254
+ .applyTo (this .context );
255
+ this .context .refresh ();
256
+ AWSCredentialsProvider awsCredentialsProvider = this .context .getBean (
257
+ AmazonWebserviceClientConfigurationUtils .CREDENTIALS_PROVIDER_BEAN_NAME ,
258
+ AWSCredentialsProvider .class );
259
+ assertThat (awsCredentialsProvider ).isNotNull ();
260
+
261
+ @ SuppressWarnings ("unchecked" )
262
+ List <CredentialsProvider > credentialsProviders = (List <CredentialsProvider >) ReflectionTestUtils
263
+ .getField (awsCredentialsProvider , "credentialsProviders" );
264
+ assertThat (credentialsProviders .size ()).isEqualTo (2 );
265
+ assertThat (EC2ContainerCredentialsProviderWrapper .class
266
+ .isInstance (credentialsProviders .get (0 ))).isTrue ();
267
+ assertThat (
268
+ ProfileCredentialsProvider .class .isInstance (credentialsProviders .get (1 )))
269
+ .isTrue ();
270
+ }
271
+
178
272
@ Test
179
273
public void credentialsProvider_profileNameConfigured_configuresProfileCredentialsProvider () {
180
274
this .context = new AnnotationConfigApplicationContext ();
@@ -202,6 +296,33 @@ public void credentialsProvider_profileNameConfigured_configuresProfileCredentia
202
296
.isEqualTo ("test" );
203
297
}
204
298
299
+ @ Test
300
+ public void credentialsProvider_dashSeparatedProfileNameConfigured_configuresProfileCredentialsProvider () {
301
+ this .context = new AnnotationConfigApplicationContext ();
302
+ this .context .register (ContextCredentialsAutoConfiguration .class );
303
+ TestPropertyValues .of ("cloud.aws.credentials.profile-name:test" )
304
+ .applyTo (this .context );
305
+ this .context .refresh ();
306
+ AWSCredentialsProvider awsCredentialsProvider = this .context .getBean (
307
+ AmazonWebserviceClientConfigurationUtils .CREDENTIALS_PROVIDER_BEAN_NAME ,
308
+ AWSCredentialsProvider .class );
309
+ assertThat (awsCredentialsProvider ).isNotNull ();
310
+
311
+ @ SuppressWarnings ("unchecked" )
312
+ List <CredentialsProvider > credentialsProviders = (List <CredentialsProvider >) ReflectionTestUtils
313
+ .getField (awsCredentialsProvider , "credentialsProviders" );
314
+ assertThat (credentialsProviders .size ()).isEqualTo (2 );
315
+ assertThat (EC2ContainerCredentialsProviderWrapper .class
316
+ .isInstance (credentialsProviders .get (0 ))).isTrue ();
317
+ assertThat (
318
+ ProfileCredentialsProvider .class .isInstance (credentialsProviders .get (1 )))
319
+ .isTrue ();
320
+
321
+ assertThat (
322
+ ReflectionTestUtils .getField (credentialsProviders .get (1 ), "profileName" ))
323
+ .isEqualTo ("test" );
324
+ }
325
+
205
326
@ Test
206
327
public void credentialsProvider_profileNameAndPathConfigured_configuresProfileCredentialsProvider ()
207
328
throws IOException {
@@ -237,4 +358,39 @@ public void credentialsProvider_profileNameAndPathConfigured_configuresProfileCr
237
358
.isEqualTo ("testSecretKey" );
238
359
}
239
360
361
+ @ Test
362
+ public void credentialsProvider_dashSeparatedProfileNameAndPathConfigured_configuresProfileCredentialsProvider ()
363
+ throws IOException {
364
+ this .context = new AnnotationConfigApplicationContext ();
365
+ this .context .register (ContextCredentialsAutoConfiguration .class );
366
+ TestPropertyValues
367
+ .of ("cloud.aws.credentials.profile-name:customProfile" ,
368
+ "cloud.aws.credentials.profile-path:" + new ClassPathResource (
369
+ getClass ().getSimpleName () + "-profile" , getClass ())
370
+ .getFile ().getAbsolutePath ())
371
+ .applyTo (this .context );
372
+ this .context .refresh ();
373
+ AWSCredentialsProvider awsCredentialsProvider = this .context .getBean (
374
+ AmazonWebserviceClientConfigurationUtils .CREDENTIALS_PROVIDER_BEAN_NAME ,
375
+ AWSCredentialsProvider .class );
376
+ assertThat (awsCredentialsProvider ).isNotNull ();
377
+
378
+ @ SuppressWarnings ("unchecked" )
379
+ List <CredentialsProvider > credentialsProviders = (List <CredentialsProvider >) ReflectionTestUtils
380
+ .getField (awsCredentialsProvider , "credentialsProviders" );
381
+ assertThat (credentialsProviders .size ()).isEqualTo (2 );
382
+ assertThat (EC2ContainerCredentialsProviderWrapper .class
383
+ .isInstance (credentialsProviders .get (0 ))).isTrue ();
384
+ assertThat (
385
+ ProfileCredentialsProvider .class .isInstance (credentialsProviders .get (1 )))
386
+ .isTrue ();
387
+
388
+ ProfileCredentialsProvider provider = (ProfileCredentialsProvider ) credentialsProviders
389
+ .get (1 );
390
+ assertThat (provider .getCredentials ().getAWSAccessKeyId ())
391
+ .isEqualTo ("testAccessKey" );
392
+ assertThat (provider .getCredentials ().getAWSSecretKey ())
393
+ .isEqualTo ("testSecretKey" );
394
+ }
395
+
240
396
}
0 commit comments