Skip to content

Commit 4a83c99

Browse files
authored
Merge pull request #1663 from OWASP/ctfdsupport
fix difficulty in mapping
2 parents a7acbe6 + f696d99 commit 4a83c99

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/main/java/org/owasp/wrongsecrets/challenges/ChallengesCtfController.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.owasp.wrongsecrets.ScoreCard;
1111
import org.owasp.wrongsecrets.definitions.ChallengeDefinition;
1212
import org.owasp.wrongsecrets.definitions.ChallengeDefinitionsConfiguration;
13+
import org.owasp.wrongsecrets.definitions.Difficulty;
1314
import org.springframework.http.MediaType;
1415
import org.springframework.web.bind.annotation.GetMapping;
1516
import org.springframework.web.bind.annotation.RestController;
@@ -68,7 +69,7 @@ public String getChallenges() {
6869
.orElse(disabledChallenge));
6970
jsonChallenge.put("solved", scoreCard.getChallengeCompleted(definition));
7071
jsonChallenge.put("disabledEnv", getDisabledEnv(definition));
71-
jsonChallenge.put("difficulty", definition.difficulty().difficulty());
72+
jsonChallenge.put("difficulty", getDificulty(definition.difficulty()));
7273
jsonArray.add(jsonChallenge);
7374
}
7475
json.put("status", "success");
@@ -78,6 +79,23 @@ public String getChallenges() {
7879
return result;
7980
}
8081

82+
private int getDificulty(Difficulty difficulty) {
83+
switch (difficulty.difficulty()) {
84+
case "easy":
85+
return 1;
86+
case "normal":
87+
return 2;
88+
case "hard":
89+
return 3;
90+
case "expert":
91+
return 4;
92+
case "master":
93+
return 5;
94+
default:
95+
return 0;
96+
}
97+
}
98+
8199
private String getCategory() {
82100
return this.wrongSecretsConfiguration.environments().stream()
83101
.filter(e -> e.equals(runtimeEnvironment.getRuntimeEnvironment()))

0 commit comments

Comments
 (0)