-
-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/djvinnie/challenge43-reddit' int…
…o djvinnie/challenge43-reddit
- Loading branch information
Showing
45 changed files
with
257 additions
and
477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/org/owasp/wrongsecrets/challenges/FixedAnswerChallenge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.owasp.wrongsecrets.challenges; | ||
|
||
import com.google.common.base.Supplier; | ||
import com.google.common.base.Suppliers; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Use this class when a challenge where the answer is fixed, meaning it will not change and does | ||
* not depend on the given answer. For example: a hardcoded key or Spring environment variable. | ||
* | ||
* <p>Why do we make this distinction? Because in the case of the fixed answer we can cache the | ||
* value. It is important to <b>NOT</b> do any reading / calculation in the constructor when using | ||
* this interface. | ||
* | ||
* <p>NOTE: If the challenge depends on a calculation you can implement {@link Challenge} | ||
*/ | ||
public abstract class FixedAnswerChallenge implements Challenge { | ||
|
||
private Supplier<String> cachedAnswer = Suppliers.memoize(() -> getAnswer()); | ||
|
||
@Override | ||
public final Spoiler spoiler() { | ||
return new Spoiler(cachedAnswer.get()); | ||
} | ||
|
||
@Override | ||
public final boolean answerCorrect(String answer) { | ||
return Objects.equals(cachedAnswer.get(), answer); | ||
} | ||
|
||
public abstract String getAnswer(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.