Skip to content

Commit

Permalink
Merge pull request #830 from AzureAD/avdunn/tests-fix
Browse files Browse the repository at this point in the history
Fix integration tests
  • Loading branch information
Avery-Dunn authored Jun 26, 2024
2 parents e1813c4 + 39a9e9a commit 52ed200
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,6 @@ void acquireTokenInteractive_ADFSv4_Federated(String environment) {
assertAcquireTokenCommon(user, cfg.organizationsAuthority(), cfg.graphDefaultScope());
}

@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);
assertAcquireTokenCommon(user, cfg.organizationsAuthority(), cfg.graphDefaultScope());
}

@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);
assertAcquireTokenCommon(user, cfg.organizationsAuthority(), cfg.graphDefaultScope());
}

@ParameterizedTest
@MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData")
void acquireTokenWithAuthorizationCode_B2C_Local(String environment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,6 @@ public void acquireTokenWithAuthorizationCode_ADFSv4_Federated(String environmen
assertAcquireTokenAAD(user, null);
}

@ParameterizedTest
@MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData")
public void acquireTokenWithAuthorizationCode_ADFSv3_Federated(String environment) {
cfg = new Config(environment);

User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_3);
assertAcquireTokenAAD(user, null);
}

@ParameterizedTest
@MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData")
public void acquireTokenWithAuthorizationCode_ADFSv2_Federated(String environment) {
cfg = new Config(environment);

User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_2);
assertAcquireTokenAAD(user, null);
}

@ParameterizedTest
@MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData")
public void acquireTokenWithAuthorizationCode_B2C_Local(String environment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void init() throws CertificateException, UnrecoverableKeyException, NoSuchAlgori

@Test
void acquireTokenClientCredentials_ClientCertificate() throws Exception {
String clientId = "2afb0add-2f32-4946-ac90-81a02aa4550e";
String clientId = TestConstants.MSIDLAB_CLIENT_ID;
assertAcquireTokenCommon(clientId, certificate, TestConstants.MICROSOFT_AUTHORITY);
}

Expand All @@ -49,14 +49,14 @@ void acquireTokenClientCredentials_ClientSecret() throws Exception {
AppCredentialProvider appProvider = new AppCredentialProvider(AzureEnvironment.AZURE);
final String clientId = appProvider.getLabVaultAppId();
final String password = appProvider.getLabVaultPassword();
IClientCredential credential = ClientCredentialFactory.createFromSecret(password);
IClientCredential credential = CertificateHelper.getClientCertificate();

assertAcquireTokenCommon(clientId, credential, TestConstants.MICROSOFT_AUTHORITY);
}

@Test
void acquireTokenClientCredentials_ClientAssertion() throws Exception {
String clientId = "2afb0add-2f32-4946-ac90-81a02aa4550e";
String clientId = TestConstants.MSIDLAB_CLIENT_ID;

ClientAssertion clientAssertion = getClientAssertion(clientId);

Expand Down Expand Up @@ -90,7 +90,7 @@ void acquireTokenClientCredentials_ClientSecret_Ciam() throws Exception {

@Test
void acquireTokenClientCredentials_Callback() throws Exception {
String clientId = "2afb0add-2f32-4946-ac90-81a02aa4550e";
String clientId = TestConstants.MSIDLAB_CLIENT_ID;

// Creates a valid client assertion using a callback, and uses it to build the client app and make a request
Callable<String> callable = () -> {
Expand All @@ -116,11 +116,9 @@ void acquireTokenClientCredentials_Callback() throws Exception {
void acquireTokenClientCredentials_DefaultCacheLookup() throws Exception {
AppCredentialProvider appProvider = new AppCredentialProvider(AzureEnvironment.AZURE);
final String clientId = appProvider.getLabVaultAppId();
final String password = appProvider.getLabVaultPassword();
IClientCredential credential = ClientCredentialFactory.createFromSecret(password);

ConfidentialClientApplication cca = ConfidentialClientApplication.builder(
clientId, credential).
clientId, CertificateHelper.getClientCertificate()).
authority(TestConstants.MICROSOFT_AUTHORITY).
build();

Expand Down Expand Up @@ -152,7 +150,7 @@ void acquireTokenClientCredentials_DefaultCacheLookup() throws Exception {

@Test
void acquireTokenClientCredentials_Regional() throws Exception {
String clientId = "2afb0add-2f32-4946-ac90-81a02aa4550e";
String clientId = TestConstants.MSIDLAB_CLIENT_ID;

assertAcquireTokenCommon_withRegion(clientId, certificate, "westus", TestConstants.REGIONAL_MICROSOFT_AUTHORITY_BASIC_HOST_WESTUS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

public class TestConstants {
public final static String KEYVAULT_DEFAULT_SCOPE = "https://vault.azure.net/.default";
public final static String MSIDLAB_DEFAULT_SCOPE = "https://msidlab.com/.default";
public final static String MSIDLAB_DEFAULT_SCOPE = "https://request.msidlab.com/.default";
public final static String MSIDLAB_VAULT_URL = "https://msidlabs.vault.azure.net/";
public final static String MSIDLAB_CLIENT_ID = "f62c5ae3-bf3a-4af5-afa8-a68b800396e9";
public final static String GRAPH_DEFAULT_SCOPE = "https://graph.windows.net/.default";
public final static String USER_READ_SCOPE = "user.read";
public final static String DEFAULT_SCOPE = ".default";
Expand Down Expand Up @@ -54,6 +55,7 @@ public class TestConstants {
public final static String B2C_READ_SCOPE = "https://msidlabb2c.onmicrosoft.com/msidlabb2capi/read";
public final static String B2C_MICROSOFTLOGIN_AUTHORITY = "https://msidlabb2c.b2clogin.com/tfp/msidlabb2c.onmicrosoft.com/";
public final static String B2C_MICROSOFTLOGIN_ROPC = B2C_MICROSOFTLOGIN_AUTHORITY + B2C_ROPC_POLICY;
public final static String B2C_UPN = "[email protected]";

public final static String LOCALHOST = "http://localhost:";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,36 +78,6 @@ void acquireTokenWithUsernamePassword_ADFSv4(String environment) throws Exceptio
assertAcquireTokenCommon(user, cfg.organizationsAuthority(), cfg.graphDefaultScope(), user.getAppId());
}

@ParameterizedTest
@MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData")
void acquireTokenWithUsernamePassword_ADFSv3(String environment) throws Exception {
cfg = new Config(environment);

UserQueryParameters query = new UserQueryParameters();
query.parameters.put(UserQueryParameters.AZURE_ENVIRONMENT, cfg.azureEnvironment);
query.parameters.put(UserQueryParameters.FEDERATION_PROVIDER, FederationProvider.ADFS_3);
query.parameters.put(UserQueryParameters.USER_TYPE, UserType.FEDERATED);

User user = labUserProvider.getLabUser(query);

assertAcquireTokenCommon(user, cfg.organizationsAuthority(), cfg.graphDefaultScope(), user.getAppId());
}

@ParameterizedTest
@MethodSource("com.microsoft.aad.msal4j.EnvironmentsProvider#createData")
void acquireTokenWithUsernamePassword_ADFSv2(String environment) throws Exception {
cfg = new Config(environment);

UserQueryParameters query = new UserQueryParameters();
query.parameters.put(UserQueryParameters.AZURE_ENVIRONMENT, cfg.azureEnvironment);
query.parameters.put(UserQueryParameters.FEDERATION_PROVIDER, FederationProvider.ADFS_2);
query.parameters.put(UserQueryParameters.USER_TYPE, UserType.FEDERATED);

User user = labUserProvider.getLabUser(query);

assertAcquireTokenCommonAAD(user);
}

@Test
void acquireTokenWithUsernamePassword_AuthorityWithPort() throws Exception {
User user = labUserProvider.getDefaultUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package infrastructure;

import com.microsoft.aad.msal4j.TestConstants;
import labapi.FederationProvider;
import labapi.LabConstants;
import labapi.User;
Expand Down Expand Up @@ -76,14 +77,6 @@ public static void performADOrCiamLogin(WebDriver driver, User user) {
LOG.info("Loggin in ... Clicking <Next> after username");
driver.findElement(new By.ById(fields.getAadSignInButtonId())).click();

if (user.getFederationProvider().equals(FederationProvider.ADFS_2) &&
!user.getLabName().equals(LabConstants.ARLINGTON_LAB_NAME)) {

LOG.info("Loggin in ... ADFS-V2 - Entering the username in ADFSv2 form");
driver.findElement(new By.ById(SeleniumConstants.ADFSV2_WEB_USERNAME_INPUT_ID)).
sendKeys(user.getUpn());
}

LOG.info("Loggin in ... Entering password");
By by = new By.ById(fields.getPasswordInputId());
waitForElementToBeVisibleAndEnable(driver, by).sendKeys(user.getPassword());
Expand Down Expand Up @@ -155,7 +148,7 @@ public static void performLocalLogin(WebDriver driver, User user) {
driver.findElement(new By.ById(SeleniumConstants.B2C_LOCAL_ACCOUNT_ID)).click();

LOG.info("Loggin in ... Entering username");
driver.findElement(new By.ById(SeleniumConstants.B2C_LOCAL_USERNAME_ID)).sendKeys(user.getUpn());
driver.findElement(new By.ById(SeleniumConstants.B2C_LOCAL_USERNAME_ID)).sendKeys(TestConstants.B2C_UPN);

LOG.info("Loggin in ... Entering password");
By by = new By.ById(SeleniumConstants.B2C_LOCAL_PASSWORD_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,10 @@ String getADFS2019UserNameInputId() {

private void determineFieldIds() {
switch (user.getFederationProvider()) {
case FederationProvider.ADFS_3:
case FederationProvider.ADFS_2019:
passwordInputId = SeleniumConstants.ADFS2019_PASSWORD_ID;
passwordSigInButtonId = SeleniumConstants.ADFS2019_SUBMIT_ID;
break;
case FederationProvider.ADFS_2:
if (LabConstants.ARLINGTON_LAB_NAME.equals(user.getLabName())) {
passwordInputId = SeleniumConstants.ADFSV2_ARLINGTON_WEB_PASSWORD_INPUT_ID;
passwordSigInButtonId = SeleniumConstants.ADFSV2_ARLINGTON_WEB_SUBMIT_BUTTON_ID;
} else {
passwordInputId = SeleniumConstants.ADFSV2_WEB_PASSWORD_INPUT_ID;
passwordSigInButtonId = SeleniumConstants.ADFSV2_WEB_SUBMIT_BUTTON_ID;
}
break;
case FederationProvider.ADFS_4:
passwordInputId = SeleniumConstants.ADFSV4_WEB_PASSWORD_ID;
passwordSigInButtonId = SeleniumConstants.ADFSV4_WEB_SUBMIT_ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
public class FederationProvider {

public static final String NONE = "none";
public static final String ADFS_2 = "adfsv2";
public static final String ADFS_3 = "adfsv3";
public static final String ADFS_4 = "adfsv4";
public static final String ADFS_2019 = "adfsv2019";
public static final String PING = "ping";
public static final String SHIBBOLETH = "shibboleth";
public static final String CIAM = "ciam";

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class KeyVaultSecretsProvider {

private final SecretClient secretClient;

private static final String CLIENT_ID = "2afb0add-2f32-4946-ac90-81a02aa4550e";
public static String CERTIFICATE_ALIAS = "MsalJavaAutomationRunner";
private static final String CLIENT_ID = TestConstants.MSIDLAB_CLIENT_ID;
public static String CERTIFICATE_ALIAS = "LabVaultAccessCert";

private static final String WIN_KEYSTORE = "Windows-MY";
private static final String KEYSTORE_PROVIDER = "SunMSCAPI";
Expand Down Expand Up @@ -82,7 +82,7 @@ CLIENT_ID, getClientCredentialFromKeyStore()).
}
}

private IClientCredential getClientCredentialFromKeyStore() {
IClientCredential getClientCredentialFromKeyStore() {
PrivateKey key;
X509Certificate publicCertificate;
try {
Expand Down
3 changes: 1 addition & 2 deletions msal4j-sdk/src/integrationtest/java/labapi/LabService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ static void initLabApp() throws MalformedURLException {
KeyVaultSecretsProvider keyVaultSecretsProvider = new KeyVaultSecretsProvider();

String appID = keyVaultSecretsProvider.getSecret(LabConstants.APP_ID_KEY_VAULT_SECRET);
String appSecret = keyVaultSecretsProvider.getSecret(LabConstants.APP_PASSWORD_KEY_VAULT_SECRET);

labApp = ConfidentialClientApplication.builder(
appID, ClientCredentialFactory.createFromSecret(appSecret)).
appID, keyVaultSecretsProvider.getClientCredentialFromKeyStore()).
authority(TestConstants.MICROSOFT_AUTHORITY).
build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ public User getCiamUser() {

UserQueryParameters query = new UserQueryParameters();
query.parameters.put(UserQueryParameters.FEDERATION_PROVIDER, FederationProvider.CIAM);
query.parameters.put(UserQueryParameters.SIGN_IN_AUDIENCE, "azureadmyorg");
query.parameters.put(UserQueryParameters.PUBLIC_CLIENT, "no");

return getLabUser(query);
}
Expand Down

0 comments on commit 52ed200

Please sign in to comment.