Files
CTF-tool/tests/test_helpers.py

32 lines
1.0 KiB
Python

# tests/test_helpers.py
from ctf.helpers import check_for_flag
# {{{ test_check_for_flag
def test_check_for_flag():
"""
Verifies that check_for_flag extracts multiple matching flags or returns empty list.
"""
res = check_for_flag("flag{one} and flag{two}")
assert set(res) == {"flag{one}", "flag{two}"}
res_custom = check_for_flag("custom{first} custom{second}", r"custom\{[a-z]+\}")
assert set(res_custom) == {"custom{first}", "custom{second}"}
assert check_for_flag("no flag matches here") == []
# }}}
# {{{ test_is_valid_flag
def test_is_valid_flag():
"""
Verifies that is_valid_flag validates flags and supports uniqueness checks.
"""
from ctf.helpers import is_valid_flag
# Valid flag
assert is_valid_flag("flag{test}")
# Invalid flag
assert not is_valid_flag("no flag here")
# Uniqueness check (success)
assert is_valid_flag("flag{new}", original="flag{old}")
# Uniqueness check (failure)
assert not is_valid_flag("flag{same}", original="flag{same}")
# }}}