|
34 | 34 | example_principal_policy_mapping = json.load(json_file) |
35 | 35 |
|
36 | 36 |
|
37 | | -class PolicyFileTestCase(unittest.TestCase): |
38 | | - # def test_output_html_output_as_string(self): |
39 | | - # example_authz_details_file = os.path.abspath( |
40 | | - # os.path.join( |
41 | | - # os.path.dirname(__file__), |
42 | | - # os.path.pardir, |
43 | | - # "files", |
44 | | - # "example-authz-details.json", |
45 | | - # ) |
46 | | - # ) |
47 | | - # with open(example_authz_details_file, "r") as json_file: |
48 | | - # cfg = json.load(json_file) |
49 | | - # decision = check_authorization_details_schema(cfg) |
50 | | - # self.assertTrue(decision) |
51 | | - # # TODO: These values are just for testing |
52 | | - # account_authorization_details_cfg = cfg |
53 | | - # exclusions = DEFAULT_EXCLUSIONS |
54 | | - # |
55 | | - # authorization_details = AuthorizationDetails(account_authorization_details_cfg) |
56 | | - # results = authorization_details.missing_resource_constraints( |
57 | | - # exclusions, modify_only=True |
58 | | - # ) |
59 | | - # |
60 | | - # principal_policy_mapping = authorization_details.principal_policy_mapping |
61 | | - # # For the IAM Principals tab, add on risk stats per principal |
62 | | - # for principal_policy_entry in principal_policy_mapping: |
63 | | - # for finding in results: |
64 | | - # if principal_policy_entry.get("PolicyName").lower() == finding.get("PolicyName").lower(): |
65 | | - # principal_policy_entry["Actions"] = len(finding["Actions"]) |
66 | | - # principal_policy_entry["PrivilegeEscalation"] = len( |
67 | | - # finding["PrivilegeEscalation"] |
68 | | - # ) |
69 | | - # principal_policy_entry["DataExfiltration"] = len( |
70 | | - # finding["DataExfiltration"] |
71 | | - # ) |
72 | | - # principal_policy_entry["ResourceExposure"] = len( |
73 | | - # finding["ResourceExposure"] |
74 | | - # ) |
75 | | - # principal_name = principal_policy_entry["Principal"] |
76 | | - # # Customer Managed Policies |
77 | | - # if finding.get("Type") == "Policy" and finding.get( |
78 | | - # "ManagedBy") == "Customer" and principal_policy_entry.get("Type") != "Policy": |
79 | | - # if "Principals" not in finding: |
80 | | - # finding["Principals"] = [principal_name] |
81 | | - # else: |
82 | | - # if principal_name not in finding["Principals"]: |
83 | | - # finding["Principals"].append(principal_name) |
84 | | - # |
85 | | - # # AWS Managed Policies |
86 | | - # if finding.get("Type") == "Policy" and finding.get("ManagedBy") == "AWS": |
87 | | - # if "Principals" not in finding: |
88 | | - # finding["Principals"] = [principal_name] |
89 | | - # else: |
90 | | - # if principal_name not in finding["Principals"]: |
91 | | - # finding["Principals"].append(principal_name) |
92 | | - # |
93 | | - # # Lazy method to get an account ID |
94 | | - # account_id = None |
95 | | - # for item in results: |
96 | | - # if item["ManagedBy"] == "Customer": |
97 | | - # account_id = item["AccountID"] |
98 | | - # break |
99 | | - # |
100 | | - # html_report = HTMLReport( |
101 | | - # account_id=account_id, |
102 | | - # account_name="CHANGEME", |
103 | | - # results=results, |
104 | | - # ) |
105 | | - # rendered_report = html_report.get_html_report() |
106 | | - # # print(rendered_report) |
107 | | - # # test_report_path = os.path.join( |
108 | | - # # os.getcwd(), |
109 | | - # # os.path.pardir, |
110 | | - # # os.path.pardir, |
111 | | - # # "tmp", |
112 | | - # # "testing_new_html_report.html" |
113 | | - # # ) |
114 | | - # # with open(test_report_path, "w") as file: |
115 | | - # # file.write(rendered_report) |
116 | | - # # print("Opening the HTML report") |
117 | | - # # url = "file://%s" % os.path.abspath(test_report_path) |
118 | | - # # webbrowser.open(url, new=2) |
119 | | - |
120 | | - |
121 | | - def test_scan_authz_details_and_output_html_as_string(self): |
122 | | - example_authz_details_file = os.path.abspath( |
123 | | - os.path.join( |
124 | | - os.path.dirname(__file__), |
125 | | - os.path.pardir, |
126 | | - "files", |
127 | | - "example-authz-details.json", |
128 | | - ) |
129 | | - ) |
130 | | - with open(example_authz_details_file, "r") as json_file: |
131 | | - cfg = json.load(json_file) |
132 | | - decision = check_authorization_details_schema(cfg) |
133 | | - self.assertTrue(decision) |
134 | | - |
135 | | - rendered_html_report = scan_account_authorization_details( |
136 | | - cfg, DEFAULT_EXCLUSIONS, account_name="Something", output_directory=os.getcwd(), |
137 | | - write_data_files=False |
138 | | - ) |
139 | | - # print(rendered_html_report) |
| 37 | +# class PolicyFileTestCase(unittest.TestCase): |
| 38 | +# def test_scan_authz_details_and_output_html_as_string(self): |
| 39 | +# example_authz_details_file = os.path.abspath( |
| 40 | +# os.path.join( |
| 41 | +# os.path.dirname(__file__), |
| 42 | +# os.path.pardir, |
| 43 | +# "files", |
| 44 | +# "example-authz-details.json", |
| 45 | +# ) |
| 46 | +# ) |
| 47 | +# with open(example_authz_details_file, "r") as json_file: |
| 48 | +# cfg = json.load(json_file) |
| 49 | +# decision = check_authorization_details_schema(cfg) |
| 50 | +# self.assertTrue(decision) |
| 51 | +# |
| 52 | +# rendered_html_report = scan_account_authorization_details( |
| 53 | +# cfg, DEFAULT_EXCLUSIONS, account_name="Something", output_directory=os.getcwd(), |
| 54 | +# write_data_files=False |
| 55 | +# ) |
| 56 | +# # print(rendered_html_report) |
0 commit comments