-
-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added 12th challenge for #43 and reverted challenge 8 to be random an…
…d log based again #37
- Loading branch information
Showing
13 changed files
with
133 additions
and
34 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
24 changes: 22 additions & 2 deletions
24
src/main/java/org/owasp/wrongsecrets/challenges/docker/Challenge8.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 |
---|---|---|
@@ -1,33 +1,53 @@ | ||
package org.owasp.wrongsecrets.challenges.docker; | ||
|
||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.owasp.wrongsecrets.ScoreCard; | ||
import org.owasp.wrongsecrets.challenges.Challenge; | ||
import org.owasp.wrongsecrets.challenges.ChallengeEnvironment; | ||
import org.owasp.wrongsecrets.challenges.ChallengeNumber; | ||
import org.owasp.wrongsecrets.challenges.Spoiler; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.Random; | ||
|
||
@Slf4j | ||
@Component | ||
@ChallengeNumber("8") | ||
public class Challenge8 extends Challenge { | ||
|
||
private final Random RANDOM = new SecureRandom(); | ||
private final String ALPHABET = "0123456789QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"; | ||
private String randomValue; | ||
|
||
public Challenge8(ScoreCard scoreCard) { | ||
super(scoreCard, ChallengeEnvironment.DOCKER); | ||
randomValue = generateRandomString(10); | ||
log.info("Initializing challenge 8 with value {}", randomValue); | ||
} | ||
|
||
@Override | ||
public Spoiler spoiler() { | ||
return new Spoiler(Constants.newKey); | ||
return new Spoiler(randomValue); | ||
} | ||
|
||
@Override | ||
public boolean answerCorrect(String answer) { | ||
return Constants.newKey.equals(answer); | ||
return randomValue.equals(answer); | ||
} | ||
|
||
@Override | ||
public boolean environmentSupported() { | ||
return true; | ||
} | ||
|
||
|
||
private String generateRandomString(int length) { | ||
StringBuffer buffer = new StringBuffer(length); | ||
for (int i = 0; i < length; i++) { | ||
buffer.append(ALPHABET.charAt(RANDOM.nextInt(ALPHABET.length()))); | ||
} | ||
return new String(buffer); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
=== Challenge 8: Generating random values | ||
|
||
Now, let's randomize the secret... Can you find the answer? | ||
How can we use this on the next startup ;-)? | ||
Now, let's randomize the secret at startup... Can you find the answer? | ||
How can we use this on the next startup ;-)? | ||
|
||
Tip: take a look at the logging of the application at startup! |
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
54 changes: 54 additions & 0 deletions
54
src/test/java/org/owasp/wrongsecrets/challenges/docker/Challenge12Test.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,54 @@ | ||
package org.owasp.wrongsecrets.challenges.docker; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.io.TempDir; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.owasp.wrongsecrets.ScoreCard; | ||
import org.owasp.wrongsecrets.challenges.Spoiler; | ||
import org.owasp.wrongsecrets.challenges.cloud.Challenge9; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class Challenge12Test { | ||
|
||
@Mock | ||
private ScoreCard scoreCard; | ||
|
||
@Test | ||
void solveChallenge12WithoutFile(@TempDir Path dir) throws Exception { | ||
var challenge = new Challenge12(scoreCard, dir.toString()); | ||
|
||
Assertions.assertThat(challenge.answerCorrect("secretvalueWitFile")).isFalse(); | ||
Assertions.assertThat(challenge.answerCorrect("if_you_see_this_please_use_docker_instead")).isTrue(); | ||
} | ||
|
||
@Test | ||
void solveChallenge12WithMNTFile(@TempDir Path dir) throws Exception { | ||
var testFile = new File(dir.toFile(), "yourkey.txt"); | ||
var secret = "secretvalueWitFile"; | ||
Files.writeString(testFile.toPath(), secret); | ||
|
||
var challenge = new Challenge12(scoreCard, dir.toString()); | ||
|
||
Assertions.assertThat(challenge.answerCorrect("secretvalueWitFile")).isTrue(); | ||
} | ||
|
||
@Test | ||
void spoilShouldReturnCorrectAnswer(@TempDir Path dir) throws IOException { | ||
var testFile = new File(dir.toFile(), "yourkey.txt"); | ||
var secret = "secretvalueWitFile"; | ||
Files.writeString(testFile.toPath(), secret); | ||
|
||
var challenge = new Challenge12(scoreCard, dir.toString()); | ||
|
||
Assertions.assertThat(challenge.spoiler()).isEqualTo(new Spoiler("secretvalueWitFile")); | ||
} | ||
|
||
} |
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