Skip to content

Commit 1cc0be6

Browse files
authored
Enhance aad it for on demand feature (Azure#18896)
* code for on-demand IT * create test user on tests.yml * add log to check test user in on-demand test * update tests.yml to fit with stages\archetype-sdk-tests.yml * add TestStepMavenInputs in AdditionalPlatforms
1 parent e48eb91 commit 1cc0be6

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed

sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/AADSeleniumITHelper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,10 @@ public void logoutTest() {
6363
Assert.assertEquals(username, id);
6464
}
6565

66+
public String httpGetWithIncreamentalConsent(String endpoint) {
67+
driver.get((app.root() + endpoint));
68+
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[type='submit']"))).click();
69+
return wait.until(presenceOfElementLocated(By.tagName("body"))).getText();
70+
}
71+
6672
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.test.aad.selenium.ondemand;
5+
6+
import com.azure.test.aad.selenium.AADSeleniumITHelper;
7+
import org.junit.After;
8+
import org.junit.Assert;
9+
import org.junit.Test;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
12+
import org.springframework.boot.autoconfigure.SpringBootApplication;
13+
import org.springframework.http.ResponseEntity;
14+
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
15+
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
16+
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient;
17+
import org.springframework.web.bind.annotation.GetMapping;
18+
import org.springframework.web.bind.annotation.RestController;
19+
20+
import java.util.Map;
21+
22+
import static com.azure.spring.test.EnvironmentVariable.AAD_USER_NAME_ON_DEMAND;
23+
import static com.azure.spring.test.EnvironmentVariable.AAD_USER_PASSWORD_ON_DEMAND;
24+
import static com.azure.test.aad.selenium.AADSeleniumITHelper.createDefaultProperties;
25+
26+
public class AADOnDemandIT {
27+
private AADSeleniumITHelper aadSeleniumITHelper;
28+
private static final Logger LOGGER = LoggerFactory.getLogger(AADOnDemandIT.class);
29+
30+
@Test
31+
public void onDemandTest() {
32+
Map<String, String> properties = createDefaultProperties();
33+
properties.put("azure.activedirectory.authorization-clients.arm.scopes",
34+
"https://management.azure.com/user_impersonation");
35+
properties.put("azure.activedirectory.authorization-clients.arm.on-demand", "true");
36+
LOGGER.info(AAD_USER_NAME_ON_DEMAND);
37+
38+
aadSeleniumITHelper = new AADSeleniumITHelper(DumbApp.class, properties,
39+
AAD_USER_NAME_ON_DEMAND, AAD_USER_PASSWORD_ON_DEMAND);
40+
aadSeleniumITHelper.logIn();
41+
42+
String httpResponse = aadSeleniumITHelper.httpGet("api/azure");
43+
Assert.assertTrue(httpResponse.contains("azure"));
44+
45+
httpResponse = aadSeleniumITHelper.httpGetWithIncreamentalConsent("api/arm");
46+
Assert.assertTrue(httpResponse.contains("arm"));
47+
}
48+
49+
@After
50+
public void destroy() {
51+
aadSeleniumITHelper.destroy();
52+
}
53+
54+
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
55+
@SpringBootApplication
56+
@RestController
57+
public static class DumbApp {
58+
59+
@GetMapping(value = "/api/azure")
60+
public ResponseEntity<String> azure(
61+
@RegisteredOAuth2AuthorizedClient("azure") OAuth2AuthorizedClient authorizedClient) {
62+
return ResponseEntity.ok("azure");
63+
}
64+
65+
@GetMapping(value = "/api/arm")
66+
public ResponseEntity<String> arm(
67+
@RegisteredOAuth2AuthorizedClient("arm") OAuth2AuthorizedClient authorizedClient) {
68+
return ResponseEntity.ok("arm");
69+
}
70+
}
71+
}

sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/EnvironmentVariable.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ public class EnvironmentVariable {
2121
public static final String AAD_TENANT_ID_2 = System.getenv("AAD_TENANT_ID_2");
2222
public static final String AAD_USER_NAME_1 = System.getenv("AAD_USER_NAME_1");
2323
public static final String AAD_USER_NAME_2 = System.getenv("AAD_USER_NAME_2");
24+
public static final String AAD_USER_NAME_ON_DEMAND = System.getenv("AAD_USER_NAME_ON_DEMAND");
2425
public static final String AAD_USER_PASSWORD_1 = System.getenv("AAD_USER_PASSWORD_1");
2526
public static final String AAD_USER_PASSWORD_2 = System.getenv("AAD_USER_PASSWORD_2");
27+
public static final String AAD_USER_PASSWORD_ON_DEMAND = System.getenv("AAD_USER_PASSWORD_ON_DEMAND");
2628
public static final String AZURE_KEYVAULT2_URI = System.getenv("AZURE_KEYVAULT2_URI");
2729
public static final String AZURE_KEYVAULT_URI = System.getenv("AZURE_KEYVAULT_URI");
2830
public static final String AZURE_STORAGE_ACCOUNT_KEY = System.getenv("AZURE_STORAGE_ACCOUNT_KEY");

sdk/spring/tests.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ stages:
7575
AAD_B2C_USER_PASSWORD: $(java-spring-aad-b2c-user-password)
7676
AAD_B2C_CLIENT_ID: $(java-spring-aad-b2c-client-id)
7777
AAD_B2C_CLIENT_SECRET: $(java-spring-aad-b2c-client-secret)
78+
AAD_USER_NAME_ON_DEMAND: "user$(System.JobId)@aadittest1.onmicrosoft.com"
79+
AAD_USER_PASSWORD_ON_DEMAND: $(java-spring-aad-user-password-1)
80+
AAD_SERVICE_PRICIPAL_CLIENT_ID: $(java-spring-aad-service-principal-client-id)
81+
AAD_SERVICE_PRICIPAL_CLIENT_SECRET: $(java-spring-aad-service-principal-client-secret)
82+
83+
PreSteps:
84+
- powershell: |
85+
az login --allow-no-subscriptions --tenant $(java-spring-aad-tenant-id-1) --service-principal -u $(java-spring-aad-service-principal-client-id) -p $(java-spring-aad-service-principal-client-secret)
86+
az ad user create --user-principal-name "$env:AAD_USER_NAME_ON_DEMAND" --display-name "user$(System.JobId)" --password "$(java-spring-aad-user-password-1)" --force-change-password-next-login false
87+
az logout
88+
env:
89+
AAD_USER_NAME_ON_DEMAND: "user$(System.JobId)@aadittest1.onmicrosoft.com"
90+
displayName: 'Create On-demand test user'
7891
7992
PostSteps:
8093
- script: |
@@ -123,3 +136,16 @@ stages:
123136
AAD_B2C_USER_PASSWORD: $(java-spring-aad-b2c-user-password)
124137
AAD_B2C_CLIENT_ID: $(java-spring-aad-b2c-client-id)
125138
AAD_B2C_CLIENT_SECRET: $(java-spring-aad-b2c-client-secret)
139+
AAD_USER_NAME_ON_DEMAND: "user$(System.JobId)@aadittest1.onmicrosoft.com"
140+
AAD_USER_PASSWORD_ON_DEMAND: $(java-spring-aad-user-password-1)
141+
AAD_SERVICE_PRICIPAL_CLIENT_ID: $(java-spring-aad-service-principal-client-id)
142+
AAD_SERVICE_PRICIPAL_CLIENT_SECRET: $(java-spring-aad-service-principal-client-secret)
143+
144+
- powershell: |
145+
az login --allow-no-subscriptions --tenant $(java-spring-aad-tenant-id-1) --service-principal -u $(java-spring-aad-service-principal-client-id) -p $(java-spring-aad-service-principal-client-secret)
146+
az ad user delete --id "$env:AAD_USER_NAME_ON_DEMAND"
147+
az logout
148+
env:
149+
AAD_USER_NAME_ON_DEMAND: "user$(System.JobId)@aadittest1.onmicrosoft.com"
150+
condition: always()
151+
displayName: 'Delete On-demand test user'

0 commit comments

Comments
 (0)