From 28e783cbd8359ce170860a116b5aad08c407eb98 Mon Sep 17 00:00:00 2001 From: Lauren Zugai Date: Tue, 20 Feb 2024 11:28:55 -0600 Subject: [PATCH] fix(signup): Disallow age submissions > 130 Because: * The age limit was 999, which is too high This commit: * Adds an age limit of 130, else we display an error tooltip fixes FXA-9104 --- .../fxa-settings/src/lib/auth-errors/en.ftl | 2 ++ packages/fxa-settings/src/pages/Signup/en.ftl | 2 -- .../src/pages/Signup/index.test.tsx | 17 +++++++++++++++++ .../fxa-settings/src/pages/Signup/index.tsx | 10 +++++++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/fxa-settings/src/lib/auth-errors/en.ftl b/packages/fxa-settings/src/lib/auth-errors/en.ftl index bdc6d565be..3428390cb8 100644 --- a/packages/fxa-settings/src/lib/auth-errors/en.ftl +++ b/packages/fxa-settings/src/lib/auth-errors/en.ftl @@ -24,4 +24,6 @@ auth-error-1003 = Local storage or cookies are still disabled auth-error-1008 = Your new password must be different auth-error-1010 = Valid password required auth-error-1011 = Valid email required +auth-error-1031 = You must enter your age to sign up +auth-error-1032 = You must enter a valid age to sign up auth-error-1062 = Invalid redirect diff --git a/packages/fxa-settings/src/pages/Signup/en.ftl b/packages/fxa-settings/src/pages/Signup/en.ftl index c0f28f0fb3..8634dbc63d 100644 --- a/packages/fxa-settings/src/pages/Signup/en.ftl +++ b/packages/fxa-settings/src/pages/Signup/en.ftl @@ -10,8 +10,6 @@ signup-change-email-link = Change email # Checking the user's age is required by COPPA. To register for an account, the user must indicate their age (number only) signup-age-check-label = .label = How old are you? -# Error displayed in a tooltip when the user attempts to submit the form without filling in their age -signup-age-check-input-error = You must enter your age to sign up # Link goes to https://www.ftc.gov/business-guidance/resources/childrens-online-privacy-protection-rule-not-just-kids-sites # This link appears just below signup-age-check-input-label signup-coppa-check-explanation-link = Why do we ask? diff --git a/packages/fxa-settings/src/pages/Signup/index.test.tsx b/packages/fxa-settings/src/pages/Signup/index.test.tsx index c8cab00c30..d904e8b15f 100644 --- a/packages/fxa-settings/src/pages/Signup/index.test.tsx +++ b/packages/fxa-settings/src/pages/Signup/index.test.tsx @@ -357,6 +357,23 @@ describe('Signup page', () => { ); }); }); + + it('with age set over 130, does not submit and displays error', async () => { + const mockBeginSignupHandler = jest.fn(); + renderWithLocalizationProvider( + + ); + await fillOutForm('131'); + + submit(); + await waitFor(() => { + expect(screen.getByTestId('tooltip')).toHaveTextContent( + 'You must enter a valid age to sign up' + ); + }); + expect(GleanMetrics.registration.submit).toHaveBeenCalledTimes(1); + expect(mockBeginSignupHandler).not.toBeCalled(); + }); }); describe('fails for Relay email masks', () => { diff --git a/packages/fxa-settings/src/pages/Signup/index.tsx b/packages/fxa-settings/src/pages/Signup/index.tsx index 01bad3c27d..a27dce1605 100644 --- a/packages/fxa-settings/src/pages/Signup/index.tsx +++ b/packages/fxa-settings/src/pages/Signup/index.tsx @@ -157,9 +157,13 @@ export const Signup = ({ const ftlMsgResolver = useFtlMsgResolver(); const localizedAgeIsRequiredError = ftlMsgResolver.getMsg( - 'signup-age-check-input-error', + 'auth-error-1031', 'You must enter your age to sign up' ); + const localizedValidAgeError = ftlMsgResolver.getMsg( + 'auth-error-1032', + 'You must enter a valid age to sign up' + ); const onFocus = () => { if (!isFocused) { @@ -198,6 +202,9 @@ export const Signup = ({ document.cookie = 'tooyoung=1;'; navigate('/cannot_create_account'); return; + } else if (Number(age) > 130) { + setAgeCheckErrorText(localizedValidAgeError); + return; } // Disable creating accounts with email masks @@ -293,6 +300,7 @@ export const Signup = ({ integration, offeredSyncEngineConfigs, isSyncOAuth, + localizedValidAgeError, ] );