Search in sources :

Example 11 with APIException

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()));
}
Also used : StorageOSUserDAO(com.emc.storageos.db.client.model.StorageOSUserDAO) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) AuthnProvider(com.emc.storageos.db.client.model.AuthnProvider)

Example 12 with APIException

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;
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) Test(org.junit.Test)

Example 13 with APIException

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;
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) Test(org.junit.Test)

Example 14 with APIException

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();
    }
}
Also used : SiteInfo(com.emc.storageos.coordinator.client.model.SiteInfo) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) Configuration(com.emc.storageos.coordinator.common.Configuration) DbClientContext(com.emc.storageos.db.client.impl.DbClientContext) Matchers.anyString(org.mockito.Matchers.anyString) PropertyInfo(com.emc.storageos.model.property.PropertyInfo) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) Test(org.junit.Test)

Example 15 with APIException

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();
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) SiteInfo(com.emc.storageos.coordinator.client.model.SiteInfo) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) SiteRestRep(com.emc.storageos.model.dr.SiteRestRep) Configuration(com.emc.storageos.coordinator.common.Configuration) InternalSiteServiceClient(com.emc.storageos.api.service.impl.resource.utils.InternalSiteServiceClient) Matchers.anyString(org.mockito.Matchers.anyString) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) Test(org.junit.Test)

Aggregations

APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)55 URI (java.net.URI)28 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)25 Produces (javax.ws.rs.Produces)22 Path (javax.ws.rs.Path)21 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)20 ArrayList (java.util.ArrayList)19 POST (javax.ws.rs.POST)19 Volume (com.emc.storageos.db.client.model.Volume)18 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)18 TaskList (com.emc.storageos.model.TaskList)17 Consumes (javax.ws.rs.Consumes)16 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)13 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)12 Operation (com.emc.storageos.db.client.model.Operation)10 DataObject (com.emc.storageos.db.client.model.DataObject)9 NamedURI (com.emc.storageos.db.client.model.NamedURI)9 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)9 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)8 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)7