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