From 027c0d4281bb83be444eaccab3b9720559ee076b Mon Sep 17 00:00:00 2001 From: "lanka@wso2.com" Date: Thu, 25 Feb 2016 11:11:23 +0530 Subject: [PATCH 1/6] Modifying mobile grant sample to demonstrate custom headers + improve dataExtractUtils code + move IDP test case to relevant package. --- .../mgt/IdentityProviderMgtServiceTestCase.java | 2 +- .../identity/integration/test/utils/DataExtractUtil.java | 6 +++--- .../tests-backend/src/test/resources/testng.xml | 2 +- .../sample/identity/oauth2/grant/mobile/MobileGrant.java | 7 +++++++ 4 files changed, 12 insertions(+), 5 deletions(-) rename modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/{identity => idp}/mgt/IdentityProviderMgtServiceTestCase.java (99%) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/identity/mgt/IdentityProviderMgtServiceTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/idp/mgt/IdentityProviderMgtServiceTestCase.java similarity index 99% rename from modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/identity/mgt/IdentityProviderMgtServiceTestCase.java rename to modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/idp/mgt/IdentityProviderMgtServiceTestCase.java index 2ac75cdb3e..c50c8430ee 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/identity/mgt/IdentityProviderMgtServiceTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/idp/mgt/IdentityProviderMgtServiceTestCase.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.identity.integration.test.identity.mgt; +package org.wso2.identity.integration.test.idp.mgt; import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.context.ConfigurationContextFactory; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/utils/DataExtractUtil.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/utils/DataExtractUtil.java index 1064dc7758..3dba6c4759 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/utils/DataExtractUtil.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/utils/DataExtractUtil.java @@ -229,9 +229,9 @@ public static String extractAccessTokenFromQueryString(String query) { String[] params = query.split("&"); for (String param : params) { String name = param.split("=")[0]; - String value = param.split("=")[1]; - if (name.contains("access_token")) - return value; + if (name.contains("access_token")) { + return param.split("=")[1]; + } } return null; } diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml index a15ddf05ba..d31459753f 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml @@ -51,7 +51,7 @@ - + diff --git a/modules/samples/oauth2/custom-grant/src/main/java/org/wso2/sample/identity/oauth2/grant/mobile/MobileGrant.java b/modules/samples/oauth2/custom-grant/src/main/java/org/wso2/sample/identity/oauth2/grant/mobile/MobileGrant.java index 9f63da5d8e..f36fc8ae3f 100644 --- a/modules/samples/oauth2/custom-grant/src/main/java/org/wso2/sample/identity/oauth2/grant/mobile/MobileGrant.java +++ b/modules/samples/oauth2/custom-grant/src/main/java/org/wso2/sample/identity/oauth2/grant/mobile/MobileGrant.java @@ -22,6 +22,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser; import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception; +import org.wso2.carbon.identity.oauth2.ResponseHeader; import org.wso2.carbon.identity.oauth2.model.RequestParameter; import org.wso2.carbon.identity.oauth2.token.OAuthTokenReqMessageContext; import org.wso2.carbon.identity.oauth2.token.handlers.grant.AbstractAuthorizationGrantHandler; @@ -67,7 +68,13 @@ public boolean validateGrant(OAuthTokenReqMessageContext oAuthTokenReqMessageCon mobileUser.setUserName(mobileNumber); oAuthTokenReqMessageContext.setAuthorizedUser(mobileUser); oAuthTokenReqMessageContext.setScope(oAuthTokenReqMessageContext.getOauth2AccessTokenReqDTO().getScope()); + } else{ + ResponseHeader responseHeader = new ResponseHeader(); + responseHeader.setKey("SampleHeader-999"); + responseHeader.setValue("Provided Mobile Number is Invalid."); + oAuthTokenReqMessageContext.addProperty("RESPONSE_HEADERS", new ResponseHeader[]{responseHeader}); } + } return authStatus; From 04e146f82fce5cbe3cdebb9f09d67e02d2db8f0d Mon Sep 17 00:00:00 2001 From: "lanka@wso2.com" Date: Thu, 25 Feb 2016 11:48:52 +0530 Subject: [PATCH 2/6] Integration tests from account disabling --- ...ccountLockingWhileSCIMEnabledTestCase.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/identity/mgt/AccountLockingWhileSCIMEnabledTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/identity/mgt/AccountLockingWhileSCIMEnabledTestCase.java index 8edf9310e9..8166bd6ae1 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/identity/mgt/AccountLockingWhileSCIMEnabledTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/identity/mgt/AccountLockingWhileSCIMEnabledTestCase.java @@ -59,6 +59,7 @@ public class AccountLockingWhileSCIMEnabledTestCase extends ISIntegrationTest { private static final String TEST_USER_PASSWORD = "Ab@123"; private static final String WRONG_PASSWORD = "wrongPassword"; private static final String TEST_ROLE = "testRole"; + private static final String DISABLED_CLAIM = "http://wso2.org/claims/identity/accountDisabled"; @SetEnvironment(executionEnvironments = {ExecutionEnvironment.ALL}) @@ -121,9 +122,27 @@ public void testSuccessfulLoginInitially() throws Exception { loginManger.logOut(); } + @SetEnvironment(executionEnvironments = {ExecutionEnvironment.ALL}) + @Test(groups = "wso2.is", description = "Check whether the user cannot login when account is disabled", + dependsOnMethods = "testSuccessfulLoginInitially", expectedExceptions = LoginAuthenticationExceptionException.class) + public void testUnsuccessfulLoginWithAccountDisabled() throws Exception { + remoteUSMServiceClient.setUserClaimValue(TEST_USER_USERNAME, DISABLED_CLAIM, "true", null); + loginManger.login(TEST_USER_USERNAME, TEST_USER_PASSWORD, isServer.getInstance().getHosts().get("default")); + loginManger.logOut(); + } + + @SetEnvironment(executionEnvironments = {ExecutionEnvironment.ALL}) + @Test(groups = "wso2.is", description = "Check whether the user can login when account is enabled again", + dependsOnMethods = "testUnsuccessfulLoginWithAccountDisabled", expectedExceptions = LoginAuthenticationExceptionException.class) + public void testSuccessfulLoginWithAccountEnabled() throws Exception { + remoteUSMServiceClient.setUserClaimValue(TEST_USER_USERNAME, DISABLED_CLAIM, "false", null); + loginManger.login(TEST_USER_USERNAME, TEST_USER_PASSWORD, isServer.getInstance().getHosts().get("default")); + loginManger.logOut(); + } + @SetEnvironment(executionEnvironments = {ExecutionEnvironment.ALL}) @Test(groups = "wso2.is", description = "Check user account verification", - dependsOnMethods = "testSuccessfulLoginInitially", expectedExceptions = LoginAuthenticationExceptionException.class) + dependsOnMethods = "testSuccessfulLoginWithAccountEnabled", expectedExceptions = LoginAuthenticationExceptionException.class) public void testUnsuccessfulFirstLogin() throws Exception { loginManger.login(TEST_USER_USERNAME, WRONG_PASSWORD, isServer.getInstance().getHosts().get("default")); loginManger.logOut(); From 8d7e53e3964d0878c5db84fd84bb2b6da26aec9b Mon Sep 17 00:00:00 2001 From: "lanka@wso2.com" Date: Thu, 25 Feb 2016 12:47:17 +0530 Subject: [PATCH 3/6] moving idp mgt test case to relevant place --- .../tests-backend/src/test/resources/testng.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml index a556715b88..5272b4ba6d 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml @@ -51,7 +51,6 @@ - @@ -97,6 +96,7 @@ + From a6b896d1124aa94ea9ef02a56d4ee5e1b748d161 Mon Sep 17 00:00:00 2001 From: "lanka@wso2.com" Date: Mon, 29 Feb 2016 18:17:10 +0530 Subject: [PATCH 4/6] moving idp mgt test case to relevant place --- .../tests-backend/src/test/resources/testng.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml index 5272b4ba6d..8d921b540f 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml @@ -48,7 +48,7 @@ - + From ad31748f36690b82add55c4e037a15cb6758a4d1 Mon Sep 17 00:00:00 2001 From: "lanka@wso2.com" Date: Sun, 6 Mar 2016 15:34:50 +0530 Subject: [PATCH 5/6] moving idp mgt test case to relevant place --- .../tests-backend/src/test/resources/testng.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml index 46ebe65a36..017415b2f1 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml @@ -48,7 +48,7 @@ - + From a26baf3d28f8f8f11ab99897e0657c0d335624e4 Mon Sep 17 00:00:00 2001 From: "lanka@wso2.com" Date: Sun, 6 Mar 2016 15:38:31 +0530 Subject: [PATCH 6/6] adapting review comments from Chamila --- .../wso2/identity/integration/test/utils/DataExtractUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/utils/DataExtractUtil.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/utils/DataExtractUtil.java index 3dba6c4759..ffd0031888 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/utils/DataExtractUtil.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/utils/DataExtractUtil.java @@ -229,7 +229,7 @@ public static String extractAccessTokenFromQueryString(String query) { String[] params = query.split("&"); for (String param : params) { String name = param.split("=")[0]; - if (name.contains("access_token")) { + if (name.contains(OAuth2Constant.ACCESS_TOKEN)) { return param.split("=")[1]; } }