Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
saragluna committed Mar 15, 2020
1 parent f32234e commit da1016a
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<String> response2 = restTemplate.exchange(app.root() + "api/all",
Expand Down

0 comments on commit da1016a

Please sign in to comment.