Skip to content

Commit

Permalink
Fix login reCaptcha score generation
Browse files Browse the repository at this point in the history
Workaround for:
cypress-io/cypress#2393

Ignores "Failed to find a valid digest in the 'integrity'
attribute for resource" error when testing user login with Cypress
  • Loading branch information
GavrilenkoGeorgi committed Oct 27, 2020
1 parent ac867c0 commit 5bc6684
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
29 changes: 18 additions & 11 deletions src/components/forms/LoginForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,24 @@ const LoginForm = ({
}, [])

const getRecaptchaScore = () => {
executeRecaptcha('login')
.then(token => {
setRecaptchaScore(token)
})
.catch(error => {
const { message, variant } = { ...error.response.data }
setNotification({
message,
variant: variant ? variant : 'danger'
}, 5)
})
if (window.Cypress) {
// we are running in Cypress
// so do something different here
setRecaptchaScore()
} else {
// we are running in a regular ol' browser
executeRecaptcha('login')
.then(token => {
setRecaptchaScore(token)
})
.catch(error => {
const { message, variant } = { ...error.response.data }
setNotification({
message,
variant: variant ? variant : 'danger'
}, 5)
})
}
}

const loginUser = useCallback(loginValues => {
Expand Down
21 changes: 15 additions & 6 deletions src/reducers/notificationReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,21 @@ export const setSearchInProgress = searching => {
*/

export const setRecaptchaScore = token => {
return async dispatch => {
const result = await recaptchaService.verify(token)
dispatch ({
type: 'SET_RECAPTCHA_SCORE',
score: result.score
})
if (window.Cypress) {
return async dispatch => {
dispatch ({
type: 'SET_RECAPTCHA_SCORE',
score: .9
})
}
} else {
return async dispatch => {
const result = await recaptchaService.verify(token)
dispatch ({
type: 'SET_RECAPTCHA_SCORE',
score: result.score
})
}
}
}

Expand Down

0 comments on commit 5bc6684

Please sign in to comment.