extraQueryParameters = new HashMap<>();
extraQueryParameters.put("test", "test");
@@ -43,12 +43,12 @@ void singleAccountInCache_RemoveAccountTest() throws Exception {
.get();
// Check that cache contains one account
- assertEquals(pca.getAccounts().join().size(), 1);
+ assertEquals(1, pca.getAccounts().join().size());
pca.removeAccount(pca.getAccounts().join().iterator().next()).join();
// Check that account has been removed
- assertEquals(pca.getAccounts().join().size(), 0);
+ assertEquals(0, pca.getAccounts().join().size());
}
@Test
@@ -65,7 +65,7 @@ void twoAccountsInCache_SameUserDifferentTenants_RemoveAccountTest() throws Exce
// check that cache is empty
assertEquals(dataToInitCache, "");
- ITokenCacheAccessAspect persistenceAspect = new TokenPersistence(dataToInitCache);
+ ITokenCacheAccessAspect persistenceAspect = new TestTokenCachePersistence(dataToInitCache);
// acquire tokens for home tenant, and serialize cache
PublicClientApplication pca = PublicClientApplication.builder(
@@ -112,22 +112,4 @@ void twoAccountsInCache_SameUserDifferentTenants_RemoveAccountTest() throws Exce
this.getClass(),
"/cache_data/remove-account-test-cache.json");
}
-
- private static class TokenPersistence implements ITokenCacheAccessAspect {
- String data;
-
- TokenPersistence(String data) {
- this.data = data;
- }
-
- @Override
- public void beforeCacheAccess(ITokenCacheAccessContext iTokenCacheAccessContext) {
- iTokenCacheAccessContext.tokenCache().deserialize(data);
- }
-
- @Override
- public void afterCacheAccess(ITokenCacheAccessContext iTokenCacheAccessContext) {
- data = iTokenCacheAccessContext.tokenCache().serialize();
- }
- }
}
diff --git a/msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/UsernamePasswordIT.java b/msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/UsernamePasswordIT.java
index f2ee9121..9b45dc41 100644
--- a/msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/UsernamePasswordIT.java
+++ b/msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/UsernamePasswordIT.java
@@ -59,17 +59,9 @@ void acquireTokenWithUsernamePassword_Ciam() throws Exception {
private void assertAcquireTokenCommon(UserConfig user, String authority, String scope, String appId)
throws Exception {
- PublicClientApplication pca = PublicClientApplication.builder(
- appId).
- authority(authority).
- build();
+ PublicClientApplication pca = IntegrationTestHelper.createPublicApp(appId, authority);
- IAuthenticationResult result = pca.acquireToken(UserNamePasswordParameters.
- builder(Collections.singleton(scope),
- user.getUpn(),
- user.getPassword().toCharArray())
- .build())
- .get();
+ IAuthenticationResult result = IntegrationTestHelper.acquireTokenByRopc(pca, user, scope);
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
assertEquals(user.getUpn(), result.account().username());
@@ -95,7 +87,6 @@ void acquireTokenWithUsernamePassword_B2C_CustomAuthority() throws Exception {
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
IAccount account = pca.getAccounts().join().iterator().next();
- SilentParameters.builder(Collections.singleton(TestConstants.B2C_READ_SCOPE), account);
result = pca.acquireTokenSilently(
SilentParameters.builder(Collections.singleton(TestConstants.B2C_READ_SCOPE), account)
@@ -125,7 +116,6 @@ void acquireTokenWithUsernamePassword_B2C_LoginMicrosoftOnline() throws Exceptio
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
IAccount account = pca.getAccounts().join().iterator().next();
- SilentParameters.builder(Collections.singleton(TestConstants.B2C_READ_SCOPE), account);
result = pca.acquireTokenSilently(
SilentParameters.builder(Collections.singleton(TestConstants.B2C_READ_SCOPE), account)
diff --git a/msal4j-sdk/src/integrationtest/java/infrastructure/SeleniumDiagnostics.java b/msal4j-sdk/src/integrationtest/java/infrastructure/SeleniumDiagnostics.java
new file mode 100644
index 00000000..996d139f
--- /dev/null
+++ b/msal4j-sdk/src/integrationtest/java/infrastructure/SeleniumDiagnostics.java
@@ -0,0 +1,186 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package infrastructure;
+
+import org.openqa.selenium.OutputType;
+import org.openqa.selenium.TakesScreenshot;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.logging.LogEntry;
+import org.openqa.selenium.logging.LogType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Utility for capturing diagnostic information from Selenium WebDriver on test failure.
+ *
+ * Captures screenshots, page source (HTML), and browser console logs to help diagnose
+ * failures in browser-based integration tests. All capture methods are fail-safe and will
+ * not throw exceptions, so they can be called safely during test teardown without masking
+ * the original test failure.
+ *
+ * Output is written to {@code target/selenium-diagnostics/} with filenames that include
+ * the test name and a timestamp for uniqueness.
+ */
+public final class SeleniumDiagnostics {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SeleniumDiagnostics.class);
+ private static final String OUTPUT_DIR = "target/selenium-diagnostics";
+
+ private SeleniumDiagnostics() {
+ }
+
+ /**
+ * Capture all available diagnostics (screenshot, page source, browser logs) for a failed test.
+ *
+ * @param driver the WebDriver instance (may be null)
+ * @param testName the name of the test method that failed
+ */
+ public static void captureAll(WebDriver driver, String testName) {
+ if (driver == null) {
+ LOG.warn("Cannot capture diagnostics: WebDriver is null");
+ return;
+ }
+
+ String sanitizedName = sanitizeFileName(testName);
+ String timestamp = new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date());
+ String filePrefix = sanitizedName + "-" + timestamp;
+
+ captureScreenshot(driver, filePrefix);
+ capturePageSource(driver, filePrefix);
+ captureBrowserLogs(driver, filePrefix);
+ }
+
+ /**
+ * Capture a screenshot of the current browser state.
+ *
+ * @param driver the WebDriver instance
+ * @param filePrefix the file name prefix (test name + timestamp)
+ */
+ static void captureScreenshot(WebDriver driver, String filePrefix) {
+ try {
+ if (!(driver instanceof TakesScreenshot)) {
+ LOG.warn("WebDriver does not support screenshots");
+ return;
+ }
+
+ File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
+ Path destination = getOutputPath(filePrefix + ".png");
+ Files.copy(screenshot.toPath(), destination, StandardCopyOption.REPLACE_EXISTING);
+ LOG.info("Screenshot saved: {}", destination);
+ } catch (Exception e) {
+ LOG.warn("Failed to capture screenshot: {}", e.getMessage());
+ }
+ }
+
+ /**
+ * Capture the current page source (HTML) for element inspection.
+ *
+ * Sensitive parameters (auth codes, tokens, etc.) in URLs and form actions are redacted.
+ *
+ * @param driver the WebDriver instance
+ * @param filePrefix the file name prefix (test name + timestamp)
+ */
+ static void capturePageSource(WebDriver driver, String filePrefix) {
+ try {
+ String pageSource = driver.getPageSource();
+ if (pageSource == null || pageSource.isEmpty()) {
+ LOG.warn("Page source is empty");
+ return;
+ }
+
+ String currentUrl = driver.getCurrentUrl();
+ String redactedUrl = redactSensitiveParams(currentUrl);
+
+ StringBuilder content = new StringBuilder();
+ content.append("\n");
+ content.append("\n");
+ content.append(pageSource);
+
+ Path destination = getOutputPath(filePrefix + ".html");
+ Files.write(destination, content.toString().getBytes("UTF-8"));
+ LOG.info("Page source saved: {}", destination);
+ } catch (Exception e) {
+ LOG.warn("Failed to capture page source: {}", e.getMessage());
+ }
+ }
+
+ /**
+ * Capture browser console logs (JavaScript errors, network issues, etc.).
+ *
+ * @param driver the WebDriver instance
+ * @param filePrefix the file name prefix (test name + timestamp)
+ */
+ static void captureBrowserLogs(WebDriver driver, String filePrefix) {
+ try {
+ List logs = driver.manage().logs().get(LogType.BROWSER).getAll();
+
+ if (logs.isEmpty()) {
+ LOG.debug("No browser console logs to capture");
+ return;
+ }
+
+ StringBuilder content = new StringBuilder();
+ content.append("Browser Console Logs\n");
+ content.append("====================\n\n");
+
+ for (LogEntry entry : logs) {
+ content.append("[").append(entry.getLevel()).append("] ");
+ content.append(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date(entry.getTimestamp())));
+ content.append(" - ").append(redactSensitiveParams(entry.getMessage()));
+ content.append("\n");
+ }
+
+ Path destination = getOutputPath(filePrefix + "-console.log");
+ Files.write(destination, content.toString().getBytes("UTF-8"));
+ LOG.info("Browser logs saved: {}", destination);
+ } catch (Exception e) {
+ LOG.warn("Failed to capture browser logs: {} (this may be expected if logging prefs are not supported)", e.getMessage());
+ }
+ }
+
+ /**
+ * Get the output path for a diagnostic file, creating the directory if needed.
+ */
+ private static Path getOutputPath(String fileName) throws IOException {
+ Path dir = Paths.get(OUTPUT_DIR);
+ if (!Files.exists(dir)) {
+ Files.createDirectories(dir);
+ }
+ return dir.resolve(fileName);
+ }
+
+ /**
+ * Sanitize a test name to be safe for use as a file name on all platforms.
+ * Removes/replaces characters that are invalid in Windows file paths.
+ */
+ private static String sanitizeFileName(String name) {
+ if (name == null) {
+ return "unknown";
+ }
+ return name.replaceAll("[^a-zA-Z0-9._-]", "_");
+ }
+
+ /**
+ * Redact sensitive OAuth parameters from URLs and log messages.
+ * Replaces values of known sensitive query parameters with "[REDACTED]".
+ */
+ public static String redactSensitiveParams(String text) {
+ if (text == null) {
+ return "";
+ }
+ return text.replaceAll(
+ "(?i)(code|access_token|id_token|refresh_token|client_secret|password|assertion)=([^&\\s\"']*)",
+ "$1=[REDACTED]");
+ }
+}
diff --git a/msal4j-sdk/src/integrationtest/java/infrastructure/SeleniumExtensions.java b/msal4j-sdk/src/integrationtest/java/infrastructure/SeleniumExtensions.java
index 7a171b05..25bcb8da 100644
--- a/msal4j-sdk/src/integrationtest/java/infrastructure/SeleniumExtensions.java
+++ b/msal4j-sdk/src/integrationtest/java/infrastructure/SeleniumExtensions.java
@@ -6,18 +6,21 @@
import com.microsoft.aad.msal4j.labapi.UserConfig;
import infrastructure.pageobjects.ADFSLoginPage;
import infrastructure.pageobjects.AzureADLoginPage;
-import infrastructure.pageobjects.B2CLocalLoginPage;
+import infrastructure.pageobjects.CIAMLoginPage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
+import org.openqa.selenium.logging.LogType;
+import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Duration;
+import java.util.logging.Level;
public class SeleniumExtensions {
@@ -28,17 +31,67 @@ private SeleniumExtensions() {
public static WebDriver createDefaultWebDriver() {
ChromeOptions options = new ChromeOptions();
- options.addArguments("--headless");
+ options.addArguments("--headless=new");
options.addArguments("--incognito");
+ // Enable browser console logging for diagnostic capture on failure
+ LoggingPreferences logPrefs = new LoggingPreferences();
+ logPrefs.enable(LogType.BROWSER, Level.ALL);
+ options.setCapability("goog:loggingPrefs", logPrefs);
+
return new ChromeDriver(options);
}
public static WebElement waitForElementToBeVisibleAndEnabled(WebDriver driver, By by, Duration timeout) {
- WebDriverWait wait = new WebDriverWait(driver, timeout.getSeconds());
+ WebDriverWait wait = new WebDriverWait(driver, timeout);
return wait.until(ExpectedConditions.elementToBeClickable(by));
}
+ /**
+ * Wait for any one of several locators to match a clickable element, returning the first match.
+ *
+ * This uses a single wait loop that checks all locators on each poll cycle, so the total
+ * wait time is bounded by {@code timeout} regardless of how many locators are provided.
+ * When a fallback locator matches (not the primary), a warning is logged to flag that
+ * the page structure may have changed.
+ *
+ * @param driver the WebDriver instance
+ * @param timeout maximum time to wait for any locator to match
+ * @param locators one or more locators to try, in priority order (primary first)
+ * @return the first clickable WebElement found
+ * @throws org.openqa.selenium.TimeoutException if no locator matches within the timeout
+ */
+ public static WebElement findWithFallback(WebDriver driver, Duration timeout, By... locators) {
+ if (locators.length == 0) {
+ throw new IllegalArgumentException("At least one locator must be provided");
+ }
+
+ if (locators.length == 1) {
+ return waitForElementToBeVisibleAndEnabled(driver, locators[0], timeout);
+ }
+
+ WebDriverWait wait = new WebDriverWait(driver, timeout);
+ final By primaryLocator = locators[0];
+
+ return wait.until(d -> {
+ for (By locator : locators) {
+ try {
+ WebElement element = d.findElement(locator);
+ if (element != null && element.isDisplayed() && element.isEnabled()) {
+ if (!locator.equals(primaryLocator)) {
+ LOG.warn("Primary locator {} not found, matched fallback: {}",
+ primaryLocator, locator);
+ }
+ return element;
+ }
+ } catch (Exception ignored) {
+ // Element not found with this locator, try next
+ }
+ }
+ return null;
+ });
+ }
+
public static void performADOrCiamLogin(WebDriver driver, UserConfig user) {
LOG.info("performADOrCiamLogin for user: {}", user.getUpn());
@@ -53,10 +106,10 @@ public static void performADFSLogin(WebDriver driver, UserConfig user) {
loginPage.login(user.getUpn(), user.getPassword());
}
- public static void performLocalLogin(WebDriver driver, UserConfig user) {
- LOG.info("performLocalLogin");
+ public static void performCiamLogin(WebDriver driver, UserConfig user) {
+ LOG.info("performCiamLogin for user: {}", user.getUpn());
- B2CLocalLoginPage loginPage = new B2CLocalLoginPage(driver);
+ CIAMLoginPage loginPage = new CIAMLoginPage(driver);
loginPage.login(user.getUpn(), user.getPassword());
}
diff --git a/msal4j-sdk/src/integrationtest/java/infrastructure/SeleniumTestWatcher.java b/msal4j-sdk/src/integrationtest/java/infrastructure/SeleniumTestWatcher.java
new file mode 100644
index 00000000..972054dc
--- /dev/null
+++ b/msal4j-sdk/src/integrationtest/java/infrastructure/SeleniumTestWatcher.java
@@ -0,0 +1,70 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package infrastructure;
+
+import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.openqa.selenium.WebDriver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * JUnit 5 extension that captures Selenium diagnostics (screenshot, page source, browser logs)
+ * when a test fails.
+ *
+ * This extension uses {@link AfterTestExecutionCallback} which runs after the test method
+ * but before {@code @AfterEach} teardown. This ordering is critical because it ensures
+ * the WebDriver is still alive when diagnostics are captured — the driver is typically closed
+ * in {@code @AfterEach}.
+ *
+ * Test classes must implement {@link WebDriverProvider} to expose their WebDriver instance.
+ * If the test class does not implement the interface, or the driver is null, diagnostics
+ * are silently skipped.
+ *
+ * Usage:
+ *
+ * {@literal @}ExtendWith(SeleniumTestWatcher.class)
+ * class MySeleniumTest implements WebDriverProvider {
+ * WebDriver driver;
+ *
+ * public WebDriver getWebDriver() { return driver; }
+ * }
+ *
+ *
+ * @see SeleniumDiagnostics
+ * @see WebDriverProvider
+ */
+public class SeleniumTestWatcher implements AfterTestExecutionCallback {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SeleniumTestWatcher.class);
+
+ @Override
+ public void afterTestExecution(ExtensionContext context) {
+ // Only capture diagnostics if the test failed
+ if (!context.getExecutionException().isPresent()) {
+ return;
+ }
+
+ Object testInstance = context.getTestInstance().orElse(null);
+ if (!(testInstance instanceof WebDriverProvider)) {
+ LOG.debug("Test class does not implement WebDriverProvider, skipping diagnostics");
+ return;
+ }
+
+ WebDriver driver = ((WebDriverProvider) testInstance).getWebDriver();
+ if (driver == null) {
+ LOG.warn("WebDriver is null, cannot capture diagnostics for failed test: {}",
+ context.getDisplayName());
+ return;
+ }
+
+ String testName = context.getTestClass()
+ .map(Class::getSimpleName)
+ .orElse("UnknownClass")
+ + "." + context.getDisplayName();
+
+ LOG.info("Test failed: {} — capturing diagnostics", testName);
+ SeleniumDiagnostics.captureAll(driver, testName);
+ }
+}
diff --git a/msal4j-sdk/src/integrationtest/java/infrastructure/WebDriverProvider.java b/msal4j-sdk/src/integrationtest/java/infrastructure/WebDriverProvider.java
new file mode 100644
index 00000000..dec68801
--- /dev/null
+++ b/msal4j-sdk/src/integrationtest/java/infrastructure/WebDriverProvider.java
@@ -0,0 +1,21 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package infrastructure;
+
+import org.openqa.selenium.WebDriver;
+
+/**
+ * Interface for test classes that manage a WebDriver instance.
+ * Used by {@link SeleniumTestWatcher} to access the driver for diagnostics on test failure.
+ */
+public interface WebDriverProvider {
+
+ /**
+ * Returns the current WebDriver instance, or null if the driver has not been initialized
+ * or has already been closed.
+ *
+ * @return the WebDriver instance, or null
+ */
+ WebDriver getWebDriver();
+}
diff --git a/msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/ADFSLoginPage.java b/msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/ADFSLoginPage.java
index ec7ccd0a..aaa30a4e 100644
--- a/msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/ADFSLoginPage.java
+++ b/msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/ADFSLoginPage.java
@@ -3,10 +3,9 @@
package infrastructure.pageobjects;
+import infrastructure.SeleniumExtensions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
-import org.openqa.selenium.support.ui.ExpectedConditions;
-import org.openqa.selenium.support.ui.WebDriverWait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -15,24 +14,37 @@
/**
* Page Object Model for ADFS login page.
* Represents the Active Directory Federation Services authentication flow.
+ *
+ * Uses fallback locators to handle ADFS version differences where element IDs
+ * may vary between ADFS 2019, 2022, and other versions.
*/
public class ADFSLoginPage {
private static final Logger LOG = LoggerFactory.getLogger(ADFSLoginPage.class);
private final WebDriver driver;
- private final WebDriverWait wait;
- // Element locators
- private static final By USERNAME_INPUT = By.id("userNameInput");
- private static final By PASSWORD_INPUT = By.id("passwordInput");
- private static final By SUBMIT_BUTTON = By.id("submitButton");
+ // Element locators with fallbacks for different ADFS versions
+ private static final By[] USERNAME_LOCATORS = {
+ By.id("userNameInput"),
+ By.id("ContentPlaceHolder1_UsernameTextBox"),
+ By.cssSelector("input[type='text'][name='UserName']"),
+ };
+ private static final By[] PASSWORD_LOCATORS = {
+ By.id("passwordInput"),
+ By.id("ContentPlaceHolder1_PasswordTextBox"),
+ By.cssSelector("input[type='password'][name='Password']"),
+ };
+ private static final By[] SUBMIT_LOCATORS = {
+ By.id("submitButton"),
+ By.id("ContentPlaceHolder1_SubmitButton"),
+ By.cssSelector("span[id='submitButton']"),
+ };
private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(15);
public ADFSLoginPage(WebDriver driver) {
this.driver = driver;
- this.wait = new WebDriverWait(driver, DEFAULT_TIMEOUT.getSeconds());
}
/**
@@ -43,7 +55,7 @@ public ADFSLoginPage(WebDriver driver) {
*/
public ADFSLoginPage enterUsername(String username) {
LOG.info("Entering username: {}", username);
- wait.until(ExpectedConditions.elementToBeClickable(USERNAME_INPUT))
+ SeleniumExtensions.findWithFallback(driver, DEFAULT_TIMEOUT, USERNAME_LOCATORS)
.sendKeys(username);
return this;
}
@@ -56,7 +68,7 @@ public ADFSLoginPage enterUsername(String username) {
*/
public ADFSLoginPage enterPassword(String password) {
LOG.info("Entering password");
- wait.until(ExpectedConditions.elementToBeClickable(PASSWORD_INPUT))
+ SeleniumExtensions.findWithFallback(driver, DEFAULT_TIMEOUT, PASSWORD_LOCATORS)
.sendKeys(password);
return this;
}
@@ -68,7 +80,7 @@ public ADFSLoginPage enterPassword(String password) {
*/
public ADFSLoginPage clickSubmit() {
LOG.info("Clicking submit button");
- wait.until(ExpectedConditions.elementToBeClickable(SUBMIT_BUTTON))
+ SeleniumExtensions.findWithFallback(driver, DEFAULT_TIMEOUT, SUBMIT_LOCATORS)
.click();
return this;
}
diff --git a/msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/AzureADLoginPage.java b/msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/AzureADLoginPage.java
index dcaab635..69b609ad 100644
--- a/msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/AzureADLoginPage.java
+++ b/msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/AzureADLoginPage.java
@@ -3,6 +3,7 @@
package infrastructure.pageobjects;
+import infrastructure.SeleniumExtensions;
import org.openqa.selenium.By;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
@@ -16,6 +17,9 @@
/**
* Page Object Model for Azure AD login page.
* Represents the standard Azure AD authentication flow.
+ *
+ * Uses fallback locators for username/password fields to handle variations
+ * in the Azure AD login page across different tenants and configurations.
*/
public class AzureADLoginPage {
@@ -24,9 +28,17 @@ public class AzureADLoginPage {
private final WebDriver driver;
private final WebDriverWait wait;
- // Element locators
- private static final By USERNAME_INPUT = By.id("i0116");
- private static final By PASSWORD_INPUT = By.id("i0118");
+ // Element locators with fallbacks
+ private static final By[] USERNAME_LOCATORS = {
+ By.id("i0116"),
+ By.name("loginfmt"),
+ By.cssSelector("input[type='email'][name='loginfmt']"),
+ };
+ private static final By[] PASSWORD_LOCATORS = {
+ By.id("i0118"),
+ By.name("passwd"),
+ By.cssSelector("input[type='password'][name='passwd']"),
+ };
private static final By NEXT_BUTTON = By.id("idSIButton9");
private static final By SUBMIT_BUTTON = By.id("idSIButton9");
@@ -43,7 +55,7 @@ public class AzureADLoginPage {
public AzureADLoginPage(WebDriver driver) {
this.driver = driver;
- this.wait = new WebDriverWait(driver, DEFAULT_TIMEOUT.getSeconds());
+ this.wait = new WebDriverWait(driver, DEFAULT_TIMEOUT);
}
/**
@@ -54,7 +66,7 @@ public AzureADLoginPage(WebDriver driver) {
*/
public AzureADLoginPage enterUsername(String username) {
LOG.info("Entering username: {}", username);
- wait.until(ExpectedConditions.elementToBeClickable(USERNAME_INPUT))
+ SeleniumExtensions.findWithFallback(driver, DEFAULT_TIMEOUT, USERNAME_LOCATORS)
.sendKeys(username);
return this;
}
@@ -79,7 +91,7 @@ public AzureADLoginPage clickNext() {
*/
public AzureADLoginPage enterPassword(String password) {
LOG.info("Entering password");
- wait.until(ExpectedConditions.elementToBeClickable(PASSWORD_INPUT))
+ SeleniumExtensions.findWithFallback(driver, DEFAULT_TIMEOUT, PASSWORD_LOCATORS)
.sendKeys(password);
return this;
}
@@ -103,7 +115,7 @@ public AzureADLoginPage clickSubmit() {
*/
public boolean isAuthenticationComplete() {
try {
- WebDriverWait shortWait = new WebDriverWait(driver, SHORT_TIMEOUT.getSeconds());
+ WebDriverWait shortWait = new WebDriverWait(driver, SHORT_TIMEOUT);
shortWait.until(ExpectedConditions.textToBePresentInElementLocated(
AUTH_COMPLETE_BODY, AUTH_COMPLETE_TEXT));
LOG.info("Authentication complete page detected");
@@ -150,7 +162,7 @@ private void handleOptionalPrompts() {
private void handleAreYouTryingToSignInPrompt() {
try {
LOG.info("Checking for 'Are you trying to sign in' prompt");
- WebDriverWait shortWait = new WebDriverWait(driver, SHORT_TIMEOUT.getSeconds());
+ WebDriverWait shortWait = new WebDriverWait(driver, SHORT_TIMEOUT);
shortWait.until(ExpectedConditions.elementToBeClickable(ARE_YOU_TRYING_TO_SIGN_IN_BUTTON))
.click();
LOG.info("Clicked Continue on 'Are you trying to sign in' prompt");
@@ -165,7 +177,7 @@ private void handleAreYouTryingToSignInPrompt() {
private void handleStaySignedInPrompt() {
try {
LOG.info("Checking for 'Stay signed in' prompt");
- WebDriverWait shortWait = new WebDriverWait(driver, SHORT_TIMEOUT.getSeconds());
+ WebDriverWait shortWait = new WebDriverWait(driver, SHORT_TIMEOUT);
shortWait.until(ExpectedConditions.elementToBeClickable(STAY_SIGNED_IN_NO_BUTTON))
.click();
LOG.info("Clicked No on 'Stay signed in' prompt");
diff --git a/msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/B2CLocalLoginPage.java b/msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/B2CLocalLoginPage.java
deleted file mode 100644
index 98bbf182..00000000
--- a/msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/B2CLocalLoginPage.java
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-package infrastructure.pageobjects;
-
-import com.microsoft.aad.msal4j.TestConstants;
-import org.openqa.selenium.By;
-import org.openqa.selenium.WebDriver;
-import org.openqa.selenium.support.ui.ExpectedConditions;
-import org.openqa.selenium.support.ui.WebDriverWait;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.time.Duration;
-
-/**
- * Page Object Model for B2C Local Account login page.
- * Represents the Azure AD B2C local account authentication flow.
- */
-public class B2CLocalLoginPage {
-
- private static final Logger LOG = LoggerFactory.getLogger(B2CLocalLoginPage.class);
-
- private final WebDriver driver;
- private final WebDriverWait wait;
-
- // Element locators
- private static final By LOCAL_ACCOUNT_BUTTON = By.id("SignInWithLogonNameExchange");
- private static final By USERNAME_INPUT = By.id("cred_userid_inputtext");
- private static final By PASSWORD_INPUT = By.id("cred_password_inputtext");
- private static final By SIGN_IN_BUTTON = By.id("cred_sign_in_button");
-
- private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(15);
-
- public B2CLocalLoginPage(WebDriver driver) {
- this.driver = driver;
- this.wait = new WebDriverWait(driver, DEFAULT_TIMEOUT.getSeconds());
- }
-
- /**
- * Click the local account sign-in option.
- *
- * @return This page object for method chaining
- */
- public B2CLocalLoginPage clickLocalAccount() {
- LOG.info("Clicking local account button");
- wait.until(ExpectedConditions.elementToBeClickable(LOCAL_ACCOUNT_BUTTON))
- .click();
- return this;
- }
-
- /**
- * Enter the username in the B2C login page.
- *
- * @param username The username to enter
- * @return This page object for method chaining
- */
- public B2CLocalLoginPage enterUsername(String username) {
- LOG.info("Entering username: {}", TestConstants.B2C_UPN);
- wait.until(ExpectedConditions.elementToBeClickable(USERNAME_INPUT))
- .sendKeys(TestConstants.B2C_UPN);
- return this;
- }
-
- /**
- * Enter the password in the B2C login page.
- *
- * @param password The password to enter
- * @return This page object for method chaining
- */
- public B2CLocalLoginPage enterPassword(String password) {
- LOG.info("Entering password");
- wait.until(ExpectedConditions.elementToBeClickable(PASSWORD_INPUT))
- .sendKeys(password);
- return this;
- }
-
- /**
- * Click the Sign in button to complete login.
- *
- * @return This page object for method chaining
- */
- public B2CLocalLoginPage clickSignIn() {
- LOG.info("Clicking sign in button");
- wait.until(ExpectedConditions.elementToBeClickable(SIGN_IN_BUTTON))
- .click();
- return this;
- }
-
- /**
- * Perform a complete B2C local account login flow.
- * This is a convenience method that chains all the necessary steps.
- *
- * @param username The username
- * @param password The password
- */
- public void login(String username, String password) {
- clickLocalAccount()
- .enterUsername(username)
- .enterPassword(password)
- .clickSignIn();
-
- LOG.info("B2C local login completed");
- }
-}
diff --git a/msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/CIAMLoginPage.java b/msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/CIAMLoginPage.java
new file mode 100644
index 00000000..6fc26ced
--- /dev/null
+++ b/msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/CIAMLoginPage.java
@@ -0,0 +1,128 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package infrastructure.pageobjects;
+
+import infrastructure.SeleniumExtensions;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.time.Duration;
+
+/**
+ * Page Object Model for CIAM (Customer Identity and Access Management) login page.
+ * Represents the Azure AD CIAM authentication flow, which uses a multi-step form
+ * with different element IDs than the standard Azure AD login page.
+ *
+ * CIAM login flow:
+ * 1. Enter email address
+ * 2. Click Next
+ * 3. Enter password
+ * 4. Click Sign in
+ *
+ * Uses fallback locators to handle variations in CIAM tenant configurations.
+ */
+public class CIAMLoginPage {
+
+ private static final Logger LOG = LoggerFactory.getLogger(CIAMLoginPage.class);
+
+ private final WebDriver driver;
+
+ // Username step locators
+ private static final By[] USERNAME_LOCATORS = {
+ By.name("username"),
+ By.cssSelector("input[type='text'][autocomplete*='username']"),
+ By.cssSelector("input[type='email']"),
+ };
+ private static final By[] NEXT_BUTTON_LOCATORS = {
+ By.id("usernamePrimaryButton"),
+ By.cssSelector("button[type='submit'][aria-label='Next']"),
+ By.cssSelector("button.ext-primary[type='submit']"),
+ };
+
+ // Password step locators
+ private static final By[] PASSWORD_LOCATORS = {
+ By.name("password"),
+ By.id("password"),
+ By.cssSelector("input[type='password']"),
+ };
+ private static final By[] SIGN_IN_BUTTON_LOCATORS = {
+ By.id("passwordPrimaryButton"),
+ By.cssSelector("button[type='submit'][aria-label='Sign in']"),
+ By.cssSelector("button.ext-primary[type='submit']"),
+ };
+
+ private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(15);
+
+ public CIAMLoginPage(WebDriver driver) {
+ this.driver = driver;
+ }
+
+ /**
+ * Enter the username/email in the CIAM login page.
+ *
+ * @param username The email address to enter
+ * @return This page object for method chaining
+ */
+ public CIAMLoginPage enterUsername(String username) {
+ LOG.info("Entering username: {}", username);
+ SeleniumExtensions.findWithFallback(driver, DEFAULT_TIMEOUT, USERNAME_LOCATORS)
+ .sendKeys(username);
+ return this;
+ }
+
+ /**
+ * Click the Next button after entering the username.
+ *
+ * @return This page object for method chaining
+ */
+ public CIAMLoginPage clickNext() {
+ LOG.info("Clicking Next button");
+ SeleniumExtensions.findWithFallback(driver, DEFAULT_TIMEOUT, NEXT_BUTTON_LOCATORS)
+ .click();
+ return this;
+ }
+
+ /**
+ * Enter the password in the CIAM login page.
+ *
+ * @param password The password to enter
+ * @return This page object for method chaining
+ */
+ public CIAMLoginPage enterPassword(String password) {
+ LOG.info("Entering password");
+ SeleniumExtensions.findWithFallback(driver, DEFAULT_TIMEOUT, PASSWORD_LOCATORS)
+ .sendKeys(password);
+ return this;
+ }
+
+ /**
+ * Click the Sign in button to complete login.
+ *
+ * @return This page object for method chaining
+ */
+ public CIAMLoginPage clickSignIn() {
+ LOG.info("Clicking Sign in button");
+ SeleniumExtensions.findWithFallback(driver, DEFAULT_TIMEOUT, SIGN_IN_BUTTON_LOCATORS)
+ .click();
+ return this;
+ }
+
+ /**
+ * Perform a complete CIAM login flow.
+ * This is a convenience method that chains all the necessary steps.
+ *
+ * @param username The email address
+ * @param password The password
+ */
+ public void login(String username, String password) {
+ enterUsername(username)
+ .clickNext()
+ .enterPassword(password)
+ .clickSignIn();
+
+ LOG.info("CIAM login completed");
+ }
+}
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AadInstanceDiscoveryTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AadInstanceDiscoveryTest.java
index f28aec53..12123d93 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AadInstanceDiscoveryTest.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AadInstanceDiscoveryTest.java
@@ -138,9 +138,9 @@ void aadInstanceDiscoveryTest_AutoDetectRegion_NoRegionDetected() throws Excepti
}
void assertValidResponse(InstanceDiscoveryMetadataEntry entry) {
- assertEquals(entry.preferredNetwork(), "login.microsoftonline.com");
- assertEquals(entry.preferredCache(), "login.windows.net");
- assertEquals(entry.aliases().size(), 4);
+ assertEquals("login.microsoftonline.com", entry.preferredNetwork());
+ assertEquals("login.windows.net", entry.preferredCache());
+ assertEquals(4, entry.aliases().size());
assertTrue(entry.aliases().contains("login.microsoftonline.com"));
assertTrue(entry.aliases().contains("login.windows.net"));
assertTrue(entry.aliases().contains("login.microsoft.com"));
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AccountTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AccountTest.java
index 10807817..60b5f434 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AccountTest.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AccountTest.java
@@ -91,22 +91,22 @@ ITokenCacheAccessAspect init(String data) {
Set accounts = pca.getAccounts().join();
- assertEquals(accounts.size(), 1);
+ assertEquals(1, accounts.size());
IAccount account = accounts.iterator().next();
Map tenantProfiles = account.getTenantProfiles();
- assertEquals(tenantProfiles.size(), 2);
+ assertEquals(2, tenantProfiles.size());
assertTrue(tenantProfiles.containsKey(BLACK_FORESRT_TENANT));
assertTrue(tenantProfiles.containsKey(WW_TENTANT));
pca.removeAccount(account).join();
accounts = pca.getAccounts().join();
- assertEquals(accounts.size(), 0);
+ assertEquals(0, accounts.size());
- assertEquals(pca.tokenCache.accounts.size(), 0);
- assertEquals(pca.tokenCache.idTokens.size(), 0);
- assertEquals(pca.tokenCache.refreshTokens.size(), 0);
- assertEquals(pca.tokenCache.accessTokens.size(), 0);
+ assertEquals(0, pca.tokenCache.accounts.size());
+ assertEquals(0, pca.tokenCache.idTokens.size());
+ assertEquals(0, pca.tokenCache.refreshTokens.size());
+ assertEquals(0, pca.tokenCache.accessTokens.size());
}
}
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AcquireTokenSilentlyTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AcquireTokenSilentlyTest.java
index f957a079..aae1214d 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AcquireTokenSilentlyTest.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AcquireTokenSilentlyTest.java
@@ -13,10 +13,6 @@
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.mockito.Mockito.*;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.concurrent.CompletableFuture;
@@ -28,7 +24,7 @@
class AcquireTokenSilentlyTest {
Account basicAccount = new Account("home_account_id", "login.windows.net", "username", null);
- String cache = readResource("/AAD_cache_data/full_cache.json");
+ String cache = TestHelper.readResource(this.getClass(), "/AAD_cache_data/full_cache.json");
@Test
void publicAppAcquireTokenSilently_emptyCache_MsalClientException() throws Throwable {
@@ -209,12 +205,4 @@ private void assertRefreshedToken(IAuthenticationResult result, String expectedT
assertEquals(expectedToken, result.accessToken());
assertEquals(expectedReason, result.metadata().cacheRefreshReason());
}
-
- String readResource(String resource) {
- try {
- return new String(Files.readAllBytes(Paths.get(getClass().getResource(resource).toURI())));
- } catch (IOException | URISyntaxException e) {
- throw new RuntimeException(e);
- }
- }
}
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AuthorityTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AuthorityTest.java
index 326e933f..3af3e794 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AuthorityTest.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AuthorityTest.java
@@ -19,31 +19,31 @@ class AuthorityTest {
@Test
void testDetectAuthorityType_AAD() throws Exception {
URL url = new URL(TestConfiguration.AAD_TENANT_ENDPOINT);
- assertEquals(Authority.detectAuthorityType(url), AuthorityType.AAD);
+ assertEquals(AuthorityType.AAD, Authority.detectAuthorityType(url));
}
@Test
void testDetectAuthorityType_ADFS() throws Exception {
URL url = new URL(TestConfiguration.ADFS_TENANT_ENDPOINT);
- assertEquals(Authority.detectAuthorityType(url), AuthorityType.ADFS);
+ assertEquals(AuthorityType.ADFS, Authority.detectAuthorityType(url));
}
@Test
void testDetectAuthorityType_B2C() throws Exception {
URL url = new URL(TestConfiguration.B2C_AUTHORITY);
- assertEquals(Authority.detectAuthorityType(url), AuthorityType.B2C);
+ assertEquals(AuthorityType.B2C, Authority.detectAuthorityType(url));
}
@ParameterizedTest
@MethodSource("com.microsoft.aad.msal4j.AuthorityTest#ciamAuthorities")
void testDetectAuthorityType_CIAM(URL authority) throws Exception {
- assertEquals(Authority.detectAuthorityType(authority), AuthorityType.CIAM);
+ assertEquals(AuthorityType.CIAM, Authority.detectAuthorityType(authority));
}
@ParameterizedTest
@MethodSource("com.microsoft.aad.msal4j.AuthorityTest#validCiamAuthoritiesAndTransformedAuthority")
void testCiamAuthorityTransformation(URL authority, URL transformedAuthority) throws Exception {
- assertEquals(CIAMAuthority.transformAuthority(authority), transformedAuthority);
+ assertEquals(transformedAuthority, CIAMAuthority.transformAuthority(authority));
}
@Test
@@ -100,35 +100,35 @@ void testValidateAuthorityEmptyPath() {
void testConstructor_AADAuthority() throws MalformedURLException {
final AADAuthority aa = new AADAuthority(new URL(TestConfiguration.AAD_TENANT_ENDPOINT));
assertNotNull(aa);
- assertEquals(aa.authority(),
- TestConfiguration.AAD_TENANT_ENDPOINT);
- assertEquals(aa.host(), TestConfiguration.AAD_HOST_NAME);
- assertEquals(aa.tokenEndpoint(),
- TestConfiguration.AAD_TENANT_ENDPOINT + "oauth2/v2.0/token");
- assertEquals(aa.selfSignedJwtAudience(),
- TestConfiguration.AAD_TENANT_ENDPOINT + "oauth2/v2.0/token");
- assertEquals(aa.tokenEndpoint(),
- TestConfiguration.AAD_TENANT_ENDPOINT + "oauth2/v2.0/token");
- assertEquals(aa.authorityType(), AuthorityType.AAD);
+ assertEquals(TestConfiguration.AAD_TENANT_ENDPOINT,
+ aa.authority());
+ assertEquals(TestConfiguration.AAD_HOST_NAME, aa.host());
+ assertEquals(TestConfiguration.AAD_TENANT_ENDPOINT + "oauth2/v2.0/token",
+ aa.tokenEndpoint());
+ assertEquals(TestConfiguration.AAD_TENANT_ENDPOINT + "oauth2/v2.0/token",
+ aa.selfSignedJwtAudience());
+ assertEquals(TestConfiguration.AAD_TENANT_ENDPOINT + "oauth2/v2.0/token",
+ aa.tokenEndpoint());
+ assertEquals(AuthorityType.AAD, aa.authorityType());
assertFalse(aa.isTenantless());
- assertEquals(aa.deviceCodeEndpoint(),
- TestConfiguration.AAD_TENANT_ENDPOINT + "oauth2/v2.0/devicecode");
+ assertEquals(TestConfiguration.AAD_TENANT_ENDPOINT + "oauth2/v2.0/devicecode",
+ aa.deviceCodeEndpoint());
}
@Test
void testConstructor_B2CAuthority() throws MalformedURLException {
final B2CAuthority aa = new B2CAuthority(new URL(TestConfiguration.B2C_AUTHORITY));
assertNotNull(aa);
- assertEquals(aa.authority(),
- TestConfiguration.B2C_AUTHORITY + "/");
- assertEquals(aa.host(), TestConfiguration.B2C_HOST_NAME);
- assertEquals(aa.selfSignedJwtAudience(),
- TestConfiguration.B2C_AUTHORITY_ENDPOINT + "/oauth2/v2.0/token?p=" + TestConfiguration.B2C_SIGN_IN_POLICY);
- assertEquals(aa.tokenEndpoint(),
- TestConfiguration.B2C_AUTHORITY_ENDPOINT + "/oauth2/v2.0/token?p=" + TestConfiguration.B2C_SIGN_IN_POLICY);
- assertEquals(aa.authorityType(), AuthorityType.B2C);
- assertEquals(aa.tokenEndpoint(),
- TestConfiguration.B2C_AUTHORITY_ENDPOINT + "/oauth2/v2.0/token?p=" + TestConfiguration.B2C_SIGN_IN_POLICY);
+ assertEquals(TestConfiguration.B2C_AUTHORITY + "/",
+ aa.authority());
+ assertEquals(TestConfiguration.B2C_HOST_NAME, aa.host());
+ assertEquals(TestConfiguration.B2C_AUTHORITY_ENDPOINT + "/oauth2/v2.0/token?p=" + TestConfiguration.B2C_SIGN_IN_POLICY,
+ aa.selfSignedJwtAudience());
+ assertEquals(TestConfiguration.B2C_AUTHORITY_ENDPOINT + "/oauth2/v2.0/token?p=" + TestConfiguration.B2C_SIGN_IN_POLICY,
+ aa.tokenEndpoint());
+ assertEquals(AuthorityType.B2C, aa.authorityType());
+ assertEquals(TestConfiguration.B2C_AUTHORITY_ENDPOINT + "/oauth2/v2.0/token?p=" + TestConfiguration.B2C_SIGN_IN_POLICY,
+ aa.tokenEndpoint());
assertFalse(aa.isTenantless());
}
@@ -136,15 +136,15 @@ void testConstructor_B2CAuthority() throws MalformedURLException {
void testConstructor_ADFSAuthority() throws MalformedURLException {
final ADFSAuthority a = new ADFSAuthority(new URL(TestConfiguration.ADFS_TENANT_ENDPOINT));
assertNotNull(a);
- assertEquals(a.authority(), TestConfiguration.ADFS_TENANT_ENDPOINT);
- assertEquals(a.host(), TestConfiguration.ADFS_HOST_NAME);
- assertEquals(a.selfSignedJwtAudience(),
- TestConfiguration.ADFS_TENANT_ENDPOINT + ADFSAuthority.TOKEN_ENDPOINT);
+ assertEquals(TestConfiguration.ADFS_TENANT_ENDPOINT, a.authority());
+ assertEquals(TestConfiguration.ADFS_HOST_NAME, a.host());
+ assertEquals(TestConfiguration.ADFS_TENANT_ENDPOINT + ADFSAuthority.TOKEN_ENDPOINT,
+ a.selfSignedJwtAudience());
- assertEquals(a.authorityType(), AuthorityType.ADFS);
+ assertEquals(AuthorityType.ADFS, a.authorityType());
- assertEquals(a.tokenEndpoint(),
- TestConfiguration.ADFS_TENANT_ENDPOINT + ADFSAuthority.TOKEN_ENDPOINT);
+ assertEquals(TestConfiguration.ADFS_TENANT_ENDPOINT + ADFSAuthority.TOKEN_ENDPOINT,
+ a.tokenEndpoint());
assertFalse(a.isTenantless());
}
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AuthorizationRequestUrlParametersTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AuthorizationRequestUrlParametersTest.java
index 034ffc0e..a200a24a 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AuthorizationRequestUrlParametersTest.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AuthorizationRequestUrlParametersTest.java
@@ -35,10 +35,10 @@ void testBuilder_onlyRequiredParameters() throws UnsupportedEncodingException {
.extraQueryParameters(extraParameters)
.build();
- assertEquals(parameters.responseMode(), ResponseMode.FORM_POST);
- assertEquals(parameters.redirectUri(), redirectUri);
- assertEquals(parameters.scopes().size(), 4);
- assertEquals(parameters.extraQueryParameters.size(), 2);
+ assertEquals(ResponseMode.FORM_POST, parameters.responseMode());
+ assertEquals(redirectUri, parameters.redirectUri());
+ assertEquals(4, parameters.scopes().size());
+ assertEquals(2, parameters.extraQueryParameters.size());
assertNull(parameters.loginHint());
assertNull(parameters.codeChallenge());
@@ -50,8 +50,8 @@ void testBuilder_onlyRequiredParameters() throws UnsupportedEncodingException {
URL authorizationUrl = app.getAuthorizationRequestUrl(parameters);
- assertEquals(authorizationUrl.getHost(), "login.microsoftonline.com");
- assertEquals(authorizationUrl.getPath(), "/common/oauth2/v2.0/authorize");
+ assertEquals("login.microsoftonline.com", authorizationUrl.getHost());
+ assertEquals("/common/oauth2/v2.0/authorize", authorizationUrl.getPath());
Map queryParameters = new HashMap<>();
String query = authorizationUrl.getQuery();
@@ -64,12 +64,12 @@ void testBuilder_onlyRequiredParameters() throws UnsupportedEncodingException {
URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
}
- assertEquals(queryParameters.get("scope"), "openid profile offline_access scope");
- assertEquals(queryParameters.get("response_type"), "code");
- assertEquals(queryParameters.get("redirect_uri"), "http://localhost:8080");
- assertEquals(queryParameters.get("client_id"), "client_id");
- assertEquals(queryParameters.get("response_mode"), "form_post");
- assertEquals(queryParameters.get("id_token_hint"),"test");
+ assertEquals("openid profile offline_access scope", queryParameters.get("scope"));
+ assertEquals("code", queryParameters.get("response_type"));
+ assertEquals("http://localhost:8080", queryParameters.get("redirect_uri"));
+ assertEquals("client_id", queryParameters.get("client_id"));
+ assertEquals("form_post", queryParameters.get("response_mode"));
+ assertEquals("test", queryParameters.get("id_token_hint"));
}
@Test
@@ -110,9 +110,9 @@ void testBuilder_responseMode() throws UnsupportedEncodingException {
.responseMode(ResponseMode.QUERY) // This should be overridden to FORM_POST
.build();
- assertEquals(parameters.responseMode(), ResponseMode.FORM_POST);
- assertEquals(parameters.redirectUri(), redirectUri);
- assertEquals(parameters.scopes().size(), 4);
+ assertEquals(ResponseMode.FORM_POST, parameters.responseMode());
+ assertEquals(redirectUri, parameters.redirectUri());
+ assertEquals(4, parameters.scopes().size());
assertNull(parameters.loginHint());
assertNull(parameters.codeChallenge());
@@ -124,8 +124,8 @@ void testBuilder_responseMode() throws UnsupportedEncodingException {
URL authorizationUrl = app.getAuthorizationRequestUrl(parameters);
- assertEquals(authorizationUrl.getHost(), "login.microsoftonline.com");
- assertEquals(authorizationUrl.getPath(), "/common/oauth2/v2.0/authorize");
+ assertEquals("login.microsoftonline.com", authorizationUrl.getHost());
+ assertEquals("/common/oauth2/v2.0/authorize", authorizationUrl.getPath());
Map queryParameters = new HashMap<>();
String query = authorizationUrl.getQuery();
@@ -138,10 +138,10 @@ void testBuilder_responseMode() throws UnsupportedEncodingException {
URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
}
- assertEquals(queryParameters.get("scope"), "openid profile offline_access scope");
- assertEquals(queryParameters.get("response_type"), "code");
- assertEquals(queryParameters.get("redirect_uri"), "http://localhost:8080");
- assertEquals(queryParameters.get("client_id"), "client_id");
- assertEquals(queryParameters.get("response_mode"), "form_post");
+ assertEquals("openid profile offline_access scope", queryParameters.get("scope"));
+ assertEquals("code", queryParameters.get("response_type"));
+ assertEquals("http://localhost:8080", queryParameters.get("redirect_uri"));
+ assertEquals("client_id", queryParameters.get("client_id"));
+ assertEquals("form_post", queryParameters.get("response_mode"));
}
}
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/CacheFormatTests.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/CacheFormatTest.java
similarity index 99%
rename from msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/CacheFormatTests.java
rename to msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/CacheFormatTest.java
index a30a3951..35d2dbf4 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/CacheFormatTests.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/CacheFormatTest.java
@@ -30,7 +30,7 @@
@ExtendWith(MockitoExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
-class CacheFormatTests {
+class CacheFormatTest {
String TOKEN_RESPONSE = "/token_response.json";
String TOKEN_RESPONSE_ID_TOKEN = "/token_response_id_token.json";
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/CacheTests.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/CacheTest.java
similarity index 99%
rename from msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/CacheTests.java
rename to msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/CacheTest.java
index ca2cf4f2..11f0d1c0 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/CacheTests.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/CacheTest.java
@@ -21,7 +21,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-class CacheTests {
+class CacheTest {
private TokenCache tokenCache;
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/DateTimeTests.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/DateTimeTest.java
similarity index 99%
rename from msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/DateTimeTests.java
rename to msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/DateTimeTest.java
index 4b3cce13..7d682ba0 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/DateTimeTests.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/DateTimeTest.java
@@ -13,7 +13,7 @@
import static org.junit.jupiter.api.Assertions.*;
-class DateTimeTests {
+class DateTimeTest {
@Test
void parseUnixTimestampInSeconds() {
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/HelperAndUtilityTests.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/HelperAndUtilityTest.java
similarity index 98%
rename from msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/HelperAndUtilityTests.java
rename to msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/HelperAndUtilityTest.java
index 08ca2e39..895570c8 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/HelperAndUtilityTests.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/HelperAndUtilityTest.java
@@ -14,7 +14,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.*;
-class HelperAndUtilityTests {
+class HelperAndUtilityTest {
@Test
void StringHelper_serializeQueryParameters_ValidUrlQueryStrings() {
@@ -78,7 +78,7 @@ void StringHelper_convertToMultiValueMap() {
assertNotNull(convertedInternalMap, "Converted map should not be null");
assertNotNull(methodReturnedMap, "Method returned map should not be null");
- assertEquals(convertedInternalMap.size(), methodReturnedMap.size(), "Maps should have the same size");
+ assertEquals(methodReturnedMap.size(), convertedInternalMap.size(), "Maps should have the same size");
for (String key : convertedInternalMap.keySet()) {
assertTrue(methodReturnedMap.containsKey(key), "Method returned map should contain key: " + key);
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/HttpHeaderTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/HttpHeaderTest.java
index 60ae060f..3c570659 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/HttpHeaderTest.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/HttpHeaderTest.java
@@ -40,12 +40,12 @@ void testHttpHeaderConstructor() {
Map httpHeaderMap = httpHeaders.getReadonlyHeaderMap();
- assertEquals(httpHeaderMap.get(HttpHeaders.PRODUCT_HEADER_NAME), HttpHeaders.PRODUCT_HEADER_VALUE);
- assertEquals(httpHeaderMap.get(HttpHeaders.PRODUCT_VERSION_HEADER_NAME), HttpHeaders.PRODUCT_VERSION_HEADER_VALUE);
- assertEquals(httpHeaderMap.get(HttpHeaders.OS_HEADER_NAME), HttpHeaders.OS_HEADER_VALUE);
- assertEquals(httpHeaderMap.get(HttpHeaders.APPLICATION_NAME_HEADER_NAME), "app-name");
- assertEquals(httpHeaderMap.get(HttpHeaders.APPLICATION_VERSION_HEADER_NAME), "app-version");
- assertEquals(httpHeaderMap.get(HttpHeaders.CORRELATION_ID_HEADER_NAME), "correlation-id");
+ assertEquals(HttpHeaders.PRODUCT_HEADER_VALUE, httpHeaderMap.get(HttpHeaders.PRODUCT_HEADER_NAME));
+ assertEquals(HttpHeaders.PRODUCT_VERSION_HEADER_VALUE, httpHeaderMap.get(HttpHeaders.PRODUCT_VERSION_HEADER_NAME));
+ assertEquals(HttpHeaders.OS_HEADER_VALUE, httpHeaderMap.get(HttpHeaders.OS_HEADER_NAME));
+ assertEquals("app-name", httpHeaderMap.get(HttpHeaders.APPLICATION_NAME_HEADER_NAME));
+ assertEquals("app-version", httpHeaderMap.get(HttpHeaders.APPLICATION_VERSION_HEADER_NAME));
+ assertEquals("correlation-id", httpHeaderMap.get(HttpHeaders.CORRELATION_ID_HEADER_NAME));
}
@Test
@@ -66,9 +66,9 @@ void testHttpHeaderConstructor_valuesNotSet() {
Map httpHeaderMap = httpHeaders.getReadonlyHeaderMap();
- assertEquals(httpHeaderMap.get(HttpHeaders.PRODUCT_HEADER_NAME), HttpHeaders.PRODUCT_HEADER_VALUE);
- assertEquals(httpHeaderMap.get(HttpHeaders.PRODUCT_VERSION_HEADER_NAME), HttpHeaders.PRODUCT_VERSION_HEADER_VALUE);
- assertEquals(httpHeaderMap.get(HttpHeaders.OS_HEADER_NAME), HttpHeaders.OS_HEADER_VALUE);
+ assertEquals(HttpHeaders.PRODUCT_HEADER_VALUE, httpHeaderMap.get(HttpHeaders.PRODUCT_HEADER_NAME));
+ assertEquals(HttpHeaders.PRODUCT_VERSION_HEADER_VALUE, httpHeaderMap.get(HttpHeaders.PRODUCT_VERSION_HEADER_NAME));
+ assertEquals(HttpHeaders.OS_HEADER_VALUE, httpHeaderMap.get(HttpHeaders.OS_HEADER_NAME));
assertNull(httpHeaderMap.get(HttpHeaders.APPLICATION_NAME_HEADER_NAME));
assertNull(httpHeaderMap.get(HttpHeaders.APPLICATION_VERSION_HEADER_NAME));
assertNotNull(httpHeaderMap.get(HttpHeaders.CORRELATION_ID_HEADER_NAME));
@@ -97,7 +97,7 @@ void testHttpHeaderConstructor_userIdentifierUPN() {
Map httpHeaderMap = httpHeaders.getReadonlyHeaderMap();
String expectedValue = String.format(HttpHeaders.X_ANCHOR_MAILBOX_UPN_FORMAT, upn);
- assertEquals(httpHeaderMap.get(HttpHeaders.X_ANCHOR_MAILBOX), expectedValue);
+ assertEquals(expectedValue, httpHeaderMap.get(HttpHeaders.X_ANCHOR_MAILBOX));
}
@Test
@@ -122,7 +122,7 @@ void testHttpHeaderConstructor_userIdentifierHomeAccountId() {
Map httpHeaderMap = httpHeaders.getReadonlyHeaderMap();
- assertEquals(httpHeaderMap.get(HttpHeaders.X_ANCHOR_MAILBOX), "oid:userObjectId@userTenantId");
+ assertEquals("oid:userObjectId@userTenantId", httpHeaderMap.get(HttpHeaders.X_ANCHOR_MAILBOX));
}
@Test
@@ -158,16 +158,16 @@ void testHttpHeaderConstructor_extraHttpHeadersOverwriteLibraryHeaders() {
Map httpHeaderMap = httpHeaders.getReadonlyHeaderMap();
// Standard headers
- assertEquals(httpHeaderMap.get(HttpHeaders.PRODUCT_HEADER_NAME), HttpHeaders.PRODUCT_HEADER_VALUE);
- assertEquals(httpHeaderMap.get(HttpHeaders.PRODUCT_VERSION_HEADER_NAME), HttpHeaders.PRODUCT_VERSION_HEADER_VALUE);
- assertEquals(httpHeaderMap.get(HttpHeaders.OS_HEADER_NAME), HttpHeaders.OS_HEADER_VALUE);
- assertEquals(httpHeaderMap.get(HttpHeaders.APPLICATION_VERSION_HEADER_NAME), "app-version");
- assertEquals(httpHeaderMap.get(HttpHeaders.CORRELATION_ID_HEADER_NAME), "correlation-id");
+ assertEquals(HttpHeaders.PRODUCT_HEADER_VALUE, httpHeaderMap.get(HttpHeaders.PRODUCT_HEADER_NAME));
+ assertEquals(HttpHeaders.PRODUCT_VERSION_HEADER_VALUE, httpHeaderMap.get(HttpHeaders.PRODUCT_VERSION_HEADER_NAME));
+ assertEquals(HttpHeaders.OS_HEADER_VALUE, httpHeaderMap.get(HttpHeaders.OS_HEADER_NAME));
+ assertEquals("app-version", httpHeaderMap.get(HttpHeaders.APPLICATION_VERSION_HEADER_NAME));
+ assertEquals("correlation-id", httpHeaderMap.get(HttpHeaders.CORRELATION_ID_HEADER_NAME));
// Overwritten standard header
- assertEquals(httpHeaderMap.get(HttpHeaders.APPLICATION_NAME_HEADER_NAME), uniqueAppName);
+ assertEquals(uniqueAppName, httpHeaderMap.get(HttpHeaders.APPLICATION_NAME_HEADER_NAME));
// Extra header
- assertEquals(httpHeaderMap.get(uniqueHeaderKey), uniqueHeaderValue);
+ assertEquals(uniqueHeaderValue, httpHeaderMap.get(uniqueHeaderKey));
}
}
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/JsonCompatibilityTests.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/JsonCompatibilityTest.java
similarity index 98%
rename from msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/JsonCompatibilityTests.java
rename to msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/JsonCompatibilityTest.java
index cc15ee94..9c60f0ae 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/JsonCompatibilityTests.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/JsonCompatibilityTest.java
@@ -12,14 +12,14 @@
//These tests were added to ensure the new usages of com.azure.json are functionally the same as the old usages of com.nimbusds packages.
//Once we are confident in the new behavior these should no longer be necessary.
-class JsonCompatibilityTests {
+class JsonCompatibilityTest {
//New style, using helper methods in JsonHelper that use com.azure.json
private final Map newStyleParsedClaims = JsonHelper.parseJsonToMap(JsonHelper.getTokenPayloadClaims(TestHelper.ENCODED_JWT));
//Old style, using com.nimbusds methods
private final Map oldStyleParsedClaims = JWTParser.parse(TestHelper.ENCODED_JWT).getJWTClaimsSet().getClaims();
- JsonCompatibilityTests() throws ParseException {
+ JsonCompatibilityTest() throws ParseException {
}
@Test
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ManagedIdentityTests.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ManagedIdentityTest.java
similarity index 99%
rename from msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ManagedIdentityTests.java
rename to msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ManagedIdentityTest.java
index f5a8ccc0..d0197cb8 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ManagedIdentityTests.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ManagedIdentityTest.java
@@ -37,7 +37,7 @@
@ExtendWith(MockitoExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
-class ManagedIdentityTests {
+class ManagedIdentityTest {
private static final String EXPECTED_SKU = "MSAL.Java";
private static final String TEST_CORRELATION_ID = "00000000-0000-0000-0000-000000000001";
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/MexParserTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/MexParserTest.java
index 131357ad..f988563c 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/MexParserTest.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/MexParserTest.java
@@ -48,8 +48,8 @@ void testMexParsingWs13() throws Exception {
}
BindingPolicy endpoint = MexParser.getWsTrustEndpointFromMexResponse(sb.toString(), false);
- assertEquals(endpoint.getUrl(),
- "https://msft.sts.microsoft.com/adfs/services/trust/13/usernamemixed");
+ assertEquals("https://msft.sts.microsoft.com/adfs/services/trust/13/usernamemixed",
+ endpoint.getUrl());
}
@Test
@@ -69,7 +69,7 @@ void testMexParsingWs2005() throws Exception {
}
BindingPolicy endpoint = MexParser.getWsTrustEndpointFromMexResponse(sb
.toString(), false);
- assertEquals(endpoint.getUrl(), "https://msft.sts.microsoft.com/adfs/services/trust/2005/usernamemixed");
+ assertEquals("https://msft.sts.microsoft.com/adfs/services/trust/2005/usernamemixed", endpoint.getUrl());
}
@Test
@@ -89,7 +89,7 @@ void testMexParsingIntegrated() throws Exception {
}
BindingPolicy endpoint = MexParser.getPolicyFromMexResponseForIntegrated(sb
.toString(), false);
- assertEquals(endpoint.getUrl(),
- "https://msft.sts.microsoft.com/adfs/services/trust/13/windowstransport");
+ assertEquals("https://msft.sts.microsoft.com/adfs/services/trust/13/windowstransport",
+ endpoint.getUrl());
}
}
\ No newline at end of file
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/MsalOauthAuthorizatonGrantTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/MsalOauthAuthorizationGrantTest.java
similarity index 95%
rename from msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/MsalOauthAuthorizatonGrantTest.java
rename to msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/MsalOauthAuthorizationGrantTest.java
index a8d8f3de..278df934 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/MsalOauthAuthorizatonGrantTest.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/MsalOauthAuthorizationGrantTest.java
@@ -15,7 +15,7 @@
import java.util.Map;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
-class MsalOauthAuthorizatonGrantTest {
+class MsalOauthAuthorizationGrantTest {
@Test
void testToParameters() {
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/OnBehalfOfTests.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/OnBehalfOfTest.java
similarity index 99%
rename from msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/OnBehalfOfTests.java
rename to msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/OnBehalfOfTest.java
index 5aeb9f27..b48d0eb3 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/OnBehalfOfTests.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/OnBehalfOfTest.java
@@ -18,7 +18,7 @@
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
-class OnBehalfOfTests {
+class OnBehalfOfTest {
@Test
void OnBehalfOf_InternalCacheLookup_Success() throws Exception {
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ServerTelemetryTests.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ServerTelemetryTest.java
similarity index 99%
rename from msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ServerTelemetryTests.java
rename to msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ServerTelemetryTest.java
index 8f809962..f9d7a394 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ServerTelemetryTests.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ServerTelemetryTest.java
@@ -20,7 +20,7 @@
import java.util.concurrent.Executors;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
-class ServerTelemetryTests {
+class ServerTelemetryTest {
private static final String SCHEMA_VERSION = "5";
private static final String CURRENT_REQUEST_HEADER_NAME = "x-client-current-telemetry";
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TelemetryTests.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TelemetryTest.java
similarity index 87%
rename from msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TelemetryTests.java
rename to msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TelemetryTest.java
index 69581641..ac3d6428 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TelemetryTests.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TelemetryTest.java
@@ -21,7 +21,7 @@
import java.util.function.Consumer;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
-class TelemetryTests {
+class TelemetryTest {
private List> eventsReceived = new ArrayList<>();
private String tenantId = "tenantId123";
@@ -32,11 +32,6 @@ private class MyTelemetryConsumer {
Consumer>> telemetryConsumer =
(List> telemetryEvents) -> {
eventsReceived.addAll(telemetryEvents);
- System.out.println("Received " + telemetryEvents.size() + " events");
- telemetryEvents.forEach(event -> {
- System.out.print("Event Name: " + event.get("event_name"));
- event.entrySet().forEach(entry -> System.out.println(" " + entry));
- });
};
}
@@ -74,7 +69,7 @@ void telemetryManagerFlush_EventCountTest() {
telemetryManager.flush(reqId, clientId);
// 1 Default event, 1 API event, 1 Http event
- assertEquals(eventsReceived.size(), 3);
+ assertEquals(3, eventsReceived.size());
}
@Test
@@ -99,7 +94,7 @@ void onSendFailureTrue_SkipEventsIfSuccessfulTest() {
telemetryManager.flush(reqId, clientId);
// API event was successful, so count should be 0
- assertEquals(eventsReceived.size(), 0);
+ assertEquals(0, eventsReceived.size());
eventsReceived.clear();
String reqId2 = telemetryManager.generateRequestId();
@@ -116,19 +111,19 @@ void onSendFailureTrue_SkipEventsIfSuccessfulTest() {
telemetryManager.flush(reqId2, clientId);
// API event failed, so count should be 3 (1 default, 1 Api, 1 http)
- assertEquals(eventsReceived.size(), 3);
+ assertEquals(3, eventsReceived.size());
}
@Test
void telemetryInternalApi_ScrubTenantFromUriTest() throws Exception {
- assertEquals(Event.scrubTenant(new URI("https://login.microsoftonline.com/common/oauth2/v2.0/token")),
- "https://login.microsoftonline.com//oauth2/v2.0/token");
+ assertEquals("https://login.microsoftonline.com//oauth2/v2.0/token",
+ Event.scrubTenant(new URI("https://login.microsoftonline.com/common/oauth2/v2.0/token")));
- assertEquals(Event.scrubTenant(new URI("https://login.microsoftonline.com/common")),
- "https://login.microsoftonline.com/");
+ assertEquals("https://login.microsoftonline.com/",
+ Event.scrubTenant(new URI("https://login.microsoftonline.com/common")));
- assertEquals(Event.scrubTenant(new URI("https://login.microsoftonline.com/tfp/msidlabb2c.onmicrosoft.com/B2C_1_ROPC_Auth")),
- "https://login.microsoftonline.com/tfp//B2C_1_ROPC_Auth");
+ assertEquals("https://login.microsoftonline.com/tfp//B2C_1_ROPC_Auth",
+ Event.scrubTenant(new URI("https://login.microsoftonline.com/tfp/msidlabb2c.onmicrosoft.com/B2C_1_ROPC_Auth")));
assertNull(Event.scrubTenant(new URI("https://msidlabb2c.b2clogin.com/tfp/msidlabb2c.onmicrosoft.com/B2C_1_ROPC_Auth")));
@@ -155,7 +150,7 @@ void telemetryContainsDefaultEventTest() {
telemetryManager.flush(reqId, clientId);
- assertEquals(eventsReceived.get(0).get("event_name"), "msal.default_event");
+ assertEquals("msal.default_event", eventsReceived.get(0).get("event_name"));
}
@Test
@@ -177,7 +172,7 @@ void telemetryFlushEventWithoutStopping_OrphanedEventIncludedTest() {
telemetryManager.stopEvent(reqId, apiEvent1);
telemetryManager.flush(reqId, clientId);
- assertEquals(eventsReceived.size(), 3);
+ assertEquals(3, eventsReceived.size());
assertTrue(eventsReceived.stream().anyMatch(event -> event.get("event_name").equals("msal.http_event")));
}
@@ -202,7 +197,7 @@ void telemetryStopEventWithoutStarting_NoExceptionThrownTest() {
telemetryManager.flush(reqId, clientId);
- assertEquals(eventsReceived.size(), 2);
+ assertEquals(2, eventsReceived.size());
assertFalse(eventsReceived.stream().anyMatch(event -> event.get("event_name").equals("msal.http_event")));
}
@@ -222,7 +217,7 @@ void piiLoggingEnabled_ApiEventHashTest() {
telemetryManager.stopEvent(reqId, apiEvent);
assertNotNull(apiEvent.get("msal.tenant_id"));
- assertNotEquals(apiEvent.get("msal.tenant_id"), tenantId);
+ assertNotEquals(tenantId, apiEvent.get("msal.tenant_id"));
}
@Test
@@ -256,7 +251,7 @@ void authorityNotInTrustedHostList_AuthorityIsNullTest() throws URISyntaxExcepti
apiEvent.setWasSuccessful(true);
telemetryManager.stopEvent(reqId, apiEvent);
- assertEquals(apiEvent.get("msal.authority"), "https://login.microsoftonline.com");
+ assertEquals("https://login.microsoftonline.com", apiEvent.get("msal.authority"));
ApiEvent apiEvent2 = new ApiEvent(false);
@@ -273,10 +268,10 @@ void xmsCliTelemetryTest_CorrectFormatTest() {
String responseHeader = "1,0,0,,";
XmsClientTelemetryInfo info = XmsClientTelemetryInfo.parseXmsTelemetryInfo(responseHeader);
- assertEquals(info.getServerErrorCode(), "0");
- assertEquals(info.getServerSubErrorCode(), "0");
- assertEquals(info.getTokenAge(), "");
- assertEquals(info.getSpeInfo(), "");
+ assertEquals("0", info.getServerErrorCode());
+ assertEquals("0", info.getServerSubErrorCode());
+ assertEquals("", info.getTokenAge());
+ assertEquals("", info.getSpeInfo());
}
@Test
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TokenRequestExecutorTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TokenRequestExecutorTest.java
index ac743755..4742459c 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TokenRequestExecutorTest.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TokenRequestExecutorTest.java
@@ -65,7 +65,7 @@ void executeOAuthRequest_SCBadRequestErrorInvalidGrant_InteractionRequiredExcept
fail("Expected MsalServiceException was not thrown");
} catch (MsalInteractionRequiredException ex) {
assertEquals(claims.replace("\\", ""), ex.claims());
- assertEquals(ex.reason(), InteractionRequiredExceptionReason.BASIC_ACTION);
+ assertEquals(InteractionRequiredExceptionReason.BASIC_ACTION, ex.reason());
}
}
@@ -239,7 +239,7 @@ void testExecuteOAuth_Success() throws MsalException, IOException, URISyntaxExce
assertNotNull(result.account());
assertNotNull(result.account().homeAccountId());
- assertEquals(result.account().username(), "idlab@msidlab4.onmicrosoft.com");
+ assertEquals("idlab@msidlab4.onmicrosoft.com", result.account().username());
assertFalse(StringHelper.isBlank(result.accessToken()));
assertFalse(StringHelper.isBlank(result.refreshToken()));
diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/WSTrustRequestTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/WSTrustRequestTest.java
index dd020db8..cccd0d47 100644
--- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/WSTrustRequestTest.java
+++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/WSTrustRequestTest.java
@@ -50,7 +50,7 @@ void escapeXMLElementDataTest() {
String DATA_TO_ESCAPE = "o_!as & a34~'fe<> \" a1";
String XML_ESCAPED_DATA = "o_!as & a34~'fe<> " a1";
- assertEquals(WSTrustRequest.escapeXMLElementData(DATA_TO_ESCAPE), XML_ESCAPED_DATA);
+ assertEquals(XML_ESCAPED_DATA, WSTrustRequest.escapeXMLElementData(DATA_TO_ESCAPE));
assertEquals(WSTrustRequest.escapeXMLElementData(DATA_TO_ESCAPE),
StringEscapeUtils.escapeXml10(DATA_TO_ESCAPE));
}