Skip to content

Commit 850fcbe

Browse files
authored
Support hint title (#184)
* Add support for hint titles released in CTFd 3.7.7
1 parent 61c03f0 commit 850fcbe

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

ctfcli/core/challenge.py

+2
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,14 @@ def _create_hints(self):
398398
if type(hint) == str:
399399
hint_payload = {
400400
"content": hint,
401+
"title": "",
401402
"cost": 0,
402403
"challenge_id": self.challenge_id,
403404
}
404405
else:
405406
hint_payload = {
406407
"content": hint["content"],
408+
"title": hint.get("title", ""),
407409
"cost": hint["cost"],
408410
"challenge_id": self.challenge_id,
409411
}

ctfcli/spec/challenge-example.yml

+3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ hints:
107107
cost: 10
108108
}
109109
- This hint is free
110+
- title: Titled Hint
111+
content: This hint has a title and costs points
112+
cost: 10
110113

111114
# Requirements are used to make a challenge require another challenge to be
112115
# solved before being available.

tests/core/test_challenge.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -699,9 +699,9 @@ def test_updates_hints(self, mock_api_constructor: MagicMock, *args, **kwargs):
699699

700700
mock_api.post.assert_has_calls(
701701
[
702-
call("/api/v1/hints", json={"content": "free hint", "cost": 0, "challenge_id": 1}),
702+
call("/api/v1/hints", json={"content": "free hint", "title": "", "cost": 0, "challenge_id": 1}),
703703
call().raise_for_status(),
704-
call("/api/v1/hints", json={"content": "paid hint", "cost": 100, "challenge_id": 1}),
704+
call("/api/v1/hints", json={"content": "paid hint", "title": "", "cost": 100, "challenge_id": 1}),
705705
call().raise_for_status(),
706706
]
707707
)
@@ -1029,7 +1029,7 @@ def test_updates_multiple_attributes_at_once(self, mock_api_constructor: MagicMo
10291029
call().raise_for_status(),
10301030
call("/api/v1/files", files=ANY, data={"challenge_id": 1, "type": "challenge"}),
10311031
call().raise_for_status(),
1032-
call("/api/v1/hints", json={"content": "free hint", "cost": 0, "challenge_id": 1}),
1032+
call("/api/v1/hints", json={"title": "", "content": "free hint", "cost": 0, "challenge_id": 1}),
10331033
call().raise_for_status(),
10341034
]
10351035
)
@@ -1237,8 +1237,8 @@ def mock_post(*args, **kwargs):
12371237
# files
12381238
call("/api/v1/files", files=ANY, data={"challenge_id": 3, "type": "challenge"}),
12391239
# hints
1240-
call("/api/v1/hints", json={"content": "free hint", "cost": 0, "challenge_id": 3}),
1241-
call("/api/v1/hints", json={"content": "paid hint", "cost": 100, "challenge_id": 3}),
1240+
call("/api/v1/hints", json={"title": "", "content": "free hint", "cost": 0, "challenge_id": 3}),
1241+
call("/api/v1/hints", json={"title": "", "content": "paid hint", "cost": 100, "challenge_id": 3}),
12421242
]
12431243
)
12441244

0 commit comments

Comments
 (0)