Skip to content

Commit a89f94e

Browse files
author
Moary Chen
authored
Add aad b2c integration test in china cloud (Azure#19435)
1 parent 0b37675 commit a89f94e

File tree

10 files changed

+84
-26
lines changed

10 files changed

+84
-26
lines changed

sdk/spring/azure-spring-boot-test-aad-b2c/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@
5151
<version>1.0.0</version> <!-- {x-version-update;com.azure.spring:azure-spring-boot-test-selenium-common;current} -->
5252
<scope>test</scope>
5353
</dependency>
54+
<dependency>
55+
<groupId>ch.qos.logback</groupId>
56+
<artifactId>logback-core</artifactId>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.slf4j</groupId>
60+
<artifactId>slf4j-api</artifactId>
61+
</dependency>
62+
<dependency>
63+
<groupId>ch.qos.logback</groupId>
64+
<artifactId>logback-classic</artifactId>
65+
</dependency>
5466
</dependencies>
5567

5668
</project>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ public static class DumbApp extends WebSecurityConfigurerAdapter {
7979

8080
private final AADB2COidcLoginConfigurer configurer;
8181

82+
private final String profileEdit;
83+
8284
public DumbApp(AADB2COidcLoginConfigurer configurer) {
85+
this.profileEdit = AAD_B2C_PROFILE_EDIT;
8386
this.configurer = configurer;
8487
}
8588

@@ -105,6 +108,7 @@ private void initializeModel(Model model, OAuth2AuthenticationToken token) {
105108
model.addAttribute("grant_type", user.getAuthorities());
106109
model.addAllAttributes(user.getAttributes());
107110
}
111+
model.addAttribute("aadb2c_profileedit", profileEdit);
108112
}
109113
}
110114
}

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,27 @@
88
import static com.azure.spring.test.EnvironmentVariable.AAD_B2C_BASE_URI;
99
import static com.azure.spring.test.EnvironmentVariable.AAD_B2C_USER_EMAIL;
1010
import static com.azure.spring.test.EnvironmentVariable.AAD_B2C_USER_PASSWORD;
11+
import static com.azure.spring.test.EnvironmentVariable.AZURE_CLOUD_TYPE;
1112
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;
1213

14+
import com.azure.spring.test.Constant;
1315
import com.azure.test.aad.common.SeleniumITHelper;
1416
import java.util.HashMap;
1517
import java.util.Map;
18+
1619
import org.openqa.selenium.By;
1720
import org.openqa.selenium.Keys;
1821
import org.openqa.selenium.support.ui.ExpectedConditions;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
1924

2025
public class AADB2CSeleniumITHelper extends SeleniumITHelper {
2126

27+
private static final Logger LOGGER = LoggerFactory.getLogger(AADB2CSeleniumITHelper.class);
28+
2229
private String userEmail;
2330
private String userPassword;
31+
private boolean isAzureCloudGlobal;
2432

2533
public static Map<String, String> createDefaultProperteis() {
2634
Map<String, String> defaultProperteis = new HashMap<>();
@@ -39,20 +47,37 @@ public AADB2CSeleniumITHelper(Class<?> appClass, Map<String, String> properties)
3947
super(appClass, properties);
4048
userEmail = AAD_B2C_USER_EMAIL;
4149
userPassword = AAD_B2C_USER_PASSWORD;
50+
isAzureCloudGlobal = Constant.AZURE_CLOUD_TYPE_GLOBAL.equalsIgnoreCase(AZURE_CLOUD_TYPE);
4251
}
4352

4453
public void logIn() {
4554
driver.get(app.root());
46-
wait.until(presenceOfElementLocated(By.id("email"))).sendKeys(userEmail);
55+
LOGGER.info("Current url is " + driver.getCurrentUrl());
56+
wait.until(ExpectedConditions.urlMatches("^https://"));
57+
if (isAzureCloudGlobal) {
58+
wait.until(presenceOfElementLocated(By.id("email"))).sendKeys(userEmail);
59+
} else {
60+
wait.until(presenceOfElementLocated(By.id("logonIdentifier"))).sendKeys(userEmail);
61+
}
62+
4763
wait.until(presenceOfElementLocated(By.id("password"))).sendKeys(userPassword);
48-
wait.until(presenceOfElementLocated(By.cssSelector("button[type='submit']"))).sendKeys(Keys.ENTER);
64+
65+
if (isAzureCloudGlobal) {
66+
wait.until(presenceOfElementLocated(By.cssSelector("button[type='submit']"))).sendKeys(Keys.ENTER);
67+
} else {
68+
wait.until(presenceOfElementLocated(By.id("next"))).sendKeys(Keys.ENTER);
69+
}
4970
manualRedirection();
5071
}
5172

5273
public void profileEditJobTitle(String newJobTitle) {
5374
wait.until(presenceOfElementLocated(By.id("profileEdit"))).click();
5475
changeJobTile(newJobTitle);
55-
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[type='submit']"))).click();
76+
if (isAzureCloudGlobal) {
77+
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[type='submit']"))).click();
78+
} else {
79+
wait.until(presenceOfElementLocated(By.id("continue"))).sendKeys(Keys.ENTER);
80+
}
5681
manualRedirection();
5782
}
5883

@@ -99,6 +124,10 @@ public String getUserFlowName() {
99124
}
100125

101126
public String getSignInButtonText() {
102-
return wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[type='submit']"))).getText();
127+
if (isAzureCloudGlobal) {
128+
return wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[type='submit']"))).getText();
129+
} else {
130+
return wait.until(ExpectedConditions.elementToBeClickable(By.id("next"))).getText();
131+
}
103132
}
104133
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<configuration>
2+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
3+
<encoder>
4+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
5+
</encoder>
6+
</appender>
7+
8+
<root level="info">
9+
<appender-ref ref="STDOUT" />
10+
</root>
11+
</configuration>

sdk/spring/azure-spring-boot-test-aad-b2c/src/test/resources/templates/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
<h1>Home page</h1>
1313
<div>
14-
<form style="display:inline" method="get" action="/oauth2/authorization/B2C_1_profileediting1">
14+
<form th:if="${aadb2c_profileedit != null}" style="display:inline" method="get"
15+
th:action="${'/oauth2/authorization/' + aadb2c_profileedit}">
1516
<button id="profileEdit" class="btn btn-md btn-primary btn-block" type="submit">Profile edit</button>
1617
</form>
1718
<form style="display:inline" method="get" action="/logout">

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ public class Constant {
99
public static String toFullNameScope(String clientId, String scope) {
1010
return "api://" + clientId + "/" + scope;
1111
}
12+
13+
public static final String AZURE_CLOUD_TYPE_CHINA = "China";
14+
public static final String AZURE_CLOUD_TYPE_GLOBAL = "Global";
1215
}

sdk/spring/azure-spring-boot-test-selenium-common/src/main/java/com/azure/test/aad/common/SeleniumITHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import java.util.Map;
1818

1919
public class SeleniumITHelper {
20-
private static Logger logger = LoggerFactory.getLogger(SeleniumITHelper.class);
20+
private static Logger LOGGER = LoggerFactory.getLogger(SeleniumITHelper.class);
2121
private static String WEB_DRIVER_FOLDER_NAME = "webdriver";
2222

2323
protected AppRunner app;
@@ -39,7 +39,7 @@ protected void createDriver() {
3939
options.addArguments("--headless");
4040
options.addArguments("--incognito", "--no-sandbox", "--disable-dev-shm-usage");
4141
driver = new ChromeDriver(options);
42-
wait = new WebDriverWait(driver, 10);
42+
wait = new WebDriverWait(driver, 15);
4343
}
4444
}
4545

@@ -68,7 +68,7 @@ public void destroy() {
6868

6969
private void setPathExecutableRecursively(File file) {
7070
if (!file.exists()) {
71-
logger.warn("Path " + file + " does not exist!");
71+
LOGGER.warn("Path " + file + " does not exist!");
7272
return;
7373
}
7474

@@ -78,7 +78,7 @@ private void setPathExecutableRecursively(File file) {
7878
}
7979
} else {
8080
if (!file.setExecutable(true)) {
81-
logger.error("Failed to set executable for " + file);
81+
LOGGER.error("Failed to set executable for " + file);
8282
}
8383
}
8484
}

sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationProperties.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.springframework.beans.factory.InitializingBean;
99
import org.springframework.boot.context.properties.ConfigurationProperties;
1010
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
11-
import org.springframework.util.ClassUtils;
1211
import org.springframework.util.StringUtils;
1312
import org.springframework.validation.annotation.Validated;
1413

@@ -144,18 +143,6 @@ public boolean allowedGroupsConfigured() {
144143
.orElse(false);
145144
}
146145

147-
public boolean isResourceServer() {
148-
return ClassUtils.isPresent(
149-
"org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken",
150-
this.getClass().getClassLoader());
151-
}
152-
153-
public boolean isWebApplication() {
154-
return ClassUtils.isPresent(
155-
"org.springframework.security.oauth2.client.registration.ClientRegistrationRepository",
156-
this.getClass().getClassLoader());
157-
}
158-
159146
public UserGroupProperties getUserGroup() {
160147
return userGroup;
161148
}

sdk/spring/spring-test-template.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ parameters:
6565
AAD_SINGLE_TENANT_CLIENT_SECRET: $(java-spring-aad-single-tenant-secret)
6666
AAD_SINGLE_TENANT_CLIENT_ID_WITH_ROLE: $(java-spring-aad-single-tenant-id-with-role)
6767
AAD_SINGLE_TENANT_CLIENT_SECRET_WITH_ROLE: $(java-spring-aad-single-tenant-secret-with-role)
68+
AAD_USER_NAME_ON_DEMAND: "user$(System.JobId)-$(Build.BuildId)@aadittest1.onmicrosoft.com"
69+
AAD_USER_PASSWORD_ON_DEMAND: $(java-spring-aad-user-password-1)
70+
AAD_SERVICE_PRICIPAL_CLIENT_ID: $(java-spring-aad-service-principal-client-id)
71+
AAD_SERVICE_PRICIPAL_CLIENT_SECRET: $(java-spring-aad-service-principal-client-secret)
6872
AAD_B2C_USER_EMAIL: "chrisgreen@abc.com"
6973
AAD_B2C_BASE_URI: "https://B2CITTest1.b2clogin.com/B2CITTest1.onmicrosoft.com"
7074
AAD_B2C_REPLY_URL: "http://localhost:8080/login/oauth2/code/"
@@ -73,10 +77,6 @@ parameters:
7377
AAD_B2C_USER_PASSWORD: $(java-spring-aad-b2c-user-password)
7478
AAD_B2C_CLIENT_ID: $(java-spring-aad-b2c-client-id)
7579
AAD_B2C_CLIENT_SECRET: $(java-spring-aad-b2c-client-secret)
76-
AAD_USER_NAME_ON_DEMAND: "user$(System.JobId)-$(Build.BuildId)@aadittest1.onmicrosoft.com"
77-
AAD_USER_PASSWORD_ON_DEMAND: $(java-spring-aad-user-password-1)
78-
AAD_SERVICE_PRICIPAL_CLIENT_ID: $(java-spring-aad-service-principal-client-id)
79-
AAD_SERVICE_PRICIPAL_CLIENT_SECRET: $(java-spring-aad-service-principal-client-secret)
8080
AZURE_CLOUD_TYPE: "Global"
8181

8282
stages:

sdk/spring/tests.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ stages:
1313
- name: azure-spring-boot-test-aad
1414
groupId: com.azure.spring
1515
safeName: azurespringboottestaad
16+
- name: azure-spring-boot-test-aad-b2c
17+
groupId: com.azure.spring
18+
safeName: azurespringboottestaadb2c
1619
EnvVars:
1720
AZURE_TEST_MODE: LIVE
1821
AAD_TENANT_ID_1: $(java-spring-aad-tenant-id-1-cn)
@@ -31,4 +34,12 @@ stages:
3134
AAD_USER_PASSWORD_ON_DEMAND: $(java-spring-aad-user-password-1-cn)
3235
AAD_SERVICE_PRICIPAL_CLIENT_ID: $(java-spring-aad-service-principal-client-id-cn)
3336
AAD_SERVICE_PRICIPAL_CLIENT_SECRET: $(java-spring-aad-service-principal-client-secret-cn)
37+
AAD_B2C_USER_EMAIL: "moary@126.com"
38+
AAD_B2C_BASE_URI: "https://moaryb2c.b2clogin.cn/moaryb2c.partner.onmschina.cn"
39+
AAD_B2C_REPLY_URL: "http://localhost:8080/login/oauth2/code/"
40+
AAD_B2C_SIGN_UP_OR_SIGN_IN: "B2C_1_signupsignin1"
41+
AAD_B2C_PROFILE_EDIT: "B2C_1_profileediting1"
42+
AAD_B2C_USER_PASSWORD: $(java-spring-aad-b2c-user-password-cn)
43+
AAD_B2C_CLIENT_ID: $(java-spring-aad-b2c-client-id-cn)
44+
AAD_B2C_CLIENT_SECRET: $(java-spring-aad-b2c-client-secret-cn)
3445
AZURE_CLOUD_TYPE: "China"

0 commit comments

Comments
 (0)