@Test public void testEnabledCloudFrontForHTMLContent() { CloudfrontAuthorizedHTMLContentDistributionRule cloudfrontAuthorizedHTMLContentDistributionRule = new CloudfrontAuthorizedHTMLContentDistributionRule(); Map<String, String> ruleParam = new HashMap<>(); ; Map<String, String> resourceAttributes = new HashMap<>(); resourceAttributes.put("_resourceid", "test-resource-id"); resourceAttributes.put("domainName", "test-domain-name"); resourceAttributes.put("deafultRootObject", "default-root-object"); resourceAttributes.put("enabled", "true"); ruleParam.put("executionId", "test-execution-id"); ruleParam.put(PacmanSdkConstants.RULE_ID, "test-rule-id"); RuleResult ruleResult = cloudfrontAuthorizedHTMLContentDistributionRule.execute(ruleParam, resourceAttributes); assertTrue(ruleResult.getStatus().equals(PacmanSdkConstants.STATUS_SUCCESS)); }
@Override public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CloudfrontAuthorizedHTMLContentDistributionRule started========="); String cloudFrontResourceID = resourceAttributes.get(PacmanSdkConstants.RESOURCE_ID); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); boolean isWebsiteHosted = false; String domainName = resourceAttributes.get("domainName"); String rootObject = resourceAttributes.get("deafultRootObject"); String enabled = resourceAttributes.get("enabled"); if (enabled != null && enabled.equalsIgnoreCase("true")) { List<String> urlListToCheck = new ArrayList<>(); if (rootObject != null && rootObject.contains("htm")) { urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName + SLASH + rootObject); } urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName); urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName + SLASH + INDEX_HTML); urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName + SLASH + INDEX_HTM); for (String url : urlListToCheck) { try { isWebsiteHosted = isWebSiteHosted(url); if (isWebsiteHosted) { String description = "CloudFront instance: " + cloudFrontResourceID + " is unauthorized for html content distribution. Content hosted on url : " + url; logger.debug(description); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, PacmanUtils.createAnnotation("", ruleParam, description, PacmanSdkConstants.SEV_HIGH, PacmanSdkConstants.SECURITY)); } } catch (Exception e) { logger.error("Exception getting from url :[{}],[{}] ", url, e.getMessage()); } } } return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }
CloudfrontAuthorizedHTMLContentDistributionRule extends BaseRule { @Override public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CloudfrontAuthorizedHTMLContentDistributionRule started========="); String cloudFrontResourceID = resourceAttributes.get(PacmanSdkConstants.RESOURCE_ID); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); boolean isWebsiteHosted = false; String domainName = resourceAttributes.get("domainName"); String rootObject = resourceAttributes.get("deafultRootObject"); String enabled = resourceAttributes.get("enabled"); if (enabled != null && enabled.equalsIgnoreCase("true")) { List<String> urlListToCheck = new ArrayList<>(); if (rootObject != null && rootObject.contains("htm")) { urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName + SLASH + rootObject); } urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName); urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName + SLASH + INDEX_HTML); urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName + SLASH + INDEX_HTM); for (String url : urlListToCheck) { try { isWebsiteHosted = isWebSiteHosted(url); if (isWebsiteHosted) { String description = "CloudFront instance: " + cloudFrontResourceID + " is unauthorized for html content distribution. Content hosted on url : " + url; logger.debug(description); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, PacmanUtils.createAnnotation("", ruleParam, description, PacmanSdkConstants.SEV_HIGH, PacmanSdkConstants.SECURITY)); } } catch (Exception e) { logger.error("Exception getting from url :[{}],[{}] ", url, e.getMessage()); } } } return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); } }
CloudfrontAuthorizedHTMLContentDistributionRule extends BaseRule { @Override public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CloudfrontAuthorizedHTMLContentDistributionRule started========="); String cloudFrontResourceID = resourceAttributes.get(PacmanSdkConstants.RESOURCE_ID); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); boolean isWebsiteHosted = false; String domainName = resourceAttributes.get("domainName"); String rootObject = resourceAttributes.get("deafultRootObject"); String enabled = resourceAttributes.get("enabled"); if (enabled != null && enabled.equalsIgnoreCase("true")) { List<String> urlListToCheck = new ArrayList<>(); if (rootObject != null && rootObject.contains("htm")) { urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName + SLASH + rootObject); } urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName); urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName + SLASH + INDEX_HTML); urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName + SLASH + INDEX_HTM); for (String url : urlListToCheck) { try { isWebsiteHosted = isWebSiteHosted(url); if (isWebsiteHosted) { String description = "CloudFront instance: " + cloudFrontResourceID + " is unauthorized for html content distribution. Content hosted on url : " + url; logger.debug(description); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, PacmanUtils.createAnnotation("", ruleParam, description, PacmanSdkConstants.SEV_HIGH, PacmanSdkConstants.SECURITY)); } } catch (Exception e) { logger.error("Exception getting from url :[{}],[{}] ", url, e.getMessage()); } } } return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }  }
CloudfrontAuthorizedHTMLContentDistributionRule extends BaseRule { @Override public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CloudfrontAuthorizedHTMLContentDistributionRule started========="); String cloudFrontResourceID = resourceAttributes.get(PacmanSdkConstants.RESOURCE_ID); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); boolean isWebsiteHosted = false; String domainName = resourceAttributes.get("domainName"); String rootObject = resourceAttributes.get("deafultRootObject"); String enabled = resourceAttributes.get("enabled"); if (enabled != null && enabled.equalsIgnoreCase("true")) { List<String> urlListToCheck = new ArrayList<>(); if (rootObject != null && rootObject.contains("htm")) { urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName + SLASH + rootObject); } urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName); urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName + SLASH + INDEX_HTML); urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName + SLASH + INDEX_HTM); for (String url : urlListToCheck) { try { isWebsiteHosted = isWebSiteHosted(url); if (isWebsiteHosted) { String description = "CloudFront instance: " + cloudFrontResourceID + " is unauthorized for html content distribution. Content hosted on url : " + url; logger.debug(description); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, PacmanUtils.createAnnotation("", ruleParam, description, PacmanSdkConstants.SEV_HIGH, PacmanSdkConstants.SECURITY)); } } catch (Exception e) { logger.error("Exception getting from url :[{}],[{}] ", url, e.getMessage()); } } } return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }  @Override RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes); boolean isWebSiteHosted(String url); @Override String getHelpText(); }
CloudfrontAuthorizedHTMLContentDistributionRule extends BaseRule { @Override public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CloudfrontAuthorizedHTMLContentDistributionRule started========="); String cloudFrontResourceID = resourceAttributes.get(PacmanSdkConstants.RESOURCE_ID); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); boolean isWebsiteHosted = false; String domainName = resourceAttributes.get("domainName"); String rootObject = resourceAttributes.get("deafultRootObject"); String enabled = resourceAttributes.get("enabled"); if (enabled != null && enabled.equalsIgnoreCase("true")) { List<String> urlListToCheck = new ArrayList<>(); if (rootObject != null && rootObject.contains("htm")) { urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName + SLASH + rootObject); } urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName); urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName + SLASH + INDEX_HTML); urlListToCheck.add(HTTP_PROTOCOL_PREFIX + domainName + SLASH + INDEX_HTM); for (String url : urlListToCheck) { try { isWebsiteHosted = isWebSiteHosted(url); if (isWebsiteHosted) { String description = "CloudFront instance: " + cloudFrontResourceID + " is unauthorized for html content distribution. Content hosted on url : " + url; logger.debug(description); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, PacmanUtils.createAnnotation("", ruleParam, description, PacmanSdkConstants.SEV_HIGH, PacmanSdkConstants.SECURITY)); } } catch (Exception e) { logger.error("Exception getting from url :[{}],[{}] ", url, e.getMessage()); } } } return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }  @Override RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes); boolean isWebSiteHosted(String url); @Override String getHelpText();  }