-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7662 from artsy/artsyjian/after-update-redir
feat: tests for pr#7626 (2FA respect after_update param).
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/v2/Components/UserSettings/TwoFactorAuthentication/__tests__/helpers.jest.ts
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,76 @@ | ||
import { afterUpdateRedirect, redirectMessage } from "../helpers" | ||
|
||
const { location: originalLocation } = window | ||
|
||
describe("afterUpdateRedirect", () => { | ||
beforeEach(() => { | ||
// @ts-expect-error STRICT_NULL_CHECK | ||
delete window.location | ||
}) | ||
afterEach(() => { | ||
window.location = originalLocation | ||
}) | ||
|
||
it("returns host for trusted domain", () => { | ||
const search = "?after_update=https%3A%2F%2Fcms.artsy.net" | ||
window.location = { search } as any | ||
expect(afterUpdateRedirect()).toEqual("https://cms.artsy.net") | ||
}) | ||
it("returns host and path for trusted domain", () => { | ||
const search = "?after_update=https%3A%2F%2Fcms.artsy.net%2Fauth%2Fartsy" | ||
window.location = { search } as any | ||
expect(afterUpdateRedirect()).toEqual("https://cms.artsy.net/auth/artsy") | ||
}) | ||
it("returns / for untrusted domains", () => { | ||
const search = "?after_update=https%3A%2F%2Fcms.evil.net" | ||
window.location = { search } as any | ||
expect(afterUpdateRedirect()).toEqual("/") | ||
}) | ||
it("returns / for relative root", () => { | ||
const search = "?after_update=/" | ||
window.location = { search } as any | ||
expect(afterUpdateRedirect()).toEqual("/") | ||
}) | ||
it("returns /foo for relative foo", () => { | ||
const search = "?after_update=/foo" | ||
window.location = { search } as any | ||
expect(afterUpdateRedirect()).toEqual("/foo") | ||
}) | ||
it("returns empty string for for no after_update param", () => { | ||
const search = "?foo=bar" | ||
window.location = { search } as any | ||
expect(afterUpdateRedirect()).toEqual("") | ||
}) | ||
it("returns empty string for for no search string at all", () => { | ||
const search = "" | ||
window.location = { search } as any | ||
expect(afterUpdateRedirect()).toEqual("") | ||
}) | ||
}) | ||
|
||
describe("redirectMessage", () => { | ||
it("returns redir message for host", () => { | ||
const url = "https://cms.artsy.net" | ||
expect(redirectMessage(url)).toEqual( | ||
"You will be redirected to: cms.artsy.net" | ||
) | ||
}) | ||
it("returns redir message for host and path", () => { | ||
const url = "https://cms.artsy.net/auth/artsy" | ||
expect(redirectMessage(url)).toEqual( | ||
"You will be redirected to: cms.artsy.net" | ||
) | ||
}) | ||
it("returns empty string for relative /", () => { | ||
const url = "/" | ||
expect(redirectMessage(url)).toEqual("") | ||
}) | ||
it("returns empty string for relative /foo", () => { | ||
const url = "/" | ||
expect(redirectMessage(url)).toEqual("") | ||
}) | ||
it("returns empty string for empty url", () => { | ||
const url = "" | ||
expect(redirectMessage(url)).toEqual("") | ||
}) | ||
}) |
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,20 @@ | ||
import { getURLHost } from "../url" | ||
|
||
describe("getURLHost", () => { | ||
it("returns host for url with host", () => { | ||
const url = "https://cms.artsy.net" | ||
expect(getURLHost(url)).toEqual("cms.artsy.net") | ||
}) | ||
it("returns host for url with host and path", () => { | ||
const url = "https://cms.artsy.net/foo" | ||
expect(getURLHost(url)).toEqual("cms.artsy.net") | ||
}) | ||
it("returns empty string for empty string", () => { | ||
const url = "" | ||
expect(getURLHost(url)).toEqual("") | ||
}) | ||
it("returns empty string for non-url", () => { | ||
const url = "!@#123" | ||
expect(getURLHost(url)).toEqual("") | ||
}) | ||
}) |