Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_expand_minimize_over_policies(self):
result = expand_minimize_over_policies(dc(POLICIES_1), expand_policy)
self.assertEqual(result, EXPANDED_POLICIES_1)
self.assertEqual(expanded_policy, EXPANDED_POLICY_1)
policy = {
"Statement": {
"NotAction": ["ec2:thispermissiondoesntexist"],
"Resource": "*",
"Effect": "Deny"
}
}
expected_policy = {
"Statement": [{
"NotAction": ["ec2:thispermissiondoesntexist"],
"Resource": "*",
"Effect": "Deny"
}]
}
expanded_policy = expand_policy(policy=dc(policy), expand_deny=False)
self.assertEqual(expanded_policy, expected_policy)
expanded_policy = expand_policy(policy=dc(policy), expand_deny=True)
self.assertEqual(type(expanded_policy['Statement']), list)
def test_expand_1(self):
expanded_policy = expand_policy(policy=dc(WILDCARD_POLICY_1))
self.assertEqual(expanded_policy, EXPANDED_POLICY_1)
policy = {
"Statement": {
"NotAction": ["ec2:thispermissiondoesntexist"],
"Resource": "*",
"Effect": "Deny"
}
}
expected_policy = {
"Statement": [{
"NotAction": ["ec2:thispermissiondoesntexist"],
"Resource": "*",
"Effect": "Deny"
}]
}
expanded_policy = expand_policy(policy=dc(policy), expand_deny=False)
def test_expand_2(self):
expanded_policy = expand_policy(policy=dc(WILDCARD_POLICY_2))
self.assertEqual(expanded_policy, EXPANDED_POLICY_2)
def test_get_actions_from_statement(self):
statement = {
"Action": "ec2:thispermissiondoesntexist",
"NotAction": list(all_permissions),
"Resource": "*",
"Effect": "Allow"
}
expected_result = {"ec2:thispermissiondoesntexist"}
result = get_actions_from_statement(statement)
self.assertEqual(result, expected_result)
get_actions_from_statement(dict(NotAction="abc"))
def test_get_actions_from_statement(self):
statement = {
"Action": "ec2:thispermissiondoesntexist",
"NotAction": list(all_permissions),
"Resource": "*",
"Effect": "Allow"
}
expected_result = {"ec2:thispermissiondoesntexist"}
result = get_actions_from_statement(statement)
self.assertEqual(result, expected_result)
get_actions_from_statement(dict(NotAction="abc"))
def test_get_actions_from_statement(self):
statement = {
"Action": "ec2:thispermissiondoesntexist",
"NotAction": list(all_permissions),
"Resource": "*",
"Effect": "Allow"
}
expected_result = {"ec2:thispermissiondoesntexist"}
result = get_actions_from_statement(statement)
self.assertEqual(result, expected_result)
get_actions_from_statement(dict(NotAction="abc"))
def test_expand_wildcard_action_3(self):
result = _expand_wildcard_action('ec2:DescribeInstances')
self.assertEqual(result, ['ec2:describeinstances'])
def test_expand_wildcard_action_2(self):
result = _expand_wildcard_action('thistechdoesntexist:*')
self.assertEqual(result, ['thistechdoesntexist:*'])
def test_expand_wildcard_action(self):
result = _expand_wildcard_action(['autoscaling:*'])
self.assertEqual(sorted(result), AUTOSCALING_PERMISSIONS)