@@ -220,4 +220,78 @@ void test_constructor_with_named_configuration() {
220220 final AwsAuthenticationDecorator decorator = new AwsAuthenticationDecorator (awsCredentialsSupplier , awsConfig , TEST_SERVICE_NAME );
221221 assertThat (decorator , notNullValue ());
222222 }
223+ @ Test
224+ void test_constructor_with_named_configuration_resolves_region_from_supplier_default () {
225+ when (awsConfig .getConfiguration ()).thenReturn ("my_named_config" );
226+ when (awsConfig .getAwsRegion ()).thenReturn (null );
227+ when (awsCredentialsSupplier .getDefaultRegion ()).thenReturn (java .util .Optional .of (Region .EU_WEST_1 ));
228+ when (awsCredentialsSupplier .getProvider ("my_named_config" )).thenReturn (awsCredentialsProvider );
229+
230+ final AwsAuthenticationDecorator decorator = new AwsAuthenticationDecorator (awsCredentialsSupplier , awsConfig , TEST_SERVICE_NAME );
231+
232+ final HttpRequest request = decorator .buildRequest (TEST_URL , TEST_PAYLOAD , null );
233+ final String authHeader = request .headers ().get ("Authorization" );
234+ assertTrue (authHeader .contains ("eu-west-1" ), "Should use region from supplier default when awsConfig.getAwsRegion() is null" );
235+ }
236+
237+ @ Test
238+ void test_constructor_with_named_configuration_uses_explicit_region_when_set () {
239+ when (awsConfig .getConfiguration ()).thenReturn ("my_named_config" );
240+ when (awsConfig .getAwsRegion ()).thenReturn (Region .AP_SOUTHEAST_1 );
241+ when (awsCredentialsSupplier .getProvider ("my_named_config" )).thenReturn (awsCredentialsProvider );
242+
243+ final AwsAuthenticationDecorator decorator = new AwsAuthenticationDecorator (awsCredentialsSupplier , awsConfig , TEST_SERVICE_NAME );
244+
245+ final HttpRequest request = decorator .buildRequest (TEST_URL , TEST_PAYLOAD , null );
246+ final String authHeader = request .headers ().get ("Authorization" );
247+ assertTrue (authHeader .contains ("ap-southeast-1" ), "Should use explicit region from awsConfig when set" );
248+ }
249+
250+ @ Test
251+ void test_constructor_with_named_configuration_calls_getProvider_with_config_name () {
252+ final String configName = "ecs_task_role" ;
253+ when (awsConfig .getConfiguration ()).thenReturn (configName );
254+ when (awsConfig .getAwsRegion ()).thenReturn (TEST_REGION );
255+ when (awsCredentialsSupplier .getProvider (configName )).thenReturn (awsCredentialsProvider );
256+
257+ new AwsAuthenticationDecorator (awsCredentialsSupplier , awsConfig , TEST_SERVICE_NAME );
258+
259+ verify (awsCredentialsSupplier ).getProvider (configName );
260+ }
261+
262+ @ Test
263+ void test_constructor_with_null_config_uses_default_credentials_provider () {
264+ when (awsCredentialsSupplier .getDefaultRegion ()).thenReturn (java .util .Optional .of (TEST_REGION ));
265+ when (awsCredentialsSupplier .getProvider (any (AwsCredentialsOptions .class ))).thenReturn (awsCredentialsProvider );
266+
267+ final AwsAuthenticationDecorator decorator = new AwsAuthenticationDecorator (awsCredentialsSupplier , null , TEST_SERVICE_NAME );
268+
269+ final ArgumentCaptor <AwsCredentialsOptions > captor = ArgumentCaptor .forClass (AwsCredentialsOptions .class );
270+ verify (awsCredentialsSupplier ).getProvider (captor .capture ());
271+ assertTrue (captor .getValue ().isUseDefaultCredentialsProvider (),
272+ "Should use default credentials provider when awsConfig is null" );
273+ }
274+
275+ @ Test
276+ void test_constructor_with_null_config_resolves_region_from_supplier_default () {
277+ when (awsCredentialsSupplier .getDefaultRegion ()).thenReturn (java .util .Optional .of (Region .US_WEST_2 ));
278+ when (awsCredentialsSupplier .getProvider (any (AwsCredentialsOptions .class ))).thenReturn (awsCredentialsProvider );
279+
280+ final AwsAuthenticationDecorator decorator = new AwsAuthenticationDecorator (awsCredentialsSupplier , null , TEST_SERVICE_NAME );
281+
282+ final HttpRequest request = decorator .buildRequest (TEST_URL , TEST_PAYLOAD , null );
283+ final String authHeader = request .headers ().get ("Authorization" );
284+ assertTrue (authHeader .contains ("us-west-2" ), "Should use region from supplier default when config is null" );
285+ }
286+
287+ @ Test
288+ void test_constructor_with_inline_config_does_not_call_getProvider_with_string () {
289+ // awsConfig has no 'configuration' set (returns null) — should use convertToCredentialOptions path
290+ when (awsConfig .getConfiguration ()).thenReturn (null );
291+
292+ createObjectUnderTest ();
293+
294+ verify (awsCredentialsSupplier ).getProvider (any (AwsCredentialsOptions .class ));
295+ verify (awsCredentialsSupplier , org .mockito .Mockito .never ()).getProvider (org .mockito .ArgumentMatchers .anyString ());
296+ }
223297}
0 commit comments