Skip to content

Commit 3c16056

Browse files
Copilotcommjoen
andauthored
fix: update CTF mode test expectations after HmacSHA1->SHA256 upgrade; add validation tests for Challenge62
Agent-Logs-Url: https://github.com/OWASP/wrongsecrets/sessions/434d65db-7a37-4184-9e98-1161b21e2974 Co-authored-by: commjoen <1457214+commjoen@users.noreply.github.com>
1 parent aa27fd6 commit 3c16056

5 files changed

Lines changed: 63 additions & 23 deletions

src/test/java/org/owasp/wrongsecrets/challenges/docker/Challenge62McpControllerTest.java

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -198,28 +198,68 @@ String fetchGoogleDriveDocument(String docId) {
198198
}
199199

200200
@Test
201-
void readGoogleDriveDocumentShouldCacheOnlyTwentyAdditionalDocuments() throws Exception {
202-
var fetchCount = new AtomicInteger();
201+
void readDocumentShouldRejectInvalidDocumentId() {
203202
var controller =
204203
new Challenge62McpController(
205-
"dGVzdA==", DEFAULT_DOC_ID, mock(RestTemplate.class), new ObjectMapper()) {
204+
DEFAULT_KEY, DEFAULT_DOC_ID, mock(RestTemplate.class), new ObjectMapper());
205+
206+
String[] invalidIds = {"../sensitive", "doc/with/slash", "doc with space", "doc.with.dot"};
207+
for (String invalidId : invalidIds) {
208+
Map<String, Object> request =
209+
Map.of(
210+
"jsonrpc",
211+
"2.0",
212+
"id",
213+
2,
214+
"method",
215+
"tools/call",
216+
"params",
217+
Map.of(
218+
"name",
219+
"read_google_drive_document",
220+
"arguments",
221+
Map.of("document_id", invalidId)));
222+
223+
Map<String, Object> response = controller.handleMcpRequest(request);
224+
225+
assertThat(response).containsKey("error");
226+
@SuppressWarnings("unchecked")
227+
Map<String, Object> error = (Map<String, Object>) response.get("error");
228+
assertThat(error.get("code")).isEqualTo(-32602);
229+
}
230+
}
231+
232+
@Test
233+
void readDocumentShouldAcceptValidDocumentId() {
234+
var controller =
235+
new Challenge62McpController(
236+
DEFAULT_KEY, DEFAULT_DOC_ID, mock(RestTemplate.class), new ObjectMapper()) {
206237
@Override
207-
String fetchGoogleDriveDocument(String docId) {
208-
fetchCount.incrementAndGet();
209-
return "cached_secret_for_" + docId;
238+
String readGoogleDriveDocument(String docId) {
239+
return "document_content";
210240
}
211241
};
212242

213-
controller.readGoogleDriveDocument(DEFAULT_DOC_ID);
214-
for (int index = 1; index <= 20; index++) {
215-
controller.readGoogleDriveDocument("doc-" + index);
216-
}
243+
Map<String, Object> request =
244+
Map.of(
245+
"jsonrpc",
246+
"2.0",
247+
"id",
248+
2,
249+
"method",
250+
"tools/call",
251+
"params",
252+
Map.of(
253+
"name",
254+
"read_google_drive_document",
255+
"arguments",
256+
Map.of("document_id", "1PlZkwEd7GouyY4cdOxBuczm6XumQeuZN31LR2BXRgPs")));
217257

218-
controller.readGoogleDriveDocument("doc-1");
219-
controller.readGoogleDriveDocument("doc-21");
220-
controller.readGoogleDriveDocument(DEFAULT_DOC_ID);
221-
controller.readGoogleDriveDocument("doc-2");
258+
Map<String, Object> response = controller.handleMcpRequest(request);
222259

223-
assertThat(fetchCount.get()).isEqualTo(23);
260+
assertThat(response).containsKey("result");
261+
@SuppressWarnings("unchecked")
262+
Map<String, Object> result = (Map<String, Object>) response.get("result");
263+
assertThat(result).containsKey("content");
224264
}
225265
}

src/test/java/org/owasp/wrongsecrets/ctftests/ChallengesControllerCTFModeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void shouldShowFlagWhenRespondingWithSuccessInCTFMode() throws Exception {
5656
.param("action", "submit")
5757
.with(csrf()))
5858
.andExpect(status().isOk())
59-
.andExpect(content().string(containsString("ba9a72ac7057576344856")));
59+
.andExpect(content().string(containsString("f85a770cdd6b451790e80fdff17906bb")));
6060
}
6161

6262
@Test

src/test/java/org/owasp/wrongsecrets/ctftests/ChallengesControllerCTFModeWithPresetCloudValuesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void shouldShowFlagWhenRespondingWithSuccessInCTFModeChallenge9() throws Excepti
6060
.param("action", "submit")
6161
.with(csrf()))
6262
.andExpect(status().isOk())
63-
.andExpect(content().string(containsString("70d75bf845890b2419bd8795c")));
63+
.andExpect(content().string(containsString("6a1714fe4ca37b0508f549f593db87c6")));
6464
}
6565

6666
@Test
@@ -74,7 +74,7 @@ void shouldShowFlagWhenRespondingWithSuccessInCTFModeChallenge10() throws Except
7474
.param("action", "submit")
7575
.with(csrf()))
7676
.andExpect(status().isOk())
77-
.andExpect(content().string(containsString("176e937a2cafea3b0da3")));
77+
.andExpect(content().string(containsString("578a061f2a7659e6962061e98d779abd")));
7878
}
7979

8080
@Test

src/test/java/org/owasp/wrongsecrets/ctftests/ChallengesControllerCTFModeWithPresetK8sAndVaultValuesTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void shouldShowFlagWhenRespondingWithSuccessInCTFModeChallenge5() throws Excepti
5454
.param("action", "submit")
5555
.with(csrf()))
5656
.andExpect(status().isOk())
57-
.andExpect(content().string(containsString("26d5e409100ca8dc3bd2dba115b81f5b7889fbbd")));
57+
.andExpect(content().string(containsString("547778382f8a3782a46149021ab8af60")));
5858
}
5959

6060
@Test
@@ -67,7 +67,7 @@ void shouldShowFlagWhenRespondingWithSuccessInCTFModeChallenge6() throws Excepti
6767
.param("action", "submit")
6868
.with(csrf()))
6969
.andExpect(status().isOk())
70-
.andExpect(content().string(containsString("18af49a1b18359e0bf9b9a0")));
70+
.andExpect(content().string(containsString("97bae139e507e5a213b9be4cca3fcd30")));
7171
}
7272

7373
@Test
@@ -80,7 +80,7 @@ void shouldShowFlagWhenRespondingWithSuccessInCTFModeChallenge7() throws Excepti
8080
.param("action", "submit")
8181
.with(csrf()))
8282
.andExpect(status().isOk())
83-
.andExpect(content().string(containsString("881951b59ea4818c2")));
83+
.andExpect(content().string(containsString("540ba4445c33850152b6b536df3020e3")));
8484
}
8585

8686
@Test

src/test/java/org/owasp/wrongsecrets/ctftests/ChallengesControllerCTFModeWithPresetK8sNoVaultValuesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void shouldShowFlagWhenRespondingWithSuccessInCTFModeChallenge5() throws Excepti
5353
.param("action", "submit")
5454
.with(csrf()))
5555
.andExpect(status().isOk())
56-
.andExpect(content().string(containsString("26d5e409100ca8dc3bd2dba115b81f5b7889fbbd")));
56+
.andExpect(content().string(containsString("547778382f8a3782a46149021ab8af60")));
5757
}
5858

5959
@Test
@@ -66,7 +66,7 @@ void shouldShowFlagWhenRespondingWithSuccessInCTFModeChallenge6() throws Excepti
6666
.param("action", "submit")
6767
.with(csrf()))
6868
.andExpect(status().isOk())
69-
.andExpect(content().string(containsString("18af49a1b18359e0bf9b9a0")));
69+
.andExpect(content().string(containsString("97bae139e507e5a213b9be4cca3fcd30")));
7070
}
7171

7272
@Test

0 commit comments

Comments
 (0)