Skip to content

Commit

Permalink
fix None type scenario in get_actions_for_service (#246)
Browse files Browse the repository at this point in the history
* fix NoneType error in get_actions_for_service
  • Loading branch information
reetasingh committed Oct 12, 2020
1 parent 2cf8f66 commit fa55d7c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions policy_sentry/querying/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def get_actions_for_service(service_prefix):
"""
service_prefix_data = get_service_prefix_data(service_prefix)
results = []
for item in service_prefix_data["privileges"]:
results.append(f"{service_prefix}:{item}")
if isinstance(service_prefix_data, dict):
for item in service_prefix_data["privileges"]:
results.append(f"{service_prefix}:{item}")
return results


Expand Down
7 changes: 7 additions & 0 deletions test/querying/test_query_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ def test_get_actions_for_service(self):
# old: 0.021s
# this one: 0.005s

def test_get_actions_for_invalid_service(self):
"""querying.actions.get_actions_for_service
for invalid service
"""
output = get_actions_for_service("invalid_service")
self.assertListEqual([], output)

def test_get_privilege_info(self):
expected_results_file = os.path.abspath(
os.path.join(
Expand Down

0 comments on commit fa55d7c

Please sign in to comment.