Skip to content

Commit

Permalink
Merge pull request #38 from frack113/double_e
Browse files Browse the repository at this point in the history
Fix check exclude option
  • Loading branch information
thomaspatzke committed Dec 9, 2023
2 parents f1dc6db + 99efd4d commit 877aad4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
22 changes: 17 additions & 5 deletions sigma/cli/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
)
@click.option(
"--exclude",
"-e",
"-x",
default=[],
show_default=True,
multiple=True,
Expand All @@ -68,13 +68,25 @@ def check(
if (
validation_config is None
): # no validation config provided, use basic config with all validators
if exclude:
click.echo(f"Ignoring these validators: {exclude}")
exclude_lower = [excluded.lower() for excluded in exclude]
exclude_invalid = [
excluded for excluded in exclude_lower if excluded not in validators.keys()
]
exclude_valid = [
excluded for excluded in exclude_lower if excluded not in exclude_invalid
]

if len(exclude_invalid) > 0:
click.echo(
f"Invalid validators name : {exclude_invalid} use 'sigma list validators'"
)
if len(exclude_valid) > 0:
click.echo(f"Ignoring these validators : {exclude_valid}'")

validators_filtered = [
validator
for validator in validators.values()
if validator.__name__.lower() not in exclude_lower
for name, validator in validators.items()
if name.lower() not in exclude_valid
]
rule_validator = SigmaValidator(validators_filtered)
else:
Expand Down
26 changes: 17 additions & 9 deletions tests/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,22 @@ def test_check_fail_on_issues():

def test_check_exclude():
cli = CliRunner()
result = cli.invoke(check, ["--fail-on-issues",
"--exclude",
"InvalidRelatedTypeValidator",
"--exclude",
"StatusExistenceValidator",
"--exclude",
"DateExistenceValidator",
"tests/files/issues/sigma_rule_with_bad_references.yml"])
result = cli.invoke(
check,
[
"--fail-on-issues",
"--exclude",
"Invalid_Related_Type",
"--exclude",
"status_existence",
"-x",
"date_existence",
"--exclude",
"MyValidator",
"tests/files/issues/sigma_rule_with_bad_references.yml",
],
)
assert result.exit_code == 0
assert "Invalid validators name" in result.stdout
assert "myvalidator" in result.stdout
assert "Ignoring these validators" in result.stdout
assert "InvalidRelatedTypeValidator" in result.stdout

0 comments on commit 877aad4

Please sign in to comment.