Skip to content

Commit 3e667d9

Browse files
fix: ensure --allow-self-signed works when placed before subcommand
The cli() function needs to accept the allow_self_signed parameter to handle the case where --allow-self-signed is placed before the subcommand (e.g., 'ggshield --allow-self-signed api-status'). Without this, the callback can't update the config at that stage because ctx.obj is None, breaking backward compatibility. Added test to verify both placements work: - ggshield api-status --allow-self-signed ✓ - ggshield --allow-self-signed api-status ✓ Issue: SCRT-5952
1 parent 9deb1cf commit 3e667d9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

ggshield/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def exit_code(ctx: click.Context, exit_code: int, **kwargs: Any) -> int:
8181
def cli(
8282
ctx: click.Context,
8383
*,
84+
allow_self_signed: Optional[bool],
8485
insecure: Optional[bool],
8586
config_path: Optional[Path],
8687
**kwargs: Any,
@@ -100,8 +101,8 @@ def cli(
100101
# Update SSL verification settings in the config
101102
# TODO: this should be reworked: if a command which writes the config is called with
102103
# --insecure, the config will contain `insecure: true`.
103-
if insecure:
104-
user_config.insecure = insecure
104+
if insecure or allow_self_signed:
105+
user_config.insecure = True
105106

106107
ctx_obj.config._dotenv_vars = load_dot_env()
107108

tests/unit/cmd/test_status.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ def test_ssl_verify(cli_fs_runner, verify):
135135
assert kwargs["session"].verify == verify
136136

137137

138+
@pytest.mark.parametrize(
139+
"cmd",
140+
[
141+
["api-status", "--allow-self-signed"],
142+
["--allow-self-signed", "api-status"],
143+
],
144+
)
145+
def test_allow_self_signed_backward_compatibility(cli_fs_runner, cmd):
146+
"""
147+
GIVEN the deprecated --allow-self-signed flag
148+
WHEN it's placed before or after the subcommand
149+
THEN SSL verification is disabled in both cases (backward compatibility)
150+
"""
151+
with mock.patch("ggshield.core.client.GGClient") as client_mock:
152+
cli_fs_runner.invoke(cli, cmd)
153+
_, kwargs = client_mock.call_args
154+
assert kwargs["session"].verify is False
155+
156+
138157
@pytest.mark.parametrize("command", ["api-status", "quota"])
139158
def test_instance_option(cli_fs_runner, command):
140159
"""

0 commit comments

Comments
 (0)