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

@@ -5,7 +5,7 @@ import stat
import sys
from click.testing import CliRunner
from ctf.utils import load_config, active_categories
from ctf.forensics import get_metadata, get_flag_strings
from ctf.forensics import get_metadata
from ctf.cli_forensics import forensics_group, inspect
# Define the persistent test environment path
@@ -269,42 +269,6 @@ def test_forensics_signatures_cli():
assert "PNG Image" in result.output
assert "89504E47" in result.output
def test_forensics_flag_detect_cli_found():
"""
Verifies that 'forensics flag-detect' successfully finds flag patterns.
"""
runner = CliRunner()
test_file = TEST_ENV / "flag_data.bin"
with open(test_file, "wb") as f:
f.write(b"random_data_here_flag{found_statically_in_file}more_data")
result = runner.invoke(forensics_group, ["flag-detect", str(test_file)])
assert result.exit_code == 0
assert "Potential Flag(s) Found" in result.output
assert "flag{found_statically_in_file}" in result.output
# (Old flag-detect tests removed)
def test_forensics_flag_detect_cli_not_found():
"""
Verifies that 'forensics flag-detect' displays 'No flag patterns found.'
when no flag matches the pattern.
"""
runner = CliRunner()
test_file = TEST_ENV / "clean_data.bin"
with open(test_file, "wb") as f:
f.write(b"this is a completely normal text file without flags.")
result = runner.invoke(forensics_group, ["flag-detect", str(test_file)])
assert result.exit_code == 0
assert "No flag patterns found" in result.output
def test_get_flag_strings_pure():
"""
Verifies that get_flag_strings extracts expected strings and matching flags directly.
"""
test_file = TEST_ENV / "pure_flag_data.bin"
with open(test_file, "wb") as f:
f.write(b"pre_flag{hello_world_1337}post_stuff")
flags = get_flag_strings(test_file, r"flag\{[a-z_0-9]+\}")
assert flags == ["flag{hello_world_1337}"]