Skip to content

Commit cc953ef

Browse files
Copilotcommjoen
andcommitted
Use Java 23 syntax: replace .get(0) with .getFirst() and enhance Challenge59
Co-authored-by: commjoen <[email protected]>
1 parent 938b181 commit cc953ef

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private String documentation(Function<ChallengeSource, String> extractor) {
109109
return challengeDefinition.source(runtimeEnvironment).map(extractor).orElse("");
110110
} else {
111111
// We cannot run the challenge but showing documentation should still be possible
112-
return extractor.apply(challengeDefinition.sources().get(0));
112+
return extractor.apply(challengeDefinition.sources().getFirst());
113113
}
114114
}
115115

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public String spoiler(@PathVariable("short-name") String shortName, Model model)
9797
Supplier<Spoiler> spoilerFromRandomChallenge =
9898
() -> {
9999
var challengeDefinition = findByShortName(shortName);
100-
return challenges.getChallenge(challengeDefinition).get(0).spoiler();
100+
return challenges.getChallenge(challengeDefinition).getFirst().spoiler();
101101
};
102102

103103
// We always want to show the spoiler even if we run in a non-supported environment

src/main/java/org/owasp/wrongsecrets/challenges/docker/Challenge14.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public String getAnswer() {
4545

4646
try (InputStream inputStream = Files.newInputStream(Paths.get(filePath))) {
4747
database = SimpleDatabase.load(creds, inputStream);
48-
return database.findEntries("alibaba").get(0).getPassword();
48+
return database.findEntries("alibaba").getFirst().getPassword();
4949
} catch (Exception | Error e) {
5050
log.error("Exception or Error with Challenge 14", e);
5151
try (InputStream inputStream =
5252
Files.newInputStream(Paths.get("src/test/resources/alibabacreds.kdbx"))) {
5353
database = SimpleDatabase.load(creds, inputStream);
54-
return database.findEntries("alibaba").get(0).getPassword();
54+
return database.findEntries("alibaba").getFirst().getPassword();
5555
} catch (Exception | Error e2) {
5656
log.error("Exception or Error with Challenge 14 second time", e2);
5757
return defaultKeepassValue;

src/main/java/org/owasp/wrongsecrets/challenges/docker/Challenge59.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private String getTelegramSecret() {
3030
// that can be accessed using the bot token below
3131

3232
// Hardcoded bot token (intentionally vulnerable for educational purposes)
33-
String botToken = getBotToken();
33+
var botToken = getBotToken();
3434

3535
// For this challenge, the secret is what you would find in the Telegram channel
3636
// Bot: @WrongsecretsBot
@@ -41,10 +41,8 @@ private String getTelegramSecret() {
4141
private String getBotToken() {
4242
// Double-encoded bot token to make it slightly more challenging
4343
// but still discoverable through code inspection
44-
return new String(
45-
Base64.decode(
46-
new String(
47-
Base64.decode("T0RFek1qZzJOalkwTXpwQlFVaEtiWFphY1haMlRUbGtTVEp5ZEVKUGRTMHRWMDFhZVUxR1ZHWklUbTg1U1E9PQo="), UTF_8)),
48-
UTF_8);
44+
var encodedToken = "T0RFek1qZzJOalkwTXpwQlFVaEtiWFphY1haMlRUbGtTVEp5ZEVKUGRTMHRWMDFhZVUxR1ZHWklUbTg1U1E9PQo=";
45+
var firstDecode = new String(Base64.decode(encodedToken), UTF_8);
46+
return new String(Base64.decode(firstDecode), UTF_8);
4947
}
5048
}

0 commit comments

Comments
 (0)