From 8274d08f3edddb78d1aceaf0a17c56dd3e82ab96 Mon Sep 17 00:00:00 2001 From: venus Date: Sat, 18 Jul 2026 02:37:43 -0500 Subject: [PATCH] Add test case verifying exemption of flag command from stdout matching --- tests/test_main.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/test_main.py b/tests/test_main.py index 4a68d53..efe816e 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -117,4 +117,40 @@ def test_flag_cmd_cli(): finally: write_config(original_config, str(config_file)) +def test_flag_cmd_exemption(capsys): + """ + Verifies that running ctf flag is exempted from triggering the stdout flag warning box. + """ + from ctf.main import main + from ctf.utils import load_config, write_config + from pathlib import Path + import sys + from unittest.mock import patch + import pytest + + config_file = Path("/home/venus/code/ctf/config.toml") + original_config = load_config(str(config_file)) + + try: + temp_config = load_config(str(config_file)) + if "Competition" not in temp_config: + temp_config["Competition"] = {} + temp_config["Competition"]["flag_format"] = r"flag\{[a-z_]+\}" + temp_config["Competition"]["last_flag"] = "flag{test_exempt_flag}" + write_config(temp_config, str(config_file)) + + with patch.object(sys, "argv", ["ctf", "flag"]): + with pytest.raises(SystemExit) as exc_info: + main() + assert exc_info.value.code == 0 + + captured = capsys.readouterr() + # Verify that the warning box is NOT in stdout + assert "Potential flag(s) detected in command output" not in captured.out + # Verify that the actual flag info IS printed + assert "Last detected flag: flag{test_exempt_flag}" in captured.out + finally: + write_config(original_config, str(config_file)) + +