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");
}
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");
}
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");
}
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);
}
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);
}
Aggregations