Search in sources :

Example 21 with OAuth2AuthorizeRespDTO

use of org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO in project identity-inbound-auth-oauth by wso2-extensions.

the class AuthorizationHandlerManagerTest method testHandleAuthorizationTokenResponseUnauthorizedAccess.

@Test
public void testHandleAuthorizationTokenResponseUnauthorizedAccess() throws Exception {
    authorizationHandlerManager = AuthorizationHandlerManager.getInstance();
    authzReqDTO.setResponseType(TestConstants.AUTHORIZATION_HANDLER_RESPONSE_TYPE_TOKEN);
    authzReqDTO.setConsumerKey(TestConstants.CLIENT_ID);
    authzReqDTO.setScopes(TestConstants.SCOPE_UNAUTHORIZED_ACCESS.split(" "));
    AuthenticatedUser user = new AuthenticatedUser();
    user.setUserName(TestConstants.USER_NAME);
    user.setTenantDomain(TestConstants.TENANT_DOMAIN);
    user.setUserStoreDomain(TestConstants.USER_DOMAIN_PRIMARY);
    authzReqDTO.setUser(user);
    OAuth2AuthorizeRespDTO respDTO = authorizationHandlerManager.handleAuthorization(authzReqDTO);
    String errorCode = respDTO.getErrorCode();
    Assert.assertNotNull(respDTO, "Response is null");
    Assert.assertNotNull(respDTO.getErrorCode(), "Error code returned is null");
    Assert.assertEquals(errorCode, OAuthError.CodeResponse.UNAUTHORIZED_CLIENT, "Expected " + OAuthError.CodeResponse.UNAUTHORIZED_CLIENT + " error code but found : " + errorCode);
}
Also used : OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO) Matchers.anyString(org.mockito.Matchers.anyString) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Example 22 with OAuth2AuthorizeRespDTO

use of org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO in project identity-inbound-auth-oauth by wso2-extensions.

the class AuthorizationHandlerManagerTest method testHandleAuthorizationTokenResponseTypeUnauthorized.

@Test
public void testHandleAuthorizationTokenResponseTypeUnauthorized() throws Exception {
    authzReqDTO.setResponseType(TestConstants.AUTHORIZATION_HANDLER_RESPONSE_TYPE_TOKEN);
    authzReqDTO.setConsumerKey(TestConstants.CLIENT_ID_UNAUTHORIZED_CLIENT);
    authzReqDTO.setScopes(TestConstants.SCOPE_STRING.split(" "));
    AuthenticatedUser user = new AuthenticatedUser();
    user.setUserName(TestConstants.USER_NAME);
    user.setTenantDomain(TestConstants.TENANT_DOMAIN);
    user.setUserStoreDomain(TestConstants.USER_DOMAIN_PRIMARY);
    authzReqDTO.setUser(user);
    OAuth2AuthorizeRespDTO respDTO = authorizationHandlerManager.handleAuthorization(authzReqDTO);
    String errorCode = respDTO.getErrorCode();
    Assert.assertNotNull(respDTO, "Response is null");
    Assert.assertNotNull(respDTO.getErrorCode(), "Error code returned is null");
    Assert.assertEquals(errorCode, TestConstants.UNAUTHORIZED_CLIENT_ERROR_CODE, "Expected unauthorized_client error code but found : " + errorCode);
}
Also used : OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO) Matchers.anyString(org.mockito.Matchers.anyString) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Example 23 with OAuth2AuthorizeRespDTO

use of org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO in project identity-inbound-auth-oauth by wso2-extensions.

the class AuthorizationHandlerManagerTest method testHandleInvalidResponseType.

@Test
public void testHandleInvalidResponseType() throws Exception {
    authzReqDTO.setResponseType(TestConstants.AUTHORIZATION_HANDLER_RESPONSE_TYPE_INVALID);
    OAuth2AuthorizeRespDTO respDTO = authorizationHandlerManager.handleAuthorization(authzReqDTO);
    String errorCode = respDTO.getErrorCode();
    Assert.assertNotNull(respDTO, "Response is null");
    Assert.assertNotNull(respDTO.getErrorCode(), "Error code returned is null");
    Assert.assertEquals(errorCode, OAuthError.CodeResponse.UNSUPPORTED_RESPONSE_TYPE, "Expected " + OAuthError.CodeResponse.UNSUPPORTED_RESPONSE_TYPE + " error code but found : " + errorCode);
}
Also used : OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Example 24 with OAuth2AuthorizeRespDTO

use of org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO in project identity-inbound-auth-oauth by wso2-extensions.

the class AuthorizationHandlerManagerTest method testHandleAuthorizationTokenResponseUnauthorizedScope.

@Test
public void testHandleAuthorizationTokenResponseUnauthorizedScope() throws Exception {
    authorizationHandlerManager = AuthorizationHandlerManager.getInstance();
    authzReqDTO.setResponseType(TestConstants.AUTHORIZATION_HANDLER_RESPONSE_TYPE_TOKEN);
    authzReqDTO.setConsumerKey(TestConstants.CLIENT_ID);
    authzReqDTO.setScopes(TestConstants.SCOPE_UNAUTHORIZED_SCOPE.split(" "));
    AuthenticatedUser user = new AuthenticatedUser();
    user.setUserName(TestConstants.USER_NAME);
    user.setTenantDomain(TestConstants.TENANT_DOMAIN);
    user.setUserStoreDomain(TestConstants.USER_DOMAIN_PRIMARY);
    authzReqDTO.setUser(user);
    OAuth2AuthorizeRespDTO respDTO = authorizationHandlerManager.handleAuthorization(authzReqDTO);
    String errorCode = respDTO.getErrorCode();
    Assert.assertNotNull(respDTO, "Response is null");
    Assert.assertNotNull(respDTO.getErrorCode(), "Error code returned is null");
    Assert.assertEquals(errorCode, OAuthError.CodeResponse.INVALID_SCOPE, "Expected " + OAuthError.CodeResponse.INVALID_SCOPE + " error code but found : " + errorCode);
}
Also used : OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO) Matchers.anyString(org.mockito.Matchers.anyString) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Example 25 with OAuth2AuthorizeRespDTO

use of org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO in project identity-inbound-auth-oauth by wso2-extensions.

the class AuthorizationHandlerManagerTest method testHandleAuthorizationIDTokenResponseTypeUnauthorized.

@Test
public void testHandleAuthorizationIDTokenResponseTypeUnauthorized() throws Exception {
    authzReqDTO.setResponseType(TestConstants.AUTHORIZATION_HANDLER_RESPONSE_TYPE_ID_TOKEN);
    authzReqDTO.setConsumerKey(TestConstants.CLIENT_ID_UNAUTHORIZED_CLIENT);
    authzReqDTO.setScopes(TestConstants.SCOPE_STRING.split(" "));
    AuthenticatedUser user = new AuthenticatedUser();
    user.setUserName(TestConstants.USER_NAME);
    user.setTenantDomain(TestConstants.TENANT_DOMAIN);
    user.setUserStoreDomain(TestConstants.USER_DOMAIN_PRIMARY);
    authzReqDTO.setUser(user);
    OAuth2AuthorizeRespDTO respDTO = authorizationHandlerManager.handleAuthorization(authzReqDTO);
    String errorCode = respDTO.getErrorCode();
    Assert.assertNotNull(respDTO, "Response is null");
    Assert.assertNotNull(respDTO.getErrorCode(), "Error code returned is null");
    Assert.assertEquals(errorCode, TestConstants.UNAUTHORIZED_CLIENT_ERROR_CODE, "Expected unauthorized_client error code but found : " + errorCode);
}
Also used : OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO) Matchers.anyString(org.mockito.Matchers.anyString) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Aggregations

OAuth2AuthorizeRespDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO)36 Test (org.testng.annotations.Test)22 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)18 Matchers.anyString (org.mockito.Matchers.anyString)13 IdentityBaseTest (org.wso2.carbon.identity.testutil.IdentityBaseTest)12 OAuth2AuthorizeReqDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeReqDTO)10 HashMap (java.util.HashMap)7 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)6 OAuthAuthzReqMessageContext (org.wso2.carbon.identity.oauth2.authz.OAuthAuthzReqMessageContext)6 AccessTokenDO (org.wso2.carbon.identity.oauth2.model.AccessTokenDO)6 OAuthAppDO (org.wso2.carbon.identity.oauth.dao.OAuthAppDO)5 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)4 Date (java.util.Date)4 OAuthResponse (org.apache.oltu.oauth2.common.message.OAuthResponse)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 BeforeTest (org.testng.annotations.BeforeTest)3 OAuthEventInterceptor (org.wso2.carbon.identity.oauth.event.OAuthEventInterceptor)3 OAuth2Parameters (org.wso2.carbon.identity.oauth2.model.OAuth2Parameters)3 RequestObject (org.wso2.carbon.identity.openidconnect.model.RequestObject)3