use of org.wso2.carbon.identity.oauth.dcr.bean.ApplicationRegistrationRequest 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));
}
}
use of org.wso2.carbon.identity.oauth.dcr.bean.ApplicationRegistrationRequest in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRMServiceTest method isClientIdExistTestWithIdentityOAuthAdminException.
@Test
public void isClientIdExistTestWithIdentityOAuthAdminException() throws Exception {
registerApplicationTestWithFailedToUpdateSP();
List<String> redirectUri = new ArrayList<>();
redirectUri.add("redirectUri1");
applicationRegistrationRequest.setRedirectUris(redirectUri);
applicationRegistrationRequest.setConsumerKey(dummyConsumerKey);
OAuthAdminService mockOAuthAdminService = mock(OAuthAdminService.class);
Whitebox.setInternalState(dcrmService, "oAuthAdminService", mockOAuthAdminService);
whenNew(OAuthAdminService.class).withNoArguments().thenReturn(mockOAuthAdminService);
IdentityOAuthAdminException identityOAuthAdminException = mock(IdentityOAuthAdminException.class);
doThrow(identityOAuthAdminException).when(mockOAuthAdminService).getOAuthApplicationData(dummyConsumerKey);
try {
dcrmService.registerApplication(applicationRegistrationRequest);
} catch (IdentityException ex) {
assertEquals(ex.getErrorCode(), DCRMConstants.ErrorMessages.FAILED_TO_GET_APPLICATION_BY_ID.toString());
return;
}
fail("Expected IdentityException was not thrown by registerApplication method");
}
use of org.wso2.carbon.identity.oauth.dcr.bean.ApplicationRegistrationRequest 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");
}
use of org.wso2.carbon.identity.oauth.dcr.bean.ApplicationRegistrationRequest in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRMServiceTest method deleteOAuthApplicationWithoutAssociatedSPwithError.
@Test(dataProvider = "redirectUriProvider")
public void deleteOAuthApplicationWithoutAssociatedSPwithError(List<String> redirectUri) throws Exception {
OAuthConsumerAppDTO oAuthConsumerApp = registerApplicationTestWithFailedToUpdateSP();
applicationRegistrationRequest.setRedirectUris(redirectUri);
doThrow(new IdentityOAuthAdminException("")).when(mockOAuthAdminService).removeOAuthApplicationData(oAuthConsumerApp.getOauthConsumerKey());
try {
startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUserRealm(mockedUserRealm);
when(mockedUserRealm.getUserStoreManager()).thenReturn(mockedUserStoreManager);
when(mockedUserStoreManager.isUserInRole(anyString(), anyString())).thenReturn(true);
dcrmService.registerApplication(applicationRegistrationRequest);
} catch (IdentityException ex) {
assertEquals(ex.getMessage(), "Error while deleting the OAuth application with consumer key: " + oAuthConsumerApp.getOauthConsumerKey());
return;
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
fail("Expected IdentityException was not thrown by registerApplication method");
}
use of org.wso2.carbon.identity.oauth.dcr.bean.ApplicationRegistrationRequest 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");
}
Aggregations