@@ -32,13 +32,6 @@ private static Object[][] getAadClouds(){
32
32
};
33
33
}
34
34
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
-
42
35
/**
43
36
* when instance_discovery flag is set to true (by default), an instance_discovery is performed for authorityType = AAD
44
37
*/
@@ -47,8 +40,7 @@ public void aadInstanceDiscoveryTrue(String authority) throws Exception{
47
40
app = PowerMock .createPartialMock (PublicClientApplication .class ,
48
41
new String []{"acquireTokenCommon" },
49
42
PublicClientApplication .builder (TestConfiguration .AAD_CLIENT_ID )
50
- .authority (authority )
51
- .instanceDiscovery (true ));
43
+ .authority (authority ));
52
44
53
45
Capture <MsalRequest > capturedMsalRequest = Capture .newInstance ();
54
46
@@ -90,14 +82,64 @@ public void aadInstanceDiscoveryTrue(String authority) throws Exception{
90
82
}
91
83
92
84
/**
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
94
86
*/
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
+
97
90
app = PowerMock .createPartialMock (PublicClientApplication .class ,
98
91
new String []{"acquireTokenCommon" },
99
- PublicClientApplication .builder (TestConstants . ADFS_APP_ID )
92
+ PublicClientApplication .builder (TestConfiguration . AAD_CLIENT_ID )
100
93
.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" )
101
143
.instanceDiscovery (true ));
102
144
103
145
Capture <MsalRequest > capturedMsalRequest = Capture .newInstance ();
@@ -140,16 +182,15 @@ public void b2cAdfsInstanceDiscoveryTrue(String authority) throws Exception{
140
182
}
141
183
142
184
/**
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.
144
186
*/
145
- @ Test (dataProvider = "aadClouds" )
146
- public void aadInstanceDiscoveryFalse (String authority ) throws Exception {
147
-
187
+ @ Test
188
+ public void b2cInstanceDiscoveryTrue () throws Exception {
148
189
app = PowerMock .createPartialMock (PublicClientApplication .class ,
149
190
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 ));
153
194
154
195
Capture <MsalRequest > capturedMsalRequest = Capture .newInstance ();
155
196
@@ -187,5 +228,8 @@ public void aadInstanceDiscoveryFalse(String authority) throws Exception {
187
228
188
229
completableFuture .get ();
189
230
Assert .assertEquals (capturedHttpRequest .getValues ().size (),0 );
231
+
190
232
}
233
+
234
+
191
235
}
0 commit comments