diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/main/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/validator/OBCibaResponseTypeValidator.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/main/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/validator/OBCibaResponseTypeValidator.java index 8366ae19..d41a98f5 100644 --- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/main/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/validator/OBCibaResponseTypeValidator.java +++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/main/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/validator/OBCibaResponseTypeValidator.java @@ -19,6 +19,7 @@ package com.wso2.openbanking.accelerator.identity.auth.extensions.response.validator; +import com.wso2.openbanking.accelerator.common.util.Generated; import org.apache.oltu.oauth2.common.exception.OAuthProblemException; import org.wso2.carbon.identity.oauth.ciba.handlers.CibaResponseTypeValidator; @@ -27,9 +28,11 @@ /** * Validates authorize responses with cibaAuthCode as response type. */ +@Generated(message = "Ignoring since method do not contain a logic") public class OBCibaResponseTypeValidator extends CibaResponseTypeValidator { @Override + @Generated(message = "Ignoring since method do not contain a logic") public void validateContentType(HttpServletRequest request) throws OAuthProblemException { // Overriding content type validation // This is for browser flow with cibaAuthCode response type. (Web-Auth link scenario) diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/test/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/handler/OBCibaResponseTypeHandlerTest.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/test/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/handler/OBCibaResponseTypeHandlerTest.java index 3f4104ef..50815ea6 100644 --- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/test/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/handler/OBCibaResponseTypeHandlerTest.java +++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/test/java/com/wso2/openbanking/accelerator/identity/auth/extensions/response/handler/OBCibaResponseTypeHandlerTest.java @@ -33,6 +33,8 @@ import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser; import org.wso2.carbon.identity.oauth.ciba.dao.CibaDAOFactory; import org.wso2.carbon.identity.oauth.ciba.dao.CibaMgtDAO; +import org.wso2.carbon.identity.oauth.ciba.exceptions.CibaCoreException; +import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception; import org.wso2.carbon.identity.oauth2.authz.OAuthAuthzReqMessageContext; import org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeReqDTO; @@ -40,6 +42,7 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @PowerMockIgnore("jdk.internal.reflect.*") @@ -114,4 +117,80 @@ public void obCibaResponseTypeHandlerValidConsentIdTest() throws Exception { obCibaResponseTypeHandler.issue(oAuthAuthzReqMessageContext); } + + @Test(expectedExceptions = IdentityOAuth2Exception.class) + public void obCibaResponseTypeHandlerInValidCallbackTest() throws Exception { + + PowerMockito.when(OpenBankingConfigParser.getInstance().getCibaAuthenticationRedirectEndpoint()) + .thenReturn(""); + OBCibaResponseTypeHandler obCibaResponseTypeHandler = new OBCibaResponseTypeHandler(); + OAuthAuthzReqMessageContext oAuthAuthzReqMessageContext = mock(OAuthAuthzReqMessageContext.class); + AuthenticatedUser cibaAuthenticatedUser = mock(AuthenticatedUser.class); + OAuth2AuthorizeReqDTO authorizationReqDTO = mock(OAuth2AuthorizeReqDTO.class); + doReturn(authorizationReqDTO).when(oAuthAuthzReqMessageContext).getAuthorizationReqDTO(); + doReturn(cibaAuthenticatedUser).when(authorizationReqDTO).getUser(); + ArrayList consentIds = new ArrayList<>(); + consentIds.add("test1"); + doReturn(consentIds).when(consentCoreServiceMock) + .getConsentIdByConsentAttributeNameAndValue(anyString(), anyString()); + DetailedConsentResource consentResourceMock = mock(DetailedConsentResource.class); + doReturn(consentResourceMock).when(consentCoreServiceMock).getDetailedConsent(anyString()); + doReturn("authorised").when(consentResourceMock).getCurrentStatus(); + + CibaMgtDAO cibaMgtDAO = mock(CibaMgtDAO.class); + doReturn(cibaMgtDAO).when(cibaDAOFactory).getCibaAuthMgtDAO(); + doReturn("authCode").when(cibaMgtDAO).getCibaAuthCodeKey(anyString()); + obCibaResponseTypeHandler.issue(oAuthAuthzReqMessageContext); + + } + + @Test(expectedExceptions = IdentityOAuth2Exception.class) + public void obCibaResponseTypeHandlerInValidTest() throws Exception { + + PowerMockito.when(OpenBankingConfigParser.getInstance().getCibaAuthenticationRedirectEndpoint()) + .thenReturn("test"); + OBCibaResponseTypeHandler obCibaResponseTypeHandler = new OBCibaResponseTypeHandler(); + OAuthAuthzReqMessageContext oAuthAuthzReqMessageContext = mock(OAuthAuthzReqMessageContext.class); + AuthenticatedUser cibaAuthenticatedUser = mock(AuthenticatedUser.class); + OAuth2AuthorizeReqDTO authorizationReqDTO = mock(OAuth2AuthorizeReqDTO.class); + doReturn(authorizationReqDTO).when(oAuthAuthzReqMessageContext).getAuthorizationReqDTO(); + doReturn(cibaAuthenticatedUser).when(authorizationReqDTO).getUser(); + ArrayList consentIds = new ArrayList<>(); + consentIds.add("test1"); + doReturn(consentIds).when(consentCoreServiceMock) + .getConsentIdByConsentAttributeNameAndValue(anyString(), anyString()); + DetailedConsentResource consentResourceMock = mock(DetailedConsentResource.class); + doReturn(consentResourceMock).when(consentCoreServiceMock).getDetailedConsent(anyString()); + doReturn("authorised").when(consentResourceMock).getCurrentStatus(); + + CibaMgtDAO cibaMgtDAO = mock(CibaMgtDAO.class); + doReturn(cibaMgtDAO).when(cibaDAOFactory).getCibaAuthMgtDAO(); + doThrow(new CibaCoreException("")).when(cibaMgtDAO).getCibaAuthCodeKey(anyString()); + obCibaResponseTypeHandler.issue(oAuthAuthzReqMessageContext); + + } + + @Test(expectedExceptions = IdentityOAuth2Exception.class) + public void obCibaResponseTypeHandlerConsentManagementErrorTest() throws Exception { + + PowerMockito.when(OpenBankingConfigParser.getInstance().getCibaAuthenticationRedirectEndpoint()) + .thenReturn("test"); + OBCibaResponseTypeHandler obCibaResponseTypeHandler = new OBCibaResponseTypeHandler(); + OAuthAuthzReqMessageContext oAuthAuthzReqMessageContext = mock(OAuthAuthzReqMessageContext.class); + AuthenticatedUser cibaAuthenticatedUser = mock(AuthenticatedUser.class); + OAuth2AuthorizeReqDTO authorizationReqDTO = mock(OAuth2AuthorizeReqDTO.class); + doReturn(authorizationReqDTO).when(oAuthAuthzReqMessageContext).getAuthorizationReqDTO(); + doReturn(cibaAuthenticatedUser).when(authorizationReqDTO).getUser(); + ArrayList consentIds = new ArrayList<>(); + consentIds.add("test1"); + doReturn(consentIds).when(consentCoreServiceMock) + .getConsentIdByConsentAttributeNameAndValue(anyString(), anyString()); + DetailedConsentResource consentResourceMock = mock(DetailedConsentResource.class); + doThrow(new ConsentManagementException("")).when(consentCoreServiceMock).getDetailedConsent(anyString()); + doReturn("authorised").when(consentResourceMock).getCurrentStatus(); + CibaMgtDAO cibaMgtDAO = mock(CibaMgtDAO.class); + doReturn(cibaMgtDAO).when(cibaDAOFactory).getCibaAuthMgtDAO(); + obCibaResponseTypeHandler.issue(oAuthAuthzReqMessageContext); + + } }