Skip to content

Support hint title #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 4, 2025
Merged
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: 2 additions & 0 deletions ctfcli/core/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,14 @@ def _create_hints(self):
if type(hint) == str:
hint_payload = {
"content": hint,
"title": "",
"cost": 0,
"challenge_id": self.challenge_id,
}
else:
hint_payload = {
"content": hint["content"],
"title": hint.get("title", ""),
"cost": hint["cost"],
"challenge_id": self.challenge_id,
}
Expand Down
3 changes: 3 additions & 0 deletions ctfcli/spec/challenge-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ hints:
cost: 10
}
- This hint is free
- title: Titled Hint
content: This hint has a title and costs points
cost: 10

# Requirements are used to make a challenge require another challenge to be
# solved before being available.
Expand Down
10 changes: 5 additions & 5 deletions tests/core/test_challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,9 @@ def test_updates_hints(self, mock_api_constructor: MagicMock, *args, **kwargs):

mock_api.post.assert_has_calls(
[
call("/api/v1/hints", json={"content": "free hint", "cost": 0, "challenge_id": 1}),
call("/api/v1/hints", json={"content": "free hint", "title": "", "cost": 0, "challenge_id": 1}),
call().raise_for_status(),
call("/api/v1/hints", json={"content": "paid hint", "cost": 100, "challenge_id": 1}),
call("/api/v1/hints", json={"content": "paid hint", "title": "", "cost": 100, "challenge_id": 1}),
call().raise_for_status(),
]
)
Expand Down Expand Up @@ -1029,7 +1029,7 @@ def test_updates_multiple_attributes_at_once(self, mock_api_constructor: MagicMo
call().raise_for_status(),
call("/api/v1/files", files=ANY, data={"challenge_id": 1, "type": "challenge"}),
call().raise_for_status(),
call("/api/v1/hints", json={"content": "free hint", "cost": 0, "challenge_id": 1}),
call("/api/v1/hints", json={"title": "", "content": "free hint", "cost": 0, "challenge_id": 1}),
call().raise_for_status(),
]
)
Expand Down Expand Up @@ -1237,8 +1237,8 @@ def mock_post(*args, **kwargs):
# files
call("/api/v1/files", files=ANY, data={"challenge_id": 3, "type": "challenge"}),
# hints
call("/api/v1/hints", json={"content": "free hint", "cost": 0, "challenge_id": 3}),
call("/api/v1/hints", json={"content": "paid hint", "cost": 100, "challenge_id": 3}),
call("/api/v1/hints", json={"title": "", "content": "free hint", "cost": 0, "challenge_id": 3}),
call("/api/v1/hints", json={"title": "", "content": "paid hint", "cost": 100, "challenge_id": 3}),
]
)

Expand Down