Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with deps CLI flags #2087

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading