-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from CrowdStrike/rtr-filters
RTR Filter and Code Coverage
- Loading branch information
Showing
10 changed files
with
313 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"""Caracara Filters: RTR Dialect. | ||
This module contains filters that are specific to the RTR API. | ||
""" | ||
from functools import partial | ||
from typing import Any, Dict | ||
|
||
from caracara_filters.dialects._base import default_filter | ||
from caracara_filters.dialects._base import rebase_filters_on_default | ||
from caracara_filters.validators import options_validator | ||
|
||
|
||
RTR_COMMANDS = [ | ||
"cat", | ||
"cd", | ||
"clear", | ||
"cp", | ||
"csrutil", | ||
"cswindiag", | ||
"encrypt", | ||
"env", | ||
"eventlog", | ||
"filehash", | ||
"get", | ||
"getsid", | ||
"history", | ||
"ifconfig", | ||
"ipconfig", | ||
"kill", | ||
"ls", | ||
"map", | ||
"memdump", | ||
"mkdir", | ||
"mount", | ||
"mv", | ||
"netstat", | ||
"ps", | ||
"put", | ||
"put-and-run", | ||
"reg", | ||
"restart", | ||
"rm", | ||
"run", | ||
"runscript", | ||
"shutdown", | ||
"tar", | ||
"umount", | ||
"unmap", | ||
"update", | ||
"users", | ||
"xmemdump", | ||
"zip", | ||
] | ||
|
||
rtr_base_command_filter = { | ||
"fql": "base_command", | ||
"validator": partial(options_validator, RTR_COMMANDS, case_sensitive=False), | ||
"help": "Filter RTR audit logs by base command.", | ||
} | ||
|
||
RTR_FILTERS: Dict[str, Dict[str, Any]] = { | ||
"basecommand": rtr_base_command_filter, | ||
"command": rtr_base_command_filter, | ||
} | ||
|
||
rebase_filters_on_default(default_filter, RTR_FILTERS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "caracara-filters" | ||
version = "0.1.0" | ||
version = "0.1.1" | ||
description = "FQL generation engine for Caracara" | ||
authors = ["Chris Hammond <[email protected]>"] | ||
license = "MIT" | ||
|
@@ -32,9 +32,10 @@ classifiers = [ | |
python = "^3.7.2" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
coverage = "^7.0" | ||
flake8 = "^5.0" | ||
pydocstyle = "^6.3.0" | ||
freezegun = "^1.2.2" | ||
pydocstyle = "^6.3.0" | ||
pylint = "^2.17.5" | ||
pytest = "^7.4.0" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import pytest | ||
|
||
from caracara_filters import FQLGenerator | ||
|
||
|
||
def test_non_existent_dialect(): | ||
with pytest.raises(ValueError): | ||
FQLGenerator(dialect='not a module') | ||
|
||
|
||
def test_filter_delete_real_id(): | ||
fql_generator = FQLGenerator(dialect='base') | ||
filter_id = fql_generator.create_new_filter("name", "testtest") | ||
fql = fql_generator.get_fql() | ||
assert fql == "name: 'testtest'" | ||
assert filter_id is not None | ||
fql_generator.remove_filter(filter_id) | ||
assert fql_generator.filters == {} | ||
|
||
|
||
def test_filter_delete_bad_id(): | ||
fql_generator = FQLGenerator() | ||
with pytest.raises(KeyError): | ||
fql_generator.remove_filter("non-existent-filter-id") | ||
|
||
|
||
def test_bad_data_type(): | ||
fql_generator = FQLGenerator(dialect='base') | ||
with pytest.raises(TypeError): | ||
fql_generator.create_new_filter("name", 123) | ||
|
||
|
||
def test_nullable_filter(): | ||
# TODO: write a test here once we have a nullable filter defined | ||
# (and validation logic to handle this) | ||
pass | ||
|
||
|
||
def test_bool_filter(): | ||
# TODO: write a test once we have a boolean filter defined | ||
pass | ||
|
||
|
||
def test_str_dunder(): | ||
fql_generator = FQLGenerator(dialect='base') | ||
fql_generator.create_new_filter("name", "testname") | ||
fql = fql_generator.get_fql() | ||
assert fql == str(fql_generator) | ||
assert fql == "name: 'testname'" |
Oops, something went wrong.