@Test public void test()throws Exception{ Collection<String> li = new ArrayList<>(); li.add("123"); BucketVersioningConfiguration configuration = new BucketVersioningConfiguration(); configuration.setMfaDeleteEnabled(false); mockStatic(PacmanUtils.class); when(PacmanUtils.doesAllHaveValue(anyString(),anyString())).thenReturn( true); Map<String,Object>map=new HashMap<String, Object>(); map.put("client", awsS3Client); CheckMFADeleteEnabledRule spy = Mockito.spy(new CheckMFADeleteEnabledRule()); Mockito.doReturn(map).when((BaseRule)spy).getClientFor(anyObject(), anyString(), anyObject()); when(awsS3Client.getBucketVersioningConfiguration(anyString())).thenReturn(configuration); spy.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 ")); assertThat(checkMFADeleteEnabledRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getEmptyMapString()), is(notNullValue())); when(awsS3Client.getBucketVersioningConfiguration(anyString())).thenThrow(new RuleExecutionFailedExeption()); assertThatThrownBy( () -> checkMFADeleteEnabledRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 "))).isInstanceOf(InvalidInputException.class); when(PacmanUtils.doesAllHaveValue(anyString(),anyString())).thenReturn( false); assertThatThrownBy( () -> checkMFADeleteEnabledRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 "))).isInstanceOf(InvalidInputException.class); }
public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CheckMFADeleteEnabledRule started========="); Map<String, Object> map = null; AmazonS3Client awsS3Client = null; Annotation annotation = null; String roleIdentifyingString = ruleParam.get(PacmanSdkConstants.Role_IDENTIFYING_STRING); String s3BucketName = ruleParam.get(PacmanSdkConstants.RESOURCE_ID); 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(severity, category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (!resourceAttributes.isEmpty()) { try { map = getClientFor(AWSService.S3, roleIdentifyingString, ruleParam); awsS3Client = (AmazonS3Client) map.get(PacmanSdkConstants.CLIENT); } catch (UnableToCreateClientException e) { logger.error("unable to get client for following input", e); throw new InvalidInputException(e.toString()); } BucketVersioningConfiguration configuration = awsS3Client.getBucketVersioningConfiguration(s3BucketName); if(configuration.isMfaDeleteEnabled()==null || !configuration.isMfaDeleteEnabled()){ annotation = Annotation.buildAnnotation(ruleParam,Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION,"S3 with no MFA delete enabled found!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "S3 with no MFA delete enabled found!!"); issueList.add(issue); annotation.put("issueDetails",issueList.toString()); logger.debug("========CheckMFADeleteEnabledRule ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========CheckMFADeleteEnabledRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE); }
CheckMFADeleteEnabledRule extends BaseRule { public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CheckMFADeleteEnabledRule started========="); Map<String, Object> map = null; AmazonS3Client awsS3Client = null; Annotation annotation = null; String roleIdentifyingString = ruleParam.get(PacmanSdkConstants.Role_IDENTIFYING_STRING); String s3BucketName = ruleParam.get(PacmanSdkConstants.RESOURCE_ID); 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(severity, category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (!resourceAttributes.isEmpty()) { try { map = getClientFor(AWSService.S3, roleIdentifyingString, ruleParam); awsS3Client = (AmazonS3Client) map.get(PacmanSdkConstants.CLIENT); } catch (UnableToCreateClientException e) { logger.error("unable to get client for following input", e); throw new InvalidInputException(e.toString()); } BucketVersioningConfiguration configuration = awsS3Client.getBucketVersioningConfiguration(s3BucketName); if(configuration.isMfaDeleteEnabled()==null || !configuration.isMfaDeleteEnabled()){ annotation = Annotation.buildAnnotation(ruleParam,Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION,"S3 with no MFA delete enabled found!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "S3 with no MFA delete enabled found!!"); issueList.add(issue); annotation.put("issueDetails",issueList.toString()); logger.debug("========CheckMFADeleteEnabledRule ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========CheckMFADeleteEnabledRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE); } }
CheckMFADeleteEnabledRule extends BaseRule { public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CheckMFADeleteEnabledRule started========="); Map<String, Object> map = null; AmazonS3Client awsS3Client = null; Annotation annotation = null; String roleIdentifyingString = ruleParam.get(PacmanSdkConstants.Role_IDENTIFYING_STRING); String s3BucketName = ruleParam.get(PacmanSdkConstants.RESOURCE_ID); 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(severity, category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (!resourceAttributes.isEmpty()) { try { map = getClientFor(AWSService.S3, roleIdentifyingString, ruleParam); awsS3Client = (AmazonS3Client) map.get(PacmanSdkConstants.CLIENT); } catch (UnableToCreateClientException e) { logger.error("unable to get client for following input", e); throw new InvalidInputException(e.toString()); } BucketVersioningConfiguration configuration = awsS3Client.getBucketVersioningConfiguration(s3BucketName); if(configuration.isMfaDeleteEnabled()==null || !configuration.isMfaDeleteEnabled()){ annotation = Annotation.buildAnnotation(ruleParam,Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION,"S3 with no MFA delete enabled found!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "S3 with no MFA delete enabled found!!"); issueList.add(issue); annotation.put("issueDetails",issueList.toString()); logger.debug("========CheckMFADeleteEnabledRule ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========CheckMFADeleteEnabledRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE); }  }
CheckMFADeleteEnabledRule extends BaseRule { public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CheckMFADeleteEnabledRule started========="); Map<String, Object> map = null; AmazonS3Client awsS3Client = null; Annotation annotation = null; String roleIdentifyingString = ruleParam.get(PacmanSdkConstants.Role_IDENTIFYING_STRING); String s3BucketName = ruleParam.get(PacmanSdkConstants.RESOURCE_ID); 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(severity, category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (!resourceAttributes.isEmpty()) { try { map = getClientFor(AWSService.S3, roleIdentifyingString, ruleParam); awsS3Client = (AmazonS3Client) map.get(PacmanSdkConstants.CLIENT); } catch (UnableToCreateClientException e) { logger.error("unable to get client for following input", e); throw new InvalidInputException(e.toString()); } BucketVersioningConfiguration configuration = awsS3Client.getBucketVersioningConfiguration(s3BucketName); if(configuration.isMfaDeleteEnabled()==null || !configuration.isMfaDeleteEnabled()){ annotation = Annotation.buildAnnotation(ruleParam,Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION,"S3 with no MFA delete enabled found!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "S3 with no MFA delete enabled found!!"); issueList.add(issue); annotation.put("issueDetails",issueList.toString()); logger.debug("========CheckMFADeleteEnabledRule ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========CheckMFADeleteEnabledRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE); }  RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes); String getHelpText(); }
CheckMFADeleteEnabledRule extends BaseRule { public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CheckMFADeleteEnabledRule started========="); Map<String, Object> map = null; AmazonS3Client awsS3Client = null; Annotation annotation = null; String roleIdentifyingString = ruleParam.get(PacmanSdkConstants.Role_IDENTIFYING_STRING); String s3BucketName = ruleParam.get(PacmanSdkConstants.RESOURCE_ID); 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(severity, category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (!resourceAttributes.isEmpty()) { try { map = getClientFor(AWSService.S3, roleIdentifyingString, ruleParam); awsS3Client = (AmazonS3Client) map.get(PacmanSdkConstants.CLIENT); } catch (UnableToCreateClientException e) { logger.error("unable to get client for following input", e); throw new InvalidInputException(e.toString()); } BucketVersioningConfiguration configuration = awsS3Client.getBucketVersioningConfiguration(s3BucketName); if(configuration.isMfaDeleteEnabled()==null || !configuration.isMfaDeleteEnabled()){ annotation = Annotation.buildAnnotation(ruleParam,Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION,"S3 with no MFA delete enabled found!!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "S3 with no MFA delete enabled found!!"); issueList.add(issue); annotation.put("issueDetails",issueList.toString()); logger.debug("========CheckMFADeleteEnabledRule ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========CheckMFADeleteEnabledRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE); }  RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes); String getHelpText();  }