use of com.emc.storageos.svcs.errorhandling.resources.APIException in project coprhd-controller by CoprHD.
the class CustomAuthenticationManagerTest method testUserRefresh.
@Test
public void testUserRefresh() throws Exception {
AuthnProvider authConfig = createValidAuthProviderInDB();
// First try to refresh a user that does not exist in the DB- Should fail with a
// BadRequestException, where the message says that the parameter is not valid
String userName = "iShouldntExistAnywhereInTheWholeWideWorld@sanity.local".toLowerCase();
boolean exceptionWasCaught = false;
try {
_authManager.refreshUser(userName);
} catch (SecurityException e) {
// should not get here.
Assert.fail("Got a securityExcpetion instead of BadRequestException, message is " + e.getLocalizedMessage());
} catch (APIException e) {
// this is what is expected
String errorMessage = "Invalid value " + userName + " for parameter username";
assertServiceError(HttpStatus.SC_BAD_REQUEST, ServiceCode.API_PARAMETER_INVALID, errorMessage, e);
exceptionWasCaught = true;
} finally {
Assert.assertTrue("Refresh user call for a user that does not exist in DB did not throw an exception", exceptionWasCaught);
}
// try to refresh a user that doesn't exist in ldap, but exists in the DB- should
// fail with a BadRequestException- Search for {0} failed for this tenant, or
// could not be found for this tenant. make sure the user gets deleted
StorageOSUserDAO userDAO = new StorageOSUserDAO();
userDAO.setId(URIUtil.createId(StorageOSUserDAO.class));
userDAO.setUserName(userName);
_dbClient.createObject(userDAO);
exceptionWasCaught = false;
try {
_authManager.refreshUser(userName);
} catch (SecurityException e) {
Assert.fail("Got a securityExcpetion instead of BadRequestException, message is " + e.getLocalizedMessage());
} catch (APIException e) {
String errorMessage = "Search for " + userName + " failed for this tenant, or could not be found for this tenant.";
assertServiceError(HttpStatus.SC_BAD_REQUEST, ServiceCode.API_BAD_REQUEST, errorMessage, e);
exceptionWasCaught = true;
} finally {
Assert.assertTrue("Refresh user call for a user that does not exist in LDAP did not throw an exception", exceptionWasCaught);
}
StorageOSUserDAO userDAOAfterRefresh = _dbClient.queryObject(StorageOSUserDAO.class, userDAO.getId());
if (userDAOAfterRefresh != null) {
Assert.assertTrue(userDAOAfterRefresh.getInactive());
}
// disable the authProvider and refresh a user- should fail with a
// BadRequestException - Search for {0} failed for this tenant, or
// could not be found for this tenant. make sure the user gets deleted
cleanupProviders();
userName = "sanity_user@sanity.local".toLowerCase();
userDAO = new StorageOSUserDAO();
userDAO.setId(URIUtil.createId(StorageOSUserDAO.class));
userDAO.setUserName(userName);
_dbClient.createObject(userDAO);
exceptionWasCaught = false;
try {
_authManager.refreshUser(userName);
} catch (SecurityException e) {
Assert.fail("Got a securityExcpetion instead of BadRequestException, message is " + e.getLocalizedMessage());
} catch (APIException e) {
String errorMessage = "Search for " + userName + " failed for this tenant, or could not be found for this tenant.";
assertServiceError(HttpStatus.SC_BAD_REQUEST, ServiceCode.API_BAD_REQUEST, errorMessage, e);
exceptionWasCaught = true;
} finally {
Assert.assertTrue("Refresh user call for a user who is not supported by any authentication handler did not throw an exception", exceptionWasCaught);
}
userDAOAfterRefresh = _dbClient.queryObject(StorageOSUserDAO.class, userDAO.getId());
if (userDAOAfterRefresh != null) {
Assert.assertTrue(userDAOAfterRefresh.getInactive());
}
// enable the authProvider and test user refresh - should not throw
authConfig = createValidAuthProviderInDB();
userDAO = new StorageOSUserDAO();
userDAO.setId(URIUtil.createId(StorageOSUserDAO.class));
userDAO.setUserName(userName);
_dbClient.createObject(userDAO);
try {
// refresh the user
_authManager.refreshUser(userName);
} catch (SecurityException e) {
Assert.fail("Got a FatalSecurityException, message is " + e.getLocalizedMessage());
} catch (APIException e) {
Assert.fail("Got a BadRequestException, message is " + e.getLocalizedMessage());
}
userDAOAfterRefresh = _dbClient.queryObject(StorageOSUserDAO.class, userDAO.getId());
Assert.assertNotNull(userDAOAfterRefresh.getTenantId());
Assert.assertTrue("sanity_user@sanity.local is supposed to be mapped to root tenant", _rootTenantId.toString().equals(userDAOAfterRefresh.getTenantId()));
}
use of com.emc.storageos.svcs.errorhandling.resources.APIException in project coprhd-controller by CoprHD.
the class ArgValidatorTest method testCheckEntityInactiveEntityBadRequest.
@Test(expected = BadRequestException.class)
public void testCheckEntityInactiveEntityBadRequest() {
try {
DataObject object = new DataObject() {
};
object.setId(URI.create("urn:storageos:StorageSystem:2b91947d-749f-4356-aad7-dcd7f7906197:vdc1"));
object.setInactive(true);
ArgValidator.checkEntity(object, object.getId(), false);
} catch (APIException bre) {
assertEquals(ServiceCode.API_PARAMETER_INACTIVE, bre.getServiceCode());
assertEquals("Entity with the given id urn:storageos:StorageSystem:2b91947d-749f-4356-aad7-dcd7f7906197:vdc1 is inactive and marked for deletion", bre.getLocalizedMessage());
throw bre;
}
}
use of com.emc.storageos.svcs.errorhandling.resources.APIException in project coprhd-controller by CoprHD.
the class ArgValidatorTest method testCheckEntityInactiveEntityNotfound.
@Test(expected = NotFoundException.class)
public void testCheckEntityInactiveEntityNotfound() {
try {
DataObject object = new DataObject() {
};
object.setId(URI.create("urn:storageos:StorageSystem:2b91947d-749f-4356-aad7-dcd7f7906197:vdc1"));
object.setInactive(true);
ArgValidator.checkEntity(object, object.getId(), true);
} catch (APIException bre) {
assertEquals(ServiceCode.API_URL_ENTITY_INACTIVE, bre.getServiceCode());
assertEquals("Entity specified in URL with the given id urn:storageos:StorageSystem:2b91947d-749f-4356-aad7-dcd7f7906197:vdc1 is inactive and marked for deletion", bre.getLocalizedMessage());
throw bre;
}
}
use of com.emc.storageos.svcs.errorhandling.resources.APIException in project coprhd-controller by CoprHD.
the class DisasterRecoveryServiceTest method testPauseStandby.
@Test
public void testPauseStandby() {
try {
drService.pauseStandby(primarySite.getUuid());
} catch (APIException e) {
assertEquals(e.getServiceCode(), ServiceCode.API_BAD_REQUEST);
}
try {
drService.pauseStandby(NONEXISTENT_ID);
} catch (APIException e) {
assertEquals(e.getServiceCode(), ServiceCode.API_PARAMETER_INVALID);
}
doNothing().when(coordinator).persistServiceConfiguration(any(Configuration.class));
doReturn(null).when(coordinator).getTargetInfo(any(String.class), eq(SiteInfo.class));
doNothing().when(coordinator).setTargetInfo(any(String.class), any(SiteInfo.class));
doReturn(new PropertyInfo()).when(coordinator).getPropertyInfo();
try {
DbClientContext mockDBClientContext = mock(DbClientContext.class);
doNothing().when(mockDBClientContext).removeDcFromStrategyOptions(any(String.class));
doReturn(mockDBClientContext).when(dbClientMock).getLocalContext();
doReturn(mockDBClientContext).when(dbClientMock).getGeoContext();
drService.pauseStandby(standbySite2.getUuid());
} catch (Exception e) {
fail();
}
}
use of com.emc.storageos.svcs.errorhandling.resources.APIException in project coprhd-controller by CoprHD.
the class DisasterRecoveryServiceTest method testResumeStandby.
@Test
public void testResumeStandby() {
try {
drService.resumeStandby(primarySite.getUuid());
} catch (APIException e) {
assertEquals(e.getServiceCode(), ServiceCode.API_BAD_REQUEST);
}
try {
drService.resumeStandby(NONEXISTENT_ID);
} catch (APIException e) {
assertEquals(e.getServiceCode(), ServiceCode.API_PARAMETER_INVALID);
}
doNothing().when(coordinator).persistServiceConfiguration(any(Configuration.class));
doReturn(null).when(coordinator).getTargetInfo(any(String.class), eq(SiteInfo.class));
doNothing().when(coordinator).setTargetInfo(any(String.class), any(SiteInfo.class));
InternalSiteServiceClient internalSiteClient = mock(InternalSiteServiceClient.class);
doReturn(internalSiteClient).when(drService).createInternalSiteServiceClient(any(Site.class));
try {
SiteRestRep response = drService.resumeStandby(standbySite1.getUuid());
assertEquals(SiteState.STANDBY_PAUSED.toString(), response.getState());
} catch (Exception e) {
fail();
}
}
Aggregations