-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests to check generated redirect url in fragment and query …
…response modes.
- Loading branch information
1 parent
f63ebe7
commit 89aab77
Showing
3 changed files
with
91 additions
and
49 deletions.
There are no files selected for viewing
49 changes: 0 additions & 49 deletions
49
...g/wso2/carbon/identity/oauth2/responsemode/provider/FragmentResponseModeProviderTest.java
This file was deleted.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
.../java/org/wso2/carbon/identity/oauth2/responsemode/provider/ResponseModeProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.wso2.carbon.identity.oauth2.responsemode.provider; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
import org.wso2.carbon.identity.oauth2.responsemode.provider.impl.FragmentResponseModeProvider; | ||
import org.wso2.carbon.identity.oauth2.responsemode.provider.impl.QueryResponseModeProvider; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
|
||
public class ResponseModeProviderTest { | ||
|
||
@DataProvider(name = "fragmentDataProvider") | ||
private Object[][] fragmentDataProvider() { | ||
|
||
return new Object[][] { | ||
// AuthorizationResponseDTO, provided callback url, expected redirect url | ||
{getAuthResponseDTO("https://www.google.com/redirects/redirect1", "code1"), | ||
"https://www.google.com/redirects/redirect1", | ||
"https://www.google.com/redirects/redirect1#code=code1&scope=openid"}, | ||
{getAuthResponseDTO("https://www.google.com/redirects/redirect2?param1=abc¶m2=xyz", | ||
"code2"), | ||
"https://www.google.com/redirects/redirect2?param1=abc¶m2=xyz", | ||
"https://www.google.com/redirects/redirect2?param1=abc¶m2=xyz#code=code2&scope=openid"}, | ||
|
||
}; | ||
} | ||
|
||
@Test(dataProvider = "fragmentDataProvider", description = "Test whether the redirect url generated " + | ||
"by the FragmentResponseModeProvider is correct.") | ||
public void testFragmentRedirectUrl(AuthorizationResponseDTO authorizationResponseDTO, String callbackUrl, | ||
String expectedRedirectUrl) { | ||
|
||
FragmentResponseModeProvider fragmentResponseModeProvider = new FragmentResponseModeProvider(); | ||
String redirectUrl = fragmentResponseModeProvider.getAuthResponseRedirectUrl(authorizationResponseDTO); | ||
|
||
Assert.assertTrue(redirectUrl.contains(callbackUrl), "Redirect url does not " + | ||
"contain the callback url provided."); | ||
Assert.assertTrue(redirectUrl.contains("#"), "Redirect url does not contain a fragment part."); | ||
Assert.assertTrue(redirectUrl.contains("code="), "Redirect url does not contain the authorization code."); | ||
Assert.assertEquals(redirectUrl, expectedRedirectUrl, "Redirect url is not as expected."); | ||
} | ||
|
||
@DataProvider(name = "queryDataProvider") | ||
private Object[][] queryDataProvider() { | ||
|
||
return new Object[][] { | ||
// AuthorizationResponseDTO, provided callback url, expected redirect url | ||
{getAuthResponseDTO("https://www.google.com/redirects/redirect1", "code1"), | ||
"https://www.google.com/redirects/redirect1", | ||
"https://www.google.com/redirects/redirect1?code=code1&scope=openid"}, | ||
{getAuthResponseDTO("https://www.google.com/redirects/redirect2?param1=abc¶m2=xyz", | ||
"code2"), | ||
"https://www.google.com/redirects/redirect2?param1=abc¶m2=xyz", | ||
"https://www.google.com/redirects/redirect2?param1=abc¶m2=xyz&code=code2&scope=openid"}, | ||
|
||
}; | ||
} | ||
|
||
@Test(dataProvider = "queryDataProvider", description = "Test whether the redirect url generated " + | ||
"by the QueryResponseModeProvider is correct.") | ||
public void testQueryRedirectUrl(AuthorizationResponseDTO authorizationResponseDTO, String callbackUrl, | ||
String expectedRedirectUrl) { | ||
|
||
QueryResponseModeProvider queryResponseModeProvider = new QueryResponseModeProvider(); | ||
String redirectUrl = queryResponseModeProvider.getAuthResponseRedirectUrl(authorizationResponseDTO); | ||
|
||
Assert.assertTrue(redirectUrl.contains(callbackUrl), "Redirect url does not " + | ||
"contain the callback url provided."); | ||
Assert.assertTrue(redirectUrl.contains("?"), "Redirect url does not contain a query part."); | ||
Assert.assertTrue(redirectUrl.contains("code="), "Redirect url does not contain the authorization code."); | ||
Assert.assertEquals(redirectUrl, expectedRedirectUrl, "Redirect url is not as expected."); | ||
} | ||
|
||
/** | ||
* This method creates and returns dummy AuthorizationResponseDTO instance. | ||
* @return AuthorizationResponseDTO DTO | ||
*/ | ||
private AuthorizationResponseDTO getAuthResponseDTO(String redirectURI, String code) { | ||
|
||
AuthorizationResponseDTO authorizationResponseDTO = new AuthorizationResponseDTO(); | ||
authorizationResponseDTO.setRedirectUrl(redirectURI); | ||
|
||
authorizationResponseDTO.getSuccessResponseDTO().setAuthorizationCode(code); | ||
authorizationResponseDTO.getSuccessResponseDTO().setScope(new HashSet<>(Arrays.asList("openid"))); | ||
|
||
return authorizationResponseDTO; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters