use of org.wso2.carbon.identity.oauth2.dto.OAuth2ClientValidationResponseDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ServiceTest method testValidateClientInfoWithInvalidClientId.
@Test
public void testValidateClientInfoWithInvalidClientId() throws Exception {
whenNew(OAuthAppDAO.class).withNoArguments().thenReturn(oAuthAppDAO);
mockStatic(IdentityTenantUtil.class);
when(IdentityTenantUtil.getTenantId(anyString())).thenReturn(-1234);
when(oAuthAppDAO.getAppInformation(null)).thenReturn(null);
OAuth2ClientValidationResponseDTO oAuth2ClientValidationResponseDTO = oAuth2Service.validateClientInfo(null, "dummyCallbackUrI");
assertNotNull(oAuth2ClientValidationResponseDTO);
assertEquals(oAuth2ClientValidationResponseDTO.getErrorCode(), "invalid_client");
assertFalse(oAuth2ClientValidationResponseDTO.isValidClient());
}
use of org.wso2.carbon.identity.oauth2.dto.OAuth2ClientValidationResponseDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ServiceTest method testValidateClientInfoWithInvalidCallbackURL.
@Test
public void testValidateClientInfoWithInvalidCallbackURL() throws Exception {
String clientId = UUID.randomUUID().toString();
getOAuthAppDO(clientId, "dummyGrantType", "dummyCallBackUrl", "carbon.super");
OAuth2ClientValidationResponseDTO oAuth2ClientValidationResponseDTO = oAuth2Service.validateClientInfo(clientId, "dummyCallBackURI");
assertEquals(oAuth2ClientValidationResponseDTO.getErrorCode(), OAuth2ErrorCodes.INVALID_CALLBACK);
}
use of org.wso2.carbon.identity.oauth2.dto.OAuth2ClientValidationResponseDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ServiceTest method testValidateClientInfo.
@Test(dataProvider = "ValidateClientInfoDataProvider")
public void testValidateClientInfo(String clientId, String grantType, String callbackUrl, String tenantDomain, String callbackURI) throws Exception {
OAuthAppDO oAuthAppDO = getOAuthAppDO(clientId, grantType, callbackUrl, tenantDomain);
OAuth2ClientValidationResponseDTO oAuth2ClientValidationResponseDTO = oAuth2Service.validateClientInfo(clientId, callbackURI);
assertNotNull(oAuth2ClientValidationResponseDTO);
assertTrue(oAuth2ClientValidationResponseDTO.isValidClient());
assertEquals(oAuth2ClientValidationResponseDTO.getApplicationName(), oAuthAppDO.getApplicationName());
assertEquals(oAuth2ClientValidationResponseDTO.isPkceMandatory(), oAuthAppDO.isPkceMandatory());
}
use of org.wso2.carbon.identity.oauth2.dto.OAuth2ClientValidationResponseDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ServiceTest method testInvalidOAuthClientException.
@Test
public void testInvalidOAuthClientException() throws Exception {
String callbackUrI = "dummyCallBackURI";
whenNew(OAuthAppDAO.class).withNoArguments().thenReturn(oAuthAppDAO);
when(oAuthAppDAO.getAppInformation(clientId)).thenThrow(new InvalidOAuthClientException("Cannot find an application associated with the given consumer key"));
mockStatic(IdentityTenantUtil.class);
when(IdentityTenantUtil.getTenantId(anyString())).thenReturn(1);
OAuth2ClientValidationResponseDTO oAuth2ClientValidationResponseDTO = oAuth2Service.validateClientInfo(clientId, callbackUrI);
assertNotNull(oAuth2ClientValidationResponseDTO);
assertEquals(oAuth2ClientValidationResponseDTO.getErrorCode(), OAuth2ErrorCodes.INVALID_CLIENT);
assertFalse(oAuth2ClientValidationResponseDTO.isValidClient());
}
use of org.wso2.carbon.identity.oauth2.dto.OAuth2ClientValidationResponseDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ServiceTest method testIdentityOAuth2Exception.
@Test
public void testIdentityOAuth2Exception() throws Exception {
String callbackUrI = "dummyCallBackURI";
whenNew(OAuthAppDAO.class).withNoArguments().thenReturn(oAuthAppDAO);
when(oAuthAppDAO.getAppInformation(clientId)).thenThrow(new IdentityOAuth2Exception("Error while retrieving the app information"));
mockStatic(IdentityTenantUtil.class);
when(IdentityTenantUtil.getTenantId(anyString())).thenReturn(1);
OAuth2ClientValidationResponseDTO oAuth2ClientValidationResponseDTO = oAuth2Service.validateClientInfo(clientId, callbackUrI);
assertNotNull(oAuth2ClientValidationResponseDTO);
assertEquals(oAuth2ClientValidationResponseDTO.getErrorCode(), OAuth2ErrorCodes.SERVER_ERROR);
assertFalse(oAuth2ClientValidationResponseDTO.isValidClient());
}
Aggregations