-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for sessionauth validation failure redirection
- Loading branch information
Showing
5 changed files
with
140 additions
and
3 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -50,6 +50,7 @@ import { | |
waitForText, | ||
waitForSTElement, | ||
backendBeforeEach, | ||
getInvalidClaimsJSON, | ||
} from "../helpers"; | ||
import fetch from "isomorphic-fetch"; | ||
import { SOMETHING_WENT_WRONG_ERROR } from "../constants"; | ||
|
@@ -535,6 +536,140 @@ describe("SuperTokens SignIn with react router dom v6", function () { | |
assert.deepStrictEqual(redirectUrl, "/dashboard"); | ||
}); | ||
|
||
it("Should not redirect to onFailureRedirections result if it's the current url and set the context", async function () { | ||
await Promise.all([ | ||
page.goto(`${TEST_CLIENT_BASE_URL}/auth`), | ||
page.waitForNavigation({ waitUntil: "networkidle0" }), | ||
]); | ||
|
||
// Set correct values. | ||
await setInputValues(page, [ | ||
{ name: "email", value: "[email protected]" }, | ||
{ name: "password", value: "Str0ngP@ssw0rd" }, | ||
]); | ||
await Promise.all([ | ||
submitFormReturnRequestAndResponse(page, SIGN_IN_API), | ||
page.waitForNavigation({ waitUntil: "networkidle0" }), | ||
]); | ||
|
||
await page.evaluate(() => { | ||
const validator = window.UserRoleClaim.validators.includes("admin"); | ||
validator.onFailureRedirection = () => window.location.href; | ||
window.setClaimValidators([validator]); | ||
}); | ||
|
||
await page.waitForSelector(".invalidClaims"); | ||
assert.deepStrictEqual(await getInvalidClaimsJSON(page), [ | ||
{ | ||
id: "st-role", | ||
reason: { | ||
actualValue: [], | ||
expectedToInclude: "admin", | ||
message: "wrong value", | ||
}, | ||
}, | ||
]); | ||
}); | ||
|
||
it("Should not redirect to onFailureRedirections result if it's the current path and set the context", async function () { | ||
await Promise.all([ | ||
page.goto( | ||
`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=${encodeURIComponent("/dashboard?test=value#asdf")}` | ||
), | ||
page.waitForNavigation({ waitUntil: "networkidle0" }), | ||
]); | ||
|
||
// Set correct values. | ||
await setInputValues(page, [ | ||
{ name: "email", value: "[email protected]" }, | ||
{ name: "password", value: "Str0ngP@ssw0rd" }, | ||
]); | ||
await Promise.all([ | ||
submitFormReturnRequestAndResponse(page, SIGN_IN_API), | ||
page.waitForNavigation({ waitUntil: "networkidle0" }), | ||
]); | ||
|
||
await page.evaluate(() => { | ||
const validator = window.UserRoleClaim.validators.includes("admin"); | ||
validator.onFailureRedirection = () => "/dashboard?test=value#asdf"; | ||
window.setClaimValidators([validator]); | ||
}); | ||
|
||
await page.waitForSelector(".invalidClaims"); | ||
assert.deepStrictEqual(await getInvalidClaimsJSON(page), [ | ||
{ | ||
id: "st-role", | ||
reason: { | ||
actualValue: [], | ||
expectedToInclude: "admin", | ||
message: "wrong value", | ||
}, | ||
}, | ||
]); | ||
}); | ||
|
||
it("Should redirect to onFailureRedirections result if it's on another domain", async function () { | ||
await Promise.all([ | ||
page.goto(`${TEST_CLIENT_BASE_URL}/auth`), | ||
page.waitForNavigation({ waitUntil: "networkidle0" }), | ||
]); | ||
|
||
// Set correct values. | ||
await setInputValues(page, [ | ||
{ name: "email", value: "[email protected]" }, | ||
{ name: "password", value: "Str0ngP@ssw0rd" }, | ||
]); | ||
await Promise.all([ | ||
submitFormReturnRequestAndResponse(page, SIGN_IN_API), | ||
page.waitForNavigation({ waitUntil: "networkidle0" }), | ||
]); | ||
|
||
await page.evaluate(() => { | ||
const validator = window.UserRoleClaim.validators.includes("admin"); | ||
validator.onFailureRedirection = () => "https://supertokens.com"; | ||
window.setClaimValidators([validator]); | ||
}); | ||
|
||
await page.waitForNavigation({ waitUntil: "networkidle0" }); | ||
|
||
let href = await page.evaluate(() => window.location.href); | ||
assert.strictEqual(href, "https://supertokens.com/"); | ||
}); | ||
|
||
it("Should redirect to onFailureRedirections result if it's a path and we are not on the websiteDomain", async function () { | ||
await Promise.all([ | ||
page.goto(`${TEST_CLIENT_BASE_URL}/auth`), | ||
page.waitForNavigation({ waitUntil: "networkidle0" }), | ||
]); | ||
|
||
// Set correct values. | ||
await setInputValues(page, [ | ||
{ name: "email", value: "[email protected]" }, | ||
{ name: "password", value: "Str0ngP@ssw0rd" }, | ||
]); | ||
|
||
await Promise.all([ | ||
submitFormReturnRequestAndResponse(page, SIGN_IN_API), | ||
page.waitForNavigation({ waitUntil: "networkidle0" }), | ||
]); | ||
|
||
await Promise.all([ | ||
page.goto( | ||
`${TEST_CLIENT_BASE_URL}/dashboard?websiteDomain=${encodeURIComponent("https://supertokens.com")}` | ||
), | ||
page.waitForNavigation({ waitUntil: "networkidle0" }), | ||
]); | ||
|
||
await page.evaluate(() => { | ||
const validator = window.UserRoleClaim.validators.includes("admin"); | ||
validator.onFailureRedirection = () => "/test"; | ||
window.setClaimValidators([validator]); | ||
}); | ||
await page.waitForNavigation({ waitUntil: "networkidle0" }); | ||
let href = await page.evaluate(() => window.location.href); | ||
assert.strictEqual(href, "https://supertokens.com/test"); | ||
}); | ||
|
||
describe("Successful Sign In with redirect to, with EmailPasswordAuth", async function () { | ||
it("First sign in", async function () { | ||
consoleLogs = await clearBrowserCookiesWithoutAffectingConsole(page, consoleLogs); | ||
|