diff --git a/msal4j-sdk/pom.xml b/msal4j-sdk/pom.xml index a7b4fde5..82b2e04a 100644 --- a/msal4j-sdk/pom.xml +++ b/msal4j-sdk/pom.xml @@ -133,6 +133,55 @@ 2.7 test + + org.mockito + mockito-core + 4.6.1 + test + + + org.mockito + mockito-inline + 3.4.6 + test + + + + net.bytebuddy + byte-buddy + 1.12.20 + + + + org.junit.jupiter + junit-jupiter-api + 5.9.2 + test + + + org.junit.jupiter + junit-jupiter-params + 5.8.1 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.8.1 + test + + + org.mockito + mockito-junit-jupiter + 4.6.1 + test + + + org.powermock + powermock-core + 2.0.9 + + @@ -197,6 +246,13 @@ -noverify + + + org.junit.platform + junit-platform-surefire-provider + 1.3.2 + + diff --git a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AcquireTokenInteractiveIT.java b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AcquireTokenInteractiveIT.java index b50e2fdb..d7c4b742 100644 --- a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AcquireTokenInteractiveIT.java +++ b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AcquireTokenInteractiveIT.java @@ -7,10 +7,12 @@ import labapi.B2CProvider; import labapi.FederationProvider; import labapi.User; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.Test; import java.net.MalformedURLException; import java.net.URI; @@ -18,13 +20,17 @@ import java.util.Collections; import java.util.concurrent.ExecutionException; -public class AcquireTokenInteractiveIT extends SeleniumTest { +import static org.junit.jupiter.api.Assertions.*; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class AcquireTokenInteractiveIT extends SeleniumTest { private final static Logger LOG = LoggerFactory.getLogger(AuthorizationCodeIT.class); private Config cfg; - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenInteractive_ManagedUser(String environment) { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenInteractive_ManagedUser(String environment) { cfg = new Config(environment); User user = labUserProvider.getDefaultUser(cfg.azureEnvironment); @@ -32,45 +38,51 @@ public void acquireTokenInteractive_ManagedUser(String environment) { } @Test() - public void acquireTokenInteractive_ADFSv2019_OnPrem() { + void acquireTokenInteractive_ADFSv2019_OnPrem() { User user = labUserProvider.getOnPremAdfsUser(FederationProvider.ADFS_2019); assertAcquireTokenADFS2019(user); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenInteractive_ADFSv2019_Federated(String environment) { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenInteractive_ADFSv2019_Federated(String environment) { cfg = new Config(environment); User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_2019); assertAcquireTokenAAD(user); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenInteractive_ADFSv4_Federated(String environment) { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenInteractive_ADFSv4_Federated(String environment) { cfg = new Config(environment); User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_4); assertAcquireTokenAAD(user); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenInteractive_ADFSv3_Federated(String environment) { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenInteractive_ADFSv3_Federated(String environment) { + cfg = new Config(environment); User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_3); assertAcquireTokenAAD(user); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenInteractive_ADFSv2_Federated(String environment) { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenInteractive_ADFSv2_Federated(String environment) { cfg = new Config(environment); User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_2); assertAcquireTokenAAD(user); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithAuthorizationCode_B2C_Local(String environment) { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithAuthorizationCode_B2C_Local(String environment) { cfg = new Config(environment); User user = labUserProvider.getB2cUser(cfg.azureEnvironment, B2CProvider.LOCAL); @@ -78,7 +90,7 @@ public void acquireTokenWithAuthorizationCode_B2C_Local(String environment) { } @Test - public void acquireTokenInteractive_ManagedUser_InstanceAware() { + void acquireTokenInteractive_ManagedUser_InstanceAware() { cfg = new Config(AzureEnvironment.AZURE); User user = labUserProvider.getDefaultUser(AzureEnvironment.AZURE_US_GOVERNMENT); @@ -101,10 +113,10 @@ private void assertAcquireTokenAAD(User user) { pca, cfg.graphDefaultScope()); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); - Assert.assertEquals(user.getUpn(), result.account().username()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); + assertEquals(user.getUpn(), result.account().username()); } private void assertAcquireTokenADFS2019(User user) { @@ -120,10 +132,10 @@ private void assertAcquireTokenADFS2019(User user) { IAuthenticationResult result = acquireTokenInteractive(user, pca, TestConstants.ADFS_SCOPE); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); - Assert.assertEquals(user.getUpn(), result.account().username()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); + assertEquals(user.getUpn(), result.account().username()); } private void assertAcquireTokenB2C(User user) { @@ -139,9 +151,9 @@ private void assertAcquireTokenB2C(User user) { } IAuthenticationResult result = acquireTokenInteractive(user, pca, user.getAppId()); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); } private void assertAcquireTokenInstanceAware(User user) { @@ -157,16 +169,16 @@ private void assertAcquireTokenInstanceAware(User user) { IAuthenticationResult result = acquireTokenInteractive_instanceAware(user, pca, cfg.graphDefaultScope()); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); - Assert.assertEquals(user.getUpn(), result.account().username()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); + assertEquals(user.getUpn(), result.account().username()); //This test is using a client app with the login.microsoftonline.com config to get tokens for a login.microsoftonline.us user, // so when using instance aware the result's environment will be for the user/account and not the client app - Assert.assertNotEquals(pca.authenticationAuthority.host, result.environment()); - Assert.assertEquals(result.account().environment(), result.environment()); - Assert.assertEquals(result.account().environment(), pca.getAccounts().join().iterator().next().environment()); + assertNotEquals(pca.authenticationAuthority.host, result.environment()); + assertEquals(result.account().environment(), result.environment()); + assertEquals(result.account().environment(), pca.getAccounts().join().iterator().next().environment()); IAuthenticationResult cachedResult; try { @@ -176,7 +188,7 @@ private void assertAcquireTokenInstanceAware(User user) { } //Ensure that the cached environment matches the original auth result environment (.us) instead of the client app's (.com) - Assert.assertEquals(result.account().environment(), cachedResult.environment()); + assertEquals(result.account().environment(), cachedResult.environment()); } //@Test @@ -223,14 +235,14 @@ public void afterCacheAccess(ITokenCacheAccessContext iTokenCacheAccessContext) build(); IAuthenticationResult result = acquireTokenInteractive(user, publicCloudPca, TestConstants.USER_READ_SCOPE); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); - Assert.assertEquals(user.getHomeUPN(), result.account().username()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); + assertEquals(user.getHomeUPN(), result.account().username()); publicCloudPca.removeAccount(publicCloudPca.getAccounts().join().iterator().next()).join(); - Assert.assertEquals(publicCloudPca.getAccounts().join().size(), 0); + assertEquals(0, publicCloudPca.getAccounts().join().size()); } private IAuthenticationResult acquireTokenInteractive( diff --git a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AcquireTokenSilentIT.java b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AcquireTokenSilentIT.java index 070ee6b2..2eb093f7 100644 --- a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AcquireTokenSilentIT.java +++ b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AcquireTokenSilentIT.java @@ -4,9 +4,12 @@ package com.microsoft.aad.msal4j; import labapi.*; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.net.MalformedURLException; import java.util.Collections; @@ -16,19 +19,22 @@ import java.util.concurrent.ExecutionException; import static com.microsoft.aad.msal4j.TestConstants.KEYVAULT_DEFAULT_SCOPE; +import static org.junit.jupiter.api.Assertions.*; -public class AcquireTokenSilentIT { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class AcquireTokenSilentIT { private LabUserProvider labUserProvider; private Config cfg; - @BeforeClass + @BeforeAll public void setUp() { labUserProvider = LabUserProvider.getInstance(); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenSilent_OrganizationAuthority_TokenRefreshed(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenSilent_OrganizationAuthority_TokenRefreshed(String environment) throws Exception { cfg = new Config(environment); // When using common, organization, or consumer tenants, cache has no way @@ -40,8 +46,9 @@ public void acquireTokenSilent_OrganizationAuthority_TokenRefreshed(String envir assertResultNotNull(result); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenSilent_LabAuthority_TokenNotRefreshed(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenSilent_LabAuthority_TokenNotRefreshed(String environment) throws Exception { cfg = new Config(environment); // Access token should be returned from cache, and not using refresh token @@ -61,12 +68,13 @@ public void acquireTokenSilent_LabAuthority_TokenNotRefreshed(String environment assertResultNotNull(result); // Check that access and id tokens are coming from cache - Assert.assertEquals(result.accessToken(), acquireSilentResult.accessToken()); - Assert.assertEquals(result.idToken(), acquireSilentResult.idToken()); + assertEquals(result.accessToken(), acquireSilentResult.accessToken()); + assertEquals(result.idToken(), acquireSilentResult.idToken()); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenSilent_ForceRefresh(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenSilent_ForceRefresh(String environment) throws Exception { cfg = new Config(environment); User user = labUserProvider.getDefaultUser(environment); @@ -87,8 +95,9 @@ public void acquireTokenSilent_ForceRefresh(String environment) throws Exception assertTokensAreNotEqual(result, resultAfterRefresh); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenSilent_MultipleAccountsInCache_UseCorrectAccount(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenSilent_MultipleAccountsInCache_UseCorrectAccount(String environment) throws Exception { cfg = new Config(environment); IPublicClientApplication pca = getPublicClientApplicationWithTokensInCache(); @@ -106,11 +115,12 @@ public void acquireTokenSilent_MultipleAccountsInCache_UseCorrectAccount(String IAuthenticationResult result = acquireTokenSilently(pca, account, cfg.graphDefaultScope(), false); assertResultNotNull(result); - Assert.assertEquals(result.account().username(), user.getUpn()); + assertEquals(result.account().username(), user.getUpn()); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenSilent_ADFS2019(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenSilent_ADFS2019(String environment) throws Exception { cfg = new Config(environment); UserQueryParameters query = new UserQueryParameters(); @@ -141,7 +151,7 @@ public void acquireTokenSilent_ADFS2019(String environment) throws Exception { // Commented out due to unclear B2C behavior causing occasional errors //@Test - public void acquireTokenSilent_B2C() throws Exception { + void acquireTokenSilent_B2C() throws Exception { UserQueryParameters query = new UserQueryParameters(); query.parameters.put(UserQueryParameters.USER_TYPE, UserType.B2C); query.parameters.put(UserQueryParameters.B2C_PROVIDER, B2CProvider.LOCAL); @@ -164,17 +174,18 @@ public void acquireTokenSilent_B2C() throws Exception { @Test - public void acquireTokenSilent_usingCommonAuthority_returnCachedAt() throws Exception { + void acquireTokenSilent_usingCommonAuthority_returnCachedAt() throws Exception { acquireTokenSilent_returnCachedTokens(cfg.organizationsAuthority()); } @Test - public void acquireTokenSilent_usingTenantSpecificAuthority_returnCachedAt() throws Exception { + void acquireTokenSilent_usingTenantSpecificAuthority_returnCachedAt() throws Exception { acquireTokenSilent_returnCachedTokens(cfg.tenantSpecificAuthority()); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenSilent_ConfidentialClient_acquireTokenSilent(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenSilent_ConfidentialClient_acquireTokenSilent(String environment) throws Exception { cfg = new Config(environment); IConfidentialClientApplication cca = getConfidentialClientApplications(); @@ -184,8 +195,8 @@ public void acquireTokenSilent_ConfidentialClient_acquireTokenSilent(String envi .build()) .get(); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); + assertNotNull(result); + assertNotNull(result.accessToken()); String cachedAt = result.accessToken(); @@ -194,12 +205,12 @@ public void acquireTokenSilent_ConfidentialClient_acquireTokenSilent(String envi .build()) .get(); - Assert.assertNotNull(result); - Assert.assertEquals(result.accessToken(), cachedAt); + assertNotNull(result); + assertEquals(result.accessToken(), cachedAt); } - @Test(expectedExceptions = ExecutionException.class) - public void acquireTokenSilent_ConfidentialClient_acquireTokenSilentDifferentScopeThrowsException() + @Test + void acquireTokenSilent_ConfidentialClient_acquireTokenSilentDifferentScopeThrowsException() throws Exception { cfg = new Config(AzureEnvironment.AZURE); @@ -210,18 +221,21 @@ public void acquireTokenSilent_ConfidentialClient_acquireTokenSilentDifferentSco .build()) .get(); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); + assertNotNull(result); + assertNotNull(result.accessToken()); - //Acquiring token for different scope, expect exception to be thrown - cca.acquireTokenSilently(SilentParameters - .builder(Collections.singleton(cfg.graphDefaultScope())) - .build()) - .get(); + Assertions.assertThrows(ExecutionException.class, () -> { + //Acquiring token for different scope, expect exception to be thrown + cca.acquireTokenSilently(SilentParameters + .builder(Collections.singleton(cfg.graphDefaultScope())) + .build()) + .get(); + }); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenSilent_WithRefreshOn(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenSilent_WithRefreshOn(String environment) throws Exception { cfg = new Config(environment); User user = labUserProvider.getDefaultUser(cfg.azureEnvironment); @@ -235,7 +249,7 @@ public void acquireTokenSilent_WithRefreshOn(String environment) throws Exceptio assertResultNotNull(resultOriginal); IAuthenticationResult resultSilent = acquireTokenSilently(pca, resultOriginal.account(), cfg.graphDefaultScope(), false); - Assert.assertNotNull(resultSilent); + assertNotNull(resultSilent); assertTokensAreEqual(resultOriginal, resultSilent); //When this test was made, token responses did not contain the refresh_in field needed for an end-to-end test. @@ -250,8 +264,8 @@ public void acquireTokenSilent_WithRefreshOn(String environment) throws Exceptio IAuthenticationResult resultSilentWithRefreshOn = acquireTokenSilently(pca, resultOriginal.account(), cfg.graphDefaultScope(), false); //Current time is before refreshOn, so token should not have been refreshed - Assert.assertNotNull(resultSilentWithRefreshOn); - Assert.assertEquals(pca.tokenCache.accessTokens.get(key).refreshOn(), Long.toString(currTimestampSec + 60)); + assertNotNull(resultSilentWithRefreshOn); + assertEquals(pca.tokenCache.accessTokens.get(key).refreshOn(), Long.toString(currTimestampSec + 60)); assertTokensAreEqual(resultSilent, resultSilentWithRefreshOn); token = pca.tokenCache.accessTokens.get(key); @@ -260,12 +274,13 @@ public void acquireTokenSilent_WithRefreshOn(String environment) throws Exceptio resultSilentWithRefreshOn = acquireTokenSilently(pca, resultOriginal.account(), cfg.graphDefaultScope(), false); //Current time is after refreshOn, so token should be refreshed - Assert.assertNotNull(resultSilentWithRefreshOn); + assertNotNull(resultSilentWithRefreshOn); assertTokensAreNotEqual(resultSilent, resultSilentWithRefreshOn); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenSilent_TenantAsParameter(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenSilent_TenantAsParameter(String environment) throws Exception { cfg = new Config(environment); User user = labUserProvider.getDefaultUser(environment); @@ -295,8 +310,9 @@ public void acquireTokenSilent_TenantAsParameter(String environment) throws Exce assertTokensAreNotEqual(result, resultWithTenantParam); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenSilent_emptyStringScope(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenSilent_emptyStringScope(String environment) throws Exception { cfg = new Config(environment); User user = labUserProvider.getDefaultUser(environment); @@ -312,11 +328,12 @@ public void acquireTokenSilent_emptyStringScope(String environment) throws Excep IAccount account = pca.getAccounts().join().iterator().next(); IAuthenticationResult silentResult = acquireTokenSilently(pca, account, emptyScope, false); assertResultNotNull(silentResult); - Assert.assertEquals(result.accessToken(), silentResult.accessToken()); + assertEquals(result.accessToken(), silentResult.accessToken()); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenSilent_emptyScopeSet(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenSilent_emptyScopeSet(String environment) throws Exception { cfg = new Config(environment); User user = labUserProvider.getDefaultUser(environment); @@ -341,7 +358,7 @@ public void acquireTokenSilent_emptyScopeSet(String environment) throws Exceptio .get(); assertResultNotNull(silentResult); - Assert.assertEquals(result.accessToken(), silentResult.accessToken()); + assertEquals(result.accessToken(), silentResult.accessToken()); } private IConfidentialClientApplication getConfidentialClientApplications() throws Exception { @@ -367,7 +384,7 @@ private void acquireTokenSilent_returnCachedTokens(String authority) throws Exce IAuthenticationResult interactiveAuthResult = acquireTokenUsernamePassword(user, pca, cfg.graphDefaultScope()); - Assert.assertNotNull(interactiveAuthResult); + assertNotNull(interactiveAuthResult); IAuthenticationResult silentAuthResult = pca.acquireTokenSilently( SilentParameters.builder( @@ -375,8 +392,8 @@ private void acquireTokenSilent_returnCachedTokens(String authority) throws Exce .build()) .get(); - Assert.assertNotNull(silentAuthResult); - Assert.assertEquals(interactiveAuthResult.accessToken(), silentAuthResult.accessToken()); + assertNotNull(silentAuthResult); + assertEquals(interactiveAuthResult.accessToken(), silentAuthResult.accessToken()); } private IPublicClientApplication getPublicClientApplicationWithTokensInCache() @@ -410,18 +427,18 @@ private IAuthenticationResult acquireTokenUsernamePassword(User user, IPublicCli } private void assertResultNotNull(IAuthenticationResult result) { - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); } private void assertTokensAreNotEqual(IAuthenticationResult result, IAuthenticationResult secondResult) { - Assert.assertNotEquals(result.accessToken(), secondResult.accessToken()); - Assert.assertNotEquals(result.idToken(), secondResult.idToken()); + assertNotEquals(result.accessToken(), secondResult.accessToken()); + assertNotEquals(result.idToken(), secondResult.idToken()); } private void assertTokensAreEqual(IAuthenticationResult result, IAuthenticationResult secondResult) { - Assert.assertEquals(result.accessToken(), secondResult.accessToken()); - Assert.assertEquals(result.idToken(), secondResult.idToken()); + assertEquals(result.accessToken(), secondResult.accessToken()); + assertEquals(result.idToken(), secondResult.idToken()); } } diff --git a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AuthorizationCodeIT.java b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AuthorizationCodeIT.java index 80058c8e..93e6cf27 100644 --- a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AuthorizationCodeIT.java +++ b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AuthorizationCodeIT.java @@ -4,10 +4,13 @@ package com.microsoft.aad.msal4j; import labapi.*; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.Test; import java.net.MalformedURLException; import java.net.URI; @@ -19,13 +22,17 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; -public class AuthorizationCodeIT extends SeleniumTest { +import static org.junit.jupiter.api.Assertions.*; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class AuthorizationCodeIT extends SeleniumTest { private final static Logger LOG = LoggerFactory.getLogger(AuthorizationCodeIT.class); private Config cfg; - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithAuthorizationCode_ManagedUser(String environment) { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithAuthorizationCode_ManagedUser(String environment) { cfg = new Config(environment); User user = labUserProvider.getDefaultUser(cfg.azureEnvironment); @@ -33,8 +40,9 @@ public void acquireTokenWithAuthorizationCode_ManagedUser(String environment) { } //TODO: Re-enable test once list of claims/capabilities and their expected behavior is known - //@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithAuthorizationCode_ManagedUserWithClaimsAndCapabilities(String environment) { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithAuthorizationCode_ManagedUserWithClaimsAndCapabilities(String environment) { cfg = new Config(environment); User user = labUserProvider.getDefaultUser(cfg.azureEnvironment); @@ -48,21 +56,23 @@ public void acquireTokenWithAuthorizationCode_ManagedUserWithClaimsAndCapabiliti } @Test - public void acquireTokenWithAuthorizationCode_ADFSv2019_OnPrem() { + void acquireTokenWithAuthorizationCode_ADFSv2019_OnPrem() { User user = labUserProvider.getOnPremAdfsUser(FederationProvider.ADFS_2019); assertAcquireTokenADFS2019(user); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithAuthorizationCode_ADFSv2019_Federated(String environment) { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithAuthorizationCode_ADFSv2019_Federated(String environment) { cfg = new Config(environment); User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_2019); assertAcquireTokenAAD(user, null); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithAuthorizationCode_ADFSv4_Federated(String environment) { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithAuthorizationCode_ADFSv4_Federated(String environment) { cfg = new Config(environment); User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_4); @@ -70,24 +80,27 @@ public void acquireTokenWithAuthorizationCode_ADFSv4_Federated(String environmen assertAcquireTokenAAD(user, null); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithAuthorizationCode_ADFSv3_Federated(String environment) { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithAuthorizationCode_ADFSv3_Federated(String environment) { cfg = new Config(environment); User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_3); assertAcquireTokenAAD(user, null); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithAuthorizationCode_ADFSv2_Federated(String environment) { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithAuthorizationCode_ADFSv2_Federated(String environment) { cfg = new Config(environment); User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_2); assertAcquireTokenAAD(user, null); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithAuthorizationCode_B2C_Local(String environment) { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithAuthorizationCode_B2C_Local(String environment) { cfg = new Config(environment); User user = labUserProvider.getB2cUser(environment, B2CProvider.LOCAL); @@ -97,7 +110,7 @@ public void acquireTokenWithAuthorizationCode_B2C_Local(String environment) { // failing on azure devOps //@Test // TODO Redirect URI localhost in not registered - public void acquireTokenWithAuthorizationCode_B2C_Google() { + void acquireTokenWithAuthorizationCode_B2C_Google() { /* LabResponse labResponse = labUserProvider.getB2cUser( B2CIdentityProvider.GOOGLE, false); @@ -112,7 +125,7 @@ public void acquireTokenWithAuthorizationCode_B2C_Google() { // TODO uncomment when lab fixes facebook test account //@Test // TODO Redirect URI localhost in not registered - public void acquireTokenWithAuthorizationCode_B2C_Facebook() { + void acquireTokenWithAuthorizationCode_B2C_Facebook() { /* LabResponse labResponse = labUserProvider.getB2cUser( B2CIdentityProvider.FACEBOOK, false); @@ -142,10 +155,10 @@ private void assertAcquireTokenADFS2019(User user) { authCode, Collections.singleton(TestConstants.ADFS_SCOPE)); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); - Assert.assertEquals(user.getUpn(), result.account().username()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); + assertEquals(user.getUpn(), result.account().username()); } private void assertAcquireTokenAAD(User user, Map> parameters) { @@ -171,10 +184,10 @@ private void assertAcquireTokenAAD(User user, Map> parameter authCode, Collections.singleton(cfg.graphDefaultScope())); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); - Assert.assertEquals(user.getUpn(), result.account().username()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); + assertEquals(user.getUpn(), result.account().username()); } private void assertAcquireTokenB2C(User user) { @@ -196,9 +209,9 @@ private void assertAcquireTokenB2C(User user) { String authCode = acquireAuthorizationCodeAutomated(user, cca, null); IAuthenticationResult result = acquireTokenInteractiveB2C(cca, authCode); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); } private IAuthenticationResult acquireTokenAuthorizationCodeFlow( diff --git a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AzureEnvironmentIT.java b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AzureEnvironmentIT.java index a46c4dd0..3981bc6f 100644 --- a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AzureEnvironmentIT.java +++ b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AzureEnvironmentIT.java @@ -4,27 +4,30 @@ package com.microsoft.aad.msal4j; import labapi.*; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.util.Collections; +import static org.junit.jupiter.api.Assertions.*; -public class AzureEnvironmentIT { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class AzureEnvironmentIT { private LabUserProvider labUserProvider; - @BeforeClass + @BeforeAll public void setUp() { labUserProvider = LabUserProvider.getInstance(); } @Test - public void acquireTokenWithUsernamePassword_AzureChina() throws Exception { + void acquireTokenWithUsernamePassword_AzureChina() throws Exception { assertAcquireTokenCommon(AzureEnvironment.AZURE_CHINA); } @Test - public void acquireTokenWithUsernamePassword_AzureGovernment() throws Exception { + void acquireTokenWithUsernamePassword_AzureGovernment() throws Exception { assertAcquireTokenCommon(AzureEnvironment.AZURE_US_GOVERNMENT); } @@ -45,10 +48,10 @@ private void assertAcquireTokenCommon(String azureEnvironment) throws Exception .build()) .get(); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); - Assert.assertEquals(user.getUpn(), result.account().username()); + assertEquals(user.getUpn(), result.account().username()); } } diff --git a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/ClientCredentialsIT.java b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/ClientCredentialsIT.java index 8c1f5256..520caff2 100644 --- a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/ClientCredentialsIT.java +++ b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/ClientCredentialsIT.java @@ -5,9 +5,8 @@ import labapi.AppCredentialProvider; import labapi.AzureEnvironment; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.security.KeyStoreException; @@ -19,24 +18,24 @@ import java.util.concurrent.Callable; import static com.microsoft.aad.msal4j.TestConstants.KEYVAULT_DEFAULT_SCOPE; +import static org.junit.jupiter.api.Assertions.*; -@Test -public class ClientCredentialsIT { - private IClientCertificate certificate; +class ClientCredentialsIT { + private static IClientCertificate certificate; - @BeforeClass - void init() throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, NoSuchProviderException, IOException { + @BeforeAll + public static void init() throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, NoSuchProviderException, IOException { certificate = CertificateHelper.getClientCertificate(); } @Test - public void acquireTokenClientCredentials_ClientCertificate() throws Exception { + void acquireTokenClientCredentials_ClientCertificate() throws Exception { String clientId = "2afb0add-2f32-4946-ac90-81a02aa4550e"; assertAcquireTokenCommon(clientId, certificate); } @Test - public void acquireTokenClientCredentials_ClientSecret() throws Exception { + void acquireTokenClientCredentials_ClientSecret() throws Exception { AppCredentialProvider appProvider = new AppCredentialProvider(AzureEnvironment.AZURE); final String clientId = appProvider.getLabVaultAppId(); final String password = appProvider.getLabVaultPassword(); @@ -46,7 +45,7 @@ public void acquireTokenClientCredentials_ClientSecret() throws Exception { } @Test - public void acquireTokenClientCredentials_ClientAssertion() throws Exception { + void acquireTokenClientCredentials_ClientAssertion() throws Exception { String clientId = "2afb0add-2f32-4946-ac90-81a02aa4550e"; ClientAssertion clientAssertion = getClientAssertion(clientId); @@ -57,7 +56,7 @@ public void acquireTokenClientCredentials_ClientAssertion() throws Exception { } @Test - public void acquireTokenClientCredentials_Callback() throws Exception { + void acquireTokenClientCredentials_Callback() throws Exception { String clientId = "2afb0add-2f32-4946-ac90-81a02aa4550e"; // Creates a valid client assertion using a callback, and uses it to build the client app and make a request @@ -81,7 +80,7 @@ public void acquireTokenClientCredentials_Callback() throws Exception { } @Test - public void acquireTokenClientCredentials_DefaultCacheLookup() throws Exception { + void acquireTokenClientCredentials_DefaultCacheLookup() throws Exception { AppCredentialProvider appProvider = new AppCredentialProvider(AzureEnvironment.AZURE); final String clientId = appProvider.getLabVaultAppId(); final String password = appProvider.getLabVaultPassword(); @@ -97,15 +96,15 @@ public void acquireTokenClientCredentials_DefaultCacheLookup() throws Exception .build()) .get(); - Assert.assertNotNull(result1); - Assert.assertNotNull(result1.accessToken()); + assertNotNull(result1); + assertNotNull(result1.accessToken()); IAuthenticationResult result2 = cca.acquireToken(ClientCredentialParameters .builder(Collections.singleton(KEYVAULT_DEFAULT_SCOPE)) .build()) .get(); - Assert.assertEquals(result1.accessToken(), result2.accessToken()); + assertEquals(result1.accessToken(), result2.accessToken()); IAuthenticationResult result3 = cca.acquireToken(ClientCredentialParameters .builder(Collections.singleton(KEYVAULT_DEFAULT_SCOPE)) @@ -113,13 +112,13 @@ public void acquireTokenClientCredentials_DefaultCacheLookup() throws Exception .build()) .get(); - Assert.assertNotNull(result3); - Assert.assertNotNull(result3.accessToken()); - Assert.assertNotEquals(result2.accessToken(), result3.accessToken()); + assertNotNull(result3); + assertNotNull(result3.accessToken()); + assertNotEquals(result2.accessToken(), result3.accessToken()); } @Test - public void acquireTokenClientCredentials_Regional() throws Exception { + void acquireTokenClientCredentials_Regional() throws Exception { String clientId = "2afb0add-2f32-4946-ac90-81a02aa4550e"; assertAcquireTokenCommon_withRegion(clientId, certificate); @@ -144,8 +143,8 @@ private void assertAcquireTokenCommon(String clientId, IClientCredential credent .build()) .get(); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); + assertNotNull(result); + assertNotNull(result.accessToken()); } private void assertAcquireTokenCommon_withParameters(String clientId, IClientCredential credential, IClientCredential credentialParam) throws Exception { @@ -160,8 +159,8 @@ private void assertAcquireTokenCommon_withParameters(String clientId, IClientCre .build()) .get(); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); + assertNotNull(result); + assertNotNull(result.accessToken()); } private void assertAcquireTokenCommon_withRegion(String clientId, IClientCredential credential) throws Exception { @@ -181,9 +180,9 @@ private void assertAcquireTokenCommon_withRegion(String clientId, IClientCredent .build()) .get(); - Assert.assertNotNull(resultNoRegion); - Assert.assertNotNull(resultNoRegion.accessToken()); - Assert.assertEquals(resultNoRegion.environment(), TestConstants.MICROSOFT_AUTHORITY_BASIC_HOST); + assertNotNull(resultNoRegion); + assertNotNull(resultNoRegion.accessToken()); + assertEquals(TestConstants.MICROSOFT_AUTHORITY_BASIC_HOST, resultNoRegion.environment()); //Ensure regional tokens are properly cached and retrievable IAuthenticationResult resultRegion = ccaRegion.acquireToken(ClientCredentialParameters @@ -191,18 +190,18 @@ private void assertAcquireTokenCommon_withRegion(String clientId, IClientCredent .build()) .get(); - Assert.assertNotNull(resultRegion); - Assert.assertNotNull(resultRegion.accessToken()); - Assert.assertEquals(resultRegion.environment(), TestConstants.REGIONAL_MICROSOFT_AUTHORITY_BASIC_HOST_WESTUS); + assertNotNull(resultRegion); + assertNotNull(resultRegion.accessToken()); + assertEquals(TestConstants.REGIONAL_MICROSOFT_AUTHORITY_BASIC_HOST_WESTUS, resultRegion.environment()); IAuthenticationResult resultRegionCached = ccaRegion.acquireToken(ClientCredentialParameters .builder(Collections.singleton(KEYVAULT_DEFAULT_SCOPE)) .build()) .get(); - Assert.assertNotNull(resultRegionCached); - Assert.assertNotNull(resultRegionCached.accessToken()); - Assert.assertEquals(resultRegionCached.accessToken(), resultRegion.accessToken()); + assertNotNull(resultRegionCached); + assertNotNull(resultRegionCached.accessToken()); + assertEquals(resultRegionCached.accessToken(), resultRegion.accessToken()); //Tokens retrieved from regional endpoints should be interchangeable with non-regional, and vice-versa //For example, if an application doesn't configure a region but gets regional tokens added to its cache, they should be retrievable @@ -212,8 +211,8 @@ private void assertAcquireTokenCommon_withRegion(String clientId, IClientCredent .build()) .get(); - Assert.assertNotNull(resultNoRegion); - Assert.assertNotNull(resultNoRegion.accessToken()); - Assert.assertEquals(resultNoRegion.accessToken(), resultRegion.accessToken()); + assertNotNull(resultNoRegion); + assertNotNull(resultNoRegion.accessToken()); + assertEquals(resultNoRegion.accessToken(), resultRegion.accessToken()); } } diff --git a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/DeviceCodeIT.java b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/DeviceCodeIT.java index aa23ffd3..14a61847 100644 --- a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/DeviceCodeIT.java +++ b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/DeviceCodeIT.java @@ -5,35 +5,39 @@ import infrastructure.SeleniumExtensions; import labapi.*; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testng.Assert; import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.testng.util.Strings; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.function.Consumer; -@Test -public class DeviceCodeIT { +import static org.junit.jupiter.api.Assertions.*; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class DeviceCodeIT { private final static Logger LOG = LoggerFactory.getLogger(DeviceCodeIT.class); private LabUserProvider labUserProvider; private WebDriver seleniumDriver; - @BeforeClass + @BeforeAll public void setUp() { labUserProvider = LabUserProvider.getInstance(); seleniumDriver = SeleniumExtensions.createDefaultWebDriver(); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void DeviceCodeFlowADTest(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void DeviceCodeFlowADTest(String environment) throws Exception { Config cfg = new Config(environment); User user = labUserProvider.getDefaultUser(cfg.azureEnvironment); @@ -53,12 +57,14 @@ public void DeviceCodeFlowADTest(String environment) throws Exception { .build()) .get(); - Assert.assertNotNull(result); - Assert.assertFalse(Strings.isNullOrEmpty(result.accessToken())); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertFalse(result.accessToken().isEmpty()); +// assertFalse(Strings.isNullOrEmpty(result.accessToken())); } @Test() - public void DeviceCodeFlowADFSv2019Test() throws Exception { + void DeviceCodeFlowADFSv2019Test() throws Exception { User user = labUserProvider.getOnPremAdfsUser(FederationProvider.ADFS_2019); @@ -77,12 +83,14 @@ public void DeviceCodeFlowADFSv2019Test() throws Exception { .build()) .get(); - Assert.assertNotNull(result); - Assert.assertFalse(Strings.isNullOrEmpty(result.accessToken())); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertFalse(result.accessToken().isEmpty()); +// assertFalse(Strings.isNullOrEmpty(result.accessToken())); } - @Test() - public void DeviceCodeFlowMSATest() throws Exception { + @Test + void DeviceCodeFlowMSATest() throws Exception { User user = labUserProvider.getMSAUser(); @@ -101,16 +109,20 @@ public void DeviceCodeFlowMSATest() throws Exception { .build()) .get(); - Assert.assertNotNull(result); - Assert.assertFalse(Strings.isNullOrEmpty(result.accessToken())); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertFalse(result.accessToken().isEmpty()); +// assertFalse(Strings.isNullOrEmpty(result.accessToken())); result = pca.acquireTokenSilently(SilentParameters. builder(Collections.singleton(""), result.account()). build()) .get(); - Assert.assertNotNull(result); - Assert.assertFalse(Strings.isNullOrEmpty(result.accessToken())); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertFalse(result.accessToken().isEmpty()); +// assertFalse(Strings.isNullOrEmpty(result.accessToken())); } private void runAutomatedDeviceCodeFlow(DeviceCode deviceCode, User user) { diff --git a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/HttpClientIT.java b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/HttpClientIT.java index 3bbbf4f7..f6b53bcf 100644 --- a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/HttpClientIT.java +++ b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/HttpClientIT.java @@ -5,28 +5,32 @@ import labapi.LabUserProvider; import labapi.User; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.util.Collections; -public class HttpClientIT { +import static org.junit.jupiter.api.Assertions.*; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class HttpClientIT { private LabUserProvider labUserProvider; - @BeforeClass + @BeforeAll public void setUp() { labUserProvider = LabUserProvider.getInstance(); } @Test - public void acquireToken_okHttpClient() throws Exception { + void acquireToken_okHttpClient() throws Exception { User user = labUserProvider.getDefaultUser(); assertAcquireTokenCommon(user, new OkHttpClientAdapter()); } @Test - public void acquireToken_apacheHttpClient() throws Exception { + void acquireToken_apacheHttpClient() throws Exception { User user = labUserProvider.getDefaultUser(); assertAcquireTokenCommon(user, new ApacheHttpClientAdapter()); } @@ -46,9 +50,9 @@ private void assertAcquireTokenCommon(User user, IHttpClient httpClient) .build()) .get(); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); - Assert.assertEquals(user.getUpn(), result.account().username()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); + assertEquals(user.getUpn(), result.account().username()); } } diff --git a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/OnBehalfOfIT.java b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/OnBehalfOfIT.java index 71d706c3..459771bc 100644 --- a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/OnBehalfOfIT.java +++ b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/OnBehalfOfIT.java @@ -4,18 +4,21 @@ package com.microsoft.aad.msal4j; import labapi.*; -import org.testng.Assert; -import org.testng.annotations.Test; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.Collections; -@Test -public class OnBehalfOfIT { +import static org.junit.jupiter.api.Assertions.*; + +class OnBehalfOfIT { private Config cfg; - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithOBO_Managed(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithOBO_Managed(String environment) throws Exception { cfg = new Config(environment); String accessToken = this.getAccessToken(); @@ -33,12 +36,13 @@ public void acquireTokenWithOBO_Managed(String environment) throws Exception { new UserAssertion(accessToken)).build()). get(); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); + assertNotNull(result); + assertNotNull(result.accessToken()); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithOBO_testCache(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithOBO_testCache(String environment) throws Exception { cfg = new Config(environment); String accessToken = this.getAccessToken(); @@ -56,8 +60,8 @@ public void acquireTokenWithOBO_testCache(String environment) throws Exception { new UserAssertion(accessToken)).build()). get(); - Assert.assertNotNull(result1); - Assert.assertNotNull(result1.accessToken()); + assertNotNull(result1); + assertNotNull(result1.accessToken()); // Same scope and userAssertion, should return cached tokens IAuthenticationResult result2 = @@ -66,7 +70,7 @@ public void acquireTokenWithOBO_testCache(String environment) throws Exception { new UserAssertion(accessToken)).build()). get(); - Assert.assertEquals(result1.accessToken(), result2.accessToken()); + assertEquals(result1.accessToken(), result2.accessToken()); // Scope 2, should return new token IAuthenticationResult result3 = @@ -75,9 +79,9 @@ public void acquireTokenWithOBO_testCache(String environment) throws Exception { new UserAssertion(accessToken)).build()). get(); - Assert.assertNotNull(result3); - Assert.assertNotNull(result3.accessToken()); - Assert.assertNotEquals(result2.accessToken(), result3.accessToken()); + assertNotNull(result3); + assertNotNull(result3.accessToken()); + assertNotEquals(result2.accessToken(), result3.accessToken()); // Scope 2, should return cached token IAuthenticationResult result4 = @@ -86,7 +90,7 @@ public void acquireTokenWithOBO_testCache(String environment) throws Exception { new UserAssertion(accessToken)).build()). get(); - Assert.assertEquals(result3.accessToken(), result4.accessToken()); + assertEquals(result3.accessToken(), result4.accessToken()); // skipCache=true, should return new token IAuthenticationResult result5 = @@ -98,10 +102,10 @@ public void acquireTokenWithOBO_testCache(String environment) throws Exception { .build()). get(); - Assert.assertNotNull(result5); - Assert.assertNotNull(result5.accessToken()); - Assert.assertNotEquals(result5.accessToken(), result4.accessToken()); - Assert.assertNotEquals(result5.accessToken(), result2.accessToken()); + assertNotNull(result5); + assertNotNull(result5.accessToken()); + assertNotEquals(result5.accessToken(), result4.accessToken()); + assertNotEquals(result5.accessToken(), result2.accessToken()); String newAccessToken = this.getAccessToken(); @@ -114,11 +118,11 @@ public void acquireTokenWithOBO_testCache(String environment) throws Exception { .build()). get(); - Assert.assertNotNull(result6); - Assert.assertNotNull(result6.accessToken()); - Assert.assertNotEquals(result6.accessToken(), result5.accessToken()); - Assert.assertNotEquals(result6.accessToken(), result4.accessToken()); - Assert.assertNotEquals(result6.accessToken(), result2.accessToken()); + assertNotNull(result6); + assertNotNull(result6.accessToken()); + assertNotEquals(result6.accessToken(), result5.accessToken()); + assertNotEquals(result6.accessToken(), result4.accessToken()); + assertNotEquals(result6.accessToken(), result2.accessToken()); } private String getAccessToken() throws Exception { diff --git a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/RefreshTokenIT.java b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/RefreshTokenIT.java index a1e5ebfb..49d34acb 100644 --- a/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/RefreshTokenIT.java +++ b/msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/RefreshTokenIT.java @@ -5,15 +5,18 @@ import labapi.LabUserProvider; import labapi.User; -import org.testng.Assert; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.Collections; import java.util.concurrent.ExecutionException; +import static org.junit.jupiter.api.Assertions.*; -@Test() -public class RefreshTokenIT { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class RefreshTokenIT { private String refreshToken; private PublicClientApplication pca; @@ -38,8 +41,9 @@ private void setUp(String environment) throws Exception { refreshToken = result.refreshToken(); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithRefreshToken(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithRefreshToken(String environment) throws Exception { cfg = new Config(environment); setUp(environment); @@ -51,18 +55,25 @@ public void acquireTokenWithRefreshToken(String environment) throws Exception { .build()) .get(); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); } - @Test(expectedExceptions = ExecutionException.class) - public void acquireTokenWithRefreshToken_WrongScopes() throws Exception { - IAuthenticationResult result = pca.acquireToken(RefreshTokenParameters - .builder( - Collections.singleton(TestConstants.KEYVAULT_DEFAULT_SCOPE), - refreshToken) - .build()) - .get(); + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithRefreshToken_WrongScopes(String environment) throws Exception { + cfg = new Config(environment); + + setUp(environment); + assertThrows(ExecutionException.class, () -> { + + pca.acquireToken(RefreshTokenParameters + .builder( + Collections.singleton(TestConstants.KEYVAULT_DEFAULT_SCOPE), + refreshToken) + .build()) + .get(); + }); } } 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 498166aa..2b5c679b 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 @@ -4,25 +4,31 @@ package com.microsoft.aad.msal4j; import labapi.*; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.Collections; -@Test() -public class UsernamePasswordIT { +import static org.junit.jupiter.api.Assertions.*; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class UsernamePasswordIT { private LabUserProvider labUserProvider; private Config cfg; - @BeforeClass + @BeforeAll public void setUp() { labUserProvider = LabUserProvider.getInstance(); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithUsernamePassword_Managed(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithUsernamePassword_Managed(String environment) throws Exception { cfg = new Config(environment); User user = labUserProvider.getDefaultUser(cfg.azureEnvironment); @@ -30,8 +36,9 @@ public void acquireTokenWithUsernamePassword_Managed(String environment) throws assertAcquireTokenCommonAAD(user); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithUsernamePassword_ADFSv2019_Federated(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithUsernamePassword_ADFSv2019_Federated(String environment) throws Exception { cfg = new Config(environment); UserQueryParameters query = new UserQueryParameters(); @@ -45,7 +52,7 @@ public void acquireTokenWithUsernamePassword_ADFSv2019_Federated(String environm } @Test - public void acquireTokenWithUsernamePassword_ADFSv2019_OnPrem() throws Exception { + void acquireTokenWithUsernamePassword_ADFSv2019_OnPrem() throws Exception { UserQueryParameters query = new UserQueryParameters(); query.parameters.put(UserQueryParameters.FEDERATION_PROVIDER, FederationProvider.ADFS_2019); query.parameters.put(UserQueryParameters.USER_TYPE, UserType.ON_PREM); @@ -55,8 +62,9 @@ public void acquireTokenWithUsernamePassword_ADFSv2019_OnPrem() throws Exception assertAcquireTokenCommonADFS(user); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithUsernamePassword_ADFSv4(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithUsernamePassword_ADFSv4(String environment) throws Exception { cfg = new Config(environment); UserQueryParameters query = new UserQueryParameters(); @@ -69,8 +77,9 @@ public void acquireTokenWithUsernamePassword_ADFSv4(String environment) throws E assertAcquireTokenCommonAAD(user); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithUsernamePassword_ADFSv3(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithUsernamePassword_ADFSv3(String environment) throws Exception { cfg = new Config(environment); UserQueryParameters query = new UserQueryParameters(); @@ -83,8 +92,9 @@ public void acquireTokenWithUsernamePassword_ADFSv3(String environment) throws E assertAcquireTokenCommonAAD(user); } - @Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class) - public void acquireTokenWithUsernamePassword_ADFSv2(String environment) throws Exception { + @ParameterizedTest + @MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData") + void acquireTokenWithUsernamePassword_ADFSv2(String environment) throws Exception { cfg = new Config(environment); UserQueryParameters query = new UserQueryParameters(); @@ -98,7 +108,7 @@ public void acquireTokenWithUsernamePassword_ADFSv2(String environment) throws E } @Test - public void acquireTokenWithUsernamePassword_AuthorityWithPort() throws Exception { + void acquireTokenWithUsernamePassword_AuthorityWithPort() throws Exception { User user = labUserProvider.getDefaultUser(); assertAcquireTokenCommon( @@ -132,14 +142,14 @@ private void assertAcquireTokenCommon(User user, String authority, String scope, .build()) .get(); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); - Assert.assertEquals(user.getUpn(), result.account().username()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); + assertEquals(user.getUpn(), result.account().username()); } @Test - public void acquireTokenWithUsernamePassword_B2C_CustomAuthority() throws Exception { + void acquireTokenWithUsernamePassword_B2C_CustomAuthority() throws Exception { UserQueryParameters query = new UserQueryParameters(); query.parameters.put(UserQueryParameters.USER_TYPE, UserType.B2C); query.parameters.put(UserQueryParameters.B2C_PROVIDER, B2CProvider.LOCAL); @@ -157,9 +167,9 @@ public void acquireTokenWithUsernamePassword_B2C_CustomAuthority() throws Except .build()) .get(); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); IAccount account = pca.getAccounts().join().iterator().next(); SilentParameters.builder(Collections.singleton(TestConstants.B2C_READ_SCOPE), account); @@ -169,13 +179,13 @@ public void acquireTokenWithUsernamePassword_B2C_CustomAuthority() throws Except .build()) .get(); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); } @Test - public void acquireTokenWithUsernamePassword_B2C_LoginMicrosoftOnline() throws Exception { + void acquireTokenWithUsernamePassword_B2C_LoginMicrosoftOnline() throws Exception { UserQueryParameters query = new UserQueryParameters(); query.parameters.put(UserQueryParameters.USER_TYPE, UserType.B2C); query.parameters.put(UserQueryParameters.B2C_PROVIDER, B2CProvider.LOCAL); @@ -193,9 +203,9 @@ public void acquireTokenWithUsernamePassword_B2C_LoginMicrosoftOnline() throws E .build()) .get(); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); IAccount account = pca.getAccounts().join().iterator().next(); SilentParameters.builder(Collections.singleton(TestConstants.B2C_READ_SCOPE), account); @@ -205,8 +215,8 @@ public void acquireTokenWithUsernamePassword_B2C_LoginMicrosoftOnline() throws E .build()) .get(); - Assert.assertNotNull(result); - Assert.assertNotNull(result.accessToken()); - Assert.assertNotNull(result.idToken()); + assertNotNull(result); + assertNotNull(result.accessToken()); + assertNotNull(result.idToken()); } } 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 db6ea553..b74db7a3 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 @@ -3,46 +3,54 @@ package com.microsoft.aad.msal4j; +import org.junit.jupiter.api.Assertions; import org.powermock.modules.testng.PowerMockTestCase; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.concurrent.CompletionException; -@Test(groups = {"checkin"}) -public class AcquireTokenSilentlyTest extends PowerMockTestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; - @Test(expectedExceptions = MsalClientException.class, - expectedExceptionsMessageRegExp = AuthenticationErrorMessage.NO_TOKEN_IN_CACHE) - public void publicAppAcquireTokenSilently_emptyCache_MsalClientException() throws Throwable { +//@Test//(groups = {"checkin"}) +class AcquireTokenSilentlyTest { + + @Test + void publicAppAcquireTokenSilently_emptyCache_MsalClientException() throws Throwable { PublicClientApplication application = PublicClientApplication .builder(TestConfiguration.AAD_CLIENT_ID) .b2cAuthority(TestConfiguration.B2C_AUTHORITY).build(); - SilentParameters parameters = SilentParameters.builder(Collections.singleton("scope")).build(); + MsalClientException exception = Assertions.assertThrows(MsalClientException.class, () -> { + SilentParameters parameters = SilentParameters.builder(Collections.singleton("scope")).build(); + try { + application.acquireTokenSilently(parameters).join(); + } catch (CompletionException ex) { + throw ex.getCause(); + } + }); - try { - application.acquireTokenSilently(parameters).join(); - } catch (CompletionException ex) { - throw ex.getCause(); - } + assertEquals(AuthenticationErrorMessage.NO_TOKEN_IN_CACHE, exception.getMessage()); } - @Test(expectedExceptions = MsalClientException.class, - expectedExceptionsMessageRegExp = AuthenticationErrorMessage.NO_TOKEN_IN_CACHE) - public void confidentialAppAcquireTokenSilently_emptyCache_MsalClientException() throws Throwable { + @Test + void confidentialAppAcquireTokenSilently_emptyCache_MsalClientException() throws Throwable { ConfidentialClientApplication application = ConfidentialClientApplication .builder(TestConfiguration.AAD_CLIENT_ID, ClientCredentialFactory.createFromSecret(TestConfiguration.AAD_CLIENT_DUMMYSECRET)) .b2cAuthority(TestConfiguration.B2C_AUTHORITY).build(); - SilentParameters parameters = SilentParameters.builder(Collections.singleton("scope")).build(); + MsalClientException exception = Assertions.assertThrows(MsalClientException.class, () -> { + SilentParameters parameters = SilentParameters.builder(Collections.singleton("scope")).build(); + + try { + application.acquireTokenSilently(parameters).join(); + } catch (CompletionException ex) { + throw ex.getCause(); + } + }); - try { - application.acquireTokenSilently(parameters).join(); - } catch (CompletionException ex) { - throw ex.getCause(); - } + assertEquals(AuthenticationErrorMessage.NO_TOKEN_IN_CACHE, exception.getMessage()); } } diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AssertionCredentialTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AssertionCredentialTest.java index 8f7e7450..11e17d1f 100644 --- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AssertionCredentialTest.java +++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AssertionCredentialTest.java @@ -3,18 +3,33 @@ package com.microsoft.aad.msal4j; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +//// @Test(groups = {"checkin"}) +class AssertionCredentialTest { + + @Test + void testAssertionNull() { + NullPointerException exception = Assertions.assertThrows(NullPointerException.class, () -> { + new ClientAssertion(null); + }); + + assertEquals("assertion", exception.getMessage()); -@Test(groups = {"checkin"}) -public class AssertionCredentialTest { - @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "assertion") - public void testAssertionNull() { - new ClientAssertion(null); } - @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "assertion") - public void testAssertionEmpty() { - new ClientAssertion(""); + @Test + void testAssertionEmpty() { + NullPointerException exception = Assertions.assertThrows(NullPointerException.class, () -> { + new ClientAssertion(""); + }); + + assertEquals("assertion", exception.getMessage()); } } 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 0db1b159..7957bd86 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 @@ -6,109 +6,131 @@ import java.net.MalformedURLException; import java.net.URL; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.powermock.core.classloader.annotations.PrepareForTest; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -@Test(groups = {"checkin"}) -@PrepareForTest({AADAuthority.class, HttpHelper.class, - JsonHelper.class, AadInstanceDiscoveryResponse.class}) +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +// @Test(groups = {"checkin"}) +////@PrepareForTest({AADAuthority.class, HttpHelper.class, +// JsonHelper.class, AadInstanceDiscoveryResponse.class}) public class AuthorityTest extends AbstractMsalTests { @Test public void testDetectAuthorityType_AAD() throws Exception { URL url = new URL(TestConfiguration.AAD_TENANT_ENDPOINT); - Assert.assertEquals(Authority.detectAuthorityType(url), AuthorityType.AAD); + assertEquals(Authority.detectAuthorityType(url), AuthorityType.AAD); } @Test public void testDetectAuthorityType_ADFS() throws Exception { URL url = new URL(TestConfiguration.ADFS_TENANT_ENDPOINT); - Assert.assertEquals(Authority.detectAuthorityType(url), AuthorityType.ADFS); + assertEquals(Authority.detectAuthorityType(url), AuthorityType.ADFS); } @Test public void testDetectAuthorityType_B2C() throws Exception { URL url = new URL(TestConfiguration.B2C_AUTHORITY); - Assert.assertEquals(Authority.detectAuthorityType(url), AuthorityType.B2C); + assertEquals(Authority.detectAuthorityType(url), AuthorityType.B2C); } - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = - "B2C 'authority' Uri should have at least 3 segments in the path \\(i.e. https:///tfp///...\\)") - public void testB2CAuthorityConstructor_NotEnoughSegments() throws MalformedURLException { - new B2CAuthority(new URL("https://something.com/tfp/somethingelse/")); + @Test + public void testB2CAuthorityConstructor_NotEnoughSegments(){ + + IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> { + new B2CAuthority(new URL("https://something.com/tfp/somethingelse/")); + }); + + assertEquals("B2C 'authority' Uri should have at least 3 segments in the path (i.e. https:///tfp///...)", exception.getMessage()); } - @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "authority should use the 'https' scheme") - public void testAADAuthorityConstructor_HttpAuthority() throws MalformedURLException { - Authority.validateAuthority(new URL("http://I.com/not/h/t/t/p/s/")); + @Test + public void testAADAuthorityConstructor_HttpAuthority(){ + IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> { + Authority.validateAuthority(new URL("http://I.com/not/h/t/t/p/s/")); + }); + + assertEquals("authority should use the 'https' scheme", exception.getMessage()); + + } - @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "authority is invalid format \\(contains fragment\\)") + @Test public void testAADAuthorityConstructor_UrlHasFragment() throws MalformedURLException { - Authority.validateAuthority(new URL("https://I.com/something/#haha")); + IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> { + Authority.validateAuthority(new URL("https://I.com/something/#haha")); + }); + + assertEquals("authority is invalid format (contains fragment)", exception.getMessage()); } - @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "authority cannot contain query parameters") + @Test public void testAADAuthorityConstructor_AuthorityHasQuery() throws MalformedURLException { - Authority.validateAuthority(new URL("https://I.com/not/?query=not-allowed")); + IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> { + Authority.validateAuthority(new URL("https://I.com/not/?query=not-allowed")); + }); + + assertEquals("authority cannot contain query parameters", exception.getMessage()); + } @Test public void testConstructor_AADAuthority() throws MalformedURLException { final AADAuthority aa = new AADAuthority(new URL(TestConfiguration.AAD_TENANT_ENDPOINT)); - Assert.assertNotNull(aa); - Assert.assertEquals(aa.authority(), + assertNotNull(aa); + assertEquals(aa.authority(), TestConfiguration.AAD_TENANT_ENDPOINT); - Assert.assertEquals(aa.host(), TestConfiguration.AAD_HOST_NAME); - Assert.assertEquals(aa.tokenEndpoint(), + assertEquals(aa.host(), TestConfiguration.AAD_HOST_NAME); + assertEquals(aa.tokenEndpoint(), TestConfiguration.AAD_TENANT_ENDPOINT + "oauth2/v2.0/token"); - Assert.assertEquals(aa.selfSignedJwtAudience(), + assertEquals(aa.selfSignedJwtAudience(), TestConfiguration.AAD_TENANT_ENDPOINT + "oauth2/v2.0/token"); - Assert.assertEquals(aa.tokenEndpoint(), + assertEquals(aa.tokenEndpoint(), TestConfiguration.AAD_TENANT_ENDPOINT + "oauth2/v2.0/token"); - Assert.assertEquals(aa.authorityType(), AuthorityType.AAD); - Assert.assertFalse(aa.isTenantless()); - Assert.assertEquals(aa.deviceCodeEndpoint(), + assertEquals(aa.authorityType(), AuthorityType.AAD); + assertFalse(aa.isTenantless()); + assertEquals(aa.deviceCodeEndpoint(), TestConfiguration.AAD_TENANT_ENDPOINT + "oauth2/v2.0/devicecode"); } @Test public void testConstructor_B2CAuthority() throws MalformedURLException { final B2CAuthority aa = new B2CAuthority(new URL(TestConfiguration.B2C_AUTHORITY)); - Assert.assertNotNull(aa); - Assert.assertEquals(aa.authority(), + assertNotNull(aa); + assertEquals(aa.authority(), TestConfiguration.B2C_AUTHORITY + "/"); - Assert.assertEquals(aa.host(), TestConfiguration.B2C_HOST_NAME); - Assert.assertEquals(aa.selfSignedJwtAudience(), + assertEquals(aa.host(), TestConfiguration.B2C_HOST_NAME); + assertEquals(aa.selfSignedJwtAudience(), TestConfiguration.B2C_AUTHORITY_ENDPOINT + "/oauth2/v2.0/token?p=" + TestConfiguration.B2C_SIGN_IN_POLICY); - Assert.assertEquals(aa.tokenEndpoint(), + assertEquals(aa.tokenEndpoint(), TestConfiguration.B2C_AUTHORITY_ENDPOINT + "/oauth2/v2.0/token?p=" + TestConfiguration.B2C_SIGN_IN_POLICY); - Assert.assertEquals(aa.authorityType(), AuthorityType.B2C); - Assert.assertEquals(aa.tokenEndpoint(), + assertEquals(aa.authorityType(), AuthorityType.B2C); + assertEquals(aa.tokenEndpoint(), TestConfiguration.B2C_AUTHORITY_ENDPOINT + "/oauth2/v2.0/token?p=" + TestConfiguration.B2C_SIGN_IN_POLICY); - Assert.assertFalse(aa.isTenantless()); + assertFalse(aa.isTenantless()); } @Test public void testConstructor_ADFSAuthority() throws MalformedURLException { final ADFSAuthority a = new ADFSAuthority(new URL(TestConfiguration.ADFS_TENANT_ENDPOINT)); - Assert.assertNotNull(a); - Assert.assertEquals(a.authority(), TestConfiguration.ADFS_TENANT_ENDPOINT); - Assert.assertEquals(a.host(), TestConfiguration.ADFS_HOST_NAME); - Assert.assertEquals(a.selfSignedJwtAudience(), + 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); - Assert.assertEquals(a.authorityType(), AuthorityType.ADFS); + assertEquals(a.authorityType(), AuthorityType.ADFS); - Assert.assertEquals(a.tokenEndpoint(), + assertEquals(a.tokenEndpoint(), TestConfiguration.ADFS_TENANT_ENDPOINT + ADFSAuthority.TOKEN_ENDPOINT); - Assert.assertFalse(a.isTenantless()); + assertFalse(a.isTenantless()); } @Test @@ -116,12 +138,12 @@ public void testB2CAuthority_SameCanonicalAuthority() throws MalformedURLExcepti PublicClientApplication pca = PublicClientApplication.builder("client_id"). b2cAuthority(TestConfiguration.B2C_AUTHORITY_CUSTOM_PORT).build(); - Assert.assertEquals(pca.authenticationAuthority.authority, + assertEquals(pca.authenticationAuthority.authority, TestConfiguration.B2C_AUTHORITY_CUSTOM_PORT_TAIL_SLASH); PublicClientApplication pca2 = PublicClientApplication.builder("client_id"). b2cAuthority(TestConfiguration.B2C_AUTHORITY_CUSTOM_PORT_TAIL_SLASH).build(); - Assert.assertEquals(pca2.authenticationAuthority.authority, + assertEquals(pca2.authenticationAuthority.authority, TestConfiguration.B2C_AUTHORITY_CUSTOM_PORT_TAIL_SLASH); } @@ -129,48 +151,56 @@ public void testB2CAuthority_SameCanonicalAuthority() throws MalformedURLExcepti public void testNoAuthorityPassedIn_DefaultsToCommonAuthority() { PublicClientApplication pca = PublicClientApplication.builder("client_id").build(); - Assert.assertEquals(pca.authority(), TestConfiguration.AAD_COMMON_AUTHORITY); - Assert.assertNotNull(pca.authenticationAuthority); + assertEquals(pca.authority(), TestConfiguration.AAD_COMMON_AUTHORITY); + assertNotNull(pca.authenticationAuthority); } @Test public void testDoStaticInstanceDiscovery_ValidateTrue_TrustedAuthority() throws Exception { final AADAuthority aa = new AADAuthority(new URL(TestConfiguration.AAD_TENANT_ENDPOINT)); - //PS Assert.assertTrue(aa.doStaticInstanceDiscovery(true)); + //PS assertTrue(aa.doStaticInstanceDiscovery(true)); } @Test public void testDoStaticInstanceDiscovery_ValidateTrue_UntrustedAuthority() throws Exception { final AADAuthority aa = new AADAuthority(new URL(TestConfiguration.AAD_UNKNOWN_TENANT_ENDPOINT)); - //PS Assert.assertFalse(aa.doStaticInstanceDiscovery(true)); + //PS assertFalse(aa.doStaticInstanceDiscovery(true)); } @Test public void testDoStaticInstanceDiscovery_ValidateFalse_TrustedAuthority() throws Exception { final AADAuthority aa = new AADAuthority(new URL(TestConfiguration.AAD_UNKNOWN_TENANT_ENDPOINT)); - //PS Assert.assertTrue(aa.doStaticInstanceDiscovery(false)); + //PS assertTrue(aa.doStaticInstanceDiscovery(false)); } - @DataProvider(name = "authoritiesWithEmptyPath") public static Object[][] createData() { return new Object[][]{{"https://login.microsoftonline.com/"}, {"https://login.microsoftonline.com//tenant"}, {"https://login.microsoftonline.com////tenant//path1"}}; } - @Test(dataProvider = "authoritiesWithEmptyPath", expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = IllegalArgumentExceptionMessages.AUTHORITY_URI_EMPTY_PATH_SEGMENT) + @ParameterizedTest + @MethodSource("createData") public void testValidateAuthorityEmptyPathSegments(String authority) throws MalformedURLException { - Authority.validateAuthority(new URL(authority)); + IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> { + Authority.validateAuthority(new URL(authority)); + }); + + assertEquals(IllegalArgumentExceptionMessages.AUTHORITY_URI_EMPTY_PATH_SEGMENT, exception.getMessage()); + } - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = IllegalArgumentExceptionMessages.AUTHORITY_URI_EMPTY_PATH) + @Test public void testValidateAuthorityEmptyPath() throws MalformedURLException { - Authority.validateAuthority(new URL("https://login.microsoftonline.com")); + IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> { + Authority.validateAuthority(new URL("https://login.microsoftonline.com")); + }); + + assertEquals(IllegalArgumentExceptionMessages.AUTHORITY_URI_EMPTY_PATH, exception.getMessage()); + } } 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 589bb339..b52b6bea 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 @@ -3,14 +3,18 @@ package com.microsoft.aad.msal4j; -import org.testng.Assert; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLDecoder; import java.util.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + public class AuthorizationRequestUrlParametersTest { @Test @@ -25,22 +29,22 @@ public void testBuilder_onlyRequiredParameters() throws UnsupportedEncodingExcep .builder(redirectUri, scope) .build(); - Assert.assertEquals(parameters.responseMode(), ResponseMode.FORM_POST); - Assert.assertEquals(parameters.redirectUri(), redirectUri); - Assert.assertEquals(parameters.scopes().size(), 4); + assertEquals(parameters.responseMode(), ResponseMode.FORM_POST); + assertEquals(parameters.redirectUri(), redirectUri); + assertEquals(parameters.scopes().size(), 4); - Assert.assertNull(parameters.loginHint()); - Assert.assertNull(parameters.codeChallenge()); - Assert.assertNull(parameters.codeChallengeMethod()); - Assert.assertNull(parameters.correlationId()); - Assert.assertNull(parameters.nonce()); - Assert.assertNull(parameters.prompt()); - Assert.assertNull(parameters.state()); + assertNull(parameters.loginHint()); + assertNull(parameters.codeChallenge()); + assertNull(parameters.codeChallengeMethod()); + assertNull(parameters.correlationId()); + assertNull(parameters.nonce()); + assertNull(parameters.prompt()); + assertNull(parameters.state()); URL authorizationUrl = app.getAuthorizationRequestUrl(parameters); - Assert.assertEquals(authorizationUrl.getHost(), "login.microsoftonline.com"); - Assert.assertEquals(authorizationUrl.getPath(), "/common/oauth2/v2.0/authorize"); + assertEquals(authorizationUrl.getHost(), "login.microsoftonline.com"); + assertEquals(authorizationUrl.getPath(), "/common/oauth2/v2.0/authorize"); Map queryParameters = new HashMap<>(); String query = authorizationUrl.getQuery(); @@ -53,22 +57,23 @@ public void testBuilder_onlyRequiredParameters() throws UnsupportedEncodingExcep URLDecoder.decode(pair.substring(idx + 1), "UTF-8")); } - Assert.assertEquals(queryParameters.get("scope"), "openid profile offline_access scope"); - Assert.assertEquals(queryParameters.get("response_type"), "code"); - Assert.assertEquals(queryParameters.get("redirect_uri"), "http://localhost:8080"); - Assert.assertEquals(queryParameters.get("client_id"), "client_id"); - Assert.assertEquals(queryParameters.get("response_mode"), "form_post"); + 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"); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBuilder_invalidRequiredParameters() { String redirectUri = ""; Set scope = Collections.singleton("scope"); - AuthorizationRequestUrlParameters parameters = - AuthorizationRequestUrlParameters - .builder(redirectUri, scope) - .build(); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + AuthorizationRequestUrlParameters + .builder(redirectUri, scope) + .build(); + }); } @Test @@ -111,23 +116,23 @@ public void testBuilder_optionalParameters() throws UnsupportedEncodingException URLDecoder.decode(pair.substring(idx + 1), "UTF-8")); } - Assert.assertEquals(queryParameters.get("scope"), + assertEquals(queryParameters.get("scope"), "openid profile offline_access scope extraScopeToConsent1 extraScopeToConsent2"); - Assert.assertEquals(queryParameters.get("response_type"), "code"); - Assert.assertEquals(queryParameters.get("redirect_uri"), "http://localhost:8080"); - Assert.assertEquals(queryParameters.get("client_id"), "client_id"); - Assert.assertEquals(queryParameters.get("prompt"), "select_account"); - Assert.assertEquals(queryParameters.get("response_mode"), "query"); - Assert.assertEquals(queryParameters.get("code_challenge"), "challenge"); - Assert.assertEquals(queryParameters.get("code_challenge_method"), "method"); - Assert.assertEquals(queryParameters.get("state"), "app_state"); - Assert.assertEquals(queryParameters.get("nonce"), "app_nonce"); - Assert.assertEquals(queryParameters.get("correlation_id"), "corr_id"); - Assert.assertEquals(queryParameters.get("login_hint"), "hint"); - Assert.assertEquals(queryParameters.get("domain_hint"), "domain_hint"); - Assert.assertEquals(queryParameters.get("claims"), "{\"id_token\":{\"auth_time\":{\"essential\":true}},\"access_token\":{\"auth_time\":{\"essential\":true},\"xms_cc\":{\"values\":[\"llt\",\"ssm\"]}}}"); + assertEquals(queryParameters.get("response_type"), "code"); + assertEquals(queryParameters.get("redirect_uri"), "http://localhost:8080"); + assertEquals(queryParameters.get("client_id"), "client_id"); + assertEquals(queryParameters.get("prompt"), "select_account"); + assertEquals(queryParameters.get("response_mode"), "query"); + assertEquals(queryParameters.get("code_challenge"), "challenge"); + assertEquals(queryParameters.get("code_challenge_method"), "method"); + assertEquals(queryParameters.get("state"), "app_state"); + assertEquals(queryParameters.get("nonce"), "app_nonce"); + assertEquals(queryParameters.get("correlation_id"), "corr_id"); + assertEquals(queryParameters.get("login_hint"), "hint"); + assertEquals(queryParameters.get("domain_hint"), "domain_hint"); + assertEquals(queryParameters.get("claims"), "{\"id_token\":{\"auth_time\":{\"essential\":true}},\"access_token\":{\"auth_time\":{\"essential\":true},\"xms_cc\":{\"values\":[\"llt\",\"ssm\"]}}}"); // CCS routing - Assert.assertEquals(queryParameters.get(HttpHeaders.X_ANCHOR_MAILBOX), String.format(HttpHeaders.X_ANCHOR_MAILBOX_UPN_FORMAT, "hint")); + assertEquals(queryParameters.get(HttpHeaders.X_ANCHOR_MAILBOX), String.format(HttpHeaders.X_ANCHOR_MAILBOX_UPN_FORMAT, "hint")); } } diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClaimsTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClaimsTest.java index 60eb99e8..e29dc421 100644 --- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClaimsTest.java +++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClaimsTest.java @@ -3,8 +3,8 @@ package com.microsoft.aad.msal4j; -import org.testng.Assert; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.Test; import java.net.URI; import java.net.URISyntaxException; @@ -13,6 +13,8 @@ import java.util.HashSet; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class ClaimsTest { @Test @@ -29,7 +31,7 @@ public void testClaimsRequest_Format() { cr.requestClaimInIdToken("sub", new RequestedClaimAdditionalInfo(true, "248289761001", null)); cr.requestClaimInIdToken("auth_time", new RequestedClaimAdditionalInfo(false, null, null)); - Assert.assertEquals(cr.formatAsJSONString(), TestConfiguration.CLAIMS_REQUEST); + assertEquals(cr.formatAsJSONString(), TestConfiguration.CLAIMS_REQUEST); } @Test @@ -64,18 +66,18 @@ public void testClaimsRequest_MergeWithClientCapabilitiesAndClaimsChallenge() th String mergedClaimsAndChallenge = JsonHelper.mergeJSONString(claimsChallenge, claimsRequest); String mergedAll = JsonHelper.mergeJSONString(claimsChallenge, mergedClaimsAndCapabilities); - Assert.assertEquals(clientCapabilities, TestConfiguration.CLIENT_CAPABILITIES); - Assert.assertEquals(claimsChallenge, TestConfiguration.CLAIMS_CHALLENGE); - Assert.assertEquals(claimsRequest, TestConfiguration.CLAIMS_REQUEST); - Assert.assertEquals(mergedClaimsAndCapabilities, TestConfiguration.MERGED_CLAIMS_AND_CAPABILITIES); - Assert.assertEquals(mergedClaimsAndChallenge, TestConfiguration.MERGED_CLAIMS_AND_CHALLENGE); - Assert.assertEquals(mergedAll, TestConfiguration.MERGED_CLAIMS_CAPABILITIES_AND_CHALLENGE); + assertEquals(clientCapabilities, TestConfiguration.CLIENT_CAPABILITIES); + assertEquals(claimsChallenge, TestConfiguration.CLAIMS_CHALLENGE); + assertEquals(claimsRequest, TestConfiguration.CLAIMS_REQUEST); + assertEquals(mergedClaimsAndCapabilities, TestConfiguration.MERGED_CLAIMS_AND_CAPABILITIES); + assertEquals(mergedClaimsAndChallenge, TestConfiguration.MERGED_CLAIMS_AND_CHALLENGE); + assertEquals(mergedAll, TestConfiguration.MERGED_CLAIMS_CAPABILITIES_AND_CHALLENGE); } @Test public void testClaimsRequest_StringToClaimsRequest() { ClaimsRequest cr = ClaimsRequest.formatAsClaimsRequest(TestConfiguration.CLAIMS_CHALLENGE); - Assert.assertEquals(cr.formatAsJSONString(), TestConfiguration.CLAIMS_CHALLENGE); + assertEquals(cr.formatAsJSONString(), TestConfiguration.CLAIMS_CHALLENGE); } } diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientCertificatePkcs12Test.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientCertificatePkcs12Test.java index 112a8f11..0b3043bf 100644 --- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientCertificatePkcs12Test.java +++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientCertificatePkcs12Test.java @@ -4,39 +4,45 @@ package com.microsoft.aad.msal4j; import org.easymock.EasyMock; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.security.KeyStore; import java.security.KeyStoreSpi; import java.util.Arrays; import java.util.Collections; -import static org.testng.AssertJUnit.assertEquals; +import static org.junit.jupiter.api.Assertions.*; -@Test +//@Test public class ClientCertificatePkcs12Test extends AbstractMsalTests { private KeyStoreSpi keyStoreSpi; private KeyStore keystore; - @BeforeMethod + @BeforeEach public void setUp() throws Exception { keyStoreSpi = EasyMock.createMock(KeyStoreSpi.class); keystore = new KeyStore(keyStoreSpi, null, "PKCS12") {}; keystore.load(null); } - @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "certificate not loaded from input stream") + @Test public void testNoEntries() throws Exception { EasyMock.expect(keyStoreSpi.engineAliases()) .andReturn(Collections.enumeration(Collections.emptyList())).times(1); EasyMock.replay(keyStoreSpi); - ClientCertificate.getPrivateKeyAlias(keystore); + IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> { + ClientCertificate.getPrivateKeyAlias(keystore); + }); + + assertEquals("certificate not loaded from input stream", exception.getMessage()); + } - @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "certificate not loaded from input stream") + @Test public void testNoPrivateKey() throws Exception { EasyMock.expect(keyStoreSpi.engineAliases()) .andReturn(Collections.enumeration(Arrays.asList("CA_cert1", "CA_cert2"))).times(1); @@ -44,10 +50,15 @@ public void testNoPrivateKey() throws Exception { EasyMock.expect(keyStoreSpi.engineEntryInstanceOf("CA_cert2", KeyStore.PrivateKeyEntry.class)).andReturn(false).times(1); EasyMock.replay(keyStoreSpi); - ClientCertificate.getPrivateKeyAlias(keystore); + IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> { + ClientCertificate.getPrivateKeyAlias(keystore); + }); + + assertEquals("certificate not loaded from input stream", exception.getMessage()); + } - @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "more than one certificate alias found in input stream") + @Test public void testMultiplePrivateKeyAliases() throws Exception { EasyMock.expect(keyStoreSpi.engineAliases()) .andReturn(Collections.enumeration(Arrays.asList("private_key1", "private_key2", "CA_cert"))).times(1); @@ -56,7 +67,11 @@ public void testMultiplePrivateKeyAliases() throws Exception { EasyMock.expect(keyStoreSpi.engineEntryInstanceOf("CA_cert", KeyStore.PrivateKeyEntry.class)).andReturn(false).times(1); EasyMock.replay(keyStoreSpi); - ClientCertificate.getPrivateKeyAlias(keystore); + IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> { + ClientCertificate.getPrivateKeyAlias(keystore); + }); + + assertEquals("more than one certificate alias found in input stream", exception.getMessage()); } @Test diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientCertificateTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientCertificateTest.java index c54aef87..0233cdac 100644 --- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientCertificateTest.java +++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientCertificateTest.java @@ -3,34 +3,44 @@ package com.microsoft.aad.msal4j; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - import java.math.BigInteger; import java.security.PrivateKey; import java.security.interfaces.RSAPrivateKey; +import java.util.Collections; import org.easymock.EasyMock; +import org.junit.jupiter.api.Assertions; import org.powermock.core.classloader.annotations.PrepareForTest; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; -@Test(groups = {"checkin"}) -@PrepareForTest({RSAPrivateKey.class}) +//@Test//(groups = {"checkin"}) +//@PrepareForTest({RSAPrivateKey.class}) public class ClientCertificateTest extends AbstractMsalTests { - @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "PrivateKey is null or empty") + @Test public void testNullKey() { - ClientCertificate.create((PrivateKey) null, null); + NullPointerException exception = Assertions.assertThrows(NullPointerException.class, () -> { + ClientCertificate.create((PrivateKey) null, null); + }); + + assertEquals("PrivateKey is null or empty", exception.getMessage()); } - @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "certificate key size must be at least 2048") + @Test public void testInvalidKeysize() { final RSAPrivateKey key = EasyMock.createMock(RSAPrivateKey.class); final BigInteger modulus = EasyMock.createMock(BigInteger.class); EasyMock.expect(modulus.bitLength()).andReturn(2047).times(1); EasyMock.expect(key.getModulus()).andReturn(modulus).times(1); EasyMock.replay(modulus, key); - ClientCertificate.create(key, null); + IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> { + ClientCertificate.create(key, null); + }); + + assertEquals("certificate key size must be at least 2048", exception.getMessage()); + } @Test diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientSecretTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientSecretTest.java index d058c8cf..e58a04ff 100644 --- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientSecretTest.java +++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientSecretTest.java @@ -3,22 +3,31 @@ package com.microsoft.aad.msal4j; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * */ public class ClientSecretTest { - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = "clientSecret is null or empty") + @Test public void testConstructorNullClientId() { - new ClientSecret(null); + IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> { + new ClientSecret(null); + }); + + assertEquals("clientSecret is null or empty", exception.getMessage()); } - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = "clientSecret is null or empty") + @Test public void testConstructorEmptyClientId() { - new ClientSecret(""); + IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> { + new ClientSecret(""); + }); + + assertEquals("clientSecret is null or empty", exception.getMessage()); } } 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 435dffe1..a1bdae33 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 @@ -3,14 +3,16 @@ package com.microsoft.aad.msal4j; -import org.testng.Assert; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.HashMap; import java.util.Map; -@Test(groups = {"checkin"}) +import static org.junit.jupiter.api.Assertions.*; + +// @Test(groups = {"checkin"}) public class HttpHeaderTest { @Test @@ -34,13 +36,13 @@ public void testHttpHeaderConstructor() { Map httpHeaderMap = httpHeaders.getReadonlyHeaderMap(); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.PRODUCT_HEADER_NAME), HttpHeaders.PRODUCT_HEADER_VALUE); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.PRODUCT_VERSION_HEADER_NAME), HttpHeaders.PRODUCT_VERSION_HEADER_VALUE); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.OS_HEADER_NAME), HttpHeaders.OS_HEADER_VALUE); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.CPU_HEADER_NAME), HttpHeaders.CPU_HEADER_VALUE); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.APPLICATION_NAME_HEADER_NAME), "app-name"); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.APPLICATION_VERSION_HEADER_NAME), "app-version"); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.CORRELATION_ID_HEADER_NAME), "correlation-id"); + 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.CPU_HEADER_NAME), HttpHeaders.CPU_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"); } @Test @@ -61,13 +63,13 @@ public void testHttpHeaderConstructor_valuesNotSet() { Map httpHeaderMap = httpHeaders.getReadonlyHeaderMap(); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.PRODUCT_HEADER_NAME), HttpHeaders.PRODUCT_HEADER_VALUE); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.PRODUCT_VERSION_HEADER_NAME), HttpHeaders.PRODUCT_VERSION_HEADER_VALUE); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.OS_HEADER_NAME), HttpHeaders.OS_HEADER_VALUE); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.CPU_HEADER_NAME), HttpHeaders.CPU_HEADER_VALUE); - Assert.assertNull(httpHeaderMap.get(HttpHeaders.APPLICATION_NAME_HEADER_NAME)); - Assert.assertNull(httpHeaderMap.get(HttpHeaders.APPLICATION_VERSION_HEADER_NAME)); - Assert.assertNotNull(httpHeaderMap.get(HttpHeaders.CORRELATION_ID_HEADER_NAME)); + 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.CPU_HEADER_NAME), HttpHeaders.CPU_HEADER_VALUE); + assertNull(httpHeaderMap.get(HttpHeaders.APPLICATION_NAME_HEADER_NAME)); + assertNull(httpHeaderMap.get(HttpHeaders.APPLICATION_VERSION_HEADER_NAME)); + assertNotNull(httpHeaderMap.get(HttpHeaders.CORRELATION_ID_HEADER_NAME)); } @Test @@ -93,7 +95,7 @@ public void testHttpHeaderConstructor_userIdentifierUPN() { Map httpHeaderMap = httpHeaders.getReadonlyHeaderMap(); String expectedValue = String.format(HttpHeaders.X_ANCHOR_MAILBOX_UPN_FORMAT, upn); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.X_ANCHOR_MAILBOX), expectedValue); + assertEquals(httpHeaderMap.get(HttpHeaders.X_ANCHOR_MAILBOX), expectedValue); } @Test @@ -118,7 +120,7 @@ public void testHttpHeaderConstructor_userIdentifierHomeAccountId() { Map httpHeaderMap = httpHeaders.getReadonlyHeaderMap(); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.X_ANCHOR_MAILBOX), "oid:userObjectId@userTenantId"); + assertEquals(httpHeaderMap.get(HttpHeaders.X_ANCHOR_MAILBOX), "oid:userObjectId@userTenantId"); } @Test @@ -154,17 +156,17 @@ public void testHttpHeaderConstructor_extraHttpHeadersOverwriteLibraryHeaders() Map httpHeaderMap = httpHeaders.getReadonlyHeaderMap(); // Standard headers - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.PRODUCT_HEADER_NAME), HttpHeaders.PRODUCT_HEADER_VALUE); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.PRODUCT_VERSION_HEADER_NAME), HttpHeaders.PRODUCT_VERSION_HEADER_VALUE); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.OS_HEADER_NAME), HttpHeaders.OS_HEADER_VALUE); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.CPU_HEADER_NAME), HttpHeaders.CPU_HEADER_VALUE); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.APPLICATION_VERSION_HEADER_NAME), "app-version"); - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.CORRELATION_ID_HEADER_NAME), "correlation-id"); + 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.CPU_HEADER_NAME), HttpHeaders.CPU_HEADER_VALUE); + assertEquals(httpHeaderMap.get(HttpHeaders.APPLICATION_VERSION_HEADER_NAME), "app-version"); + assertEquals(httpHeaderMap.get(HttpHeaders.CORRELATION_ID_HEADER_NAME), "correlation-id"); // Overwritten standard header - Assert.assertEquals(httpHeaderMap.get(HttpHeaders.APPLICATION_NAME_HEADER_NAME), uniqueAppName); + assertEquals(httpHeaderMap.get(HttpHeaders.APPLICATION_NAME_HEADER_NAME), uniqueAppName); // Extra header - Assert.assertEquals(httpHeaderMap.get(uniqueHeaderKey), uniqueHeaderValue); + assertEquals(httpHeaderMap.get(uniqueHeaderKey), uniqueHeaderValue); } } diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/HttpUtilsTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/HttpUtilsTest.java index 46b3da59..6dcb8927 100644 --- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/HttpUtilsTest.java +++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/HttpUtilsTest.java @@ -3,8 +3,8 @@ package com.microsoft.aad.msal4j; -import org.testng.Assert; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; @@ -12,7 +12,10 @@ import java.util.List; import java.util.Map; -@Test(groups = {"checkin"}) +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +// @Test(groups = {"checkin"}) public class HttpUtilsTest { private final String COOKIE_HEADER_NAME = "Set-Cookie"; @@ -27,7 +30,7 @@ public void testHttpUtils_singleValueHeader() { }}; String headerValue = HttpUtils.headerValue(singleValuedHeader, COOKIE_HEADER_NAME); - Assert.assertEquals(headerValue, COOKIE_HEADER_VALUE_1); + assertEquals(headerValue, COOKIE_HEADER_VALUE_1); } @Test @@ -39,7 +42,7 @@ public void testHttpUtils_multiValueHeader() { String headerValue = HttpUtils.headerValue(multiValuedHeader, COOKIE_HEADER_NAME); String expectedValue = COOKIE_HEADER_VALUE_1 + "," + COOKIE_HEADER_VALUE_2; - Assert.assertEquals(headerValue, expectedValue); + assertEquals(headerValue, expectedValue); } @Test @@ -50,6 +53,6 @@ public void testHttpUtils_HeaderValueNull() { }}; String headerValue = HttpUtils.headerValue(nullValuedHeader, COOKIE_HEADER_NAME); - Assert.assertNull(headerValue); + assertNull(headerValue); } } diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/MsalOauthAuthorizatonGrantTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/MsalOauthAuthorizatonGrantTest.java index e465b409..1b749b93 100644 --- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/MsalOauthAuthorizatonGrantTest.java +++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/MsalOauthAuthorizatonGrantTest.java @@ -5,13 +5,15 @@ import com.nimbusds.oauth2.sdk.AuthorizationCode; import com.nimbusds.oauth2.sdk.AuthorizationCodeGrant; -import org.testng.Assert; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.Test; import java.net.URI; import java.net.URISyntaxException; import java.util.HashMap; +import static org.junit.jupiter.api.Assertions.assertNotNull; + /** * */ @@ -21,7 +23,7 @@ public class MsalOauthAuthorizatonGrantTest { public void testConstructor() { final OAuthAuthorizationGrant grant = new OAuthAuthorizationGrant(null, new HashMap<>()); - Assert.assertNotNull(grant); + assertNotNull(grant); } @Test @@ -30,7 +32,7 @@ public void testToParameters() throws URISyntaxException { new AuthorizationCodeGrant(new AuthorizationCode("grant"), new URI("http://microsoft.com")), null); - Assert.assertNotNull(grant); - Assert.assertNotNull(grant.toParameters()); + assertNotNull(grant); + assertNotNull(grant.toParameters()); } } diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TelemetryTests.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TelemetryTests.java index 7f159d36..8903e8b5 100644 --- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TelemetryTests.java +++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TelemetryTests.java @@ -3,9 +3,9 @@ package com.microsoft.aad.msal4j; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.Test; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import java.net.URI; import java.net.URISyntaxException; @@ -14,7 +14,9 @@ import java.util.List; import java.util.function.Consumer; -@Test(groups = {"checkin"}) +import static org.junit.jupiter.api.Assertions.*; + +// @Test(groups = {"checkin"}) public class TelemetryTests { private List> eventsReceived = new ArrayList<>(); @@ -34,7 +36,7 @@ private class MyTelemetryConsumer { }; } - @AfterMethod + @AfterEach private void cleanUp() { eventsReceived.clear(); } @@ -45,7 +47,7 @@ public void telemetryConsumerRegistration_ConsumerNotNullTest() { .telemetryConsumer(new MyTelemetryConsumer().telemetryConsumer) .build(); - Assert.assertNotNull(app.telemetryConsumer()); + assertNotNull(app.telemetryConsumer()); } @Test @@ -68,7 +70,7 @@ public void telemetryManagerFlush_EventCountTest() { telemetryManager.flush(reqId, clientId); // 1 Default event, 1 API event, 1 Http event - Assert.assertEquals(eventsReceived.size(), 3); + assertEquals(eventsReceived.size(), 3); } @Test @@ -93,7 +95,7 @@ public void onSendFailureTrue_SkipEventsIfSuccessfulTest() { telemetryManager.flush(reqId, clientId); // API event was successful, so count should be 0 - Assert.assertEquals(eventsReceived.size(), 0); + assertEquals(eventsReceived.size(), 0); eventsReceived.clear(); String reqId2 = telemetryManager.generateRequestId(); @@ -110,23 +112,23 @@ public void onSendFailureTrue_SkipEventsIfSuccessfulTest() { telemetryManager.flush(reqId2, clientId); // API event failed, so count should be 3 (1 default, 1 Api, 1 http) - Assert.assertEquals(eventsReceived.size(), 3); + assertEquals(eventsReceived.size(), 3); } @Test public void telemetryInternalApi_ScrubTenantFromUriTest() throws Exception { - Assert.assertEquals(Event.scrubTenant(new URI("https://login.microsoftonline.com/common/oauth2/v2.0/token")), + assertEquals(Event.scrubTenant(new URI("https://login.microsoftonline.com/common/oauth2/v2.0/token")), "https://login.microsoftonline.com//oauth2/v2.0/token"); - Assert.assertEquals(Event.scrubTenant(new URI("https://login.microsoftonline.com/common")), + assertEquals(Event.scrubTenant(new URI("https://login.microsoftonline.com/common")), "https://login.microsoftonline.com/"); - Assert.assertEquals(Event.scrubTenant(new URI("https://login.microsoftonline.com/tfp/msidlabb2c.onmicrosoft.com/B2C_1_ROPC_Auth")), + 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"); - Assert.assertNull(Event.scrubTenant(new URI("https://msidlabb2c.b2clogin.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"))); - Assert.assertNull(Event.scrubTenant(new URI("https://login.contoso.com/adfs"))); + assertNull(Event.scrubTenant(new URI("https://login.contoso.com/adfs"))); } @Test @@ -149,7 +151,7 @@ public void telemetryContainsDefaultEventTest() { telemetryManager.flush(reqId, clientId); - Assert.assertEquals(eventsReceived.get(0).get("event_name"), "msal.default_event"); + assertEquals(eventsReceived.get(0).get("event_name"), "msal.default_event"); } @Test @@ -171,8 +173,8 @@ public void telemetryFlushEventWithoutStopping_OrphanedEventIncludedTest() { telemetryManager.stopEvent(reqId, apiEvent1); telemetryManager.flush(reqId, clientId); - Assert.assertEquals(eventsReceived.size(), 3); - Assert.assertTrue(eventsReceived.stream().anyMatch(event -> event.get("event_name").equals("msal.http_event"))); + assertEquals(eventsReceived.size(), 3); + assertTrue(eventsReceived.stream().anyMatch(event -> event.get("event_name").equals("msal.http_event"))); } @Test @@ -196,8 +198,8 @@ public void telemetryStopEventWithoutStarting_NoExceptionThrownTest() { telemetryManager.flush(reqId, clientId); - Assert.assertEquals(eventsReceived.size(), 2); - Assert.assertFalse(eventsReceived.stream().anyMatch(event -> event.get("event_name").equals("msal.http_event"))); + assertEquals(eventsReceived.size(), 2); + assertFalse(eventsReceived.stream().anyMatch(event -> event.get("event_name").equals("msal.http_event"))); } @Test @@ -215,8 +217,8 @@ public void piiLoggingEnabled_ApiEventHashTest() { apiEvent.setWasSuccessful(true); telemetryManager.stopEvent(reqId, apiEvent); - Assert.assertNotNull(apiEvent.get("msal.tenant_id")); - Assert.assertNotEquals(apiEvent.get("msal.tenant_id"), tenantId); + assertNotNull(apiEvent.get("msal.tenant_id")); + assertNotEquals(apiEvent.get("msal.tenant_id"), tenantId); } @Test @@ -234,7 +236,7 @@ public void piiLoggingEnabledFalse_TenantIdUserIdSetToNullTest() { apiEvent.setWasSuccessful(true); telemetryManager.stopEvent(reqId, apiEvent); - Assert.assertNull(apiEvent.get("msal.tenant_id")); + assertNull(apiEvent.get("msal.tenant_id")); } @Test @@ -250,7 +252,7 @@ public void authorityNotInTrustedHostList_AuthorityIsNullTest() throws URISyntax apiEvent.setWasSuccessful(true); telemetryManager.stopEvent(reqId, apiEvent); - Assert.assertEquals(apiEvent.get("msal.authority"), "https://login.microsoftonline.com"); + assertEquals(apiEvent.get("msal.authority"), "https://login.microsoftonline.com"); ApiEvent apiEvent2 = new ApiEvent(false); @@ -259,7 +261,7 @@ public void authorityNotInTrustedHostList_AuthorityIsNullTest() throws URISyntax apiEvent2.setWasSuccessful(true); telemetryManager.stopEvent(reqId, apiEvent2); - Assert.assertNull(apiEvent2.get("msal.authority")); + assertNull(apiEvent2.get("msal.authority")); } @Test @@ -267,10 +269,10 @@ public void xmsCliTelemetryTest_CorrectFormatTest() { String responseHeader = "1,0,0,,"; XmsClientTelemetryInfo info = XmsClientTelemetryInfo.parseXmsTelemetryInfo(responseHeader); - Assert.assertEquals(info.getServerErrorCode(), "0"); - Assert.assertEquals(info.getServerSubErrorCode(), "0"); - Assert.assertEquals(info.getTokenAge(), ""); - Assert.assertEquals(info.getSpeInfo(), ""); + assertEquals(info.getServerErrorCode(), "0"); + assertEquals(info.getServerSubErrorCode(), "0"); + assertEquals(info.getTokenAge(), ""); + assertEquals(info.getSpeInfo(), ""); } @Test @@ -278,10 +280,10 @@ public void xmsCliTelemetryTest_IncorrectFormatTest() { String responseHeader = "1,2,3,4,5,6"; XmsClientTelemetryInfo info = XmsClientTelemetryInfo.parseXmsTelemetryInfo(responseHeader); - Assert.assertNull(info.getServerErrorCode()); - Assert.assertNull(info.getServerSubErrorCode()); - Assert.assertNull(info.getTokenAge()); - Assert.assertNull(info.getSpeInfo()); + assertNull(info.getServerErrorCode()); + assertNull(info.getServerSubErrorCode()); + assertNull(info.getTokenAge()); + assertNull(info.getSpeInfo()); } @Test @@ -289,7 +291,7 @@ public void xmsCliTelemetryTest_IncorrectHeaderTest() { String responseHeader = "3,0,0,,"; XmsClientTelemetryInfo info = XmsClientTelemetryInfo.parseXmsTelemetryInfo(responseHeader); - Assert.assertNull(info); + assertNull(info); } private ApiEvent createApiEvent(Boolean logPii) { diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TokenResponseTest.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TokenResponseTest.java index 2eaa76f8..615707bc 100644 --- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TokenResponseTest.java +++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TokenResponseTest.java @@ -11,10 +11,12 @@ import com.nimbusds.oauth2.sdk.token.RefreshToken; import com.nimbusds.oauth2.sdk.util.JSONObjectUtils; import com.nimbusds.openid.connect.sdk.token.OIDCTokens; -import org.testng.Assert; -import org.testng.annotations.Test; -@Test(groups = {"checkin"}) +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +// @Test(groups = {"checkin"}) public class TokenResponseTest extends AbstractMsalTests { private final String idToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik5HVEZ2ZEstZnl0aEV1THdqcHdBSk9NOW4tQSJ9." @@ -39,11 +41,11 @@ public void testConstructor() throws ParseException { final TokenResponse response = new TokenResponse( new BearerAccessToken("access_token"), new RefreshToken( "refresh_token"), idToken, null, null, expiresIn, extExpiresIn, null, refreshIn); - Assert.assertNotNull(response); + assertNotNull(response); OIDCTokens tokens = response.getOIDCTokens(); - Assert.assertNotNull(tokens); + assertNotNull(tokens); final JWT jwt = tokens.getIDToken(); - Assert.assertTrue(jwt.getJWTClaimsSet().getClaims().size() >= 0); + assertTrue(jwt.getJWTClaimsSet().getClaims().size() >= 0); } @Test @@ -52,12 +54,12 @@ public void testParseJsonObject() final TokenResponse response = TokenResponse .parseJsonObject(JSONObjectUtils .parse(TestConfiguration.TOKEN_ENDPOINT_OK_RESPONSE)); - Assert.assertNotNull(response); + assertNotNull(response); OIDCTokens tokens = response.getOIDCTokens(); - Assert.assertNotNull(tokens); - Assert.assertNotNull(tokens.getIDToken()); - Assert.assertFalse(StringHelper.isBlank(tokens.getIDTokenString())); - Assert.assertFalse(StringHelper.isBlank(response.getScope())); + assertNotNull(tokens); + assertNotNull(tokens.getIDToken()); + assertFalse(StringHelper.isBlank(tokens.getIDTokenString())); + assertFalse(StringHelper.isBlank(response.getScope())); } @Test @@ -67,10 +69,10 @@ public void testEmptyIdToken() { new RefreshToken("refresh_token"), "", null, null, expiresIn, extExpiresIn, null, refreshIn); - Assert.assertNotNull(response); + assertNotNull(response); OIDCTokens tokens = response.getOIDCTokens(); - Assert.assertNotNull(tokens); + assertNotNull(tokens); final AccessToken accessToken = tokens.getAccessToken(); - Assert.assertNotNull(accessToken); + assertNotNull(accessToken); } } 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 151b7804..9d414c05 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 @@ -4,10 +4,13 @@ package com.microsoft.aad.msal4j; import org.apache.commons.text.StringEscapeUtils; -import org.testng.Assert; -import org.testng.annotations.Test; -@Test(groups = {"checkin"}) +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +// @Test(groups = {"checkin"}) public class WSTrustRequestTest { @Test @@ -15,7 +18,7 @@ public void buildMessage_cloudAudienceUrnNotNull() throws Exception { String msg = WSTrustRequest.buildMessage("address", "username", "password", WSTrustVersion.WSTRUST2005, "cloudAudienceUrn").toString(); - Assert.assertTrue(msg.contains("cloudAudienceUrn")); + assertTrue(msg.contains("cloudAudienceUrn")); } @Test @@ -23,7 +26,7 @@ public void buildMessage_cloudAudienceUrnNull() throws Exception { String msg = WSTrustRequest.buildMessage("address", "username", "password", WSTrustVersion.WSTRUST2005, null).toString(); - Assert.assertTrue(msg.contains("" + WSTrustRequest.DEFAULT_APPLIES_TO + "")); + assertTrue(msg.contains("" + WSTrustRequest.DEFAULT_APPLIES_TO + "")); } @Test @@ -31,7 +34,7 @@ public void buildMessage_cloudAudienceUrnEmpty() throws Exception { String msg = WSTrustRequest.buildMessage("address", "username", "password", WSTrustVersion.WSTRUST2005, "").toString(); - Assert.assertTrue(msg.contains("" + WSTrustRequest.DEFAULT_APPLIES_TO + "")); + assertTrue(msg.contains("" + WSTrustRequest.DEFAULT_APPLIES_TO + "")); } @Test @@ -39,8 +42,8 @@ public void buildMessage_integrated() throws Exception { String msg = WSTrustRequest.buildMessage("address", null, null, WSTrustVersion.WSTRUST13, "cloudAudienceUrn").toString(); - Assert.assertTrue(msg.contains("cloudAudienceUrn")); - Assert.assertTrue(!msg.contains("cloudAudienceUrn")); + assertTrue(!msg.contains("