Search in sources :

Example 11 with BadRequestException

use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.

the class PasswordValidationUnitTest method testExpireRule.

@Test
public void testExpireRule() {
    ExpireRule expireRule = new ExpireRule(1);
    long current = System.currentTimeMillis();
    long twoDaysAgo = current - 2 * 24 * 60 * 60 * 1000;
    Password password = new Password("svcuser", "oldpassword", "password");
    PasswordHistory passwordHistory = new PasswordHistory();
    LongMap map = new LongMap();
    map.put("hashedPassword", twoDaysAgo);
    passwordHistory.setUserPasswordHash(map);
    password.setPasswordHistory(passwordHistory);
    logger.info("current=" + current + ", 2daysAgo = " + twoDaysAgo);
    try {
        expireRule.validate(password);
        Assert.fail("password already expired, should fail");
    } catch (BadRequestException e) {
        logger.info(e.getServiceCode().toString());
        logger.info(e.getMessage());
    }
}
Also used : LongMap(com.emc.storageos.db.client.model.LongMap) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) ExpireRule(com.emc.storageos.security.password.rules.ExpireRule) PasswordHistory(com.emc.storageos.db.client.model.PasswordHistory) Password(com.emc.storageos.security.password.Password) Test(org.junit.Test)

Example 12 with BadRequestException

use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.

the class PasswordValidationUnitTest method changedNumberRule.

@Test
public void changedNumberRule() {
    ChangedNumberRule rule = new ChangedNumberRule(4);
    Password password = new Password("1122334455", "1122334455");
    try {
        rule.validate(password);
        Assert.fail("old password same as new password, should fail");
    } catch (BadRequestException e) {
        logger.info(e.getServiceCode().toString());
        logger.info(e.getMessage());
        Assert.assertTrue(e.getMessage().contains("characters be changed between the old and new passwords"));
    }
    try {
        password = new Password("aab2334455", "1122334455");
        rule.validate(password);
        Assert.fail("old password 3 characters differ than new password, should fail");
    } catch (BadRequestException e) {
        logger.info(e.getServiceCode().toString());
        logger.info(e.getMessage());
        Assert.assertTrue(e.getMessage().contains("characters be changed between the old and new passwords"));
    }
    // test change number of characters between passwords applies Levenshtein Distance
    try {
        password = new Password("ChangeMe", "hangeMe");
        rule.validate(password);
        Assert.fail("only remove 1 character from front, should fail");
    } catch (BadRequestException e) {
        logger.info(e.getServiceCode().toString());
        logger.info(e.getMessage());
        Assert.assertTrue(e.getMessage().contains("characters be changed between the old and new passwords"));
    }
    try {
        password = new Password("ChangeMe", "ChIangeMe");
        rule.validate(password);
        Assert.fail("only insert 1 character in the middle, should fail");
    } catch (BadRequestException e) {
        logger.info(e.getServiceCode().toString());
        logger.info(e.getMessage());
        Assert.assertTrue(e.getMessage().contains("characters be changed between the old and new passwords"));
    }
    password = new Password("aabb334455", "1122334455");
    rule.validate(password);
}
Also used : ChangedNumberRule(com.emc.storageos.security.password.rules.ChangedNumberRule) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) Password(com.emc.storageos.security.password.Password) Test(org.junit.Test)

Example 13 with BadRequestException

use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.

the class SendEvent method buildAlertFile.

/**
 * Builds alert file with all required information - type of event,
 * attachments and sends to ConnectEMC
 */
protected void buildAlertFile(EmaApiConnectHome alertFile, EmaApiLogType log) throws Exception {
    _log.info("Start SendEvent::buildEventType");
    alertFile.eventAdd(getEventType(), log);
    // Create event file to attach
    String eventFilename = CONNECT_EMC_HOME + EmaApiUtils.emaGenerateFilename(_fileId);
    _log.info("Event filename: {}", eventFilename);
    ArrayList<String> fileList = genAttachFiles();
    BadRequestException badRequestException = null;
    if (fileList != null && !fileList.isEmpty()) {
        boolean attachLogs = true;
        try {
            validateAttachmentSize(fileList);
        } catch (BadRequestException e) {
            if (forceAttachLogs) {
                throw e;
            }
            badRequestException = e;
            attachLogs = false;
        }
        ArrayList<EmaApiFilenameType> attachFiles = new ArrayList<EmaApiFilenameType>();
        if (attachLogs) {
            for (String file : fileList) {
                EmaApiFilenameType filename = new EmaApiFilenameType();
                filename.setQualifiedFileName(file);
                filename.setTargetFileName(getTargetFileName(file));
                attachFiles.add(filename);
            }
        } else {
            // log size too big, not to attach logs
            for (String file : fileList) {
                if (file.equals(SYSTEM_LOGS_FILE_PATH) || file.equals(SYSTEM_EVENT_FILE_PATH)) {
                    continue;
                }
                EmaApiFilenameType filename = new EmaApiFilenameType();
                filename.setQualifiedFileName(file);
                filename.setTargetFileName(getTargetFileName(file));
                attachFiles.add(filename);
            }
            AlertsLogger.getAlertsLogger().warn("ConnectEMC alert will be sent without logs attached due to logs have exceeded max allowed size (" + this.getAttachmentsMaxSizeMB() + " MB)");
        }
        alertFile.addFileRawData(eventFilename, attachFiles, log);
    }
    alertFile.write(eventFilename, log);
    alertFile.emaCreateDotEndFile(eventFilename, log);
    _log.info("Finish SendEvent::buildEventType");
    if (badRequestException != null) {
        throw badRequestException;
    }
}
Also used : ArrayList(java.util.ArrayList) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException)

Example 14 with BadRequestException

use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.

the class RemoteRepositoryTest method testBadVersion.

@Test
public void testBadVersion() throws Exception {
    repositoryUrl = DIRECTORY_REPO;
    repositoryProxy = null;
    username = USERNAME;
    password = PASSWORD;
    _repo = RemoteRepository.getInstance();
    try {
        _repo.checkVersionDownloadable(new SoftwareVersion("1.0.0.0.688"));
    } catch (BadRequestException e) {
        Assert.assertTrue(e.getMessage().contains("not accessible at URL"));
    }
}
Also used : SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) Test(org.junit.Test)

Example 15 with BadRequestException

use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.

the class RemoteRepositoryTest method testDirectoryRepository.

@Test
public void testDirectoryRepository() throws Exception {
    repositoryUrl = DIRECTORY_REPO;
    _repo = RemoteRepository.getInstance();
    Assert.assertTrue(_repo != null);
    final List<SoftwareVersion> remoteVersions = _repo.getVersions();
    Assert.assertTrue(remoteVersions != null);
    Assert.assertTrue(!remoteVersions.isEmpty());
    for (SoftwareVersion v : remoteVersions) {
        System.out.println(v);
    }
    int downloadableVersions = 0;
    for (SoftwareVersion v : remoteVersions) {
        try {
            _repo.checkVersionDownloadable(v);
        } catch (RemoteRepositoryException e) {
            continue;
        } catch (BadRequestException e) {
            continue;
        }
        final InputStream in = _repo.getImageInputStream(v);
        Assert.assertTrue(in != null);
        byte[] buffer = new byte[0x10000];
        Assert.assertTrue("getImageInputStream failed for " + v, in.read(buffer) > 0);
        in.close();
        downloadableVersions++;
    }
    // Make sure there are at least some downloadable versiosn
    Assert.assertTrue(downloadableVersions > 0);
    System.out.println("Found " + downloadableVersions + " downloadable versions out of " + remoteVersions.size());
    final SoftwareVersion version = (SoftwareVersion) remoteVersions.toArray()[0];
    File file = startBackgroundDownload(version);
    Assert.assertNotNull(file);
    while (_downloader.isDownloading()) {
        System.out.println("Downloading " + file);
        Thread.sleep(2000);
    }
    Assert.assertTrue(file.exists());
}
Also used : SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) InputStream(java.io.InputStream) RemoteRepositoryException(com.emc.storageos.systemservices.exceptions.RemoteRepositoryException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) File(java.io.File) Test(org.junit.Test)

Aggregations

BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)30 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)15 Operation (com.emc.storageos.db.client.model.Operation)14 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)13 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)13 URISyntaxException (java.net.URISyntaxException)13 FileShare (com.emc.storageos.db.client.model.FileShare)12 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)12 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)11 ControllerException (com.emc.storageos.volumecontroller.ControllerException)11 Path (javax.ws.rs.Path)11 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)10 Test (org.junit.Test)10 URI (java.net.URI)8 ArrayList (java.util.ArrayList)8 Produces (javax.ws.rs.Produces)8 NamedURI (com.emc.storageos.db.client.model.NamedURI)7 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)7 Consumes (javax.ws.rs.Consumes)7