Search in sources :

Example 21 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 registerOAuthApplicationWithExistingSP.

@Test
public void registerOAuthApplicationWithExistingSP() throws IdentityApplicationManagementException {
    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);
    try {
        dcrManagementService.registerOAuthApplication(registrationRequestProfile);
    } catch (IdentityException ex) {
        assertEquals(ex.getMessage(), "Service Provider with name: " + applicationName + " already registered");
        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 22 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 registerOAuthApplicationWithNewSPWithFragmentRedirectUri.

@Test(dataProvider = "invalidRedirectUriProvider")
public void registerOAuthApplicationWithNewSPWithFragmentRedirectUri(List<String> redirectUri) throws IdentityApplicationManagementException {
    registerOAuthApplication();
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    when(mockApplicationManagementService.getServiceProvider(applicationName, tenantDomain)).thenReturn(null, new ServiceProvider());
    registrationRequestProfile.setRedirectUris(redirectUri);
    try {
        dcrManagementService.registerOAuthApplication(registrationRequestProfile);
    } catch (IdentityException ex) {
        assertEquals(ex.getMessage(), "Redirect URI: " + redirectUri.get(0) + ", is invalid");
        return;
    }
    fail("Expected IdentityException was not thrown by registerOAuthApplication");
}
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 23 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 registerOAuthApplicationWithIAMException.

@Test
public void registerOAuthApplicationWithIAMException() throws IdentityApplicationManagementException {
    registerOAuthApplication();
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    doThrow(new IdentityApplicationManagementException("")).when(mockApplicationManagementService).getServiceProvider(applicationName, tenantDomain);
    try {
        dcrManagementService.registerOAuthApplication(registrationRequestProfile);
    } catch (IdentityException ex) {
        assertEquals(ex.getMessage(), "Error occurred while reading service provider, " + applicationName);
        return;
    }
    fail("Expected IdentityException was not thrown by registerOAuthApplication 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) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 24 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 registerOAuthApplicationWithNewSPWithRedirectUri.

@Test(dataProvider = "serviceProviderData")
public void registerOAuthApplicationWithNewSPWithRedirectUri(String oauthConsumerSecret, List<String> redirectUris, List<String> dummyGrantType) throws Exception {
    registerOAuthApplication();
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    registrationRequestProfile.setGrantTypes(dummyGrantType);
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    when(mockApplicationManagementService.getServiceProvider(applicationName, tenantDomain)).thenReturn(null, new ServiceProvider());
    registrationRequestProfile.setRedirectUris(redirectUris);
    OAuthAdminService mockOAuthAdminService = mock(OAuthAdminService.class);
    OAuthConsumerAppDTO oAuthConsumerApp = new OAuthConsumerAppDTO();
    oAuthConsumerApp.setApplicationName(applicationName);
    oAuthConsumerApp.setOAuthVersion(OAUTH_VERSION);
    oAuthConsumerApp.setCallbackUrl("dummyCallback");
    oAuthConsumerApp.setOauthConsumerSecret(oauthConsumerSecret);
    if (dummyGrantType.size() > 1) {
        oAuthConsumerApp.setGrantTypes(dummyGrantType.get(0) + " " + dummyGrantType.get(1));
    } else if (dummyGrantType.size() == 1) {
        oAuthConsumerApp.setGrantTypes(dummyGrantType.get(0));
    }
    whenNew(OAuthAdminService.class).withNoArguments().thenReturn(mockOAuthAdminService);
    when(mockOAuthAdminService.getOAuthApplicationDataByAppName(applicationName)).thenReturn(oAuthConsumerApp);
    when(mockOAuthAdminService.registerAndRetrieveOAuthApplicationData(Matchers.any(OAuthConsumerAppDTO.class))).thenReturn(oAuthConsumerApp);
    RegistrationResponseProfile registrationRqstProfile = dcrManagementService.registerOAuthApplication(registrationRequestProfile);
    assertEquals(registrationRqstProfile.getGrantTypes(), dummyGrantType);
    assertEquals(registrationRqstProfile.getClientName(), applicationName);
}
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) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO) RegistrationResponseProfile(org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponseProfile) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 25 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 oAuthApplicationAvailableTest.

@Test(dataProvider = "oauthApplicationDataProvider")
public void oAuthApplicationAvailableTest(Object serviceProvider, boolean expected) throws Exception {
    startTenantFlow();
    String dummyApplicationName = "dummyApplicationName";
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    when(mockApplicationManagementService.getServiceProvider(dummyApplicationName, tenantDomain)).thenReturn((ServiceProvider) serviceProvider);
    assertEquals(dcrManagementService.isOAuthApplicationAvailable(dummyApplicationName), expected);
}
Also used : DCRDataHolder(org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) 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