added a gemini.md file, added some commands to main.py modified readme
and made a forensiscs page
This commit is contained in:
5
tests/env/config.toml
vendored
Normal file
5
tests/env/config.toml
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
[Competition]
|
||||
name = "PersistentComp"
|
||||
|
||||
[Enviroment]
|
||||
data_dir = "/home/venus/code/ctf/tests/env"
|
||||
@@ -1,28 +1,48 @@
|
||||
from pathlib import Path
|
||||
import toml
|
||||
from ctf.utils import load_config
|
||||
from ctf.utils import load_config, active_categories, active_competitions
|
||||
|
||||
def test_load_config_valid_file(tmp_path):
|
||||
# 1. Setup: Create a temporary TOML file
|
||||
config_file = tmp_path / "test_config.toml"
|
||||
# Define the persistent test environment path
|
||||
TEST_ENV = Path("tests/env")
|
||||
|
||||
def test_load_config_static():
|
||||
"""
|
||||
Verifies load_config using the persistent test file.
|
||||
Demonstrates: Reading from a specific relative Path.
|
||||
"""
|
||||
config_file = TEST_ENV / "config.toml"
|
||||
test_data = {
|
||||
"Competition": {"name": "TestComp"},
|
||||
"Environment": {"data_dir": "/tmp/ctf"}
|
||||
"Competition": {"name": "PersistentComp"},
|
||||
"Enviroment": {"data_dir": str(TEST_ENV.absolute())}
|
||||
}
|
||||
with open(config_file, "w") as f:
|
||||
toml.dump(test_data, f)
|
||||
|
||||
# 2. Act: Load the config using our function
|
||||
loaded_data = load_config(str(config_file))
|
||||
|
||||
# 3. Assert: Verify the data matches
|
||||
assert loaded_data["Competition"]["name"] == "TestComp"
|
||||
assert loaded_data["Environment"]["data_dir"] == "/tmp/ctf"
|
||||
assert loaded_data["Competition"]["name"] == "PersistentComp"
|
||||
|
||||
def test_load_config_missing_file():
|
||||
# Act: Try to load a file that doesn't exist
|
||||
loaded_data = load_config("nonexistent_file.toml")
|
||||
def test_active_categories_static():
|
||||
"""
|
||||
Verifies active_categories using the pre-created 'comp1' folder.
|
||||
Demonstrates: Path.iterdir() behavior on a real directory.
|
||||
"""
|
||||
comp_dir = TEST_ENV / "comp1"
|
||||
cats = active_categories(comp_dir)
|
||||
cat_names = [c.name for c in cats]
|
||||
|
||||
# Assert: Should return an empty dictionary
|
||||
assert loaded_data == {}
|
||||
# We expect 'web' and 'pwn' which were created in the setup step
|
||||
assert "web" in cat_names
|
||||
assert "pwn" in cat_names
|
||||
|
||||
def test_active_competitions_static():
|
||||
"""
|
||||
Verifies active_competitions skips the 'tools' folder in TEST_ENV.
|
||||
Demonstrates: Guard clauses and directory filtering.
|
||||
"""
|
||||
# Note: active_competitions takes a string path
|
||||
comps = active_competitions(str(TEST_ENV))
|
||||
comp_names = [p.name for p in comps.keys()]
|
||||
|
||||
assert "comp1" in comp_names
|
||||
assert "comp2" in comp_names
|
||||
assert "tools" not in comp_names # The 'tools' folder exists but should be ignored
|
||||
|
||||
Reference in New Issue
Block a user