Search in sources :

Example 1 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 registerApplicationTestWithRedirectURls.

@Test(dataProvider = "redirectUriWithQueryParamsProvider")
public void registerApplicationTestWithRedirectURls(List<String> redirectUri, List<String> validCallbackList, List<String> invalidCallbackList) throws Exception {
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    Whitebox.setInternalState(dcrmService, "oAuthAdminService", mockOAuthAdminService);
    startTenantFlow();
    dummyGrantTypes.add("implicit");
    applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
    String grantType = StringUtils.join(applicationRegistrationRequest.getGrantTypes(), " ");
    ServiceProvider serviceProvider = new ServiceProvider();
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    when(mockApplicationManagementService.getServiceProvider(dummyClientName, dummyTenantDomain)).thenReturn(null, serviceProvider);
    applicationRegistrationRequest.setRedirectUris(redirectUri);
    OAuthConsumerAppDTO oAuthConsumerApp = new OAuthConsumerAppDTO();
    oAuthConsumerApp.setApplicationName(dummyClientName);
    oAuthConsumerApp.setGrantTypes(grantType);
    oAuthConsumerApp.setOAuthVersion(OAUTH_VERSION);
    oAuthConsumerApp.setCallbackUrl(OAuthConstants.CALLBACK_URL_REGEXP_PREFIX + dcrmService.createRegexPattern(redirectUri));
    when(mockOAuthAdminService.getOAuthApplicationDataByAppName(dummyClientName)).thenReturn(oAuthConsumerApp);
    when(mockOAuthAdminService.registerAndRetrieveOAuthApplicationData(any(OAuthConsumerAppDTO.class))).thenReturn(oAuthConsumerApp);
    Application application = dcrmService.registerApplication(applicationRegistrationRequest);
    assertEquals(application.getClientName(), dummyClientName);
    String regexp = application.getRedirectUris().get(0).substring(OAuthConstants.CALLBACK_URL_REGEXP_PREFIX.length());
    for (String validCallback : validCallbackList) {
        assertTrue(validCallback.matches(regexp));
    }
    for (String invalidCallback : invalidCallbackList) {
        assertFalse(invalidCallback.matches(regexp));
    }
}
Also used : DCRDataHolder(org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO) Matchers.anyString(org.mockito.Matchers.anyString) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) Application(org.wso2.carbon.identity.oauth.dcr.bean.Application) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 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 registerApplicationTestWithSPWithFailCallback.

@Test(dataProvider = "RedirectAndGrantTypeProvider")
public void registerApplicationTestWithSPWithFailCallback(String grantTypeVal) throws Exception {
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    Whitebox.setInternalState(dcrmService, "oAuthAdminService", mockOAuthAdminService);
    startTenantFlow();
    dummyGrantTypes.add(grantTypeVal);
    applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
    String grantType = StringUtils.join(applicationRegistrationRequest.getGrantTypes(), " ");
    ServiceProvider serviceProvider = new ServiceProvider();
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    when(mockApplicationManagementService.getServiceProvider(dummyClientName, dummyTenantDomain)).thenReturn(null, serviceProvider);
    OAuthConsumerAppDTO oAuthConsumerApp = new OAuthConsumerAppDTO();
    oAuthConsumerApp.setApplicationName(dummyClientName);
    oAuthConsumerApp.setGrantTypes(grantType);
    oAuthConsumerApp.setOAuthVersion(OAUTH_VERSION);
    when(mockOAuthAdminService.getOAuthApplicationDataByAppName(dummyClientName)).thenReturn(oAuthConsumerApp);
    try {
        dcrmService.registerApplication(applicationRegistrationRequest);
    } catch (IdentityException ex) {
        assertEquals(ex.getErrorCode(), DCRMConstants.ErrorMessages.BAD_REQUEST_INVALID_INPUT.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) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO) Matchers.anyString(org.mockito.Matchers.anyString) 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 3 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 registerApplicationTestWithExistSP.

@Test
public void registerApplicationTestWithExistSP() throws DCRMException, IdentityApplicationManagementException {
    dummyGrantTypes.add("dummy1");
    dummyGrantTypes.add("dummy2");
    applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
    startTenantFlow();
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    when(mockApplicationManagementService.getServiceProvider(dummyClientName, dummyTenantDomain)).thenReturn(new ServiceProvider());
    try {
        dcrmService.registerApplication(applicationRegistrationRequest);
    } catch (IdentityException ex) {
        assertEquals(ex.getErrorCode(), DCRMConstants.ErrorMessages.CONFLICT_EXISTING_APPLICATION.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) 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 4 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 registerApplicationTestWithDeleteCreatedSP.

@Test(dataProvider = "redirectUriProvider")
public void registerApplicationTestWithDeleteCreatedSP(List<String> redirectUri) throws Exception {
    mockStatic(IdentityProviderManager.class);
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    Whitebox.setInternalState(dcrmService, "oAuthAdminService", mockOAuthAdminService);
    startTenantFlow();
    dummyGrantTypes.add("implicit");
    applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
    String grantType = StringUtils.join(applicationRegistrationRequest.getGrantTypes(), " ");
    ServiceProvider serviceProvider = new ServiceProvider();
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    when(mockApplicationManagementService.getServiceProvider(dummyClientName, dummyTenantDomain)).thenReturn(null, serviceProvider);
    applicationRegistrationRequest.setRedirectUris(redirectUri);
    OAuthConsumerAppDTO oAuthConsumerApp = new OAuthConsumerAppDTO();
    oAuthConsumerApp.setApplicationName(dummyClientName);
    oAuthConsumerApp.setGrantTypes(grantType);
    oAuthConsumerApp.setOAuthVersion(OAUTH_VERSION);
    whenNew(OAuthConsumerAppDTO.class).withNoArguments().thenReturn(oAuthConsumerApp);
    doThrow(new IdentityOAuthAdminException("")).when(mockOAuthAdminService).registerOAuthApplicationData(oAuthConsumerApp);
    try {
        dcrmService.registerApplication(applicationRegistrationRequest);
    } catch (IdentityException ex) {
        assertEquals(ex.getErrorCode(), DCRMConstants.ErrorMessages.FAILED_TO_REGISTER_APPLICATION.toString());
        return;
    }
    fail("Expected IdentityException was not thrown by registerApplication method");
}
Also used : IdentityOAuthAdminException(org.wso2.carbon.identity.oauth.IdentityOAuthAdminException) DCRDataHolder(org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO) Matchers.anyString(org.mockito.Matchers.anyString) 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 5 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 registerApplicationTestWithFailedToUpdateSP.

private OAuthConsumerAppDTO registerApplicationTestWithFailedToUpdateSP() throws Exception {
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    Whitebox.setInternalState(dcrmService, "oAuthAdminService", mockOAuthAdminService);
    startTenantFlow();
    dummyGrantTypes.add("implicit");
    applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
    String grantType = StringUtils.join(applicationRegistrationRequest.getGrantTypes(), " ");
    ServiceProvider serviceProvider = new ServiceProvider();
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    when(mockApplicationManagementService.getServiceProvider(dummyClientName, dummyTenantDomain)).thenReturn(null, serviceProvider);
    OAuthConsumerAppDTO oAuthConsumerApp = new OAuthConsumerAppDTO();
    oAuthConsumerApp.setApplicationName(dummyClientName);
    oAuthConsumerApp.setGrantTypes(grantType);
    oAuthConsumerApp.setOAuthVersion(OAUTH_VERSION);
    oAuthConsumerApp.setOauthConsumerKey("dummyConsumerKey");
    oAuthConsumerApp.setUsername(dummyUserName.concat("@").concat(dummyTenantDomain));
    when(mockOAuthAdminService.getOAuthApplicationDataByAppName(dummyClientName)).thenReturn(oAuthConsumerApp);
    when(mockOAuthAdminService.getOAuthApplicationData("dummyConsumerKey")).thenReturn(oAuthConsumerApp);
    when(mockOAuthAdminService.getAllOAuthApplicationData()).thenReturn(new OAuthConsumerAppDTO[] { oAuthConsumerApp });
    when(mockOAuthAdminService.registerAndRetrieveOAuthApplicationData(any(OAuthConsumerAppDTO.class))).thenReturn(oAuthConsumerApp);
    doThrow(new IdentityApplicationManagementException("ehweh")).when(mockApplicationManagementService).updateApplication(serviceProvider, dummyTenantDomain, dummyUserName);
    when(mockApplicationManagementService.getServiceProviderNameByClientId(oAuthConsumerApp.getOauthConsumerKey(), DCRMConstants.OAUTH2, dummyTenantDomain)).thenReturn(IdentityApplicationConstants.DEFAULT_SP_CONFIG);
    return oAuthConsumerApp;
}
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) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO) Matchers.anyString(org.mockito.Matchers.anyString) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService)

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