Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

CI: Tests need correct repo_path and challenge_path

Kilian Lieret577baa7ad35d
diff --git a/tests/conftest.py b/tests/conftest.py
index d6c70ff6..e52e52d5 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -43,6 +43,13 @@ def test_ctf_trajectories_path(test_data_path) -> Path:
return p
+def ctf_data_path(test_data_sources_path) -> Path:
+ p = test_data_sources_path / "ctf"
+ assert p.is_dir()
+ return p
+
+
@pytest.fixture
def test_data_sources_path(test_data_path) -> Path:
p = test_data_path / "data_sources"
diff --git a/tests/test_data/data_sources/ctf/misc/Networking 1/README.md b/tests/test_data/data_sources/ctf/misc/networking_1/README.md
similarity index 100%
rename from tests/test_data/data_sources/ctf/misc/Networking 1/README.md
rename to tests/test_data/data_sources/ctf/misc/networking_1/README.md
diff --git a/tests/test_data/data_sources/ctf/misc/Networking 1/challenge.json b/tests/test_data/data_sources/ctf/misc/networking_1/challenge.json
similarity index 100%
rename from tests/test_data/data_sources/ctf/misc/Networking 1/challenge.json
rename to tests/test_data/data_sources/ctf/misc/networking_1/challenge.json
diff --git a/tests/test_data/data_sources/ctf/misc/Networking 1/networking.pcap b/tests/test_data/data_sources/ctf/misc/networking_1/networking.pcap
similarity index 100%
rename from tests/test_data/data_sources/ctf/misc/Networking 1/networking.pcap
rename to tests/test_data/data_sources/ctf/misc/networking_1/networking.pcap
diff --git a/tests/test_data/data_sources/ctf/web/I Got Id/000-default.conf b/tests/test_data/data_sources/ctf/web/i_got_id_demo/000-default.conf
similarity index 100%
rename from tests/test_data/data_sources/ctf/web/I Got Id/000-default.conf
rename to tests/test_data/data_sources/ctf/web/i_got_id_demo/000-default.conf
diff --git a/tests/test_data/data_sources/ctf/web/I Got Id/Dockerfile b/tests/test_data/data_sources/ctf/web/i_got_id_demo/Dockerfile
similarity index 100%
rename from tests/test_data/data_sources/ctf/web/I Got Id/Dockerfile
rename to tests/test_data/data_sources/ctf/web/i_got_id_demo/Dockerfile
diff --git a/tests/test_data/data_sources/ctf/web/I Got Id/cgi/file.pl b/tests/test_data/data_sources/ctf/web/i_got_id_demo/cgi/file.pl
similarity index 100%
rename from tests/test_data/data_sources/ctf/web/I Got Id/cgi/file.pl
rename to tests/test_data/data_sources/ctf/web/i_got_id_demo/cgi/file.pl
diff --git a/tests/test_data/data_sources/ctf/web/I Got Id/cgi/forms.pl b/tests/test_data/data_sources/ctf/web/i_got_id_demo/cgi/forms.pl
similarity index 100%
rename from tests/test_data/data_sources/ctf/web/I Got Id/cgi/forms.pl
rename to tests/test_data/data_sources/ctf/web/i_got_id_demo/cgi/forms.pl
diff --git a/tests/test_data/data_sources/ctf/web/I Got Id/cgi/hello.pl b/tests/test_data/data_sources/ctf/web/i_got_id_demo/cgi/hello.pl
similarity index 100%
rename from tests/test_data/data_sources/ctf/web/I Got Id/cgi/hello.pl
rename to tests/test_data/data_sources/ctf/web/i_got_id_demo/cgi/hello.pl
diff --git a/tests/test_data/data_sources/ctf/web/I Got Id/challenge.json b/tests/test_data/data_sources/ctf/web/i_got_id_demo/challenge.json
similarity index 100%
rename from tests/test_data/data_sources/ctf/web/I Got Id/challenge.json
rename to tests/test_data/data_sources/ctf/web/i_got_id_demo/challenge.json
diff --git a/tests/test_data/data_sources/ctf/web/I Got Id/docker-compose.yml b/tests/test_data/data_sources/ctf/web/i_got_id_demo/docker-compose.yml
similarity index 100%
rename from tests/test_data/data_sources/ctf/web/I Got Id/docker-compose.yml
rename to tests/test_data/data_sources/ctf/web/i_got_id_demo/docker-compose.yml
diff --git a/tests/test_data/data_sources/ctf/web/I Got Id/flag b/tests/test_data/data_sources/ctf/web/i_got_id_demo/flag
similarity index 100%
rename from tests/test_data/data_sources/ctf/web/I Got Id/flag
rename to tests/test_data/data_sources/ctf/web/i_got_id_demo/flag
diff --git a/tests/test_data/data_sources/ctf/web/I Got Id/index.html b/tests/test_data/data_sources/ctf/web/i_got_id_demo/index.html
similarity index 100%
rename from tests/test_data/data_sources/ctf/web/I Got Id/index.html
rename to tests/test_data/data_sources/ctf/web/i_got_id_demo/index.html
diff --git a/tests/test_data/data_sources/ctf/web/I Got Id/solution.txt b/tests/test_data/data_sources/ctf/web/i_got_id_demo/solution.txt
similarity index 100%
rename from tests/test_data/data_sources/ctf/web/I Got Id/solution.txt
rename to tests/test_data/data_sources/ctf/web/i_got_id_demo/solution.txt
diff --git a/tests/test_replay_ctf.py b/tests/test_replay_ctf.py
index 327ad3ab..dac60956 100644
--- a/tests/test_replay_ctf.py
+++ b/tests/test_replay_ctf.py
@@ -1,9 +1,18 @@
from __future__ import annotations
+import sys
+
import pytest
from run_replay import get_args, main
+_TEST_OUTPUTS = {
+ "pwn/warmup.traj": r"Closed connection to pwn.chal.csaw.io port 8000\nFLAG{LET_US_BEGIN_CSAW_2016}",
+ "forensics/flash.traj": r"the black flag waved night and day from the",
+ # "web/i_got_id_demo.traj": r"4365",
+ "misc/networking_1.traj": r"Password: \nflag{d316759c281bf925d600be698a4973d5}",
+}
+
@pytest.mark.slow
@pytest.mark.ctf
@@ -11,12 +20,22 @@ from run_replay import get_args, main
"traj_rel_path",
["pwn/warmup.traj", "forensics/flash.traj", "web/i_got_id_demo.traj", "rev/rock.traj", "misc/networking_1.traj"],
)
-def test_ctf_traj_replay(test_ctf_trajectories_path, traj_rel_path):
+def test_ctf_traj_replay(test_ctf_trajectories_path, traj_rel_path, ctf_data_path, capsys):
+ if sys.platform == "darwin" and traj_rel_path in ["pwn/warmup.traj", "rev/rock.traj"]:
+ pytest.skip("Skipping test on macOS")
traj_path = test_ctf_trajectories_path / traj_rel_path
+ challenge_dir = ctf_data_path / traj_rel_path.removesuffix(".traj")
+ assert challenge_dir.is_dir()
+ data_path = challenge_dir / "challenge.json"
+ assert data_path.is_file()
assert traj_path.is_file()
args = [
"--traj_path",
str(traj_path),
+ "--data_path",
+ str(data_path),
+ "--repo_path",
+ str(challenge_dir),
"--config_file",
"config/default_ctf.yaml",
"--raise_exceptions",
@@ -24,3 +43,6 @@ def test_ctf_traj_replay(test_ctf_trajectories_path, traj_rel_path):
]
args, remaining_args = get_args(args)
main(**vars(args), forward_args=remaining_args)
+ captured = capsys.readouterr()
+ if traj_rel_path in _TEST_OUTPUTS:
+ assert _TEST_OUTPUTS[traj_rel_path] in captured.out