@Test public void test()throws Exception{ GetSAMLProviderResult keysResult = new GetSAMLProviderResult(); keysResult.getSAMLMetadataDocument(); mockStatic(PacmanUtils.class); when(PacmanUtils.doesAllHaveValue(anyString(),anyString(),anyString())).thenReturn( true); Map<String,Object>map=new HashMap<String, Object>(); map.put("client", identityManagementClient); CheckIamIdentityProviderWithADFSRule spy = Mockito.spy(new CheckIamIdentityProviderWithADFSRule()); Mockito.doReturn(map).when((BaseRule)spy).getClientFor(anyObject(), anyString(), anyObject()); when(identityManagementClient.getSAMLProvider(anyObject())).thenReturn(keysResult); spy.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 ")); when(identityManagementClient.getSAMLProvider(anyObject())).thenThrow(new RuleExecutionFailedExeption()); assertThatThrownBy( () -> checkIamIdentityProviderWithADFSRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 "))).isInstanceOf(InvalidInputException.class); when(PacmanUtils.doesAllHaveValue(anyString(),anyString(),anyString())).thenReturn( false); assertThatThrownBy( () -> checkIamIdentityProviderWithADFSRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 "))).isInstanceOf(InvalidInputException.class); }
@Override public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CheckIamIdentityProviderWithADFSRule started========="); Map<String, String> temp = new HashMap<>(); temp.putAll(ruleParam); temp.put("region", "us-west-2"); Annotation annotation = null; String accountId = resourceAttributes.get("accountid"); logger.info(resourceAttributes.get("accountid")); logger.info(resourceAttributes.get("accountname")); String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); String roleIdentifyingString = ruleParam .get(PacmanSdkConstants.Role_IDENTIFYING_STRING); 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, roleIdentifyingString)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException( PacmanRuleConstants.MISSING_CONFIGURATION); } Map<String, Object> map = null; AmazonIdentityManagementClient identityManagementClient = null; try { map = getClientFor(AWSService.IAM, roleIdentifyingString, temp); identityManagementClient = (AmazonIdentityManagementClient) map .get(PacmanSdkConstants.CLIENT); GetSAMLProviderRequest request = new GetSAMLProviderRequest(); request.setSAMLProviderArn("arn:aws:iam::" + accountId + ":saml-provider/ADFS"); identityManagementClient .getSAMLProvider(request); } catch (UnableToCreateClientException e) { logger.error("unable to get client for following input", e); throw new InvalidInputException(e.toString()); }catch(Exception e){ logger.error("e", e); annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation .put(PacmanSdkConstants.DESCRIPTION, "CORP ADFS identity provider not configured for this AWS account"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "CORP ADFS identity provider not configured for this AWS account"); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug( "========CheckIamIdentityProviderWithADFSRule ended with an annotation {} : =========", annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } logger.debug("========CheckIamIdentityProviderWithADFSRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }
CheckIamIdentityProviderWithADFSRule extends BaseRule { @Override public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CheckIamIdentityProviderWithADFSRule started========="); Map<String, String> temp = new HashMap<>(); temp.putAll(ruleParam); temp.put("region", "us-west-2"); Annotation annotation = null; String accountId = resourceAttributes.get("accountid"); logger.info(resourceAttributes.get("accountid")); logger.info(resourceAttributes.get("accountname")); String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); String roleIdentifyingString = ruleParam .get(PacmanSdkConstants.Role_IDENTIFYING_STRING); 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, roleIdentifyingString)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException( PacmanRuleConstants.MISSING_CONFIGURATION); } Map<String, Object> map = null; AmazonIdentityManagementClient identityManagementClient = null; try { map = getClientFor(AWSService.IAM, roleIdentifyingString, temp); identityManagementClient = (AmazonIdentityManagementClient) map .get(PacmanSdkConstants.CLIENT); GetSAMLProviderRequest request = new GetSAMLProviderRequest(); request.setSAMLProviderArn("arn:aws:iam::" + accountId + ":saml-provider/ADFS"); identityManagementClient .getSAMLProvider(request); } catch (UnableToCreateClientException e) { logger.error("unable to get client for following input", e); throw new InvalidInputException(e.toString()); }catch(Exception e){ logger.error("e", e); annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation .put(PacmanSdkConstants.DESCRIPTION, "CORP ADFS identity provider not configured for this AWS account"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "CORP ADFS identity provider not configured for this AWS account"); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug( "========CheckIamIdentityProviderWithADFSRule ended with an annotation {} : =========", annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } logger.debug("========CheckIamIdentityProviderWithADFSRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); } }
CheckIamIdentityProviderWithADFSRule extends BaseRule { @Override public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CheckIamIdentityProviderWithADFSRule started========="); Map<String, String> temp = new HashMap<>(); temp.putAll(ruleParam); temp.put("region", "us-west-2"); Annotation annotation = null; String accountId = resourceAttributes.get("accountid"); logger.info(resourceAttributes.get("accountid")); logger.info(resourceAttributes.get("accountname")); String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); String roleIdentifyingString = ruleParam .get(PacmanSdkConstants.Role_IDENTIFYING_STRING); 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, roleIdentifyingString)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException( PacmanRuleConstants.MISSING_CONFIGURATION); } Map<String, Object> map = null; AmazonIdentityManagementClient identityManagementClient = null; try { map = getClientFor(AWSService.IAM, roleIdentifyingString, temp); identityManagementClient = (AmazonIdentityManagementClient) map .get(PacmanSdkConstants.CLIENT); GetSAMLProviderRequest request = new GetSAMLProviderRequest(); request.setSAMLProviderArn("arn:aws:iam::" + accountId + ":saml-provider/ADFS"); identityManagementClient .getSAMLProvider(request); } catch (UnableToCreateClientException e) { logger.error("unable to get client for following input", e); throw new InvalidInputException(e.toString()); }catch(Exception e){ logger.error("e", e); annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation .put(PacmanSdkConstants.DESCRIPTION, "CORP ADFS identity provider not configured for this AWS account"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "CORP ADFS identity provider not configured for this AWS account"); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug( "========CheckIamIdentityProviderWithADFSRule ended with an annotation {} : =========", annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } logger.debug("========CheckIamIdentityProviderWithADFSRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }  }
CheckIamIdentityProviderWithADFSRule extends BaseRule { @Override public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CheckIamIdentityProviderWithADFSRule started========="); Map<String, String> temp = new HashMap<>(); temp.putAll(ruleParam); temp.put("region", "us-west-2"); Annotation annotation = null; String accountId = resourceAttributes.get("accountid"); logger.info(resourceAttributes.get("accountid")); logger.info(resourceAttributes.get("accountname")); String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); String roleIdentifyingString = ruleParam .get(PacmanSdkConstants.Role_IDENTIFYING_STRING); 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, roleIdentifyingString)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException( PacmanRuleConstants.MISSING_CONFIGURATION); } Map<String, Object> map = null; AmazonIdentityManagementClient identityManagementClient = null; try { map = getClientFor(AWSService.IAM, roleIdentifyingString, temp); identityManagementClient = (AmazonIdentityManagementClient) map .get(PacmanSdkConstants.CLIENT); GetSAMLProviderRequest request = new GetSAMLProviderRequest(); request.setSAMLProviderArn("arn:aws:iam::" + accountId + ":saml-provider/ADFS"); identityManagementClient .getSAMLProvider(request); } catch (UnableToCreateClientException e) { logger.error("unable to get client for following input", e); throw new InvalidInputException(e.toString()); }catch(Exception e){ logger.error("e", e); annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation .put(PacmanSdkConstants.DESCRIPTION, "CORP ADFS identity provider not configured for this AWS account"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "CORP ADFS identity provider not configured for this AWS account"); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug( "========CheckIamIdentityProviderWithADFSRule ended with an annotation {} : =========", annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } logger.debug("========CheckIamIdentityProviderWithADFSRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }  @Override RuleResult execute(Map<String, String> ruleParam,
            Map<String, String> resourceAttributes); @Override String getHelpText(); }
CheckIamIdentityProviderWithADFSRule extends BaseRule { @Override public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========CheckIamIdentityProviderWithADFSRule started========="); Map<String, String> temp = new HashMap<>(); temp.putAll(ruleParam); temp.put("region", "us-west-2"); Annotation annotation = null; String accountId = resourceAttributes.get("accountid"); logger.info(resourceAttributes.get("accountid")); logger.info(resourceAttributes.get("accountname")); String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); String roleIdentifyingString = ruleParam .get(PacmanSdkConstants.Role_IDENTIFYING_STRING); 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, roleIdentifyingString)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException( PacmanRuleConstants.MISSING_CONFIGURATION); } Map<String, Object> map = null; AmazonIdentityManagementClient identityManagementClient = null; try { map = getClientFor(AWSService.IAM, roleIdentifyingString, temp); identityManagementClient = (AmazonIdentityManagementClient) map .get(PacmanSdkConstants.CLIENT); GetSAMLProviderRequest request = new GetSAMLProviderRequest(); request.setSAMLProviderArn("arn:aws:iam::" + accountId + ":saml-provider/ADFS"); identityManagementClient .getSAMLProvider(request); } catch (UnableToCreateClientException e) { logger.error("unable to get client for following input", e); throw new InvalidInputException(e.toString()); }catch(Exception e){ logger.error("e", e); annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation .put(PacmanSdkConstants.DESCRIPTION, "CORP ADFS identity provider not configured for this AWS account"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "CORP ADFS identity provider not configured for this AWS account"); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug( "========CheckIamIdentityProviderWithADFSRule ended with an annotation {} : =========", annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } logger.debug("========CheckIamIdentityProviderWithADFSRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }  @Override RuleResult execute(Map<String, String> ruleParam,
            Map<String, String> resourceAttributes); @Override String getHelpText();  }