@Test public void executeTest() throws Exception { mockStatic(PacmanUtils.class); when(PacmanUtils.doesAllHaveValue(anyString(),anyString(),anyString())).thenReturn( true); assertThat(sslCertificateExpiryRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 ")), is(notNullValue())); assertThat(sslCertificateExpiryRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getEmptyMapString()), is(notNullValue())); when(PacmanUtils.doesAllHaveValue(anyString(),anyString(),anyString())).thenReturn( false); assertThatThrownBy( () -> sslCertificateExpiryRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 "))).isInstanceOf(InvalidInputException.class); }
public RuleResult execute(final Map<String, String> ruleParam,Map<String, String> resourceAttributes) { logger.debug("========SSLCertificateExpiryRule started========="); Annotation annotation = null; String validTo = null; long expiredDuration; long targetExpiredDuration; String targetExpiryDurationInString = ruleParam.get(PacmanRuleConstants.EXPIRED_DURATION); String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String,Object>>issueList = new ArrayList<>(); LinkedHashMap<String,Object>issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(targetExpiryDurationInString,severity,category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { validTo = StringUtils.trim(resourceAttributes.get(PacmanRuleConstants.VALID_TO)); expiredDuration = calculateSslExpiredDuration(validTo); targetExpiredDuration = Long.parseLong(targetExpiryDurationInString); if (expiredDuration > 0) { if (expiredDuration <= targetExpiredDuration) { annotation = Annotation.buildAnnotation(ruleParam,Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION,"SSL Expiry within "+ targetExpiryDurationInString+ " days found!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "SSL Expiry within "+ targetExpiryDurationInString+ " days found!!"); issueList.add(issue); annotation.put("issueDetails",issueList.toString()); logger.debug("========SSLCertificateExpiryRule ended with annotation {} : =========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } else { logger.info("Elb with SSL validity not expired"); } } logger.debug("========SSLCertificateExpiryRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE); }
SSLCertificateExpiryRule extends BaseRule { public RuleResult execute(final Map<String, String> ruleParam,Map<String, String> resourceAttributes) { logger.debug("========SSLCertificateExpiryRule started========="); Annotation annotation = null; String validTo = null; long expiredDuration; long targetExpiredDuration; String targetExpiryDurationInString = ruleParam.get(PacmanRuleConstants.EXPIRED_DURATION); String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String,Object>>issueList = new ArrayList<>(); LinkedHashMap<String,Object>issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(targetExpiryDurationInString,severity,category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { validTo = StringUtils.trim(resourceAttributes.get(PacmanRuleConstants.VALID_TO)); expiredDuration = calculateSslExpiredDuration(validTo); targetExpiredDuration = Long.parseLong(targetExpiryDurationInString); if (expiredDuration > 0) { if (expiredDuration <= targetExpiredDuration) { annotation = Annotation.buildAnnotation(ruleParam,Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION,"SSL Expiry within "+ targetExpiryDurationInString+ " days found!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "SSL Expiry within "+ targetExpiryDurationInString+ " days found!!"); issueList.add(issue); annotation.put("issueDetails",issueList.toString()); logger.debug("========SSLCertificateExpiryRule ended with annotation {} : =========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } else { logger.info("Elb with SSL validity not expired"); } } logger.debug("========SSLCertificateExpiryRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE); } }
SSLCertificateExpiryRule extends BaseRule { public RuleResult execute(final Map<String, String> ruleParam,Map<String, String> resourceAttributes) { logger.debug("========SSLCertificateExpiryRule started========="); Annotation annotation = null; String validTo = null; long expiredDuration; long targetExpiredDuration; String targetExpiryDurationInString = ruleParam.get(PacmanRuleConstants.EXPIRED_DURATION); String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String,Object>>issueList = new ArrayList<>(); LinkedHashMap<String,Object>issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(targetExpiryDurationInString,severity,category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { validTo = StringUtils.trim(resourceAttributes.get(PacmanRuleConstants.VALID_TO)); expiredDuration = calculateSslExpiredDuration(validTo); targetExpiredDuration = Long.parseLong(targetExpiryDurationInString); if (expiredDuration > 0) { if (expiredDuration <= targetExpiredDuration) { annotation = Annotation.buildAnnotation(ruleParam,Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION,"SSL Expiry within "+ targetExpiryDurationInString+ " days found!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "SSL Expiry within "+ targetExpiryDurationInString+ " days found!!"); issueList.add(issue); annotation.put("issueDetails",issueList.toString()); logger.debug("========SSLCertificateExpiryRule ended with annotation {} : =========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } else { logger.info("Elb with SSL validity not expired"); } } logger.debug("========SSLCertificateExpiryRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE); }  }
SSLCertificateExpiryRule extends BaseRule { public RuleResult execute(final Map<String, String> ruleParam,Map<String, String> resourceAttributes) { logger.debug("========SSLCertificateExpiryRule started========="); Annotation annotation = null; String validTo = null; long expiredDuration; long targetExpiredDuration; String targetExpiryDurationInString = ruleParam.get(PacmanRuleConstants.EXPIRED_DURATION); String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String,Object>>issueList = new ArrayList<>(); LinkedHashMap<String,Object>issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(targetExpiryDurationInString,severity,category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { validTo = StringUtils.trim(resourceAttributes.get(PacmanRuleConstants.VALID_TO)); expiredDuration = calculateSslExpiredDuration(validTo); targetExpiredDuration = Long.parseLong(targetExpiryDurationInString); if (expiredDuration > 0) { if (expiredDuration <= targetExpiredDuration) { annotation = Annotation.buildAnnotation(ruleParam,Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION,"SSL Expiry within "+ targetExpiryDurationInString+ " days found!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "SSL Expiry within "+ targetExpiryDurationInString+ " days found!!"); issueList.add(issue); annotation.put("issueDetails",issueList.toString()); logger.debug("========SSLCertificateExpiryRule ended with annotation {} : =========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } else { logger.info("Elb with SSL validity not expired"); } } logger.debug("========SSLCertificateExpiryRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE); }  RuleResult execute(final Map<String, String> ruleParam,Map<String, String> resourceAttributes); String getHelpText(); }
SSLCertificateExpiryRule extends BaseRule { public RuleResult execute(final Map<String, String> ruleParam,Map<String, String> resourceAttributes) { logger.debug("========SSLCertificateExpiryRule started========="); Annotation annotation = null; String validTo = null; long expiredDuration; long targetExpiredDuration; String targetExpiryDurationInString = ruleParam.get(PacmanRuleConstants.EXPIRED_DURATION); String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String,Object>>issueList = new ArrayList<>(); LinkedHashMap<String,Object>issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(targetExpiryDurationInString,severity,category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { validTo = StringUtils.trim(resourceAttributes.get(PacmanRuleConstants.VALID_TO)); expiredDuration = calculateSslExpiredDuration(validTo); targetExpiredDuration = Long.parseLong(targetExpiryDurationInString); if (expiredDuration > 0) { if (expiredDuration <= targetExpiredDuration) { annotation = Annotation.buildAnnotation(ruleParam,Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION,"SSL Expiry within "+ targetExpiryDurationInString+ " days found!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "SSL Expiry within "+ targetExpiryDurationInString+ " days found!!"); issueList.add(issue); annotation.put("issueDetails",issueList.toString()); logger.debug("========SSLCertificateExpiryRule ended with annotation {} : =========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } else { logger.info("Elb with SSL validity not expired"); } } logger.debug("========SSLCertificateExpiryRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE); }  RuleResult execute(final Map<String, String> ruleParam,Map<String, String> resourceAttributes); String getHelpText();  }