Skip to content

Commit

Permalink
fixed unit tests that were failing in pypanther
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-githubs committed Aug 22, 2024
1 parent 77f83ed commit 254fa34
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 3 additions & 0 deletions global_helpers/crowdstrike_event_streams_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def audit_keys_dict(event):
def str_to_list(liststr: str) -> list[str]:
"""Several crowdstrike values are returned as a list like "[x y z]". This function convetrs
such entries to Python list of strings, like: ["x", "y", "z"]."""
# Return empty list for empty string
if not liststr:
return []
# Validate
if liststr[0] != "[" or liststr[-1] != "]":
raise ValueError(f"Invalid list string: {liststr}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ def getlist(key: str):
case "CreateAllowlistGroup":
added_cidrs = str_to_list(audit_keys.get("cidrs", []))
added_contexts = str_to_list(audit_keys.get("contexts", []))
case _:
# Raise error if there's another operationname
# This is in case we update the rule logic but forget to update this logic too
raise ValueError(f"Unepected Operation Name: {op_name}")

context.update(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ def title(event):

# contexts_str: one of API, UI, or API & UI
# Also a more general case: API, UI, and XX (for if they add extra contexts in the future)
contexts = str_to_list(audit_keys_dict(event)["contexts"])
if len(contexts) == 1:
contexts = str_to_list(audit_keys_dict(event).get("contexts", ""))
if len(contexts) == 0:
contexts_str = "no contexts"
elif len(contexts) == 1:
contexts_str = contexts[0]
else:
contexts_str = ", ".join(contexts[:-1]) + " & " + contexts[-1]
Expand Down

0 comments on commit 254fa34

Please sign in to comment.