88
99import org .powermock .core .classloader .annotations .PrepareForTest ;
1010import org .testng .Assert ;
11+ import org .testng .annotations .DataProvider ;
1112import org .testng .annotations .Test ;
1213
13- @ Test (groups = { "checkin" })
14- @ PrepareForTest ({ AADAuthority .class , HttpHelper .class ,
15- JsonHelper .class , AadInstanceDiscoveryResponse .class })
14+ @ Test (groups = {"checkin" })
15+ @ PrepareForTest ({AADAuthority .class , HttpHelper .class ,
16+ JsonHelper .class , AadInstanceDiscoveryResponse .class })
1617public class AuthorityTest extends AbstractMsalTests {
1718
1819 @ Test
@@ -33,45 +34,28 @@ public void testDetectAuthorityType_B2C() throws Exception {
3334 Assert .assertEquals (Authority .detectAuthorityType (url ), AuthorityType .B2C );
3435 }
3536
36- @ Test (expectedExceptions = IllegalArgumentException .class ,
37- expectedExceptionsMessageRegExp =
38- "authority Uri should have at least one segment in the path \\ (i.e. https://<host>/<path>/...\\ )" )
39- public void testAADAuthorityConstructor_NoPathAuthority () throws MalformedURLException {
40- new AADAuthority (new URL ("https://something.com/" ));
41- }
42-
4337 @ Test (expectedExceptions = IllegalArgumentException .class ,
4438 expectedExceptionsMessageRegExp =
4539 "B2C 'authority' Uri should have at least 3 segments in the path \\ (i.e. https://<host>/tfp/<tenant>/<policy>/...\\ )" )
4640 public void testB2CAuthorityConstructor_NotEnoughSegments () throws MalformedURLException {
4741 new B2CAuthority (new URL ("https://something.com/tfp/somethingelse/" ));
4842 }
4943
50- @ Test (expectedExceptions = NullPointerException .class , expectedExceptionsMessageRegExp = "canonicalAuthorityUrl" )
51- public void testAADAuthorityConstructor_NullAuthority () {
52- new AADAuthority (null );
53- }
54-
55- @ Test (expectedExceptions = NullPointerException .class , expectedExceptionsMessageRegExp = "canonicalAuthorityUrl" )
56- public void testB2CAuthorityConstructor_NullAuthority () {
57- new B2CAuthority (null );
58- }
59-
6044 @ Test (expectedExceptions = IllegalArgumentException .class , expectedExceptionsMessageRegExp = "authority should use the 'https' scheme" )
6145 public void testAADAuthorityConstructor_HttpAuthority () throws MalformedURLException {
62- new AADAuthority (new URL ("http://I.com/not/h/t/t/p/s/" ));
46+ Authority . validateAuthority (new URL ("http://I.com/not/h/t/t/p/s/" ));
6347 }
6448
6549 @ Test (expectedExceptions = IllegalArgumentException .class , expectedExceptionsMessageRegExp = "authority is invalid format \\ (contains fragment\\ )" )
6650 public void testAADAuthorityConstructor_UrlHasFragment () throws MalformedURLException {
67- new AADAuthority (new URL ("https://I.com/something/#haha" ));
51+ Authority . validateAuthority (new URL ("https://I.com/something/#haha" ));
6852 }
6953
7054
7155 @ Test (expectedExceptions = IllegalArgumentException .class , expectedExceptionsMessageRegExp = "authority cannot contain query parameters" )
7256 public void testAADAuthorityConstructor_AuthorityHasQuery ()
7357 throws MalformedURLException {
74- new AADAuthority (new URL ("https://I.com/not/?query=not-allowed" ));
58+ Authority . validateAuthority (new URL ("https://I.com/not/?query=not-allowed" ));
7559 }
7660
7761
@@ -96,7 +80,7 @@ public void testConstructor_AADAuthority() throws MalformedURLException {
9680
9781 @ Test
9882 public void testConstructor_B2CAuthority () throws MalformedURLException {
99- final B2CAuthority aa = new B2CAuthority (new URL (TestConfiguration .B2C_AUTHORITY ));
83+ final B2CAuthority aa = new B2CAuthority (new URL (TestConfiguration .B2C_AUTHORITY ));
10084 Assert .assertNotNull (aa );
10185 Assert .assertEquals (aa .authority (),
10286 TestConfiguration .B2C_AUTHORITY + "/" );
@@ -128,22 +112,22 @@ public void testConstructor_ADFSAuthority() throws MalformedURLException {
128112 }
129113
130114 @ Test
131- public void testB2CAuthority_SameCanonicalAuthority () throws MalformedURLException {
115+ public void testB2CAuthority_SameCanonicalAuthority () throws MalformedURLException {
132116
133- PublicClientApplication pca = PublicClientApplication .builder ("client_id" ).
117+ PublicClientApplication pca = PublicClientApplication .builder ("client_id" ).
134118 b2cAuthority (TestConfiguration .B2C_AUTHORITY_CUSTOM_PORT ).build ();
135119 Assert .assertEquals (pca .authenticationAuthority .authority ,
136120 TestConfiguration .B2C_AUTHORITY_CUSTOM_PORT_TAIL_SLASH );
137121
138- PublicClientApplication pca2 = PublicClientApplication .builder ("client_id" ).
122+ PublicClientApplication pca2 = PublicClientApplication .builder ("client_id" ).
139123 b2cAuthority (TestConfiguration .B2C_AUTHORITY_CUSTOM_PORT_TAIL_SLASH ).build ();
140124 Assert .assertEquals (pca2 .authenticationAuthority .authority ,
141125 TestConfiguration .B2C_AUTHORITY_CUSTOM_PORT_TAIL_SLASH );
142126 }
143127
144128 @ Test
145- public void testNoAuthorityPassedIn_DefaultsToCommonAuthority (){
146- PublicClientApplication pca = PublicClientApplication .builder ("client_id" ).build ();
129+ public void testNoAuthorityPassedIn_DefaultsToCommonAuthority () {
130+ PublicClientApplication pca = PublicClientApplication .builder ("client_id" ).build ();
147131
148132 Assert .assertEquals (pca .authority (), TestConfiguration .AAD_COMMON_AUTHORITY );
149133 Assert .assertNotNull (pca .authenticationAuthority );
@@ -153,7 +137,7 @@ public void testNoAuthorityPassedIn_DefaultsToCommonAuthority(){
153137 public void testDoStaticInstanceDiscovery_ValidateTrue_TrustedAuthority ()
154138 throws MalformedURLException , Exception {
155139 final AADAuthority aa = new AADAuthority (new URL (TestConfiguration .AAD_TENANT_ENDPOINT ));
156- //PS Assert.assertTrue(aa.doStaticInstanceDiscovery(true));
140+ //PS Assert.assertTrue(aa.doStaticInstanceDiscovery(true));
157141 }
158142
159143 @ Test
@@ -169,4 +153,25 @@ public void testDoStaticInstanceDiscovery_ValidateFalse_TrustedAuthority()
169153 final AADAuthority aa = new AADAuthority (new URL (TestConfiguration .AAD_UNKNOWN_TENANT_ENDPOINT ));
170154 //PS Assert.assertTrue(aa.doStaticInstanceDiscovery(false));
171155 }
156+
157+
158+ @ DataProvider (name = "authoritiesWithEmptyPath" )
159+ public static Object [][] createData () {
160+ return new Object [][]{{"https://login.microsoftonline.com/" },
161+ {"https://login.microsoftonline.com//" },
162+ {"https://login.microsoftonline.com//tenant" },
163+ {"https://login.microsoftonline.com////tenant//path1" }};
164+ }
165+
166+ @ Test (dataProvider = "authoritiesWithEmptyPath" , expectedExceptions = IllegalArgumentException .class ,
167+ expectedExceptionsMessageRegExp = IllegalArgumentExceptionMessages .AUTHORITY_URI_EMPTY_PATH_SEGMENT )
168+ public void testValidateAuthorityEmptyPathSegments (String authority ) throws MalformedURLException {
169+ Authority .validateAuthority (new URL (authority ));
170+ }
171+
172+ @ Test (expectedExceptions = IllegalArgumentException .class ,
173+ expectedExceptionsMessageRegExp = IllegalArgumentExceptionMessages .AUTHORITY_URI_EMPTY_PATH )
174+ public void testValidateAuthorityEmptyPath () throws MalformedURLException {
175+ Authority .validateAuthority (new URL ("https://login.microsoftonline.com" ));
176+ }
172177}
0 commit comments