Skip to content

Commit

Permalink
Fixes to tests and policies and 0.9.1 version and dependencies bump (#…
Browse files Browse the repository at this point in the history
…221)

* Fixes to tests and IOAs and 0.9.1 version and dependencies bump

* Linter fix

* Fix failing CustomIOA unit test (#223)

---------

Co-authored-by: Atte Niemi <[email protected]>
  • Loading branch information
ChristopherHammond13 and hur authored Nov 13, 2024
1 parent 4d878b5 commit c5f605c
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 50 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ jobs:
- name: Install dependencies
run: poetry install

- name: Run unit tests
run: poetry run py.test tests/unit_tests

- name: Lint package source with flake8
if: success() || failure()
run: |
poetry run flake8 caracara/ --show-source --statistics
poetry run flake8 examples/ --show-source --statistics
Expand Down
4 changes: 2 additions & 2 deletions caracara/common/policy_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def _load_data_dict(self, data_dict: Dict = None):
self.groups.append(GroupAssignment(data_dict=group_dict))

# Load all groups of settings
settings_groups: List[Dict] = data_dict.get(self.settings_key_name)
settings_groups: List[Dict] = data_dict.get(self.settings_key_name, [])
for settings_group_dict in settings_groups:
self.settings_groups.append(PolicySettingGroup(data_dict=settings_group_dict))

Expand Down Expand Up @@ -409,7 +409,7 @@ def flat_dump(self) -> Dict:
"description": self.description,
"name": self.name,
"platform_name": self.platform_name,
"settings": settings,
self.settings_key_name: settings,
}
if self.policy_id:
data["id"] = self.policy_id
Expand Down
1 change: 0 additions & 1 deletion caracara/modules/custom_ioa/custom_ioa.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ def _update_create_delete_rules(self, group: IoaRuleGroup, comment: str) -> IoaR
raw_rule,
rule_type=self._get_rule_types_cached()[raw_rule["ruletype_id"]],
)
new_rule.rulegroup_id = group.id_
new_rules.append(new_rule)
new_group.version += 1

Expand Down
5 changes: 4 additions & 1 deletion caracara/modules/custom_ioa/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ def from_data_dict(data_dict: dict, rule_type_map: Dict[str, RuleType]) -> IoaRu
# The following line might raise an index error if there's a rule type on this rule that
# we don't know about. I don't catch this since I don't think it's likely to happen.
rule_type = rule_type_map[raw_rule["ruletype_id"]]
raw_rule["rulegroup_id"] = rule_group.id_ # API doesn't populate this field, so we do
rule = CustomIoaRule.from_data_dict(data_dict=raw_rule, rule_type=rule_type)
rule_group.rules.append(rule)

Expand Down Expand Up @@ -330,6 +329,7 @@ class CustomIoaRule:
modified_on: datetime
version_ids: List[str]
pattern_id: str
rulegroup_id: str

def __init__(
self,
Expand Down Expand Up @@ -385,6 +385,7 @@ def __init__(
self.modified_on = None
self.version_ids = None
self.pattern_id = None
self.rulegroup_id = None

def __repr__(self):
"""Return an unambiguous string representation of the CustomIoaRule and its properties.
Expand Down Expand Up @@ -441,6 +442,7 @@ def from_data_dict(data_dict: dict, rule_type: RuleType) -> CustomIoaRule:
rule.version_ids = data_dict["version_ids"]
rule.pattern_id = data_dict["pattern_id"]
rule.comment = data_dict["comment"]
rule.rulegroup_id = data_dict["rulegroup_id"]

rule.fields = {}
for field_value in data_dict["field_values"]:
Expand Down Expand Up @@ -622,6 +624,7 @@ def dump(self) -> dict:
"action_label": self.action_label,
"ruletype_id": self.rule_type.id_,
"ruletype_name": self.rule_type.name,
"rulegroup_id": self.rulegroup_id,
"field_values": list(self.fields.values()),
"enabled": self.enabled,
"deleted": self.deleted,
Expand Down
45 changes: 23 additions & 22 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "caracara"
version = "0.9.0"
version = "0.9.1"
description = "The CrowdStrike Falcon Developer Toolkit"
authors = [ "CrowdStrike <[email protected]>" ]
readme = "README.md"
Expand Down
9 changes: 8 additions & 1 deletion tests/unit_tests/test_custom_ioas.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def mock_create_rule(body, comment=None):
"pattern_severity": body["pattern_severity"],
"disposition_id": body["disposition_id"],
"action_label": rule_type.disposition_map[body["disposition_id"]],
"rulegroup_id": "test_group_01",
"ruletype_id": body["ruletype_id"],
"ruletype_name": rule_type.name,
"field_values": body["field_values"],
Expand Down Expand Up @@ -332,6 +333,7 @@ def test_describe_rule_groups_with_rules(
"action_label": list(simple_rule_type.disposition_map.values())[0],
"ruletype_id": simple_rule_type.id_,
"ruletype_name": simple_rule_type.name,
"rulegroup_id": "test_group_01",
"field_values": [],
"enabled": True,
"deleted": False,
Expand Down Expand Up @@ -373,7 +375,6 @@ def mock_query_rule_groups_full(offset, limit, filter):

# Call caracara
groups = client.custom_ioas.describe_rule_groups(filters="test_filter")

assert len(mock_groups) == len(groups)
for mock_group in mock_groups:
assert mock_group["id"] in groups.keys()
Expand Down Expand Up @@ -508,6 +509,7 @@ def test_update_rule_groups_with_rule_changes(
"action_label": list(simple_rule_type.disposition_map.values())[0],
"ruletype_id": simple_rule_type.id_,
"ruletype_name": simple_rule_type.name,
"rulegroup_id": "test_group_01",
"field_values": [],
"enabled": True,
"deleted": False,
Expand All @@ -532,6 +534,7 @@ def test_update_rule_groups_with_rule_changes(
"action_label": list(simple_rule_type.disposition_map.values())[0],
"ruletype_id": simple_rule_type.id_,
"ruletype_name": simple_rule_type.name,
"rulegroup_id": "test_group_01",
"field_values": [],
"enabled": True,
"deleted": False,
Expand Down Expand Up @@ -617,6 +620,7 @@ def mock_create_rule(body):
"action_label": list(simple_rule_type.disposition_map.values())[0],
"ruletype_id": body["ruletype_id"],
"ruletype_name": simple_rule_type.name,
"rulegroup_id": "test_group_01",
"field_values": body["field_values"],
"enabled": False,
"deleted": False,
Expand Down Expand Up @@ -735,6 +739,7 @@ def test_update_rule_group_with_new_rules(
"action_label": list(simple_rule_type.disposition_map.values())[0],
"ruletype_id": simple_rule_type.id_,
"ruletype_name": simple_rule_type.name,
"rulegroup_id": "test_group_01",
"field_values": [],
"enabled": True,
"deleted": False,
Expand All @@ -759,6 +764,7 @@ def test_update_rule_group_with_new_rules(
"action_label": list(simple_rule_type.disposition_map.values())[0],
"ruletype_id": simple_rule_type.id_,
"ruletype_name": simple_rule_type.name,
"rulegroup_id": "test_group_01",
"field_values": [],
"enabled": True,
"deleted": False,
Expand Down Expand Up @@ -808,6 +814,7 @@ def mock_create_rule(body):
"action_label": list(simple_rule_type.disposition_map.values())[0],
"ruletype_id": body["ruletype_id"],
"ruletype_name": simple_rule_type.name,
"rulegroup_id": "test_group_01",
"field_values": body["field_values"],
"enabled": False,
"deleted": False,
Expand Down
Loading

0 comments on commit c5f605c

Please sign in to comment.