Skip to content

Commit

Permalink
Fixing the misconception that there are no challengeas after challeng…
Browse files Browse the repository at this point in the history
…e 6 ;-)
  • Loading branch information
commjoen committed Feb 18, 2024
1 parent a1a5b8d commit 9af4e07
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/owasp/wrongsecrets/Challenges.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public boolean isFirstChallenge(ChallengeDefinition challengeDefinition) {
return challengeDefinition.equals(definitions.challenges().get(0));
}

public boolean isLastChallenge(ChallengeDefinition challengeDefinition) {
return challengeDefinition.equals(definitions.challenges().getLast());
}

public List<ChallengeDefinition> getChallengeDefinitions() {
return definitions.challenges();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ChallengesController {
@Value("${ctf_enabled}")
private boolean ctfModeEnabled;

private boolean spoilingEnabled;
private final boolean spoilingEnabled;

@Value("${ctf_key}")
private String ctfKey;
Expand Down Expand Up @@ -93,7 +93,7 @@ public String spoiler(@PathVariable("short-name") String shortName, Model model)
model.addAttribute("spoiler", new Spoiler("Spoils are disabled in the configuration"));
} else {
Optional<Spoiler> spoilerFromRuntimeEnvironment =
challenges.findChallenge(shortName, runtimeEnvironment).map(c -> c.spoiler());
challenges.findChallenge(shortName, runtimeEnvironment).map(Challenge::spoiler);
Supplier<Spoiler> spoilerFromRandomChallenge =
() -> {
var challengeDefinition = findByShortName(shortName);
Expand Down Expand Up @@ -151,8 +151,13 @@ public String challenge(Model model, @PathVariable("short-name") String shortNam
model.addAttribute("answerCorrect", null);
model.addAttribute("answerIncorrect", null);
model.addAttribute("solution", null);
String clickNext =
"This challenge has been disabled. Click \"next\" to go to the next challenge.";
if (challenges.isLastChallenge(challengeDefinition)) {
clickNext = "This challenge has been disabled";
}
if (!isChallengeEnabled(challengeDefinition)) {
model.addAttribute("answerIncorrect", "This challenge has been disabled.");
model.addAttribute("answerIncorrect", "This challenge has been disabled." + clickNext);
}
if (ctfModeEnabled && challenges.isFirstChallenge(challengeDefinition)) {
if (!Strings.isNullOrEmpty(ctfServerAddress) && !ctfServerAddress.equals("not_set")) {
Expand Down Expand Up @@ -331,7 +336,7 @@ private void enrichWithHintsAndReasons(Model model) {
private void fireEnding(Model model) {
var notCompleted =
challenges.getDefinitions().challenges().stream()
.filter(def -> isChallengeEnabled(def))
.filter(this::isChallengeEnabled)
.filter(this::challengeNotCompleted)
.count();
if (notCompleted == 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/explanations/missing_cloud.adoc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
We are running outside a properly configured Cloud environment. Please run this in an AWS/Azure/GCP environment as
explained in the https://github.com/OWASP/wrongsecrets#cloud-challenges[README.md]

There are still supported challenges after this one. Please try another challenge instead!
2 changes: 2 additions & 0 deletions src/main/resources/explanations/missing_k8s.adoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
We are running outside a K8s cluster.
Please run this in the K8s cluster as explained in the
https://github.com/OWASP/wrongsecrets#basic-k8s-exercise[README.md]

There are still supported challenges after this one. Please try another challenge instead!
2 changes: 2 additions & 0 deletions src/main/resources/explanations/missing_vault.adoc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
We are running outside a K8s cluster with Vault. Please run this in the K8s cluster as explained in the
https://github.com/OWASP/wrongsecrets#vault-exercises-with-minikube[README.md]

There might still be supported challenges after this one. Please try another challenge instead!

0 comments on commit 9af4e07

Please sign in to comment.