use of org.wso2.carbon.identity.oauth2.model.AuthzCodeDO in project identity-inbound-auth-oauth by wso2-extensions.
the class AuthorizationCodeGrantHandlerTest method buildErrorTokenRequestMessageContext.
@DataProvider(name = "buildErrorTokenRequestMessageContext")
public Object[][] buildErrorTokenRequestMessageContext() {
OAuthTokenReqMessageContext oAuthTokenReqMessageContext1 = new OAuthTokenReqMessageContext(new OAuth2AccessTokenReqDTO());
oAuthTokenReqMessageContext1.getOauth2AccessTokenReqDTO().setAuthorizationCode("123456");
oAuthTokenReqMessageContext1.getOauth2AccessTokenReqDTO().setCallbackURI("callBackUrl2");
OAuthTokenReqMessageContext oAuthTokenReqMessageContext2 = new OAuthTokenReqMessageContext(new OAuth2AccessTokenReqDTO());
oAuthTokenReqMessageContext2.getOauth2AccessTokenReqDTO().setAuthorizationCode("123456");
oAuthTokenReqMessageContext2.getOauth2AccessTokenReqDTO().setCallbackURI("callBackUrl");
AuthzCodeDO authzCodeDO1 = new AuthzCodeDO();
authzCodeDO1.setState(OAuthConstants.AuthorizationCodeState.INACTIVE);
AuthenticatedUser authenticatedUser = new AuthenticatedUser();
authenticatedUser.setUserName("user");
WhiteboxImpl.setInternalState(authzCodeDO1, "authorizedUser", authenticatedUser);
WhiteboxImpl.setInternalState(authzCodeDO1, "callbackUrl", "callBackUrl");
WhiteboxImpl.setInternalState(authzCodeDO1, "state", "INACTIVE");
AuthzCodeDO authzCodeDO2 = new AuthzCodeDO();
WhiteboxImpl.setInternalState(authzCodeDO2, "authorizedUser", authenticatedUser);
WhiteboxImpl.setInternalState(authzCodeDO2, "callbackUrl", "callBackUrl");
WhiteboxImpl.setInternalState(authzCodeDO2, "validityPeriod", 3000000L);
return new Object[][] { { oAuthTokenReqMessageContext1, null, CLIENT_ID_VALUE, true, 1000L, "Invalid authorization code" }, { oAuthTokenReqMessageContext1, authzCodeDO1, CLIENT_ID_VALUE, true, 1000L, "Inactive authorization code" }, { oAuthTokenReqMessageContext1, authzCodeDO2, CLIENT_ID_VALUE, true, 1000L, "Expired authorization code" }, { oAuthTokenReqMessageContext1, authzCodeDO2, CLIENT_ID_VALUE, true, System.currentTimeMillis(), "Callback url mismatch" }, { oAuthTokenReqMessageContext2, authzCodeDO2, CLIENT_ID_VALUE, false, System.currentTimeMillis(), "PKCE validation failed" }, { oAuthTokenReqMessageContext2, authzCodeDO2, INVALID_CLIENT, true, System.currentTimeMillis(), "Error while retrieving app information" } };
}
use of org.wso2.carbon.identity.oauth2.model.AuthzCodeDO in project identity-inbound-auth-oauth by wso2-extensions.
the class AuthorizationCodeDAOImplTest method testInsertAuthorizationCode.
@Test
public void testInsertAuthorizationCode() throws Exception {
String consumerKey = UUID.randomUUID().toString();
String authzCodeID = UUID.randomUUID().toString();
String authzCode = UUID.randomUUID().toString();
mockStatic(OAuth2Util.class);
when(OAuth2Util.getTenantId(anyString())).thenReturn(DEFAULT_TENANT_ID);
AuthzCodeDO authzCodeDO = persistAuthorizationCode(consumerKey, authzCodeID, authzCode, OAuthConstants.AuthorizationCodeState.ACTIVE);
Assert.assertEquals(authorizationCodeDAO.getCodeIdByAuthorizationCode(authzCode), authzCodeDO.getAuthzCodeId());
Assert.assertNull(authorizationCodeDAO.getCodeIdByAuthorizationCode(UUID.randomUUID().toString()));
}
use of org.wso2.carbon.identity.oauth2.model.AuthzCodeDO in project identity-inbound-auth-oauth by wso2-extensions.
the class AuthorizationCodeDAOImplTest method persistAuthorizationCodeWithModifiedScope.
private AuthzCodeDO persistAuthorizationCodeWithModifiedScope(String consumerKey, String authzCodeId, String authzCode, String status, String[] scope) throws Exception {
createApplication(consumerKey, UUID.randomUUID().toString(), DEFAULT_TENANT_ID);
AuthzCodeDO authzCodeDO = new AuthzCodeDO(authenticatedUser, scope, new Timestamp(System.currentTimeMillis()), 3600000L, CALLBACK, consumerKey, authzCode, authzCodeId, status, null, null);
authorizationCodeDAO.insertAuthorizationCode(authzCode, consumerKey, CALLBACK, authzCodeDO);
return authzCodeDO;
}
use of org.wso2.carbon.identity.oauth2.model.AuthzCodeDO in project identity-inbound-auth-oauth by wso2-extensions.
the class AuthorizationCodeDAOImplTest method testGetAuthorizationCodesByUser.
@Test
public void testGetAuthorizationCodesByUser() throws Exception {
String consumerKey = UUID.randomUUID().toString();
String authzCodeID = UUID.randomUUID().toString();
String authzCode = UUID.randomUUID().toString();
AuthenticatedUser dummyAuthenticatedUser = new AuthenticatedUser();
dummyAuthenticatedUser.setTenantDomain("super.wso2");
dummyAuthenticatedUser.setUserName("MockedUser");
dummyAuthenticatedUser.setUserStoreDomain(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME);
mockStatic(OAuth2Util.class);
when(OAuth2Util.getTenantId(anyString())).thenReturn(DEFAULT_TENANT_ID);
when(OAuth2Util.getUserStoreDomain(any())).thenReturn(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME);
AuthzCodeDO authzCodeDO = persistAuthorizationCode(consumerKey, authzCodeID, authzCode, OAuthConstants.AuthorizationCodeState.ACTIVE);
mockStatic(OAuth2Util.class);
mockStatic(IdentityUtil.class);
when(OAuth2Util.getTenantId(anyString())).thenReturn(DEFAULT_TENANT_ID);
when(IdentityUtil.isUserStoreInUsernameCaseSensitive(anyString())).thenReturn(true);
when(OAuth2Util.isHashDisabled()).thenReturn(true);
// Allow the method to pass the validation without wanting to traverse internally.
when(OAuth2Util.calculateValidityInMillis(anyLong(), anyLong())).thenReturn(2000L);
Assert.assertTrue((authorizationCodeDAO.getAuthorizationCodesByUser(authenticatedUser).contains(authzCodeDO.getAuthorizationCode())));
Assert.assertTrue(authorizationCodeDAO.getAuthorizationCodesByUser(dummyAuthenticatedUser).isEmpty());
}
use of org.wso2.carbon.identity.oauth2.model.AuthzCodeDO in project identity-inbound-auth-oauth by wso2-extensions.
the class AuthorizationCodeDAOImplTest method testDeactivateAuthorizationCodes.
@Test
public void testDeactivateAuthorizationCodes() throws Exception {
String consumerKey1 = UUID.randomUUID().toString();
String authzCodeID1 = UUID.randomUUID().toString();
String authzCode1 = UUID.randomUUID().toString();
String consumerKey2 = UUID.randomUUID().toString();
String authzCodeID2 = UUID.randomUUID().toString();
String authzCode2 = UUID.randomUUID().toString();
AuthzCodeDO authzCodeDO1 = persistAuthorizationCode(consumerKey1, authzCodeID1, authzCode1, OAuthConstants.AuthorizationCodeState.ACTIVE);
AuthzCodeDO authzCodeDO2 = persistAuthorizationCode(consumerKey2, authzCodeID2, authzCode2, OAuthConstants.AuthorizationCodeState.ACTIVE);
mockStatic(OAuth2Util.class);
mockStatic(IdentityUtil.class);
authzCodeDO1.setOauthTokenId(UUID.randomUUID().toString());
// If state is EXPIRED/INACTIVE needs to revoke token as well.
mockStatic(OAuth2TokenUtil.class);
doNothing().when(OAuth2TokenUtil.class, "postRevokeCode", anyString(), anyString(), anyString());
List<AuthzCodeDO> revokeAuthzCodeList = new ArrayList<>();
revokeAuthzCodeList.add(authzCodeDO1);
revokeAuthzCodeList.add(authzCodeDO2);
authorizationCodeDAO.deactivateAuthorizationCodes(revokeAuthzCodeList);
Assert.assertTrue(authorizationCodeDAO.getActiveAuthorizationCodesByConsumerKey(authzCodeDO1.getConsumerKey()).isEmpty());
Assert.assertTrue(authorizationCodeDAO.getActiveAuthorizationCodesByConsumerKey(authzCodeDO2.getConsumerKey()).isEmpty());
}
Aggregations