From a466ca273dcc7801f5d46935af019dc9768a9835 Mon Sep 17 00:00:00 2001 From: Sebastian Obregoso Date: Thu, 4 Jul 2024 16:14:48 +0200 Subject: [PATCH 1/3] fix default option when no rule is provided --- guarddog/cli.py | 8 ++++++-- tests/core/test_cli.py | 13 +++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/guarddog/cli.py b/guarddog/cli.py index 8e2cddfa..d41c66f9 100644 --- a/guarddog/cli.py +++ b/guarddog/cli.py @@ -153,8 +153,12 @@ def cli(log_level): pass -def _get_rule_param(rules: tuple[str, ...], exclude_rules: tuple[str, ...], ecosystem: ECOSYSTEM) -> set: - rule_param = set() +def _get_rule_param(rules: tuple[str, ...], exclude_rules: tuple[str, ...], ecosystem: ECOSYSTEM) -> Optional[set]: + """ + This function should return None if no rules are provided + Else a set of rules to be used for scanning + """ + rule_param = None if len(rules) > 0: rule_param = set(rules) diff --git a/tests/core/test_cli.py b/tests/core/test_cli.py index 5b6d8788..f2c1b85b 100644 --- a/tests/core/test_cli.py +++ b/tests/core/test_cli.py @@ -24,13 +24,22 @@ def test_get_rule_param_include(): """ Test the parsing function returns the included parameter """ - assert len(guarddog.cli._get_rule_param(("shady-links",), (), ECOSYSTEM.NPM)) == 1 - + rules = guarddog.cli._get_rule_param(("shady-links",), (), ECOSYSTEM.NPM) + assert rules + assert len(rules) == 1 def test_get_rule_param_exclude(): """ Test the parsing function returns returns a list without the excluded parameter """ rules = guarddog.cli._get_rule_param((), ("shady-links",), ECOSYSTEM.PYPI) + assert rules assert len(rules) != 1 assert "shady-links" not in rules + +def test_get_rule_param_empty(): + """ + Test the parsing function returns returns a list without the excluded parameter + """ + rules = guarddog.cli._get_rule_param((), (), ECOSYSTEM.PYPI) + assert rules is None From 6bd9b2667d0acfb61d6e0be42ddefd3a8f4d2efe Mon Sep 17 00:00:00 2001 From: Sebastian Obregoso Date: Thu, 4 Jul 2024 16:18:28 +0200 Subject: [PATCH 2/3] format --- guarddog/cli.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/guarddog/cli.py b/guarddog/cli.py index d41c66f9..a501e1ab 100644 --- a/guarddog/cli.py +++ b/guarddog/cli.py @@ -4,11 +4,11 @@ Includes rules based on package registry metadata and source code analysis. """ +import json as js import logging import os import sys -from typing import cast, Optional -import json as js +from typing import Optional, cast import click from prettytable import PrettyTable @@ -153,7 +153,9 @@ def cli(log_level): pass -def _get_rule_param(rules: tuple[str, ...], exclude_rules: tuple[str, ...], ecosystem: ECOSYSTEM) -> Optional[set]: +def _get_rule_param( + rules: tuple[str, ...], exclude_rules: tuple[str, ...], ecosystem: ECOSYSTEM +) -> Optional[set]: """ This function should return None if no rules are provided Else a set of rules to be used for scanning From 6f414ec7a5fb64036adef7f206104ced44370250 Mon Sep 17 00:00:00 2001 From: Sebastian Obregoso Date: Thu, 4 Jul 2024 16:20:25 +0200 Subject: [PATCH 3/3] improving comments --- tests/core/test_cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/core/test_cli.py b/tests/core/test_cli.py index f2c1b85b..404bc754 100644 --- a/tests/core/test_cli.py +++ b/tests/core/test_cli.py @@ -30,7 +30,7 @@ def test_get_rule_param_include(): def test_get_rule_param_exclude(): """ - Test the parsing function returns returns a list without the excluded parameter + Test the parsing function returns a list without the excluded parameter """ rules = guarddog.cli._get_rule_param((), ("shady-links",), ECOSYSTEM.PYPI) assert rules @@ -39,7 +39,7 @@ def test_get_rule_param_exclude(): def test_get_rule_param_empty(): """ - Test the parsing function returns returns a list without the excluded parameter + Test the parsing function returns None when no rules are provided """ rules = guarddog.cli._get_rule_param((), (), ECOSYSTEM.PYPI) assert rules is None