-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IAMRISK-2916] Added support for Auth0 v2 captcha provider (#1368)
Co-authored-by: Frederik Prijck <[email protected]>
- Loading branch information
1 parent
f54cf1b
commit f5e1f71
Showing
3 changed files
with
79 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,12 +192,14 @@ describe('captcha rendering', function () { | |
const HCAPTCHA_PROVIDER = 'hcaptcha'; | ||
const FRIENDLY_CAPTCHA_PROVIDER = 'friendly_captcha'; | ||
const ARKOSE_PROVIDER = 'arkose'; | ||
const AUTH0_V2_CAPTCHA_PROVIDER = 'auth0_v2'; | ||
|
||
[ | ||
RECAPTCHA_V2_PROVIDER, | ||
RECAPTCHA_ENTERPRISE_PROVIDER, | ||
HCAPTCHA_PROVIDER, | ||
FRIENDLY_CAPTCHA_PROVIDER | ||
FRIENDLY_CAPTCHA_PROVIDER, | ||
AUTH0_V2_CAPTCHA_PROVIDER | ||
].forEach(provider => { | ||
const getScript = () => { | ||
switch (provider) { | ||
|
@@ -209,19 +211,19 @@ describe('captcha rendering', function () { | |
return 'enterprise.js'; | ||
case FRIENDLY_CAPTCHA_PROVIDER: | ||
return 'widget.min.js'; | ||
case AUTH0_V2_CAPTCHA_PROVIDER: | ||
return 'api.js'; | ||
} | ||
}; | ||
const getHostname = () => { | ||
switch (provider) { | ||
case RECAPTCHA_V2_PROVIDER: | ||
return 'recaptcha.net'; | ||
case RECAPTCHA_ENTERPRISE_PROVIDER: | ||
return 'recaptcha.net'; | ||
case HCAPTCHA_PROVIDER: | ||
return 'hcaptcha.com'; | ||
case FRIENDLY_CAPTCHA_PROVIDER: | ||
return 'jsdelivr.net'; | ||
const hosts = { | ||
[RECAPTCHA_V2_PROVIDER]: 'recaptcha.net', | ||
[RECAPTCHA_ENTERPRISE_PROVIDER]: 'recaptcha.net', | ||
[HCAPTCHA_PROVIDER]: 'hcaptcha.com', | ||
[FRIENDLY_CAPTCHA_PROVIDER]: 'jsdelivr.net', | ||
[AUTH0_V2_CAPTCHA_PROVIDER]: 'cloudflare.com' | ||
} | ||
return hosts[provider]; | ||
}; | ||
const getSubdomain = () => { | ||
switch (provider) { | ||
|
@@ -233,6 +235,8 @@ describe('captcha rendering', function () { | |
return 'js'; | ||
case FRIENDLY_CAPTCHA_PROVIDER: | ||
return 'cdn'; | ||
case AUTH0_V2_CAPTCHA_PROVIDER: | ||
return 'challenges'; | ||
} | ||
}; | ||
const getPath = () => { | ||
|
@@ -245,6 +249,8 @@ describe('captcha rendering', function () { | |
return '1'; | ||
case FRIENDLY_CAPTCHA_PROVIDER: | ||
return 'npm/[email protected]'; | ||
case AUTH0_V2_CAPTCHA_PROVIDER: | ||
return 'turnstile/v0'; | ||
} | ||
}; | ||
const setMockGlobal = mock => { | ||
|
@@ -261,6 +267,9 @@ describe('captcha rendering', function () { | |
case FRIENDLY_CAPTCHA_PROVIDER: | ||
window.friendlyChallenge = mock; | ||
break; | ||
case AUTH0_V2_CAPTCHA_PROVIDER: | ||
window.turnstile = mock; | ||
break; | ||
} | ||
}; | ||
describe(`when challenge is required and provider is ${provider}`, function () { | ||
|
@@ -303,8 +312,13 @@ describe('captcha rendering', function () { | |
`${getSubdomain()}.${getHostname()}` | ||
); | ||
expect(scriptUrl.pathname).to.equal(`/${getPath()}/${getScript()}`); | ||
if (provider !== FRIENDLY_CAPTCHA_PROVIDER) { | ||
if ( | ||
provider !== FRIENDLY_CAPTCHA_PROVIDER && | ||
provider !== AUTH0_V2_CAPTCHA_PROVIDER | ||
) { | ||
expect(scriptUrl.query.hl).to.equal('en'); | ||
} | ||
if (provider !== FRIENDLY_CAPTCHA_PROVIDER) { | ||
expect(scriptUrl.query).to.have.property('onload'); | ||
} | ||
}); | ||
|
@@ -748,12 +762,14 @@ describe('passwordless captcha rendering', function () { | |
const HCAPTCHA_PROVIDER = 'hcaptcha'; | ||
const FRIENDLY_CAPTCHA_PROVIDER = 'friendly_captcha'; | ||
const ARKOSE_PROVIDER = 'arkose'; | ||
const AUTH0_V2_CAPTCHA_PROVIDER = 'auth0_v2'; | ||
|
||
[ | ||
RECAPTCHA_V2_PROVIDER, | ||
RECAPTCHA_ENTERPRISE_PROVIDER, | ||
HCAPTCHA_PROVIDER, | ||
FRIENDLY_CAPTCHA_PROVIDER | ||
FRIENDLY_CAPTCHA_PROVIDER, | ||
AUTH0_V2_CAPTCHA_PROVIDER | ||
].forEach(provider => { | ||
const getScript = () => { | ||
switch (provider) { | ||
|
@@ -765,19 +781,19 @@ describe('passwordless captcha rendering', function () { | |
return 'enterprise.js'; | ||
case FRIENDLY_CAPTCHA_PROVIDER: | ||
return 'widget.min.js'; | ||
case AUTH0_V2_CAPTCHA_PROVIDER: | ||
return 'api.js'; | ||
} | ||
}; | ||
const getHostname = () => { | ||
switch (provider) { | ||
case RECAPTCHA_V2_PROVIDER: | ||
return 'recaptcha.net'; | ||
case RECAPTCHA_ENTERPRISE_PROVIDER: | ||
return 'recaptcha.net'; | ||
case HCAPTCHA_PROVIDER: | ||
return 'hcaptcha.com'; | ||
case FRIENDLY_CAPTCHA_PROVIDER: | ||
return 'jsdelivr.net'; | ||
const hosts = { | ||
[RECAPTCHA_V2_PROVIDER]: 'recaptcha.net', | ||
[RECAPTCHA_ENTERPRISE_PROVIDER]: 'recaptcha.net', | ||
[HCAPTCHA_PROVIDER]: 'hcaptcha.com', | ||
[FRIENDLY_CAPTCHA_PROVIDER]: 'jsdelivr.net', | ||
[AUTH0_V2_CAPTCHA_PROVIDER]: 'cloudflare.com' | ||
} | ||
return hosts[provider]; | ||
}; | ||
const getSubdomain = () => { | ||
switch (provider) { | ||
|
@@ -789,6 +805,8 @@ describe('passwordless captcha rendering', function () { | |
return 'js'; | ||
case FRIENDLY_CAPTCHA_PROVIDER: | ||
return 'cdn'; | ||
case AUTH0_V2_CAPTCHA_PROVIDER: | ||
return 'challenges'; | ||
} | ||
}; | ||
const getPath = () => { | ||
|
@@ -801,6 +819,8 @@ describe('passwordless captcha rendering', function () { | |
return '1'; | ||
case FRIENDLY_CAPTCHA_PROVIDER: | ||
return 'npm/[email protected]'; | ||
case AUTH0_V2_CAPTCHA_PROVIDER: | ||
return 'turnstile/v0'; | ||
} | ||
}; | ||
const setMockGlobal = mock => { | ||
|
@@ -817,6 +837,9 @@ describe('passwordless captcha rendering', function () { | |
case FRIENDLY_CAPTCHA_PROVIDER: | ||
window.friendlyChallenge = mock; | ||
break; | ||
case AUTH0_V2_CAPTCHA_PROVIDER: | ||
window.turnstile = mock; | ||
break; | ||
} | ||
}; | ||
describe(`when challenge is required and provider is ${provider}`, function () { | ||
|
@@ -861,8 +884,13 @@ describe('passwordless captcha rendering', function () { | |
`${getSubdomain()}.${getHostname()}` | ||
); | ||
expect(scriptUrl.pathname).to.equal(`/${getPath()}/${getScript()}`); | ||
if (provider !== FRIENDLY_CAPTCHA_PROVIDER) { | ||
if ( | ||
provider !== FRIENDLY_CAPTCHA_PROVIDER && | ||
provider !== AUTH0_V2_CAPTCHA_PROVIDER | ||
) { | ||
expect(scriptUrl.query.hl).to.equal('en'); | ||
} | ||
if (provider !== FRIENDLY_CAPTCHA_PROVIDER) { | ||
expect(scriptUrl.query).to.have.property('onload'); | ||
} | ||
}); | ||
|