Skip to content

FIX: Reject explicitly supplied --config-file paths that do not exist - #3767

Merged
Roman Lutz (romanlutz) merged 3 commits into
microsoft:mainfrom
Kiddo4993:fix/issue-3706
Nov 1, 2026
Merged

Roman Lutz (romanlutz) merged 3 commits into
microsoft:mainfrom
Kiddo4993:fix/issue-3706

Conversation

@Kiddo4993

Copy link
Copy Markdown
Contributor

Resolves #3706.

Problem

If you passed a --config-file path that doesn't exist, the CLI dropped it without saying anything and carried on with defaults. A typo could therefore leave pyrit_scan or pyrit_shell pointed at an unintended server or auth mode. For example, pyrit_scan list-targets --config-file /does/not/exist.yaml ... exited 0.

Change

  • pyrit/cli/_config_reader.py: added a small _resolve_config_paths helper. read_server_settings (and so read_server_url) and validate_client_config now use it instead of each building the path list themselves.
    • The auto-discovered default ~/.pyrit/.pyrit_conf is still optional.
    • An explicitly supplied config_file that doesn't exist now raises ConfigError("Config file <path> does not exist.").
  • Updated the ConfigError docstring and the Raises: sections to match.

Both pyrit_scan.main and pyrit_shell.main already call validate_client_config before doing anything else, and they already catch ConfigError, print Error: ... to stderr and return 1. The new error is reported the same way as the existing malformed-config error.

Tests

  • tests/unit/cli/test_config_reader.py: the two tests that asserted a missing path is silently ignored now pass config_file=None. They still check that a missing default file is fine. New tests check that a missing explicit config raises in read_server_url, read_server_settings (even when a valid default exists) and validate_client_config.
  • tests/unit/cli/test_pyrit_scan.py: added test_main_missing_config_is_hard_error, modelled on the existing malformed-config test. It checks for exit code 1 and the message on stderr.
  • tests/unit/cli/test_pyrit_shell.py: test_main_log_level_and_config_file passed a path that didn't exist. It now creates that file first so the test still covers what it was meant to.

I couldn't run the test suite in this environment, so these tests have not been run.

Fixes #3706


Happy to adjust anything or close it if it isn't a fit.

@romanlutz Roman Lutz (romanlutz) self-assigned this Nov 1, 2026
Comment thread tests/unit/cli/test_pyrit_shell.py Resolved
Assert missing explicit config paths fail before the banner or shell is initialized, with and without a default config and with server/auth overrides.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Nov 1, 2026
Merged via the queue into microsoft:main with commit b47f847 Nov 1, 2026
64 of 65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reject explicitly missing config files instead of silently using defaults

2 participants