-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fa4030
commit f067cc0
Showing
5 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
CMD:=poetry run | ||
PYMODULE:=ctff | ||
TESTS:=tests | ||
EXTRACODE:= | ||
EXTRACODE:=example | ||
|
||
all: type test format lint | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .main import app | ||
|
||
__all__ = ["app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import Generator | ||
|
||
import pytest | ||
from flask.testing import FlaskClient, FlaskCliRunner | ||
|
||
from ctff import CTFF | ||
from example import app as example_app_instance | ||
|
||
|
||
@pytest.fixture | ||
def example_app() -> Generator[CTFF, None, None]: | ||
yield example_app_instance | ||
|
||
|
||
@pytest.fixture | ||
def client(example_app: CTFF) -> FlaskClient: | ||
return example_app.test_client() | ||
|
||
|
||
@pytest.fixture | ||
def runner(example_app: CTFF) -> FlaskCliRunner: | ||
return example_app.test_cli_runner() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from flask.testing import FlaskClient | ||
|
||
from ctff import CTFF | ||
|
||
|
||
class TestCTFFIndex: | ||
def test_get(self, example_app: CTFF, client: FlaskClient) -> None: | ||
resp = client.get("/") | ||
|
||
assert resp.status_code == 200 | ||
assert example_app.introduction_html in resp.text | ||
assert "This CTF contains 1 categories of challenge." in resp.text | ||
assert '<a href="/basic-challenges">Basic Challenges</a>' in resp.text | ||
|
||
|
||
class TestCTFFChallengeGroup: | ||
def test_get(self, example_app: CTFF, client: FlaskClient) -> None: | ||
resp = client.get("/basic-challenges") | ||
|
||
challenge_group = example_app._challenge_groups[0] | ||
|
||
assert resp.status_code == 200 | ||
assert challenge_group.introduction_html in resp.text | ||
assert f"<h1>{challenge_group.name}</h1>" in resp.text | ||
assert '<a href="/basic-challenges/super-easy">Super Easy</a>' in resp.text | ||
|
||
|
||
class TestCTFFChallenge: | ||
def test_get(self, example_app: CTFF, client: FlaskClient) -> None: | ||
resp = client.get("/basic-challenges/super-easy") | ||
|
||
challenge_group = example_app._challenge_groups[0] | ||
challenge = challenge_group._challenges[0] | ||
|
||
assert resp.status_code == 200 | ||
assert f"<h1>{challenge.title}</h1>" in resp.text # type: ignore[attr-defined] | ||
for part in challenge.parts: # type: ignore[attr-defined] | ||
assert part.render() in resp.text | ||
|
||
def test_post(self, example_app: CTFF, client: FlaskClient) -> None: | ||
resp = client.post("/basic-challenges/super-easy", data={"example": "bees"}) | ||
|
||
challenge_group = example_app._challenge_groups[0] | ||
challenge = challenge_group._challenges[0] | ||
|
||
assert resp.status_code == 200 | ||
assert f"<h1>{challenge.title}</h1>" in resp.text # type: ignore[attr-defined] | ||
assert "You completed the challenge." in resp.text | ||
assert "flag{exampleFlag}" in resp.text | ||
for part in challenge.parts: # type: ignore[attr-defined] | ||
assert part.render() in resp.text | ||
|
||
def test_post_incorrect(self, example_app: CTFF, client: FlaskClient) -> None: | ||
resp = client.post("/basic-challenges/super-easy", data={"example": "wasps"}) | ||
|
||
challenge_group = example_app._challenge_groups[0] | ||
challenge = challenge_group._challenges[0] | ||
|
||
assert resp.status_code == 200 | ||
assert f"<h1>{challenge.title}</h1>" in resp.text # type: ignore[attr-defined] | ||
assert "Incorrect." in resp.text | ||
for part in challenge.parts: # type: ignore[attr-defined] | ||
assert part.render() in resp.text |