ParametersValidator { private static Map<String, String> validate(@NotNull Map<String, String> runnerParams, boolean runtime) { final Map<String, String> invalids = new HashMap<String, String>(); invalids.putAll(AWSCommonParams.validate(runnerParams, !runtime)); boolean uploadStepEnabled = false; boolean registerStepEnabled = false; boolean deployStepEnabled = false; final String deploymentSteps = getDeploymentSteps(runnerParams); if (StringUtil.isEmptyOrSpaces(deploymentSteps)) { invalids.put(DEPLOYMENT_STEPS_PARAM, DEPLOYMENT_STEPS_LABEL + " must not be empty"); } else { uploadStepEnabled = isUploadStepEnabled(runnerParams); registerStepEnabled = isRegisterStepEnabled(runnerParams); deployStepEnabled = isDeployStepEnabled(runnerParams); if (!uploadStepEnabled && !registerStepEnabled && !deployStepEnabled) { invalids.put(DEPLOYMENT_STEPS_PARAM, DEPLOYMENT_STEPS_LABEL + " has unexpected value " + deploymentSteps); } } if (uploadStepEnabled) { final String revisionPaths = getRevisionPaths(runnerParams); if (StringUtil.isEmptyOrSpaces(revisionPaths)) { invalids.put(REVISION_PATHS_PARAM, REVISION_PATHS_LABEL + " must not be empty"); } else if (!isReference(revisionPaths, runtime)) { final String readyRevision = getReadyRevision(revisionPaths); if (readyRevision == null) { if (getRevisionPathMappings(revisionPaths).isEmpty()) { invalids.put(REVISION_PATHS_PARAM, REVISION_PATHS_LABEL + " has unexpected value, " + REVISION_PATHS_NOTE); } } } } if (uploadStepEnabled || registerStepEnabled || deployStepEnabled) { final String s3BucketName = getS3BucketName(runnerParams); if (StringUtil.isEmptyOrSpaces(s3BucketName)) { invalids.put(S3_BUCKET_NAME_PARAM, S3_BUCKET_NAME_LABEL + " must not be empty"); } else if (s3BucketName.contains("/")) { invalids.put(S3_BUCKET_NAME_PARAM, S3_BUCKET_NAME_LABEL + " must not contain / characters. For addressing folders use " + S3_OBJECT_KEY_LABEL + " parameter"); } final String s3ObjectKey = getS3ObjectKey(runnerParams); if (StringUtil.isEmptyOrSpaces(s3ObjectKey)) { if (!uploadStepEnabled) { invalids.put(S3_OBJECT_KEY_PARAM, S3_OBJECT_KEY_LABEL + " must not be empty"); } } else { validateS3Key(invalids, s3ObjectKey, S3_OBJECT_KEY_PARAM, S3_OBJECT_KEY_LABEL, runtime); if (registerStepEnabled || deployStepEnabled) { validateBundleType(invalids, s3ObjectKey, S3_OBJECT_KEY_PARAM, S3_OBJECT_KEY_LABEL, runtime); } } } if (registerStepEnabled || deployStepEnabled) { if (StringUtil.isEmptyOrSpaces(getAppName(runnerParams))) { invalids.put(APP_NAME_PARAM, APP_NAME_LABEL + " must not be empty"); } } if (deployStepEnabled) { if (StringUtil.isEmptyOrSpaces(getDeploymentGroupName(runnerParams))) { invalids.put(DEPLOYMENT_GROUP_NAME_PARAM, DEPLOYMENT_GROUP_NAME_LABEL + " must not be empty"); } final String fileExistsParam = getFileExistsBehavior(runnerParams); if (StringUtil.isNotEmpty(fileExistsParam)) { validateFileExistsBehavior(invalids, fileExistsParam, FILE_EXISTS_BEHAVIOR_PARAM, FILE_EXISTS_BEHAVIOR_PARAM, runtime); } if (isDeploymentWaitEnabled(runnerParams)) { final String waitTimeoutSec = getWaitTimeOutSec(runnerParams); if (StringUtil.isEmptyOrSpaces(waitTimeoutSec)) { invalids.put(WAIT_TIMEOUT_SEC_PARAM, WAIT_TIMEOUT_SEC_LABEL + " must not be empty"); } else { validatePositiveInteger(invalids, waitTimeoutSec, WAIT_TIMEOUT_SEC_PARAM, WAIT_TIMEOUT_SEC_LABEL, runtime); } } } return invalids; }    }
@Test public void s3_bucket_slashes() { then(validate(DEPLOYMENT_STEPS_PARAM, UPLOAD_STEP, S3_BUCKET_NAME_PARAM, "abra/kadabra")).as("Must detect slashes in s3 bucket name"). containsEntry(S3_BUCKET_NAME_PARAM, "S3 bucket must not contain / characters. For addressing folders use S3 object key parameter"); }
@Test public void s3_object_key_unsafe_chars() { then(validate(DEPLOYMENT_STEPS_PARAM, UPLOAD_STEP, S3_OBJECT_KEY_PARAM, "abra~kadabra")).as("Must detect unsafe characters in s3 object key"). containsEntry(S3_OBJECT_KEY_PARAM, "S3 object key must contain only safe characters"); }
@Test public void s3_object_key_unexpected_bundle_type() { then(validate(DEPLOYMENT_STEPS_PARAM, DEPLOY_STEP, S3_OBJECT_KEY_PARAM, "abrakadabra.jar")).as("Must detect unexpected bundle type in s3 object key"). containsEntry(S3_OBJECT_KEY_PARAM, "S3 object key provides invalid bundle type, supported bundle types are .zip, .tar and .tar.gz"); }
@Test public void unexpected_wait_timeout() { then(validate(DEPLOYMENT_STEPS_PARAM, DEPLOY_STEP, WAIT_FLAG_PARAM, "true", WAIT_TIMEOUT_SEC_PARAM, "10min")).as("Must detect unexpected wait timeout"). containsEntry(WAIT_TIMEOUT_SEC_PARAM, "Timeout (seconds) must be a positive integer value"); }
@Test public void mandatory_params() { then(validate()).as("Must detect empty params").hasSize(5). containsEntry(DEPLOYMENT_STEPS_PARAM, "Deployment steps must not be empty"). containsEntry(REGION_NAME_PARAM, "AWS region must not be empty"). containsEntry(CREDENTIALS_TYPE_PARAM, "Credentials type must not be empty"). containsEntry(ACCESS_KEY_ID_PARAM, "Access key ID must not be empty"). containsEntry(SECURE_SECRET_ACCESS_KEY_PARAM, "Secret access key must not be empty"); }
@Test public void unexpected_deployment_steps() { then(validate(DEPLOYMENT_STEPS_PARAM, "abrakadabra")).as("Must detect unexpected deployment steps"). containsEntry(DEPLOYMENT_STEPS_PARAM, "Deployment steps has unexpected value abrakadabra"); }
@Test public void upload_mandatory_params() { then(validate(DEPLOYMENT_STEPS_PARAM, UPLOAD_STEP)).as("Must detect empty params").hasSize(6). containsEntry(REGION_NAME_PARAM, "AWS region must not be empty"). containsEntry(CREDENTIALS_TYPE_PARAM, "Credentials type must not be empty"). containsEntry(ACCESS_KEY_ID_PARAM, "Access key ID must not be empty"). containsEntry(SECURE_SECRET_ACCESS_KEY_PARAM, "Secret access key must not be empty"). containsEntry(REVISION_PATHS_PARAM, "Application revision must not be empty"). containsEntry(S3_BUCKET_NAME_PARAM, "S3 bucket must not be empty"); }
@Test public void register_mandatory_params() { then(validate(DEPLOYMENT_STEPS_PARAM, REGISTER_STEP)).as("Must detect empty params").hasSize(7). containsEntry(REGION_NAME_PARAM, "AWS region must not be empty"). containsEntry(CREDENTIALS_TYPE_PARAM, "Credentials type must not be empty"). containsEntry(ACCESS_KEY_ID_PARAM, "Access key ID must not be empty"). containsEntry(SECURE_SECRET_ACCESS_KEY_PARAM, "Secret access key must not be empty"). containsEntry(S3_BUCKET_NAME_PARAM, "S3 bucket must not be empty"). containsEntry(S3_OBJECT_KEY_PARAM, "S3 object key must not be empty"). containsEntry(APP_NAME_PARAM, "Application name must not be empty"); }
@Test public void deploy_mandatory_params() { then(validate(DEPLOYMENT_STEPS_PARAM, DEPLOY_STEP)).as("Must detect empty params").hasSize(8). containsEntry(REGION_NAME_PARAM, "AWS region must not be empty"). containsEntry(CREDENTIALS_TYPE_PARAM, "Credentials type must not be empty"). containsEntry(ACCESS_KEY_ID_PARAM, "Access key ID must not be empty"). containsEntry(SECURE_SECRET_ACCESS_KEY_PARAM, "Secret access key must not be empty"). containsEntry(S3_BUCKET_NAME_PARAM, "S3 bucket must not be empty"). containsEntry(S3_OBJECT_KEY_PARAM, "S3 object key must not be empty"). containsEntry(APP_NAME_PARAM, "Application name must not be empty"). containsEntry(DEPLOYMENT_GROUP_NAME_PARAM, "Deployment group must not be empty"); }
@Test public void deploy_params_with_references() { then(validate( DEPLOYMENT_STEPS_PARAM, DEPLOY_STEP, REGION_NAME_PARAM, "us-east-1", CREDENTIALS_TYPE_PARAM, ACCESS_KEYS_OPTION, ACCESS_KEY_ID_PARAM, "%access.key.id%", SECURE_SECRET_ACCESS_KEY_PARAM, "%secret.access.key.id%", S3_BUCKET_NAME_PARAM, "%s3.bucket.name%", S3_OBJECT_KEY_PARAM, "%s3.object.key%", APP_NAME_PARAM, "%app.name%", DEPLOYMENT_GROUP_NAME_PARAM, "%deployment.group%" )).as("Must respect param refs").isEmpty(); }
@Test public void deploy_params_with_tricky_references() { then(validate( DEPLOYMENT_STEPS_PARAM, DEPLOY_STEP, REGION_NAME_PARAM, "us-east-1", CREDENTIALS_TYPE_PARAM, ACCESS_KEYS_OPTION, ACCESS_KEY_ID_PARAM, "%access.key.id%.suff", SECURE_SECRET_ACCESS_KEY_PARAM, "pref.%secret.access.key.id%.suff", S3_BUCKET_NAME_PARAM, "pref.%s3.bucket.name%", S3_OBJECT_KEY_PARAM, "%s3 object key%.zip", APP_NAME_PARAM, "%app name%", DEPLOYMENT_GROUP_NAME_PARAM, "%deployment group%" )).as("Must respect param refs").isEmpty(); }
@Test public void unexpected_revision_paths() { then(validate(DEPLOYMENT_STEPS_PARAM, UPLOAD_STEP, REVISION_PATHS_PARAM, "=>")).as("Must detect unexpected revision paths"). containsEntry(REVISION_PATHS_PARAM, "Application revision has unexpected value, Ant-style wildcards as well as target directories like out*.zip => dist supported"); }