State Debugger
@@ -447,7 +555,11 @@ export default function JoinForm() {
+
@@ -497,7 +617,7 @@ export default function JoinForm() {
size="large"
href="https://nycmesh.net/"
>
- Go Home
+ {t("fields.submit.goHome")}
diff --git a/src/components/JoinForm/hide_recaptcha_badge.css b/src/components/JoinForm/hide_recaptcha_badge.css
new file mode 100644
index 0000000..545f6b0
--- /dev/null
+++ b/src/components/JoinForm/hide_recaptcha_badge.css
@@ -0,0 +1,3 @@
+.grecaptcha-badge {
+ visibility: hidden;
+}
diff --git a/src/lib/endpoint.ts b/src/lib/endpoint.ts
index 721e220..0a4ffcd 100644
--- a/src/lib/endpoint.ts
+++ b/src/lib/endpoint.ts
@@ -7,3 +7,16 @@ export async function getMeshDBAPIEndpoint() {
}
return process.env.MESHDB_URL;
}
+
+// Literally just ask the server what captcha keys to use
+export async function getRecaptchaKeys() {
+ if (!process.env.RECAPTCHA_V2_KEY) {
+ console.warn("RECAPTCHA_V2_KEY not set");
+ }
+
+ if (!process.env.RECAPTCHA_V3_KEY) {
+ console.warn("RECAPTCHA_V3_KEY not set");
+ }
+
+ return [process.env.RECAPTCHA_V2_KEY, process.env.RECAPTCHA_V3_KEY];
+}
diff --git a/tests/02_join_form.spec.ts b/tests/02_join_form.spec.ts
index 8a49b33..eaee3f0 100644
--- a/tests/02_join_form.spec.ts
+++ b/tests/02_join_form.spec.ts
@@ -415,3 +415,36 @@ test("fail nj", async ({ page }) => {
);
}
});
+
+test.describe("user triggered captchaV2", () => {
+ test.skip(process.env.RUN_CAPTCHA !== "true");
+ test("user triggered captchaV2", async ({ page }) => {
+ test.setTimeout(joinFormTimeout);
+ await page.goto("/join");
+
+ // Is the page title correct?
+ await expect(page).toHaveTitle(/Join Our Community Network!/);
+
+ // Set up sample data.
+ let botTriggeringData: JoinFormValues = Object.assign({}, sampleData);
+
+ await fillOutJoinForm(page, botTriggeringData);
+
+ await submitAndCheckToast(
+ page,
+ "Please complete an additional verification step to confirm your submission",
+ );
+
+ await page.waitForTimeout(1000);
+
+ // Make the robot check the "I'm not a robot" button (commit voter fraud)
+ await page
+ .locator("[title='reCAPTCHA']")
+ .nth(1)
+ .contentFrame()
+ .locator("[id='recaptcha-anchor']")
+ .click();
+
+ await submitSuccessExpected(page, unitTestTimeout);
+ });
+});
diff --git a/tests/mock/handlers.ts b/tests/mock/handlers.ts
index d5e78a4..8d4cadf 100644
--- a/tests/mock/handlers.ts
+++ b/tests/mock/handlers.ts
@@ -73,6 +73,17 @@ export default [
return HttpResponse.json(r, { status: 409 });
}
+ // Mock response for if we want to trigger a captchaV2 response
+ if (
+ request.headers.get("X-Recaptcha-V2-Token") === "" &&
+ process.env.RECAPTCHA_V2_KEY
+ ) {
+ return HttpResponse.json(
+ { detail: "Captcha verification failed" },
+ { status: 401 },
+ );
+ }
+
// If anything else is wrong with the form we got, then bail
if (!isDeepStrictEqual(joinRequest, expectedAPIRequestData)) {
console.error(
diff --git a/tests/util.ts b/tests/util.ts
index 1acdd62..a5674b2 100644
--- a/tests/util.ts
+++ b/tests/util.ts
@@ -14,7 +14,7 @@ export const sampleData: JoinFormValues = {
state: "NY",
zip_code: "11238",
roof_access: true,
- referral: "I googled it.",
+ referral: "Mock Sample Data",
ncl: true,
trust_me_bro: false,
};
@@ -30,7 +30,7 @@ export const sampleJoinRecord: JoinRecord = {
state: "NY",
zip_code: "11238",
roof_access: true,
- referral: "I googled it.",
+ referral: "Mock Sample Data",
ncl: true,
trust_me_bro: false,
submission_time: "2024-11-01T08:24:24",
@@ -50,7 +50,7 @@ export const expectedTrustMeBroValues: JoinFormValues = {
state: "NY",
zip_code: "11238",
roof_access: true,
- referral: "I googled it.",
+ referral: "Mock Sample Data",
ncl: true,
trust_me_bro: false,
};
@@ -66,7 +66,7 @@ export const sampleNJData: JoinFormValues = {
zip_code: "07030",
apartment: "1",
roof_access: true,
- referral: "I googled it.",
+ referral: "Mock Sample Data",
ncl: true,
trust_me_bro: false,
};