Skip to content

Commit

Permalink
chore: synchronize workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Nov 13, 2024
1 parent c23154f commit e37f844
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 72 deletions.
176 changes: 141 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
"dependencies": {
"@ory/client-fetch": "^1.15.6",
"cookie": "^1.0.1",
"set-cookie-parser": "^2.7.0",
"tldjs": "^2.3.1"
"parse-domain": "^8.2.2",
"psl": "^1.10.0",
"set-cookie-parser": "^2.7.0"
},
"devDependencies": {
"@types/cookie": "^0.6.0",
"@types/psl": "^1.1.3",
"@types/set-cookie-parser": "^2.4.10",
"@types/tldjs": "^2.3.4",
"tsup": "8.3.0"
},
"keywords": [
Expand Down
52 changes: 28 additions & 24 deletions packages/nextjs/src/utils/cookie.test.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,54 @@
// Copyright © 2024 Ory Corp
// SPDX-License-Identifier: Apache-2.0

import { guessCookieDomain } from "./cookie"

describe("cookie guesser", () => {
test("uses force domain", () => {
test("uses force domain", async () => {
expect(
guessCookieDomain("https://localhost", {
forceCookieDomain: "some-domain",
}),
).toEqual("some-domain")
})

test("does not use any guessing domain", () => {
expect(guessCookieDomain("https://localhost", {})).toEqual(undefined)
test("does not use any guessing domain", async () => {
expect(guessCookieDomain("https://localhost", {})).toEqual("localhost")
})

test("is not confused by invalid data", () => {
expect(guessCookieDomain("5qw5tare4g", {})).toEqual(undefined)
test("is not confused by invalid data", async () => {
expect(guessCookieDomain("https://123.123.123.123.123", {})).toEqual(
undefined,
)
})

test("is not confused by IP", () => {
expect(guessCookieDomain("https://123.123.123.123", {})).toEqual(undefined)
expect(
guessCookieDomain("https://2001:0db8:0000:0000:0000:ff00:0042:8329", {}),
).toEqual(undefined)
test("is not confused by IPv4", async () => {
expect(guessCookieDomain("https://123.123.123.123", {})).toEqual(
"123.123.123.123",
)
})

test("returns undefined for public suffix", () => {
expect(guessCookieDomain("https://asdf.vercel.app", {})).toEqual(undefined)
test("is not confused by IPv6", async () => {
expect(
guessCookieDomain("https://2001:0000:130F:0000:0000:09C0:876A:130B", {}),
).toEqual(undefined)
})

test("uses TLD", () => {
expect(guessCookieDomain("https://foo.localhost", {})).toEqual(
"foo.localhost",
test("uses TLD", async () => {
expect(guessCookieDomain("https://www.example.org", {})).toEqual(
"example.org",
)

expect(guessCookieDomain("https://foo.localhost:1234", {})).toEqual(
expect(guessCookieDomain("https://www.example.org:1234", {})).toEqual(
"example.org",
)
expect(guessCookieDomain("https://localhost/123", {})).toEqual("localhost")
expect(guessCookieDomain("https://foo.localhost/123", {})).toEqual(
"foo.localhost",
)
expect(guessCookieDomain("https://localhost:1234/123", {})).toEqual(
"localhost",
)
})

test("understands public suffix list", () => {
expect(
guessCookieDomain(
"https://spark-public.s3.amazonaws.com/dataanalysis/loansData.csv",
Expand All @@ -53,10 +59,8 @@ describe("cookie guesser", () => {
expect(guessCookieDomain("spark-public.s3.amazonaws.com", {})).toEqual(
"spark-public.s3.amazonaws.com",
)

expect(guessCookieDomain("https://localhost/123", {})).toEqual("localhost")
expect(guessCookieDomain("https://localhost:1234/123", {})).toEqual(
"localhost",
)
expect(
guessCookieDomain("https://docs-gamma-seven.vercel.app", {}),
).toEqual("docs-gamma-seven.vercel.app")
})
})
Loading

0 comments on commit e37f844

Please sign in to comment.