Search in sources :

Example 6 with OAuth2ClientValidationResponseDTO

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());
}
Also used : OAuth2ClientValidationResponseDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2ClientValidationResponseDTO) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Example 7 with OAuth2ClientValidationResponseDTO

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);
}
Also used : OAuth2ClientValidationResponseDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2ClientValidationResponseDTO) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Example 8 with OAuth2ClientValidationResponseDTO

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());
}
Also used : OAuthAppDO(org.wso2.carbon.identity.oauth.dao.OAuthAppDO) OAuth2ClientValidationResponseDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2ClientValidationResponseDTO) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Example 9 with OAuth2ClientValidationResponseDTO

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());
}
Also used : OAuth2ClientValidationResponseDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2ClientValidationResponseDTO) Matchers.anyString(org.mockito.Matchers.anyString) InvalidOAuthClientException(org.wso2.carbon.identity.oauth.common.exception.InvalidOAuthClientException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Example 10 with OAuth2ClientValidationResponseDTO

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());
}
Also used : OAuth2ClientValidationResponseDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2ClientValidationResponseDTO) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Aggregations

OAuth2ClientValidationResponseDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2ClientValidationResponseDTO)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 Test (org.testng.annotations.Test)10 PowerMockIdentityBaseTest (org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)7 HashMap (java.util.HashMap)6 Matchers.anyString (org.mockito.Matchers.anyString)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 RequestObject (org.wso2.carbon.identity.openidconnect.model.RequestObject)5 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)3 AfterTest (org.testng.annotations.AfterTest)3 BeforeTest (org.testng.annotations.BeforeTest)3 IdentityEventService (org.wso2.carbon.identity.event.services.IdentityEventService)3 OAuthAppDO (org.wso2.carbon.identity.oauth.dao.OAuthAppDO)3 HashSet (java.util.HashSet)2 Hashtable (java.util.Hashtable)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Response (javax.ws.rs.core.Response)2 OAuthResponse (org.apache.oltu.oauth2.common.message.OAuthResponse)2 OAuthValidator (org.apache.oltu.oauth2.common.validators.OAuthValidator)2 JSONObject (org.json.JSONObject)2