Skip to content

Commit

Permalink
Merge pull request #2087 from blacklanternsecurity/misc-bugfixes
Browse files Browse the repository at this point in the history
Fix bug with deps CLI flags
  • Loading branch information
TheTechromancer authored Dec 17, 2024
2 parents 5bd7682 + 6aa0e28 commit 1078d47
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
23 changes: 13 additions & 10 deletions bbot/scanner/preset/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,17 @@ def preset_from_args(self):
args_preset.core.merge_custom({"modules": {"stdout": {"event_types": self.parsed.event_types}}})

# dependencies
deps_config = args_preset.core.custom_config.get("deps", {})
if self.parsed.retry_deps:
args_preset.core.custom_config["deps_behavior"] = "retry_failed"
deps_config["behavior"] = "retry_failed"
elif self.parsed.force_deps:
args_preset.core.custom_config["deps_behavior"] = "force_install"
deps_config["behavior"] = "force_install"
elif self.parsed.no_deps:
args_preset.core.custom_config["deps_behavior"] = "disable"
deps_config["behavior"] = "disable"
elif self.parsed.ignore_failed_deps:
args_preset.core.custom_config["deps_behavior"] = "ignore_failed"
deps_config["behavior"] = "ignore_failed"
if deps_config:
args_preset.core.merge_custom({"deps": deps_config})

# other scan options
if self.parsed.name is not None:
Expand Down Expand Up @@ -295,6 +298,12 @@ def create_parser(self, *args, **kwargs):
)

output = p.add_argument_group(title="Output")
output.add_argument(
"-o",
"--output-dir",
help="Directory to output scan results",
metavar="DIR",
)
output.add_argument(
"-om",
"--output-modules",
Expand All @@ -304,12 +313,6 @@ def create_parser(self, *args, **kwargs):
metavar="MODULE",
)
output.add_argument("-lo", "--list-output-modules", action="store_true", help="List available output modules")
output.add_argument(
"-o",
"--output-dir",
help="Directory to output scan results",
metavar="DIR",
)
output.add_argument("--json", "-j", action="store_true", help="Output scan data in JSON format")
output.add_argument("--brief", "-br", action="store_true", help="Output only the data itself")
output.add_argument("--event-types", nargs="+", default=[], help="Choose which event types to display")
Expand Down
2 changes: 1 addition & 1 deletion bbot/scanner/preset/preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ def to_dict(self, include_target=False, full_config=False, redact_secrets=False)
# misc scan options
if self.scan_name:
preset_dict["scan_name"] = self.scan_name
if self.scan_name:
if self.scan_name and self.output_dir is not None:
preset_dict["output_dir"] = self.output_dir

# conditions
Expand Down
17 changes: 16 additions & 1 deletion bbot/test/test_step_1/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import yaml

from ..bbot_fixtures import *

from bbot import cli
Expand Down Expand Up @@ -143,6 +145,20 @@ async def test_cli_args(monkeypatch, caplog, capsys, clean_default_config):
assert len(out.splitlines()) == 1
assert out.count(".") > 1

# deps behavior
monkeypatch.setattr("sys.argv", ["bbot", "-n", "depstest", "--retry-deps", "--current-preset"])
result = await cli._main()
assert result is None
out, err = capsys.readouterr()
print(out)
# parse YAML output
preset = yaml.safe_load(out)
assert preset == {
"description": "depstest",
"scan_name": "depstest",
"config": {"deps": {"behavior": "retry_failed"}},
}

# list modules
monkeypatch.setattr("sys.argv", ["bbot", "--list-modules"])
result = await cli._main()
Expand Down Expand Up @@ -401,7 +417,6 @@ async def test_cli_args(monkeypatch, caplog, capsys, clean_default_config):
async def test_cli_customheaders(monkeypatch, caplog, capsys):
monkeypatch.setattr(sys, "exit", lambda *args, **kwargs: True)
monkeypatch.setattr(os, "_exit", lambda *args, **kwargs: True)
import yaml

# test custom headers
monkeypatch.setattr(
Expand Down

0 comments on commit 1078d47

Please sign in to comment.