From c879e55ce3b6243a2ab4d09aebc71e9db26d699b Mon Sep 17 00:00:00 2001 From: frack113 <62423083+frack113@users.noreply.github.com> Date: Fri, 8 Dec 2023 20:16:50 +0100 Subject: [PATCH 1/3] Fix check exclude option --- sigma/cli/check.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sigma/cli/check.py b/sigma/cli/check.py index 7d40465..fed7dbc 100644 --- a/sigma/cli/check.py +++ b/sigma/cli/check.py @@ -49,7 +49,7 @@ ) @click.option( "--exclude", - "-e", + "-x", default=[], show_default=True, multiple=True, @@ -73,8 +73,8 @@ def check( exclude_lower = [excluded.lower() for excluded in exclude] 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_lower ] rule_validator = SigmaValidator(validators_filtered) else: From 51accf1d1a791768b0cfb09e98b3e9746242bf1c Mon Sep 17 00:00:00 2001 From: frack113 <62423083+frack113@users.noreply.github.com> Date: Sat, 9 Dec 2023 08:22:33 +0100 Subject: [PATCH 2/3] Fix exclude option --- sigma/cli/check.py | 18 +++++++++++++++--- tests/test_check.py | 26 +++++++++++++++++--------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/sigma/cli/check.py b/sigma/cli/check.py index fed7dbc..8f7761b 100644 --- a/sigma/cli/check.py +++ b/sigma/cli/check.py @@ -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 validator'" + ) + if len(exclude_valid) > 0: + click.echo(f"Ignoring these validators : {exclude_valid}'") + validators_filtered = [ validator for name, validator in validators.items() - if name.lower() not in exclude_lower + if name.lower() not in exclude_valid ] rule_validator = SigmaValidator(validators_filtered) else: diff --git a/tests/test_check.py b/tests/test_check.py index 02a091e..c9aed7b 100644 --- a/tests/test_check.py +++ b/tests/test_check.py @@ -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 From 99efd4d450b6fdf85718122c4a8ee65cbb2b4da0 Mon Sep 17 00:00:00 2001 From: frack113 <62423083+frack113@users.noreply.github.com> Date: Sat, 9 Dec 2023 08:26:16 +0100 Subject: [PATCH 3/3] Small Typo fix --- sigma/cli/check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sigma/cli/check.py b/sigma/cli/check.py index 8f7761b..a9d410c 100644 --- a/sigma/cli/check.py +++ b/sigma/cli/check.py @@ -78,7 +78,7 @@ def check( if len(exclude_invalid) > 0: click.echo( - f"Invalid validators name : {exclude_invalid} use 'sigma list validator'" + f"Invalid validators name : {exclude_invalid} use 'sigma list validators'" ) if len(exclude_valid) > 0: click.echo(f"Ignoring these validators : {exclude_valid}'")