Skip to content

Commit b5cad22

Browse files
committed
separated b2c and adfs tests
1 parent 568c0d4 commit b5cad22

File tree

2 files changed

+64
-23
lines changed

2 files changed

+64
-23
lines changed

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

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ private static Object[][] getAadClouds(){
3232
};
3333
}
3434

35-
@DataProvider(name = "b2cAdfsClouds")
36-
private static Object[][] getNonAadClouds(){
37-
return new Object[][] {{"https://contoso.com/adfs"},//ADFS
38-
// {"https://login.b2clogin.com/contoso/b2c_policy"}//B2C
39-
};
40-
}
41-
4235
/**
4336
* when instance_discovery flag is set to true (by default), an instance_discovery is performed for authorityType = AAD
4437
*/
@@ -47,8 +40,7 @@ public void aadInstanceDiscoveryTrue(String authority) throws Exception{
4740
app = PowerMock.createPartialMock(PublicClientApplication.class,
4841
new String[]{"acquireTokenCommon"},
4942
PublicClientApplication.builder(TestConfiguration.AAD_CLIENT_ID)
50-
.authority(authority)
51-
.instanceDiscovery(true));
43+
.authority(authority));
5244

5345
Capture<MsalRequest> capturedMsalRequest = Capture.newInstance();
5446

@@ -90,14 +82,64 @@ public void aadInstanceDiscoveryTrue(String authority) throws Exception{
9082
}
9183

9284
/**
93-
* when instance_discovery flag is set to true (by default), an instance_discovery is NOT performed for b2c.
85+
* when instance_discovery flag is set to false, instance_discovery is not performed
9486
*/
95-
@Test( dataProvider = "b2cAdfsClouds")
96-
public void b2cAdfsInstanceDiscoveryTrue(String authority) throws Exception{
87+
@Test (dataProvider = "aadClouds")
88+
public void aadInstanceDiscoveryFalse(String authority) throws Exception {
89+
9790
app = PowerMock.createPartialMock(PublicClientApplication.class,
9891
new String[]{"acquireTokenCommon"},
99-
PublicClientApplication.builder(TestConstants.ADFS_APP_ID)
92+
PublicClientApplication.builder(TestConfiguration.AAD_CLIENT_ID)
10093
.authority(authority)
94+
.instanceDiscovery(false));
95+
96+
Capture<MsalRequest> capturedMsalRequest = Capture.newInstance();
97+
98+
PowerMock.expectPrivate(app, "acquireTokenCommon",
99+
EasyMock.capture(capturedMsalRequest), EasyMock.isA(AADAuthority.class)).andReturn(
100+
AuthenticationResult.builder().
101+
accessToken("accessToken").
102+
expiresOn(new Date().getTime() + 100).
103+
refreshToken("refreshToken").
104+
idToken("idToken").environment("environment").build());
105+
106+
PowerMock.mockStatic(HttpHelper.class);
107+
108+
HttpResponse instanceDiscoveryResponse = new HttpResponse();
109+
instanceDiscoveryResponse.statusCode(200);
110+
instanceDiscoveryResponse.body(TestConfiguration.INSTANCE_DISCOVERY_RESPONSE);
111+
112+
Capture<HttpRequest> capturedHttpRequest = Capture.newInstance();
113+
114+
EasyMock.expect(
115+
HttpHelper.executeHttpRequest(
116+
EasyMock.capture(capturedHttpRequest),
117+
EasyMock.isA(RequestContext.class),
118+
EasyMock.isA(ServiceBundle.class)))
119+
.andReturn(instanceDiscoveryResponse);
120+
121+
PowerMock.replay(HttpHelper.class, HttpResponse.class);
122+
123+
CompletableFuture<IAuthenticationResult> completableFuture = app.acquireToken(
124+
AuthorizationCodeParameters.builder
125+
("auth_code",
126+
new URI(TestConfiguration.AAD_DEFAULT_REDIRECT_URI))
127+
.scopes(Collections.singleton("default-scope"))
128+
.build());
129+
130+
completableFuture.get();
131+
Assert.assertEquals(capturedHttpRequest.getValues().size(),0);
132+
}
133+
134+
/**
135+
* when instance_discovery flag is set to true (by default), an instance_discovery is NOT performed for adfs.
136+
*/
137+
@Test
138+
public void adfsInstanceDiscoveryTrue() throws Exception{
139+
app = PowerMock.createPartialMock(PublicClientApplication.class,
140+
new String[]{"acquireTokenCommon"},
141+
PublicClientApplication.builder(TestConstants.ADFS_APP_ID)
142+
.authority("https://contoso.com/adfs")
101143
.instanceDiscovery(true));
102144

103145
Capture<MsalRequest> capturedMsalRequest = Capture.newInstance();
@@ -140,16 +182,15 @@ public void b2cAdfsInstanceDiscoveryTrue(String authority) throws Exception{
140182
}
141183

142184
/**
143-
* when instance_discovery flag is set to false, instance_discovery is not performed
185+
* when instance_discovery flag is set to true (by default), an instance_discovery is NOT performed for b2c.
144186
*/
145-
@Test (dataProvider = "aadClouds")
146-
public void aadInstanceDiscoveryFalse(String authority) throws Exception {
147-
187+
@Test
188+
public void b2cInstanceDiscoveryTrue() throws Exception{
148189
app = PowerMock.createPartialMock(PublicClientApplication.class,
149190
new String[]{"acquireTokenCommon"},
150-
PublicClientApplication.builder(TestConfiguration.AAD_CLIENT_ID)
151-
.authority(authority)
152-
.instanceDiscovery(false));
191+
PublicClientApplication.builder(TestConstants.ADFS_APP_ID)
192+
.b2cAuthority(TestConstants.B2C_MICROSOFTLOGIN_ROPC)
193+
.instanceDiscovery(true));
153194

154195
Capture<MsalRequest> capturedMsalRequest = Capture.newInstance();
155196

@@ -187,5 +228,8 @@ public void aadInstanceDiscoveryFalse(String authority) throws Exception {
187228

188229
completableFuture.get();
189230
Assert.assertEquals(capturedHttpRequest.getValues().size(),0);
231+
190232
}
233+
234+
191235
}

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AadInstanceDiscoveryTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package com.microsoft.aad.msal4j;
55

66
import org.powermock.api.easymock.PowerMock;
7-
import org.powermock.core.classloader.annotations.PowerMockIgnore;
87
import org.powermock.core.classloader.annotations.PrepareForTest;
98
import org.powermock.modules.testng.PowerMockTestCase;
109
import org.testng.Assert;
@@ -14,7 +13,6 @@
1413
import java.net.URI;
1514
import java.net.URL;
1615

17-
@PowerMockIgnore({"javax.net.ssl.*"})
1816
@PrepareForTest({AadInstanceDiscoveryProvider.class})
1917
public class AadInstanceDiscoveryTest extends PowerMockTestCase {
2018

@@ -188,5 +186,4 @@ public void aadInstanceDiscoveryTest_AutoDetectRegion_NoRegionDetected() throws
188186
Assert.assertTrue(entry.aliases().contains("login.microsoft.com"));
189187
Assert.assertTrue(entry.aliases().contains("sts.windows.net"));
190188
}
191-
192189
}

0 commit comments

Comments
 (0)