Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ctfcli/core/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def create(self, ignore: tuple[str] = ()) -> None:
if not self.get("name", False):
raise InvalidChallengeDefinition("Challenge does not provide a name")

if not self.get("value", False) and self.get("type", "standard") != "dynamic":
if self.get("value") is None and self.get("type", "standard") != "dynamic":
raise InvalidChallengeDefinition("Challenge does not provide a value")

ctx = PropertyContext(self, ignore=ignore)
Expand Down
23 changes: 23 additions & 0 deletions tests/core/test_challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from ctfcli.core.challenge import Challenge
from ctfcli.core.exceptions import (
InvalidChallengeDefinition,
InvalidChallengeFile,
LintException,
RemoteChallengeNotFound,
Expand Down Expand Up @@ -2096,6 +2097,28 @@ def mock_post(*args, **kwargs):
mock_api.get.assert_not_called()
mock_api.delete.assert_not_called()

@mock.patch("ctfcli.core.challenge.API")
def test_creates_challenge_with_zero_value(self, mock_api_constructor: MagicMock, *args, **kwargs):
challenge = Challenge(self.minimal_challenge, {"value": 0})

mock_api: MagicMock = mock_api_constructor.return_value
mock_api.post.return_value.json.return_value = {"success": True, "data": {"id": 3}}

challenge.create()

mock_api.post.assert_called_once_with("/api/v1/challenges", json=ANY)
self.assertEqual(mock_api.post.call_args.kwargs["json"]["value"], 0)

@mock.patch("ctfcli.core.challenge.API")
def test_does_not_create_challenge_without_value(self, mock_api_constructor: MagicMock, *args, **kwargs):
challenge = Challenge(self.minimal_challenge, {"value": None})

with self.assertRaises(InvalidChallengeDefinition) as e:
challenge.create()

self.assertEqual(str(e.exception), "Challenge does not provide a value")
mock_api_constructor.return_value.post.assert_not_called()


class TestLintChallenge(unittest.TestCase):
minimal_challenge = BASE_DIR / "fixtures" / "challenges" / "test-challenge-minimal" / "challenge.yml"
Expand Down
Loading