docs/test: add tests and documentation for competition-aware patterns and commands

This commit is contained in:
venus
2026-07-17 02:18:55 -05:00
parent 9e91f8ef0f
commit f2b349c42d
5 changed files with 243 additions and 7 deletions

View File

@@ -101,3 +101,52 @@ def test_basic_set_flag_format_validation_cli():
assert result3.exit_code != 0
assert "Original flag cannot be empty or whitespace only." in result3.output
def test_basic_set_competition_cli():
"""
Verifies that 'basic set-competition' updates the competition name in config.toml.
"""
from ctf.utils import load_config
runner = CliRunner()
config_file = Path("/home/venus/code/ctf/config.toml")
original_config = load_config(str(config_file))
try:
result = runner.invoke(basic_group, ["set-competition", "CyberCTF2026"])
assert result.exit_code == 0
assert "Competition name set to: CyberCTF2026" in result.output
updated_config = load_config(str(config_file))
assert updated_config["Competition"]["competition"] == "CyberCTF2026"
finally:
from ctf.utils import write_config
write_config(original_config, str(config_file))
def test_basic_set_flag_format_warning_cli():
"""
Verifies that if competition name is set and not present in the example flag,
set-flag-format outputs a warning.
"""
from ctf.utils import load_config, write_config
runner = CliRunner()
config_file = Path("/home/venus/code/ctf/config.toml")
original_config = load_config(str(config_file))
try:
# Set competition name first
temp_config = load_config(str(config_file))
if "Competition" not in temp_config:
temp_config["Competition"] = {}
temp_config["Competition"]["competition"] = "SECURE"
write_config(temp_config, str(config_file))
# Now run set-flag-format with an example flag that has no "SECURE" substring
# We also pass input "1" to satisfy the choice prompt
result = runner.invoke(basic_group, ["set-flag-format", "-o", "CTF{easy_flag_123}"], input="1\n")
assert result.exit_code == 0
assert "Warning: Current competition name 'SECURE' was not found in the example flag." in result.output
finally:
write_config(original_config, str(config_file))