@Test public void executeTest() throws Exception { mockStatic(PacmanUtils.class); when(PacmanUtils.doesAllHaveValue(anyString(),anyString(),anyString())).thenReturn( true); when(PacmanUtils.formatUrl(anyObject(),anyString())).thenReturn("host"); when(PacmanUtils.isGuardDutyFindingsExists(anyString(),anyString(),anyString())).thenReturn(true); assertThat(checkGuardDutyFindingsExists.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 ")), is(notNullValue())); when(PacmanUtils.isGuardDutyFindingsExists(anyString(),anyString(),anyString())).thenReturn(false); assertThat(checkGuardDutyFindingsExists.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 ")), is(notNullValue())); when(PacmanUtils.doesAllHaveValue(anyString(),anyString(),anyString())).thenReturn( false); assertThatThrownBy( () -> checkGuardDutyFindingsExists.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("========CheckGuardDutyFindingsExists started========="); String resourceId = null; Annotation annotation = null; String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); String guardDutyEsUrl = null; String formattedUrl = PacmanUtils.formatUrl(ruleParam,PacmanRuleConstants.ES_GUARD_DUTY_URL); if(!StringUtils.isNullOrEmpty(formattedUrl)){ guardDutyEsUrl = formattedUrl; } 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(severity, category, guardDutyEsUrl)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { resourceId = StringUtils.trim(resourceAttributes .get(PacmanSdkConstants.RESOURCE_ID)); Boolean isGuardDutyFindingsExists = PacmanUtils .isGuardDutyFindingsExists(resourceId, guardDutyEsUrl, PacmanRuleConstants.GUARD_DUTY_INSTANCE_ATTR); if (isGuardDutyFindingsExists) { annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION, "Guard Duty findings exists!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "Ec2 instance associated to a guard duty!!"); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug("========CheckGuardDutyFindingsExists ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========CheckGuardDutyFindingsExists ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }
CheckGuardDutyFindingsExists extends BaseRule { public RuleResult execute(final Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CheckGuardDutyFindingsExists started========="); String resourceId = null; Annotation annotation = null; String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); String guardDutyEsUrl = null; String formattedUrl = PacmanUtils.formatUrl(ruleParam,PacmanRuleConstants.ES_GUARD_DUTY_URL); if(!StringUtils.isNullOrEmpty(formattedUrl)){ guardDutyEsUrl = formattedUrl; } 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(severity, category, guardDutyEsUrl)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { resourceId = StringUtils.trim(resourceAttributes .get(PacmanSdkConstants.RESOURCE_ID)); Boolean isGuardDutyFindingsExists = PacmanUtils .isGuardDutyFindingsExists(resourceId, guardDutyEsUrl, PacmanRuleConstants.GUARD_DUTY_INSTANCE_ATTR); if (isGuardDutyFindingsExists) { annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION, "Guard Duty findings exists!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "Ec2 instance associated to a guard duty!!"); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug("========CheckGuardDutyFindingsExists ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========CheckGuardDutyFindingsExists ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); } }
CheckGuardDutyFindingsExists extends BaseRule { public RuleResult execute(final Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CheckGuardDutyFindingsExists started========="); String resourceId = null; Annotation annotation = null; String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); String guardDutyEsUrl = null; String formattedUrl = PacmanUtils.formatUrl(ruleParam,PacmanRuleConstants.ES_GUARD_DUTY_URL); if(!StringUtils.isNullOrEmpty(formattedUrl)){ guardDutyEsUrl = formattedUrl; } 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(severity, category, guardDutyEsUrl)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { resourceId = StringUtils.trim(resourceAttributes .get(PacmanSdkConstants.RESOURCE_ID)); Boolean isGuardDutyFindingsExists = PacmanUtils .isGuardDutyFindingsExists(resourceId, guardDutyEsUrl, PacmanRuleConstants.GUARD_DUTY_INSTANCE_ATTR); if (isGuardDutyFindingsExists) { annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION, "Guard Duty findings exists!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "Ec2 instance associated to a guard duty!!"); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug("========CheckGuardDutyFindingsExists ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========CheckGuardDutyFindingsExists ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }  }
CheckGuardDutyFindingsExists extends BaseRule { public RuleResult execute(final Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CheckGuardDutyFindingsExists started========="); String resourceId = null; Annotation annotation = null; String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); String guardDutyEsUrl = null; String formattedUrl = PacmanUtils.formatUrl(ruleParam,PacmanRuleConstants.ES_GUARD_DUTY_URL); if(!StringUtils.isNullOrEmpty(formattedUrl)){ guardDutyEsUrl = formattedUrl; } 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(severity, category, guardDutyEsUrl)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { resourceId = StringUtils.trim(resourceAttributes .get(PacmanSdkConstants.RESOURCE_ID)); Boolean isGuardDutyFindingsExists = PacmanUtils .isGuardDutyFindingsExists(resourceId, guardDutyEsUrl, PacmanRuleConstants.GUARD_DUTY_INSTANCE_ATTR); if (isGuardDutyFindingsExists) { annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION, "Guard Duty findings exists!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "Ec2 instance associated to a guard duty!!"); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug("========CheckGuardDutyFindingsExists ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========CheckGuardDutyFindingsExists ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }  RuleResult execute(final Map<String, String> ruleParam,
            Map<String, String> resourceAttributes); String getHelpText(); }
CheckGuardDutyFindingsExists extends BaseRule { public RuleResult execute(final Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CheckGuardDutyFindingsExists started========="); String resourceId = null; Annotation annotation = null; String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); String guardDutyEsUrl = null; String formattedUrl = PacmanUtils.formatUrl(ruleParam,PacmanRuleConstants.ES_GUARD_DUTY_URL); if(!StringUtils.isNullOrEmpty(formattedUrl)){ guardDutyEsUrl = formattedUrl; } 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(severity, category, guardDutyEsUrl)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { resourceId = StringUtils.trim(resourceAttributes .get(PacmanSdkConstants.RESOURCE_ID)); Boolean isGuardDutyFindingsExists = PacmanUtils .isGuardDutyFindingsExists(resourceId, guardDutyEsUrl, PacmanRuleConstants.GUARD_DUTY_INSTANCE_ATTR); if (isGuardDutyFindingsExists) { annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION, "Guard Duty findings exists!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "Ec2 instance associated to a guard duty!!"); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug("========CheckGuardDutyFindingsExists ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========CheckGuardDutyFindingsExists ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }  RuleResult execute(final Map<String, String> ruleParam,
            Map<String, String> resourceAttributes); String getHelpText();  }