Skip to content

Commit

Permalink
adding unit tests for util/conditions.py is_condition_key_match method (
Browse files Browse the repository at this point in the history
#250)

* fix exception handling in get_action_for_service

* adding unit tests

* rename unit test file
  • Loading branch information
reetasingh committed Oct 14, 2020
1 parent 695a0ef commit 0b3398a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/util/test_conditions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest
from policy_sentry.util.conditions import is_condition_key_match

class ConditionsTestCase(unittest.TestCase):
def test_is_condition_key_match_case_1(self):
"""exact match. return True"""
document_key = "s3:prefix"
str_to_match = "s3:prefix"
self.assertTrue(is_condition_key_match(document_key, str_to_match))

def test_is_condition_key_match_case_2(self):
"""no match. return False"""
document_key = "s3:prefix"
str_to_match = "secretsmanager:SecretId"
self.assertFalse(is_condition_key_match(document_key, str_to_match))

def test_is_condition_key_match_case_3(self):
"""match with string before $"""
document_key = "aws:ResourceTag/${TagKey}"
str_to_match = "aws:Resourcetag/${TagKey1}"
self.assertTrue(is_condition_key_match(document_key, str_to_match))

def test_is_condition_key_match_case_4(self):
"""match with string before <"""
document_key = "s3:ExistingObjectTag/<key>"
str_to_match = "s3:ExistingObjectTag/<sample-key>"
self.assertTrue(is_condition_key_match(document_key, str_to_match))

0 comments on commit 0b3398a

Please sign in to comment.