This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bypass Recaptcha for automated testing (#262)
* bypass captcha logic and separate recaptcha implemented * Add license header * Add enableRecaptcha flag to e2e config * More config fixes * Changes to the context data attribute * chore: refactor use of e2eTestMode flag and add to context * chore: cleanup after PR review * chore: move mode flag to camel case --------- Co-authored-by: Robert Bo Davis <[email protected]>
- Loading branch information
1 parent
97f56d6
commit 646d436
Showing
9 changed files
with
89 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (C) 2021-2023 Technology Matters | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see https://www.gnu.org/licenses/. | ||
*/ | ||
|
||
import React, { useRef } from 'react'; | ||
import ReCAPTCHA from 'react-google-recaptcha'; | ||
|
||
import { RECAPTCHA_KEY } from '../../../private/secret'; | ||
import { validateUser } from './recaptchaValidation'; | ||
|
||
type Props = { | ||
bypassCaptcha: boolean | undefined; | ||
onRecaptchaChange: (verified: boolean) => void; | ||
}; | ||
|
||
const ReCaptcha: React.FC<Props> = ({ bypassCaptcha, onRecaptchaChange }) => { | ||
const recaptchaRef = useRef<ReCAPTCHA>(null); | ||
|
||
const onChange = (token: string | null) => { | ||
const verified = token !== null; | ||
onRecaptchaChange(verified); | ||
|
||
if (verified) { | ||
try { | ||
validateUser(token ?? ''); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
}; | ||
|
||
if (bypassCaptcha) { | ||
return null; | ||
} | ||
|
||
return <ReCAPTCHA sitekey={RECAPTCHA_KEY} size="normal" ref={recaptchaRef} onChange={onChange} />; | ||
}; | ||
|
||
export default ReCaptcha; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters