33
44package com .microsoft .aad .msal4j ;
55
6- import labapi .*;
6+ import com .microsoft .aad .msal4j .labapi .*;
7+ import static com .microsoft .aad .msal4j .labapi .KeyVaultSecrets .*;
78import org .junit .jupiter .api .AfterEach ;
8- import org .junit .jupiter .api .BeforeAll ;
99import org .junit .jupiter .api .BeforeEach ;
10+ import org .junit .jupiter .api .Test ;
1011import org .junit .jupiter .api .condition .DisabledIfSystemProperty ;
1112import org .slf4j .Logger ;
1213import org .slf4j .LoggerFactory ;
13- import org .junit .jupiter .api .Test ;
1414import org .junit .jupiter .api .TestInstance ;
15- import org .junit .jupiter .params .ParameterizedTest ;
16- import org .junit .jupiter .params .provider .MethodSource ;
1715import static org .junit .jupiter .api .Assertions .assertEquals ;
1816import static org .junit .jupiter .api .Assertions .assertNotEquals ;
1917
2927class AcquireTokenInteractiveIT extends SeleniumTest {
3028 private static final Logger LOG = LoggerFactory .getLogger (AcquireTokenInteractiveIT .class );
3129
32- private Config cfg ;
33-
34-
35- @ BeforeAll
36- public void setupUserProvider () {
37- setUpLapUserProvider ();
38- }
39-
4030 @ AfterEach
4131 public void stopBrowser () {
4232 cleanUp ();
@@ -47,79 +37,67 @@ public void startBrowser() {
4737 startUpBrowser ();
4838 }
4939
50- @ ParameterizedTest
51- @ MethodSource ("com.microsoft.aad.msal4j.EnvironmentsProvider#createData" )
52- void acquireTokenInteractive_ManagedUser (String environment ) {
53- cfg = new Config (environment );
54-
55- User user = labUserProvider .getDefaultUser (cfg .azureEnvironment );
56- assertAcquireTokenCommon (user , cfg .commonAuthority (), cfg .graphDefaultScope ());
57- }
40+ @ Test
41+ void acquireTokenInteractive_ManagedUser () {
42+ AppConfig app = LabResponseHelper .getAppConfig (APP_MULTI_TENANT );
43+ UserConfig user = LabResponseHelper .getUserConfig (USER_PUBLIC_CLOUD );
5844
59- @ Test ()
60- @ DisabledIfSystemProperty (named = "adfs.disabled" , matches = "true" )
61- void acquireTokenInteractive_ADFSv2019_OnPrem () {
62- User user = labUserProvider .getOnPremAdfsUser (FederationProvider .ADFS_2019 );
63- assertAcquireTokenCommon (user , TestConstants .ADFS_AUTHORITY , TestConstants .ADFS_SCOPE );
45+ assertAcquireTokenCommon (user , app .getAppId (), app .getAuthority () + "common" , TestConstants .GRAPH_DEFAULT_SCOPE );
6446 }
6547
66- @ ParameterizedTest
67- @ MethodSource ("com.microsoft.aad.msal4j.EnvironmentsProvider#createData" )
68- @ DisabledIfSystemProperty (named = "adfs.disabled" , matches = "true" )
69- void acquireTokenInteractive_ADFSv2019_Federated (String environment ) {
70- cfg = new Config (environment );
48+ @ Test
49+ void acquireTokenInteractive_Arlington () {
50+ AppConfig app = LabResponseHelper .getAppConfig (APP_ARLINGTON );
51+ UserConfig user = LabResponseHelper .getUserConfig (USER_ARLINGTON );
7152
72- User user = labUserProvider .getFederatedAdfsUser (cfg .azureEnvironment , FederationProvider .ADFS_2019 );
73- assertAcquireTokenCommon (user , cfg .organizationsAuthority (), cfg .graphDefaultScope ());
53+ assertAcquireTokenCommon (user , app .getAppId (), app .getAuthority () + "common" , TestConstants .GRAPH_DEFAULT_SCOPE );
7454 }
7555
76- @ ParameterizedTest
77- @ MethodSource ("com.microsoft.aad.msal4j.EnvironmentsProvider#createData" )
56+ @ Test ()
7857 @ DisabledIfSystemProperty (named = "adfs.disabled" , matches = "true" )
79- void acquireTokenInteractive_ADFSv4_Federated (String environment ) {
80- cfg = new Config (environment );
58+ void acquireTokenInteractive_ADFSv2022 () {
59+ AppConfig app = LabResponseHelper .getAppConfig (APP_PCACLIENT );
60+ UserConfig user = LabResponseHelper .getUserConfig (USER_FED_DEFAULT );
8161
82- User user = labUserProvider .getFederatedAdfsUser (cfg .azureEnvironment , FederationProvider .ADFS_4 );
83- assertAcquireTokenCommon (user , cfg .organizationsAuthority (), cfg .graphDefaultScope ());
62+ assertAcquireTokenCommon (user , app .getAppId (), app .getAuthority () + "organizations/" , TestConstants .ADFS_SCOPE );
8463 }
8564
86- @ ParameterizedTest
87- @ MethodSource ( "com.microsoft.aad.msal4j.EnvironmentsProvider#createData" )
88- void acquireTokenWithAuthorizationCode_B2C_Local ( String environment ) {
89- cfg = new Config ( environment );
65+ @ Test
66+ void acquireTokenWithAuthorizationCode_B2C_Local () {
67+ AppConfig app = LabResponseHelper . getAppConfig ( APP_B2C );
68+ UserConfig user = LabResponseHelper . getUserConfig ( USER_B2C );
9069
91- User user = labUserProvider .getB2cUser (cfg .azureEnvironment , B2CProvider .LOCAL );
92- assertAcquireTokenB2C (user , TestConstants .B2C_AUTHORITY );
70+ assertAcquireTokenB2C (user , TestConstants .B2C_AUTHORITY , app .getAppId ());
9371 }
9472
95- @ ParameterizedTest
96- @ MethodSource ( "com.microsoft.aad.msal4j.EnvironmentsProvider#createData" )
97- void acquireTokenWithAuthorizationCode_B2C_LegacyFormat ( String environment ) {
98- cfg = new Config ( environment );
73+ @ Test
74+ void acquireTokenWithAuthorizationCode_B2C_LegacyFormat () {
75+ AppConfig app = LabResponseHelper . getAppConfig ( APP_B2C );
76+ UserConfig user = LabResponseHelper . getUserConfig ( USER_B2C );
9977
100- User user = labUserProvider .getB2cUser (cfg .azureEnvironment , B2CProvider .LOCAL );
101- assertAcquireTokenB2C (user , TestConstants .B2C_AUTHORITY_LEGACY_FORMAT );
78+ assertAcquireTokenB2C (user , TestConstants .B2C_AUTHORITY_LEGACY_FORMAT , app .getAppId ());
10279 }
10380
10481 @ Test
10582 void acquireTokenInteractive_ManagedUser_InstanceAware () {
106- cfg = new Config (AzureEnvironment .AZURE );
83+ AppConfig app = LabResponseHelper .getAppConfig (APP_ARLINGTON );
84+ UserConfig user = LabResponseHelper .getUserConfig (USER_ARLINGTON );
10785
108- User user = labUserProvider .getDefaultUser (AzureEnvironment .AZURE_US_GOVERNMENT );
109- assertAcquireTokenInstanceAware (user );
86+ assertAcquireTokenInstanceAware (user , app .getAppId (), TestConstants .ARLINGTON_TENANT_ID );
11087 }
11188
11289 @ Test
11390 void acquireTokenInteractive_Ciam () {
114- User user = labUserProvider .getCiamCudUser ();
91+ AppConfig app = LabResponseHelper .getAppConfig (APP_CIAM );
92+ UserConfig user = LabResponseHelper .getUserConfig (USER_CIAM );
11593
11694 Map <String , String > extraQueryParameters = new HashMap <>();
11795
11896 PublicClientApplication pca ;
11997 try {
12098 pca = PublicClientApplication .builder (
121- user .getAppId ()).
122- authority ("https://" + user . getLabName () + ".ciamlogin.com/" )
99+ app .getAppId ()).
100+ authority (app . getAuthority () )
123101 .build ();
124102 } catch (MalformedURLException ex ) {
125103 throw new RuntimeException (ex .getMessage ());
@@ -153,8 +131,8 @@ void acquireTokenInteractive_Ciam() {
153131 assertEquals (user .getUpn (), result .account ().username ());
154132 }
155133
156- private void assertAcquireTokenCommon (User user , String authority , String scope ) {
157- PublicClientApplication pca = IntegrationTestHelper .createPublicApp (user . getAppId () , authority );
134+ private void assertAcquireTokenCommon (UserConfig user , String appId , String authority , String scope ) {
135+ PublicClientApplication pca = IntegrationTestHelper .createPublicApp (appId , authority );
158136
159137 IAuthenticationResult result = acquireTokenInteractive (
160138 user ,
@@ -165,26 +143,26 @@ private void assertAcquireTokenCommon(User user, String authority, String scope)
165143 assertEquals (user .getUpn (), result .account ().username ());
166144 }
167145
168- private void assertAcquireTokenB2C (User user , String authority ) {
146+ private void assertAcquireTokenB2C (UserConfig user , String authority , String appId ) {
169147
170148 PublicClientApplication pca ;
171149 try {
172150 pca = PublicClientApplication .builder (
173- user . getAppId () ).
151+ appId ).
174152 b2cAuthority (authority + TestConstants .B2C_SIGN_IN_POLICY ).
175153 build ();
176154 } catch (MalformedURLException ex ) {
177155 throw new RuntimeException (ex .getMessage ());
178156 }
179157
180- IAuthenticationResult result = acquireTokenInteractive (user , pca , user . getAppId () );
158+ IAuthenticationResult result = acquireTokenInteractive (user , pca , appId );
181159 IntegrationTestHelper .assertAccessAndIdTokensNotNull (result );
182160 }
183161
184- private void assertAcquireTokenInstanceAware (User user ) {
185- PublicClientApplication pca = IntegrationTestHelper .createPublicApp (user . getAppId () , TestConstants .MICROSOFT_AUTHORITY_HOST + user . getTenantID () );
162+ private void assertAcquireTokenInstanceAware (UserConfig user , String appId , String tenantId ) {
163+ PublicClientApplication pca = IntegrationTestHelper .createPublicApp (appId , TestConstants .MICROSOFT_AUTHORITY_HOST + tenantId );
186164
187- IAuthenticationResult result = acquireTokenInteractive_instanceAware (user , pca , cfg . graphDefaultScope () );
165+ IAuthenticationResult result = acquireTokenInteractive_instanceAware (user , pca , TestConstants . GRAPH_DEFAULT_SCOPE );
188166
189167 IntegrationTestHelper .assertAccessAndIdTokensNotNull (result );
190168 assertEquals (user .getUpn (), result .account ().username ());
@@ -197,7 +175,7 @@ private void assertAcquireTokenInstanceAware(User user) {
197175
198176 IAuthenticationResult cachedResult ;
199177 try {
200- cachedResult = acquireTokenSilently (pca , result .account (), cfg . graphDefaultScope () );
178+ cachedResult = acquireTokenSilently (pca , result .account (), TestConstants . GRAPH_DEFAULT_SCOPE );
201179 } catch (Exception ex ) {
202180 throw new RuntimeException (ex .getMessage ());
203181 }
@@ -213,7 +191,7 @@ private IAuthenticationResult acquireTokenSilently(IPublicClientApplication pca,
213191 }
214192
215193 private IAuthenticationResult acquireTokenInteractive (
216- User user ,
194+ UserConfig user ,
217195 PublicClientApplication pca ,
218196 String scope ) {
219197
@@ -243,7 +221,7 @@ private IAuthenticationResult acquireTokenInteractive(
243221 }
244222
245223 private IAuthenticationResult acquireTokenInteractive_instanceAware (
246- User user ,
224+ UserConfig user ,
247225 PublicClientApplication pca ,
248226 String scope ) {
249227
@@ -274,10 +252,10 @@ private IAuthenticationResult acquireTokenInteractive_instanceAware(
274252
275253 class SeleniumOpenBrowserAction implements OpenBrowserAction {
276254
277- private User user ;
255+ private UserConfig user ;
278256 private PublicClientApplication pca ;
279257
280- SeleniumOpenBrowserAction (User user , PublicClientApplication pca ) {
258+ SeleniumOpenBrowserAction (UserConfig user , PublicClientApplication pca ) {
281259 this .user = user ;
282260 this .pca = pca ;
283261 }
0 commit comments