Update test suite for FlagDetectorStream and remove old flag-detect command

This commit is contained in:
venus
2026-07-18 02:21:38 -05:00
parent 24ce48610d
commit 817f70e925
2 changed files with 46 additions and 38 deletions

View File

@@ -16,3 +16,47 @@ def test_main_entry_point_help():
# Verify it exits with a successful exit code (0)
assert exc_info.value.code == 0
def test_flag_detector_stream_detection():
"""
Verifies that FlagDetectorStream successfully intercepts writes to output potential flags.
"""
from io import StringIO
from ctf.main import FlagDetectorStream
out = StringIO()
stream = FlagDetectorStream(out, r"flag\{[a-z_]+\}")
stream.write("Some text before flag{my_flag_here} and text after.")
output = out.getvalue()
assert "Potential flag(s) detected in command output" in output
assert "flag{my_flag_here}" in output
def test_flag_detector_stream_anchored_stripping():
"""
Verifies that FlagDetectorStream strips standard anchors ^ and $ to support substring searches.
"""
from io import StringIO
from ctf.main import FlagDetectorStream
out = StringIO()
stream = FlagDetectorStream(out, r"^flag\{[a-z_]+\}$")
stream.write("random flag{my_flag_here} data")
output = out.getvalue()
assert "Potential flag(s) detected in command output" in output
assert "flag{my_flag_here}" in output
def test_flag_detector_stream_no_pattern():
"""
Verifies that FlagDetectorStream passes through text unmodified if no flag pattern is configured.
"""
from io import StringIO
from ctf.main import FlagDetectorStream
out = StringIO()
stream = FlagDetectorStream(out, "")
stream.write("normal output flag{hello}")
assert out.getvalue() == "normal output flag{hello}"