Add test case verifying exemption of flag command from stdout matching
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user