Skip to content

Commit 4583a7d

Browse files
committed
Remove unused code, limit scopes, and restore final tests
1 parent a71e033 commit 4583a7d

19 files changed

Lines changed: 234 additions & 343 deletions

msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AuthorizationCodeIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ public void acquireTokenWithAuthorizationCode_CiamCud() throws Exception {
9494
assertEquals(resultSilent.account().username(), result.account().username());
9595
}
9696

97-
//TODO: need to sort out ADFS 2022 configuration
9897
@Test
9998
@DisabledIfSystemProperty(named = "adfs.disabled", matches = "true")
10099
void acquireTokenWithAuthorizationCode_ADFSv2022() {

msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/TokenCacheIT.java

Lines changed: 62 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.microsoft.aad.msal4j.labapi2.*;
77
import org.junit.jupiter.api.Test;
88
import org.junit.jupiter.api.TestInstance;
9+
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
910

1011
import static org.junit.jupiter.api.Assertions.assertEquals;
1112

@@ -49,72 +50,67 @@ void singleAccountInCache_RemoveAccountTest() throws Exception {
4950
assertEquals(pca.getAccounts().join().size(), 0);
5051
}
5152

52-
// TODO: labapi2 doesn't have guest user configuration yet - will be pulled from MSAL.NET
53-
// @Test
54-
// @DisabledIfSystemProperty(named = "adfs.disabled", matches = "true")
55-
// void twoAccountsInCache_SameUserDifferentTenants_RemoveAccountTest() throws Exception {
56-
//
57-
// UserQuery query = new UserQuery();
58-
// query.setUserType(LabServiceParameters.UserType.GUEST);
59-
//
60-
// LabResponse labResponse = LabUserHelper.getLabUserData(query);
61-
// LabUser guestUser = labResponse.getUser();
62-
// Lab lab = labResponse.getLab();
63-
//
64-
// String dataToInitCache = TestHelper.readResource(
65-
// this.getClass(),
66-
// "/cache_data/remove-account-test-cache.json");
67-
//
68-
// // check that cache is empty
69-
// assertEquals(dataToInitCache, "");
70-
//
71-
// ITokenCacheAccessAspect persistenceAspect = new TokenPersistence(dataToInitCache);
72-
//
73-
// // acquire tokens for home tenant, and serialize cache
74-
// PublicClientApplication pca = PublicClientApplication.builder(
75-
// guestUser.getAppId()).
76-
// authority(TestConstants.ORGANIZATIONS_AUTHORITY)
77-
// .setTokenCacheAccessAspect(persistenceAspect)
78-
// .build();
79-
//
80-
// pca.acquireToken(UserNamePasswordParameters.
81-
// builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
82-
// guestUser.getHomeUPN(),
83-
// guestUser.getPassword().toCharArray())
84-
// .build())
85-
// .get();
86-
//
87-
// String guestTenantAuthority = TestConstants.MICROSOFT_AUTHORITY_HOST + lab.getTenantId();
88-
//
89-
// // initialize pca with tenant where user is guest, deserialize cache, and acquire second token
90-
// PublicClientApplication pca2 = PublicClientApplication.builder(
91-
// guestUser.getAppId()).
92-
// authority(guestTenantAuthority).
93-
// setTokenCacheAccessAspect(persistenceAspect).
94-
// build();
95-
//
96-
// pca2.acquireToken(UserNamePasswordParameters.
97-
// builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
98-
// guestUser.getHomeUPN(),
99-
// guestUser.getPassword().toCharArray())
100-
// .build())
101-
// .get();
102-
//
103-
// // There should be two tokens in cache, with same accounts except for tenant
104-
// assertEquals(pca2.getAccounts().join().iterator().next().getTenantProfiles().size(), 2);
105-
//
106-
// IAccount account = pca2.getAccounts().get().iterator().next();
107-
//
108-
// // RemoveAccount should remove both cache entities
109-
// pca2.removeAccount(account).join();
110-
//
111-
// assertEquals(0, pca2.getAccounts().join().size());
112-
//
113-
// //clean up file
114-
// TestHelper.deleteFileContent(
115-
// this.getClass(),
116-
// "/cache_data/remove-account-test-cache.json");
117-
// }
53+
@Test
54+
@DisabledIfSystemProperty(named = "adfs.disabled", matches = "true")
55+
void twoAccountsInCache_SameUserDifferentTenants_RemoveAccountTest() throws Exception {
56+
57+
LabResponse labResponse = LabUserHelper.getDefaultUser();
58+
LabUser guestUser = labResponse.getUser();
59+
60+
String dataToInitCache = TestHelper.readResource(
61+
this.getClass(),
62+
"/cache_data/remove-account-test-cache.json");
63+
64+
// check that cache is empty
65+
assertEquals(dataToInitCache, "");
66+
67+
ITokenCacheAccessAspect persistenceAspect = new TokenPersistence(dataToInitCache);
68+
69+
// acquire tokens for home tenant, and serialize cache
70+
PublicClientApplication pca = PublicClientApplication.builder(
71+
labResponse.getApp().getAppId()).
72+
authority(TestConstants.ORGANIZATIONS_AUTHORITY)
73+
.setTokenCacheAccessAspect(persistenceAspect)
74+
.build();
75+
76+
pca.acquireToken(UserNamePasswordParameters.
77+
builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
78+
guestUser.getHomeUPN(),
79+
guestUser.getPassword().toCharArray())
80+
.build())
81+
.get();
82+
83+
String guestTenantAuthority = TestConstants.MICROSOFT_AUTHORITY_HOST + guestUser.getTenantId();
84+
85+
// initialize pca with tenant where user is guest, deserialize cache, and acquire second token
86+
PublicClientApplication pca2 = PublicClientApplication.builder(
87+
labResponse.getApp().getAppId()).
88+
authority(guestTenantAuthority).
89+
setTokenCacheAccessAspect(persistenceAspect).
90+
build();
91+
92+
pca2.acquireToken(UserNamePasswordParameters.
93+
builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
94+
guestUser.getHomeUPN(),
95+
guestUser.getPassword().toCharArray())
96+
.build())
97+
.get();
98+
99+
// There should be two tokens in cache, with same accounts except for tenant
100+
assertEquals(pca2.getAccounts().join().iterator().next().getTenantProfiles().size(), 2);
101+
102+
IAccount account = pca2.getAccounts().get().iterator().next();
103+
104+
// RemoveAccount should remove both cache entities
105+
pca2.removeAccount(account).join();
106+
107+
assertEquals(0, pca2.getAccounts().join().size());
108+
109+
//clean up file
110+
TestHelper.deleteFileContent(
111+
this.getClass(),
112+
"/cache_data/remove-account-test-cache.json");
113+
}
118114

119115
private static class TokenPersistence implements ITokenCacheAccessAspect {
120116
String data;

msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/UsernamePasswordIT.java

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import static org.junit.jupiter.api.Assertions.assertEquals;
1414

1515
import java.util.Collections;
16+
import java.util.HashMap;
17+
import java.util.Map;
1618

1719
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
1820
class UsernamePasswordIT {
@@ -26,42 +28,39 @@ void acquireTokenWithUsernamePassword_Managed() throws Exception {
2628
assertAcquireTokenCommon(labResponse.getUser(), cfg.organizationsAuthority(), cfg.graphDefaultScope(), labResponse.getApp().getAppId());
2729
}
2830

29-
// @Test
30-
// void acquireTokenWithUsernamePassword_AuthorityWithPort() throws Exception {
31-
// LabResponse labResponse = LabUserHelper.getDefaultUser();
32-
// LabUser user = labResponse.getUser();
33-
//
34-
// assertAcquireTokenCommon(
35-
// user,
36-
// TestConstants.COMMON_AUTHORITY_WITH_PORT,
37-
// TestConstants.GRAPH_DEFAULT_SCOPE,
38-
// labResponse.getApp().getAppId());
39-
// }
40-
41-
// @Test
42-
// void acquireTokenWithUsernamePassword_Ciam() throws Exception {
43-
// Map<String, String> extraQueryParameters = new HashMap<>();
44-
//
45-
// UserQuery query = new UserQuery();
46-
// query.setUserType(LabServiceParameters.UserType.CLOUD);
47-
// query.setAzureEnvironment(LabServiceParameters.AzureEnvironment.AZURE_CIAM);
48-
//
49-
// LabResponse labResponse = LabUserHelper.getLabUserData(query);
50-
//
51-
// LabUser user = labResponse.getUser(); PublicClientApplication pca = PublicClientApplication.builder(user.getAppId())
52-
// .authority("https://" + user.getLabName() + ".ciamlogin.com/")
53-
// .build();
54-
//
55-
// IAuthenticationResult result = pca.acquireToken(UserNamePasswordParameters.
56-
// builder(Collections.singleton(TestConstants.USER_READ_SCOPE),
57-
// user.getUpn(),
58-
// user.getPassword().toCharArray())
59-
// .extraQueryParameters(extraQueryParameters)
60-
// .build())
61-
// .get();
62-
//
63-
// IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
64-
// }
31+
@Test
32+
void acquireTokenWithUsernamePassword_AuthorityWithPort() throws Exception {
33+
LabResponse labResponse = LabUserHelper.getDefaultUser();
34+
LabUser user = labResponse.getUser();
35+
36+
assertAcquireTokenCommon(
37+
user,
38+
TestConstants.MICROSOFT_AUTHORITY_HOST_WITH_PORT + user.getTenantId(),
39+
TestConstants.GRAPH_DEFAULT_SCOPE,
40+
labResponse.getApp().getAppId());
41+
}
42+
43+
@Test
44+
void acquireTokenWithUsernamePassword_Ciam() throws Exception {
45+
Map<String, String> extraQueryParameters = new HashMap<>();
46+
47+
LabResponse labResponse = LabUserHelper.getCiamCudUser();
48+
LabUser user = labResponse.getUser();
49+
50+
PublicClientApplication pca = PublicClientApplication.builder(user.getAppId())
51+
.authority("https://" + user.getLabName() + ".ciamlogin.com/")
52+
.build();
53+
54+
IAuthenticationResult result = pca.acquireToken(UserNamePasswordParameters.
55+
builder(Collections.singleton(TestConstants.USER_READ_SCOPE),
56+
user.getUpn(),
57+
user.getPassword().toCharArray())
58+
.extraQueryParameters(extraQueryParameters)
59+
.build())
60+
.get();
61+
62+
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
63+
}
6564

6665
private void assertAcquireTokenCommon(LabUser user, String authority, String scope, String appId)
6766
throws Exception {

msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/labapi2/AppCredentialProvider.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
public class AppCredentialProvider {
77

8-
private String clientId;
9-
private String oboClientId;
10-
private String oboAppPassword;
11-
private String oboAppIdURI;
8+
private final String clientId;
9+
private final String oboClientId;
10+
private final String oboAppPassword;
11+
private final String oboAppIdURI;
1212

13-
public AppCredentialProvider() {
13+
AppCredentialProvider() {
1414
KeyVaultSecretsProvider keyVaultSecretsProvider = new KeyVaultSecretsProvider();
1515

1616
clientId = "54a2d933-8bf8-483b-a8f8-0a31924f3c1f";

msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/labapi2/AzureEnvironment.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
package com.microsoft.aad.msal4j.labapi2;
55

6-
public class AzureEnvironment {
6+
class AzureEnvironment {
77

8-
public static final String AZURE = "azurecloud";
9-
public static final String AZURE_US_GOVERNMENT = "azureusgovernment";
8+
static final String AZURE_US_GOVERNMENT = "azureusgovernment";
109
}

msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/labapi2/Config.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
package com.microsoft.aad.msal4j.labapi2;
55

66
public class Config {
7-
private String commonAuthority;
8-
private String organizationsAuthority;
9-
private String graphDefaultScope;
10-
private AppCredentialProvider appProvider;
11-
private String tenant;
7+
private final String commonAuthority;
8+
private final String organizationsAuthority;
9+
private final String graphDefaultScope;
10+
private final AppCredentialProvider appProvider;
11+
private final String tenant;
1212

1313
String azureEnvironment;
1414

@@ -34,10 +34,6 @@ public String graphDefaultScope() {
3434
return this.graphDefaultScope;
3535
}
3636

37-
public String tenant() {
38-
return this.tenant;
39-
}
40-
4137
public String tenantSpecificAuthority() {
4238
return LabConstants.MICROSOFT_AUTHORITY_HOST + tenant;
4339
}

msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/labapi2/KeyVaultSecretsProvider.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,45 @@
1111
import com.microsoft.aad.msal4j.*;
1212
import org.slf4j.Logger;
1313
import org.slf4j.LoggerFactory;
14+
import reactor.core.publisher.Mono;
1415

15-
import java.security.cert.X509Certificate;
1616
import java.security.KeyStore;
1717
import java.security.PrivateKey;
18+
import java.security.cert.X509Certificate;
1819
import java.time.OffsetDateTime;
1920
import java.time.ZoneOffset;
2021
import java.util.Collections;
21-
import reactor.core.publisher.Mono;
2222

2323
public class KeyVaultSecretsProvider implements AutoCloseable {
2424

2525
private static final Logger log = LoggerFactory.getLogger(KeyVaultSecretsProvider.class);
2626

27-
public static class KeyVaultInstance {
27+
static class KeyVaultInstance {
2828
/**
2929
* The KeyVault maintained by the MSID. It is recommended for use.
3030
*/
31-
public static final String MSID_LAB = "https://msidlabs.vault.azure.net";
31+
static final String MSID_LAB = "https://msidlabs.vault.azure.net";
3232

3333
/**
3434
* The KeyVault maintained by the MSAL.NET team and have full control over.
3535
* Should be used temporarily - secrets should be stored and managed by MSID Lab.
3636
*/
37-
public static final String MSAL_TEAM = "https://id4skeyvault.vault.azure.net/";
37+
static final String MSAL_TEAM = "https://id4skeyvault.vault.azure.net/";
3838
}
3939

4040
private final SecretClient secretClient;
4141

4242
/**
4343
* Initialize the secrets provider with the specified Key Vault address.
44-
*
44+
* <p>
4545
* Authentication using client certificate:
46-
* 1. Register Azure AD application of "Web app / API" type.
47-
* To set up certificate based access to the application PowerShell should be used.
48-
* 2. Add an access policy entry to target Key Vault instance for this application.
46+
* 1. Register Azure AD application of "Web app / API" type.
47+
* To set up certificate based access to the application PowerShell should be used.
48+
* 2. Add an access policy entry to target Key Vault instance for this application.
4949
*
5050
* @param keyVaultAddress The Key Vault URI (defaults to MSID_LAB)
5151
*/
52-
public KeyVaultSecretsProvider(String keyVaultAddress) {
52+
KeyVaultSecretsProvider(String keyVaultAddress) {
5353
String vaultUrl = keyVaultAddress != null ? keyVaultAddress : KeyVaultInstance.MSID_LAB;
5454
log.debug("Initializing KeyVault secrets provider for: {}", vaultUrl);
5555

msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/labapi2/Lab.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,4 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
7373
public String getTenantId() {
7474
return this.tenantId;
7575
}
76-
77-
public String getAuthority() {
78-
return this.authority;
79-
}
80-
81-
public String getFederationProvider() {
82-
return this.federationProvider;
83-
}
8476
}

msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/labapi2/LabApp.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,4 @@ public String getAuthority() {
8383
public String getAppId() {
8484
return appId;
8585
}
86-
8786
}

0 commit comments

Comments
 (0)