Skip to content

Commit

Permalink
Merge pull request #1663 from OWASP/ctfdsupport
Browse files Browse the repository at this point in the history
fix difficulty in mapping
  • Loading branch information
commjoen authored Oct 10, 2024
2 parents a7acbe6 + f696d99 commit 4a83c99
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.owasp.wrongsecrets.ScoreCard;
import org.owasp.wrongsecrets.definitions.ChallengeDefinition;
import org.owasp.wrongsecrets.definitions.ChallengeDefinitionsConfiguration;
import org.owasp.wrongsecrets.definitions.Difficulty;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -68,7 +69,7 @@ public String getChallenges() {
.orElse(disabledChallenge));
jsonChallenge.put("solved", scoreCard.getChallengeCompleted(definition));
jsonChallenge.put("disabledEnv", getDisabledEnv(definition));
jsonChallenge.put("difficulty", definition.difficulty().difficulty());
jsonChallenge.put("difficulty", getDificulty(definition.difficulty()));
jsonArray.add(jsonChallenge);
}
json.put("status", "success");
Expand All @@ -78,6 +79,23 @@ public String getChallenges() {
return result;
}

private int getDificulty(Difficulty difficulty) {
switch (difficulty.difficulty()) {
case "easy":
return 1;
case "normal":
return 2;
case "hard":
return 3;
case "expert":
return 4;
case "master":
return 5;
default:
return 0;
}
}

private String getCategory() {
return this.wrongSecretsConfiguration.environments().stream()
.filter(e -> e.equals(runtimeEnvironment.getRuntimeEnvironment()))
Expand Down

0 comments on commit 4a83c99

Please sign in to comment.