Skip to content

Commit 77b9115

Browse files
authored
Merge pull request #51 from HMAKT99/test/turnstile-hostname-mismatch
Test that Turnstile rejects a verified token for an unlisted hostname
2 parents 9710ade + de171a1 commit 77b9115

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

worker/test/index.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ function makeDependencies(options = {}) {
128128
});
129129
}
130130

131+
if (token === "wrong-hostname-token") {
132+
return Response.json({
133+
success: true,
134+
action,
135+
hostname: "phishing.example.com",
136+
});
137+
}
138+
131139
return Response.json({
132140
success: true,
133141
action,
@@ -322,6 +330,26 @@ test("rejects invalid or mismatched Turnstile tokens without writing", async ()
322330
}
323331
});
324332

333+
test("rejects Turnstile tokens verified for an unlisted hostname", async () => {
334+
const env = makeEnv();
335+
const { calls, dependencies } = makeDependencies();
336+
const response = await handleRequest(
337+
makeRequest(
338+
"/suggestions",
339+
suggestionBody({ turnstile_token: "wrong-hostname-token" }),
340+
),
341+
env,
342+
undefined,
343+
dependencies,
344+
);
345+
const body = await response.json();
346+
347+
assert.equal(response.status, 400);
348+
assert.equal(body.code, "verification_failed");
349+
assert.equal(calls.turnstile.length, 1);
350+
assert.equal(calls.siteData.length, 0);
351+
});
352+
325353
test("rate limits invalid-token floods before calling Siteverify", async () => {
326354
const rateLimitCalls = [];
327355
const env = makeEnv({

0 commit comments

Comments
 (0)