Search in sources :

Example 11 with DCRDataHolder

use of org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder in project identity-inbound-auth-oauth by wso2-extensions.

the class DCRManagementServiceTest method registerApplicationWithMetaDataValidationError.

@Test
public void registerApplicationWithMetaDataValidationError() throws Exception {
    List<String> redirectUri = new ArrayList<>();
    redirectUri.add("redirectUri1");
    registerOAuthApplication();
    registrationRequestProfile.setRedirectUris(redirectUri);
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    when(mockApplicationManagementService.getServiceProvider(applicationName, tenantDomain)).thenReturn(null, new ServiceProvider());
    OAuthAdminService mockOAuthAdminService = mock(OAuthAdminService.class);
    whenNew(OAuthAdminService.class).withNoArguments().thenReturn(mockOAuthAdminService);
    when(mockOAuthAdminService.registerAndRetrieveOAuthApplicationData(Matchers.any(OAuthConsumerAppDTO.class))).thenThrow(IdentityOAuthAdminException.class);
    try {
        dcrManagementService.registerOAuthApplication(registrationRequestProfile);
    } catch (IdentityException ex) {
        assertEquals(ex.getErrorCode(), ErrorCodes.META_DATA_VALIDATION_FAILED.toString());
        return;
    }
    fail("Expected IdentityException was not thrown by registerOAuthApplication method");
}
Also used : DCRDataHolder(org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder) OAuthAdminService(org.wso2.carbon.identity.oauth.OAuthAdminService) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ArrayList(java.util.ArrayList) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) IdentityException(org.wso2.carbon.identity.base.IdentityException) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with DCRDataHolder

use of org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder in project identity-inbound-auth-oauth by wso2-extensions.

the class DCRManagementServiceTest method unRegister.

private void unRegister() throws Exception {
    startTenantFlow();
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    ServiceProvider serviceProvider = new ServiceProvider();
    dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    OAuthAdminService mockOAuthAdminService = mock(OAuthAdminService.class);
    applicationName = "dummyApplicationName";
    whenNew(OAuthAdminService.class).withNoArguments().thenReturn(mockOAuthAdminService);
    when(mockApplicationManagementService.getServiceProvider(applicationName, tenantDomain)).thenReturn(serviceProvider);
    mockStatic(MultitenantUtils.class);
    when(MultitenantUtils.getTenantDomain(userID)).thenReturn(tenantDomain);
    when(MultitenantUtils.getTenantAwareUsername(userID)).thenReturn(userName);
    OAuthConsumerAppDTO dto = new OAuthConsumerAppDTO();
    dto.setApplicationName(applicationName);
    when(mockOAuthAdminService.getOAuthApplicationData(consumerkey)).thenReturn(dto);
}
Also used : OAuthAdminService(org.wso2.carbon.identity.oauth.OAuthAdminService) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService)

Example 13 with DCRDataHolder

use of org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder in project identity-inbound-auth-oauth by wso2-extensions.

the class DCRMServiceTest method registerApplicationTestWithFailedToGetSP.

@Test
public void registerApplicationTestWithFailedToGetSP() throws DCRMException, IdentityApplicationManagementException {
    dummyGrantTypes.add("dummy1");
    dummyGrantTypes.add("dummy2");
    applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
    startTenantFlow();
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    doThrow(new IdentityApplicationManagementException("")).when(mockApplicationManagementService).getServiceProvider(dummyClientName, dummyTenantDomain);
    try {
        dcrmService.registerApplication(applicationRegistrationRequest);
    } catch (IdentityException ex) {
        assertEquals(ex.getErrorCode(), DCRMConstants.ErrorMessages.FAILED_TO_GET_SP.toString());
        return;
    }
    fail("Expected IdentityException was not thrown by registerApplication method");
}
Also used : DCRDataHolder(org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) IdentityException(org.wso2.carbon.identity.base.IdentityException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 14 with DCRDataHolder

use of org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder in project identity-inbound-auth-oauth by wso2-extensions.

the class DCRMServiceTest method registerApplicationTestWithFailedToRegisterSP.

@Test
public void registerApplicationTestWithFailedToRegisterSP() throws Exception {
    dummyGrantTypes.add("dummy1");
    dummyGrantTypes.add("dummy2");
    applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
    startTenantFlow();
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    try {
        dcrmService.registerApplication(applicationRegistrationRequest);
    } catch (IdentityException ex) {
        assertEquals(ex.getErrorCode(), DCRMConstants.ErrorMessages.FAILED_TO_REGISTER_SP.toString());
        return;
    }
    fail("Expected IdentityException was not thrown by registerApplication method");
}
Also used : DCRDataHolder(org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) IdentityException(org.wso2.carbon.identity.base.IdentityException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 15 with DCRDataHolder

use of org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder in project identity-inbound-auth-oauth by wso2-extensions.

the class DCRMServiceTest method registerApplicationTestWithErrorCreataingSPTenantTest.

@Test(dataProvider = "redirectUriProvider")
public void registerApplicationTestWithErrorCreataingSPTenantTest(List<String> redirectUri) throws Exception {
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    Whitebox.setInternalState(dcrmService, "oAuthAdminService", mockOAuthAdminService);
    startTenantFlow();
    dummyGrantTypes.add("implicit");
    applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
    ServiceProvider serviceProvider = new ServiceProvider();
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    when(mockApplicationManagementService.getServiceProvider(dummyClientName, dummyTenantDomain)).thenReturn(null, serviceProvider);
    applicationRegistrationRequest.setRedirectUris(redirectUri);
    applicationRegistrationRequest.setSpTemplateName(dummyTemplateName);
    whenNew(ServiceProvider.class).withNoArguments().thenReturn(serviceProvider);
    when(mockApplicationManagementService.isExistingApplicationTemplate(dummyTemplateName, dummyTenantDomain)).thenReturn(true);
    doThrow(new IdentityApplicationManagementException("")).when(mockApplicationManagementService).createApplicationWithTemplate(serviceProvider, dummyTenantDomain, dummyUserName, dummyTemplateName);
    try {
        dcrmService.registerApplication(applicationRegistrationRequest);
    } catch (IdentityException ex) {
        assertEquals(ex.getErrorCode(), ErrorCodes.BAD_REQUEST.toString());
        return;
    }
    fail("Expected IdentityException was not thrown by registerApplication method");
}
Also used : DCRDataHolder(org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) IdentityException(org.wso2.carbon.identity.base.IdentityException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

DCRDataHolder (org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder)24 ApplicationManagementService (org.wso2.carbon.identity.application.mgt.ApplicationManagementService)23 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 Test (org.testng.annotations.Test)21 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)19 IdentityException (org.wso2.carbon.identity.base.IdentityException)16 OAuthConsumerAppDTO (org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO)11 BeforeTest (org.testng.annotations.BeforeTest)10 Matchers.anyString (org.mockito.Matchers.anyString)7 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)6 OAuthAdminService (org.wso2.carbon.identity.oauth.OAuthAdminService)4 ArrayList (java.util.ArrayList)2 IdentityOAuthAdminException (org.wso2.carbon.identity.oauth.IdentityOAuthAdminException)2 OAuthServerConfiguration (org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration)2 Application (org.wso2.carbon.identity.oauth.dcr.bean.Application)2 BeforeMethod (org.testng.annotations.BeforeMethod)1 DCRException (org.wso2.carbon.identity.oauth.dcr.DCRException)1 ApplicationRegistrationRequest (org.wso2.carbon.identity.oauth.dcr.bean.ApplicationRegistrationRequest)1 ApplicationUpdateRequest (org.wso2.carbon.identity.oauth.dcr.bean.ApplicationUpdateRequest)1 RegistrationResponseProfile (org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponseProfile)1