Skip to content

Commit

Permalink
Merge pull request #406 from DataDog/s.obregoso/hotfix_rules_assigment
Browse files Browse the repository at this point in the history
Hotfix: No rules are ran by default
  • Loading branch information
sobregosodd authored Jul 4, 2024
2 parents 413e7d0 + 6f414ec commit eef97a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
14 changes: 10 additions & 4 deletions guarddog/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -153,8 +153,14 @@ 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)

Expand Down
15 changes: 12 additions & 3 deletions tests/core/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Test the parsing function 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 None when no rules are provided
"""
rules = guarddog.cli._get_rule_param((), (), ECOSYSTEM.PYPI)
assert rules is None

0 comments on commit eef97a5

Please sign in to comment.