use of org.wso2.carbon.identity.oauth2.model.AuthzCodeDO in project identity-inbound-auth-oauth by wso2-extensions.
the class AuthorizationCodeDAOImplTest method testGetAuthorizationCodesByConsumerKey.
@Test
public void testGetAuthorizationCodesByConsumerKey() 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);
Set<String> availableAuthzCodes = new HashSet<>();
availableAuthzCodes.add(authzCode);
Assert.assertEquals(authorizationCodeDAO.getAuthorizationCodesByConsumerKey(authzCodeDO.getConsumerKey()), availableAuthzCodes);
Assert.assertTrue(authorizationCodeDAO.getAuthorizationCodesByConsumerKey(UUID.randomUUID().toString()).isEmpty());
}
use of org.wso2.carbon.identity.oauth2.model.AuthzCodeDO in project identity-inbound-auth-oauth by wso2-extensions.
the class AuthorizationCodeDAOImplTest method testGetActiveAuthorizationCodesByConsumerKey.
@Test
public void testGetActiveAuthorizationCodesByConsumerKey() 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();
mockStatic(OAuth2Util.class);
when(OAuth2Util.getTenantId(anyString())).thenReturn(DEFAULT_TENANT_ID);
AuthzCodeDO authzCodeDO1 = persistAuthorizationCode(consumerKey1, authzCodeID1, authzCode1, OAuthConstants.AuthorizationCodeState.ACTIVE);
AuthzCodeDO authzCodeDO2 = persistAuthorizationCode(consumerKey2, authzCodeID2, authzCode2, OAuthConstants.AuthorizationCodeState.ACTIVE);
// If state is EXPIRED/INACTIVE needs to revoke token as well.
mockStatic(OAuth2TokenUtil.class);
doNothing().when(OAuth2TokenUtil.class, "postRevokeCode", anyString(), anyString(), anyString());
authorizationCodeDAO.updateAuthorizationCodeState(authzCodeDO1.getAuthorizationCode(), OAuthConstants.AuthorizationCodeState.REVOKED);
Set<String> availableAuthzCodes = new HashSet<>();
availableAuthzCodes.add(authzCode2);
Assert.assertEquals(authorizationCodeDAO.getActiveAuthorizationCodesByConsumerKey(authzCodeDO2.getConsumerKey()), availableAuthzCodes);
Assert.assertTrue(authorizationCodeDAO.getActiveAuthorizationCodesByConsumerKey(UUID.randomUUID().toString()).isEmpty());
Assert.assertTrue(authorizationCodeDAO.getActiveAuthorizationCodesByConsumerKey(authzCodeDO1.getConsumerKey()).isEmpty());
}
use of org.wso2.carbon.identity.oauth2.model.AuthzCodeDO in project identity-inbound-auth-oauth by wso2-extensions.
the class AuthorizationCodeDAOImplTest method persistAuthorizationCode.
private AuthzCodeDO persistAuthorizationCode(String consumerKey, String authzCodeId, String authzCode, String status) throws Exception {
createApplication(consumerKey, UUID.randomUUID().toString(), DEFAULT_TENANT_ID);
AuthzCodeDO authzCodeDO = new AuthzCodeDO(authenticatedUser, scopes, new Timestamp(System.currentTimeMillis()), 3600000L, CALLBACK, consumerKey, authzCode, authzCodeId, status, null, null);
mockStatic(OAuth2Util.class);
when(OAuth2Util.getTenantId(anyString())).thenReturn(DEFAULT_TENANT_ID);
when(OAuth2Util.getUserStoreDomain(any())).thenReturn(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME);
when(OAuth2Util.getAuthenticatedIDP(any())).thenReturn("LOCAL");
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 testDeactivateAuthorizationCode.
@Test
public void testDeactivateAuthorizationCode() 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());
authorizationCodeDAO.deactivateAuthorizationCode(authzCodeDO1);
Assert.assertTrue(authorizationCodeDAO.getActiveAuthorizationCodesByConsumerKey(authzCodeDO1.getConsumerKey()).isEmpty());
Assert.assertFalse(authorizationCodeDAO.getAuthorizationCodesByConsumerKey(authzCodeDO2.getConsumerKey()).isEmpty());
}
use of org.wso2.carbon.identity.oauth2.model.AuthzCodeDO in project identity-inbound-auth-oauth by wso2-extensions.
the class AuthorizationCodeDAOImplTest method testValidateAuthorizationCode.
@Test
public void testValidateAuthorizationCode() throws Exception {
String consumerKey = UUID.randomUUID().toString();
String authzCodeID = UUID.randomUUID().toString();
String authzCode = UUID.randomUUID().toString();
AuthzCodeDO authzCodeDO = persistAuthorizationCode(consumerKey, authzCodeID, authzCode, OAuthConstants.AuthorizationCodeState.ACTIVE);
OAuth2ServiceComponentHolder.setIDPIdColumnEnabled(false);
OAuth2ServiceComponentHolder.setApplicationMgtService(mockedApplicationManagementService);
when(mockedApplicationManagementService.getServiceProviderByClientId(anyString(), any(), anyString())).thenReturn(mockedServiceProvider);
when(OAuth2Util.createAuthenticatedUser(anyString(), anyString(), anyString(), anyString())).thenReturn(mockedAuthenticatedUser);
doNothing().when(mockedAuthenticatedUser, "setAuthenticatedSubjectIdentifier", anyString(), anyObject());
Assert.assertNotNull(authorizationCodeDAO.validateAuthorizationCode(authzCodeDO.getConsumerKey(), authzCodeDO.getAuthorizationCode()));
}
Aggregations