Search in sources :

Example 6 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 updateApplication.

private OAuthConsumerAppDTO updateApplication() throws IdentityOAuthAdminException, IdentityApplicationManagementException {
    startTenantFlow();
    dummyGrantTypes.add("dummy1");
    dummyGrantTypes.add("dummy2");
    applicationUpdateRequest = new ApplicationUpdateRequest();
    applicationUpdateRequest.setClientName(dummyClientName);
    applicationUpdateRequest.setGrantTypes(dummyGrantTypes);
    applicationUpdateRequest.setTokenType(dummyTokenType);
    applicationUpdateRequest.setBackchannelLogoutUri(dummyBackchannelLogoutUri);
    OAuthConsumerAppDTO dto = new OAuthConsumerAppDTO();
    dto.setApplicationName(dummyClientName);
    dto.setOauthConsumerSecret(dummyConsumerSecret);
    dto.setOauthConsumerKey(dummyConsumerKey);
    dto.setCallbackUrl(dummyCallbackUrl);
    dto.setUsername(dummyUserName.concat("@").concat(dummyTenantDomain));
    when(mockOAuthAdminService.getOAuthApplicationData(dummyConsumerKey)).thenReturn(dto);
    Whitebox.setInternalState(dcrmService, "oAuthAdminService", mockOAuthAdminService);
    ServiceProvider serviceProvider = new ServiceProvider();
    serviceProvider.setApplicationName(dummyClientName);
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    when(mockApplicationManagementService.getServiceProvider(dummyClientName, dummyTenantDomain)).thenReturn(serviceProvider);
    return dto;
}
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) ApplicationUpdateRequest(org.wso2.carbon.identity.oauth.dcr.bean.ApplicationUpdateRequest)

Example 7 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 registerOAuthApplicationWithNewSPNoRedirectUri.

@Test
public void registerOAuthApplicationWithNewSPNoRedirectUri() throws Exception {
    registerOAuthApplication();
    registrationRequestProfile.setRedirectUris(new ArrayList<>());
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    when(mockApplicationManagementService.getServiceProvider(applicationName, tenantDomain)).thenReturn(null, new ServiceProvider());
    try {
        dcrManagementService.registerOAuthApplication(registrationRequestProfile);
    } catch (IdentityException ex) {
        assertEquals(ex.getMessage(), "RedirectUris property must have at least one URI value.");
        return;
    }
    fail("Expected IdentityException was not thrown by registerOAuthApplication 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) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 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 registerOAuthApplicationWithInvalidSPName.

@Test
public void registerOAuthApplicationWithInvalidSPName() throws Exception {
    registerOAuthApplication();
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    ServiceProvider serviceProvider = new ServiceProvider();
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    when(mockApplicationManagementService.getServiceProvider(applicationName, tenantDomain)).thenReturn(serviceProvider);
    assertNotNull(dcrDataHolder);
    registrationRequestProfile.setClientName(invalidClientName);
    try {
        dcrManagementService.registerOAuthApplication(registrationRequestProfile);
    } catch (IdentityException ex) {
        assertEquals(ex.getMessage(), "The Application name: " + invalidClientName + " is not valid! It is not adhering to" + " the regex: " + DCRMUtils.getSPValidatorRegex());
        return;
    }
    fail("Expected IdentityException was not thrown by registerOAuthApplication 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) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 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 oAuthApplicationAvailableExceptionTest.

@Test
public void oAuthApplicationAvailableExceptionTest() throws Exception {
    startTenantFlow();
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    doThrow(new IdentityApplicationManagementException("")).when(mockApplicationManagementService).getServiceProvider(applicationName, tenantDomain);
    try {
        dcrManagementService.isOAuthApplicationAvailable(applicationName);
    } catch (DCRException ex) {
        assertEquals(ex.getMessage(), "Error occurred while retrieving information of OAuthApp " + applicationName);
        return;
    }
    fail("Expected IdentityException was not thrown by isOAuthApplicationAvailable 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) DCRException(org.wso2.carbon.identity.oauth.dcr.DCRException) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 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 registerOAuthApplicationWithNullExistingSP.

@Test
public void registerOAuthApplicationWithNullExistingSP() {
    registerOAuthApplication();
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    assertNotNull(dcrDataHolder, "null DCRDataHolder");
    try {
        dcrManagementService.registerOAuthApplication(registrationRequestProfile);
    } catch (IdentityException ex) {
        assertEquals(ex.getMessage(), "Couldn't create Service Provider Application " + applicationName);
        return;
    }
    fail("Expected IdentityException was not thrown by registerOAuthApplication 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) BeforeTest(org.testng.annotations.BeforeTest) 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