Skip to content

Commit

Permalink
feat(issue-641): reformat files
Browse files Browse the repository at this point in the history
  • Loading branch information
disaverio committed Aug 28, 2024
1 parent 36d3c84 commit 9fe5880
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
7 changes: 4 additions & 3 deletions packages/opal-client/opal_client/policy_store/opa_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@


def should_ignore_path(path, ignore_paths):
"""Helper function to check if the policy-store should ignore the given path."""
paths_to_ignore = [p for p in ignore_paths if not p.startswith('!')]
paths_to_not_ignore = [p[1:] for p in ignore_paths if p.startswith('!')]
"""Helper function to check if the policy-store should ignore the given
path."""
paths_to_ignore = [p for p in ignore_paths if not p.startswith("!")]
paths_to_not_ignore = [p[1:] for p in ignore_paths if p.startswith("!")]

# Check if the path matches any path to not be ignored
if PathUtils.glob_style_match_path_to_list(path, paths_to_not_ignore) is not None:
Expand Down
30 changes: 25 additions & 5 deletions packages/opal-client/opal_client/tests/opa_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,98 +112,118 @@ def get_badly_ordered_ops(self):
order_strict_ops.get_badly_ordered_ops()
)


def test_should_not_ignore_anything_with_no_ignore_paths():
ignore_paths = []
assert should_ignore_path("myFolder", ignore_paths) == False
assert should_ignore_path("myFolder/file.txt", ignore_paths) == False
assert should_ignore_path("otherFolder", ignore_paths) == False
assert should_ignore_path("otherFolder/file.txt", ignore_paths) == False


def test_should_ignore_everything_with_root_as_ignore_paths():
ignore_paths = ["/"]
assert should_ignore_path("myFolder", ignore_paths) == True
assert should_ignore_path("myFolder/file.txt", ignore_paths) == True
assert should_ignore_path("otherFolder", ignore_paths) == True
assert should_ignore_path("otherFolder/file.txt", ignore_paths) == True


def test_should_ignore_everything_with_root_and_asterisks_as_ignore_paths():
ignore_paths = ["/**"]
assert should_ignore_path("myFolder", ignore_paths) == True
assert should_ignore_path("myFolder/file.txt", ignore_paths) == True
assert should_ignore_path("otherFolder", ignore_paths) == True
assert should_ignore_path("otherFolder/file.txt", ignore_paths) == True


def test_should_ignore_path_but_not_his_contents_when_path_is_defined_without_asterisks():
ignore_paths = ["myFolder"]
assert should_ignore_path("myFolder", ignore_paths) == True
assert should_ignore_path("myFolder/file.txt", ignore_paths) == False
assert should_ignore_path("otherFolder", ignore_paths) == False
assert should_ignore_path("otherFolder/file.txt", ignore_paths) == False


def test_should_ignore_path_and_his_contents_when_path_is_defined_with_asterisks():
ignore_paths = ["myFolder/**"]
assert should_ignore_path("myFolder", ignore_paths) == True
assert should_ignore_path("myFolder/file.txt", ignore_paths) == True
assert should_ignore_path("otherFolder", ignore_paths) == False
assert should_ignore_path("otherFolder/file.txt", ignore_paths) == False


def test_should_not_ignore_anything_with_not_ignore_paths_only():
ignore_paths = ["!myFolder/**"]
assert should_ignore_path("myFolder", ignore_paths) == False
assert should_ignore_path("myFolder/file.txt", ignore_paths) == False
assert should_ignore_path("otherFolder", ignore_paths) == False
assert should_ignore_path("otherFolder/file.txt", ignore_paths) == False


def test_should_ignore_path_but_ones_specified_as_not_ignore_paths():
ignore_paths = ["/", "!myFolder"]
assert should_ignore_path("myFolder", ignore_paths) == False
assert should_ignore_path("myFolder/file.txt", ignore_paths) == True
assert should_ignore_path("otherFolder", ignore_paths) == True
assert should_ignore_path("otherFolder/file.txt", ignore_paths) == True


def test_should_ignore_path_but_ones_specified_as_not_ignore_paths_and_his_contents_when_defined_with_asterisks():
ignore_paths = ["/", "!myFolder/**"]
assert should_ignore_path("myFolder", ignore_paths) == False
assert should_ignore_path("myFolder/file.txt", ignore_paths) == False
assert should_ignore_path("otherFolder", ignore_paths) == True
assert should_ignore_path("otherFolder/file.txt", ignore_paths) == True


def test_should_ignore_path_keeping_higher_priority_to_ones_defined_as_not_to_ignore_A():
ignore_paths = ["myFolder/**", "!myFolder/subFolder/**"]
assert should_ignore_path("myFolder/file.txt", ignore_paths) == True
assert should_ignore_path("myFolder/subFolder", ignore_paths) == False
assert should_ignore_path("myFolder/subFolder/file.txt", ignore_paths) == False
assert should_ignore_path("myFolder/anotherSubFolder", ignore_paths) == True
assert should_ignore_path("myFolder/anotherSubFolder/file.txt", ignore_paths) == True
assert (
should_ignore_path("myFolder/anotherSubFolder/file.txt", ignore_paths) == True
)
assert should_ignore_path("otherFolder", ignore_paths) == False
assert should_ignore_path("otherFolder/file.txt", ignore_paths) == False


def test_should_ignore_path_keeping_higher_priority_to_ones_defined_as_not_to_ignore_B():
ignore_paths = ["/", "myFolder/**", "!myFolder/subFolder/**"]
assert should_ignore_path("myFolder/file.txt", ignore_paths) == True
assert should_ignore_path("myFolder/subFolder", ignore_paths) == False
assert should_ignore_path("myFolder/subFolder/file.txt", ignore_paths) == False
assert should_ignore_path("myFolder/anotherSubFolder", ignore_paths) == True
assert should_ignore_path("myFolder/anotherSubFolder/file.txt", ignore_paths) == True
assert (
should_ignore_path("myFolder/anotherSubFolder/file.txt", ignore_paths) == True
)
assert should_ignore_path("otherFolder", ignore_paths) == True
assert should_ignore_path("otherFolder/file.txt", ignore_paths) == True


def test_should_ignore_path_keeping_higher_priority_to_ones_defined_as_not_to_ignore_C():
ignore_paths = ["!myFolder/**", "myFolder/subFolder/**"]
assert should_ignore_path("myFolder/file.txt", ignore_paths) == False
assert should_ignore_path("myFolder/subFolder", ignore_paths) == False
assert should_ignore_path("myFolder/subFolder/file.txt", ignore_paths) == False
assert should_ignore_path("myFolder/anotherSubFolder", ignore_paths) == False
assert should_ignore_path("myFolder/anotherSubFolder/file.txt", ignore_paths) == False
assert (
should_ignore_path("myFolder/anotherSubFolder/file.txt", ignore_paths) == False
)
assert should_ignore_path("otherFolder", ignore_paths) == False
assert should_ignore_path("otherFolder/file.txt", ignore_paths) == False


def test_should_ignore_path_keeping_higher_priority_to_ones_defined_as_not_to_ignore_D():
ignore_paths = ["/", "!myFolder/**", "myFolder/subFolder/**"]
assert should_ignore_path("myFolder/file.txt", ignore_paths) == False
assert should_ignore_path("myFolder/subFolder", ignore_paths) == False
assert should_ignore_path("myFolder/subFolder/file.txt", ignore_paths) == False
assert should_ignore_path("myFolder/anotherSubFolder", ignore_paths) == False
assert should_ignore_path("myFolder/anotherSubFolder/file.txt", ignore_paths) == False
assert (
should_ignore_path("myFolder/anotherSubFolder/file.txt", ignore_paths) == False
)
assert should_ignore_path("otherFolder", ignore_paths) == True
assert should_ignore_path("otherFolder/file.txt", ignore_paths) == True
assert should_ignore_path("otherFolder/file.txt", ignore_paths) == True

0 comments on commit 9fe5880

Please sign in to comment.