diff --git a/azure-spring-boot-tests/azure-spring-boot-test-aad/src/test/java/com/microsoft/azure/test/keyvault/group/AADAuthenticationFilterIT.java b/azure-spring-boot-tests/azure-spring-boot-test-aad/src/test/java/com/microsoft/azure/test/keyvault/group/AADAuthenticationFilterIT.java index 84355ab2f..10b233bd6 100644 --- a/azure-spring-boot-tests/azure-spring-boot-test-aad/src/test/java/com/microsoft/azure/test/keyvault/group/AADAuthenticationFilterIT.java +++ b/azure-spring-boot-tests/azure-spring-boot-test-aad/src/test/java/com/microsoft/azure/test/keyvault/group/AADAuthenticationFilterIT.java @@ -51,20 +51,28 @@ public class AADAuthenticationFilterIT { @Test public void testAADAuthenticationFilterWithSingleTenantApp() { - testAADAuthenticationFilter(System.getenv(SINGLE_TENANT_AAD_CLIENT_ID), - System.getenv(SINGLE_TENANT_AAD_CLIENT_SECRET)); + final String clientId = System.getenv(SINGLE_TENANT_AAD_CLIENT_ID); + final String clientSecret = System.getenv(SINGLE_TENANT_AAD_CLIENT_SECRET); + + final OAuthResponse authResponse = OAuthUtils.executeOAuth2ROPCFlow(clientId, clientSecret); + assertNotNull(authResponse); + + testAADAuthenticationFilter(clientId, clientSecret, authResponse.getIdToken()); } @Test public void testAADAuthenticationFilterWithMultiTenantApp() { - testAADAuthenticationFilter(System.getenv(AAD_CLIENT_ID), System.getenv(AAD_CLIENT_SECRET)); - } + final String clientId = System.getenv(AAD_CLIENT_ID); + final String clientSecret = System.getenv(AAD_CLIENT_SECRET); - - private void testAADAuthenticationFilter(String clientId, String clientSecret) { final OAuthResponse authResponse = OAuthUtils.executeOAuth2ROPCFlow(clientId, clientSecret); assertNotNull(authResponse); + testAADAuthenticationFilter(clientId, clientSecret, authResponse.getIdToken()); + } + + + private void testAADAuthenticationFilter(String clientId, String clientSecret, String idToken) { try (AppRunner app = new AppRunner(DumbApp.class)) { app.property("azure.activedirectory.client-id", clientId); @@ -79,7 +87,7 @@ private void testAADAuthenticationFilter(String clientId, String clientSecret) { assertEquals("home", response.getBody()); final HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", String.format("Bearer %s", authResponse.getIdToken())); + headers.set("Authorization", String.format("Bearer %s", idToken)); HttpEntity entity = new HttpEntity(headers); final ResponseEntity response2 = restTemplate.exchange(app.root() + "api/all",