Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions packages/core/test/actions/callback/stateless.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, test, expect, vi, beforeEach, afterEach } from "vitest"
import { describe, test, expect, vi } from "vitest"
import { GET, jose, oauthCustomService, openIDCustomProvider, openIDMetadata, RS256PEMFormat } from "@test/presets.ts"
import { clearResolvedProviderCache } from "@/shared/oidc/resolve-provider.ts"
import { clearJWKSCache } from "@/shared/oidc/jwks.ts"
Expand All @@ -8,14 +8,6 @@ import { setCookie, getSetCookie } from "@/cookie.ts"
import { AURA_AUTH_VERSION } from "@/shared/utils.ts"
import { createAuth } from "@/createAuth.ts"

beforeEach(() => {
vi.stubEnv("BASE_URL", undefined)
})

afterEach(() => {
vi.unstubAllEnvs()
})

describe("callbackAction", () => {
test("invalid endpoint", async () => {
const response = await GET(new Request("https://example.com/callback/invalid"))
Expand Down
10 changes: 1 addition & 9 deletions packages/core/test/actions/csrfToken/stateless.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { describe, test, expect, vi, beforeEach, afterEach } from "vitest"
import { describe, test, expect } from "vitest"
import { GET } from "@test/presets.ts"
import { setCookie } from "@/cookie.ts"

beforeEach(() => {
vi.stubEnv("BASE_URL", undefined)
})

afterEach(() => {
vi.unstubAllEnvs()
})

describe("csrfTokenAction", () => {
test("generates a CSRF token and sets it in a cookie", async () => {
const response = await GET(new Request("https://example.com/auth/csrfToken"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,7 @@
import { describe, test, expect, vi, afterEach, beforeEach } from "vitest"
import { describe, test, expect, vi } from "vitest"
import { createCSRF } from "@/shared/crypto.ts"
import { GET, jose, oauthTokens, sessionPayload } from "@test/presets.ts"

beforeEach(() => {
vi.stubEnv("BASE_URL", undefined)
})

afterEach(() => {
vi.unstubAllEnvs()
vi.restoreAllMocks()
vi.unstubAllGlobals()
})

vi.mock("@aura-stack/rate-limiter", async () => {
const actual = await vi.importActual<typeof import("@aura-stack/rate-limiter")>("@aura-stack/rate-limiter")
return {
...actual,
createRateLimiter: (...args: Parameters<typeof actual.createRateLimiter>) => {
const limiters = actual.createRateLimiter(...args)

for (const limiter of Object.values(limiters)) {
limiter.check = vi.fn().mockResolvedValue({
ok: true,
limit: Number.MAX_SAFE_INTEGER,
remaining: Number.MAX_SAFE_INTEGER,
resetAt: Date.now() + 60000,
retryAfter: 0,
toResponse: () => new Response(),
})
}

return limiters
},
}
})

describe("connectedAction", () => {
test("throws error when provider is not configured", async () => {
const response = await GET(new Request("https://example.com/auth/providers/unsupported", { headers: new Headers() }))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
import { describe, test, expect, vi, afterEach, beforeEach } from "vitest"
import { describe, test, expect, vi } from "vitest"
import { createAuth } from "@/createAuth.ts"
import { createCSRF } from "@/shared/crypto.ts"
import { jose, oauthCustomService, oauthTokens, POST, sessionPayload } from "@test/presets.ts"

beforeEach(() => {
vi.stubEnv("BASE_URL", undefined)
})

afterEach(() => {
vi.unstubAllEnvs()
vi.restoreAllMocks()
vi.unstubAllGlobals()
})

vi.mock("@aura-stack/rate-limiter", async () => {
const actual = await vi.importActual<typeof import("@aura-stack/rate-limiter")>("@aura-stack/rate-limiter")
return {
...actual,
createRateLimiter: (...args: Parameters<typeof actual.createRateLimiter>) => {
const limiters = actual.createRateLimiter(...args)

for (const limiter of Object.values(limiters)) {
limiter.check = vi.fn().mockResolvedValue({
ok: true,
limit: Number.MAX_SAFE_INTEGER,
remaining: Number.MAX_SAFE_INTEGER,
resetAt: Date.now() + 60000,
retryAfter: 0,
toResponse: () => new Response(),
})
}

return limiters
},
}
})

describe("Revoke Action", () => {
test("throws error when provider is not configured", async () => {
const response = await POST(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { describe, test, expect, vi, afterEach, beforeEach } from "vitest"
import { describe, test, expect, vi } from "vitest"
import { authInstance, jose, oauthCustomService, sessionEntityWithUser } from "@test/presets.ts"
import { createAuth } from "@/createAuth.ts"
import { createBasicAuthHeader } from "@/shared/utils.ts"
import type { OAuthProviderConfig } from "@/@types/oauth.ts"
import { createCSRF } from "@/shared/crypto.ts"

beforeEach(() => {
vi.stubEnv("BASE_URL", undefined)
})

afterEach(() => {
vi.unstubAllEnvs()
vi.restoreAllMocks()
vi.unstubAllGlobals()
})

describe("tokensAction (Stateful)", async () => {
test("should return 422 if the provider is not supported", async () => {
const getSessionByTokenMock = vi.fn()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { describe, test, expect, vi, afterEach, beforeEach } from "vitest"
import { describe, test, expect, vi } from "vitest"
import { createAuth } from "@/createAuth.ts"
import { createCSRF } from "@/shared/crypto.ts"
import { GET, jose, oauthCustomService, oauthTokens, sessionPayload } from "@test/presets.ts"
import { createBasicAuthHeader } from "@/shared/utils.ts"
import type { OAuthProviderConfig } from "@/@types/oauth.ts"

beforeEach(() => {
vi.stubEnv("BASE_URL", undefined)
})

afterEach(() => {
vi.unstubAllEnvs()
vi.restoreAllMocks()
vi.unstubAllGlobals()
})

describe("tokensAction", async () => {
const { encodeJWT } = jose

Expand Down
34 changes: 1 addition & 33 deletions packages/core/test/actions/providers/user/stateless.test.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,9 @@
import { describe, test, expect, vi, beforeEach, afterEach } from "vitest"
import { describe, test, expect, vi } from "vitest"
import { jose, oauthCustomService, oauthTokens, POST, sessionPayload } from "@test/presets.ts"
import { createCSRF } from "@/shared/crypto.ts"
import { createAuth } from "@/createAuth.ts"
import { AURA_AUTH_VERSION } from "@/shared/utils.ts"

beforeEach(() => {
vi.stubEnv("BASE_URL", undefined)
})

afterEach(() => {
vi.unstubAllEnvs()
vi.unstubAllGlobals()
})

vi.mock("@aura-stack/rate-limiter", async () => {
const actual = await vi.importActual<typeof import("@aura-stack/rate-limiter")>("@aura-stack/rate-limiter")
return {
...actual,
createRateLimiter: (...args: Parameters<typeof actual.createRateLimiter>) => {
const limiters = actual.createRateLimiter(...args)

for (const limiter of Object.values(limiters)) {
limiter.check = vi.fn().mockResolvedValue({
ok: true,
limit: Number.MAX_SAFE_INTEGER,
remaining: Number.MAX_SAFE_INTEGER,
resetAt: Date.now() + 60000,
retryAfter: 0,
toResponse: () => new Response(),
})
}

return limiters
},
}
})

describe("refreshUserInfo action", () => {
test("unsupported oauth provider", async () => {
const response = await POST(new Request("https://example.com/auth/unsupported/user/refresh", { method: "POST" }))
Expand Down
12 changes: 1 addition & 11 deletions packages/core/test/actions/session/session/stateful.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { describe, test, expect, vi, afterEach, beforeEach } from "vitest"
import { describe, test, expect, vi } from "vitest"
import { authInstance, jose, sessionEntityWithUser, sessionPayload, userEntity } from "@test/presets.ts"
import { createSchemaRegistry } from "@/validator/registry.ts"

beforeEach(() => {
vi.stubEnv("BASE_URL", undefined)
})

afterEach(() => {
vi.unstubAllEnvs()
vi.restoreAllMocks()
vi.unstubAllGlobals()
})

describe("sessionAction", () => {
const { encodeJWT } = jose

Expand Down
12 changes: 1 addition & 11 deletions packages/core/test/actions/session/session/stateless.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import { describe, test, expect, vi, afterEach, beforeEach } from "vitest"
import { describe, test, expect, vi } from "vitest"
import { createPKCE } from "@/shared/crypto.ts"
import { AURA_AUTH_VERSION } from "@/shared/utils.ts"
import { GET, jose, sessionPayload } from "@test/presets.ts"
import { setCookie, getSetCookie, createCookieStore, getCookie } from "@/cookie.ts"

beforeEach(() => {
vi.stubEnv("BASE_URL", undefined)
})

afterEach(() => {
vi.unstubAllEnvs()
vi.restoreAllMocks()
vi.unstubAllGlobals()
})

describe("sessionAction", () => {
const { encodeJWT } = jose

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
import { describe, test, expect } from "vitest"
import { getSetCookie } from "@/cookie.ts"
import { createAuth } from "@/createAuth.ts"
import { createCSRF } from "@/shared/crypto.ts"
import { jose, PATCH, sessionPayload } from "@test/presets.ts"
import { identitySchema as UserIdentityArkType } from "@/identity/arktype.ts"
import { identitySchema as UserIdentityValibot } from "@/identity/valibot.ts"
import { jose, PATCH, sessionPayload } from "@test/presets.ts"
import { describe, test, expect, vi } from "vitest"

vi.mock("@aura-stack/rate-limiter", async () => {
const actual = await vi.importActual<typeof import("@aura-stack/rate-limiter")>("@aura-stack/rate-limiter")
return {
...actual,
createRateLimiter: (...args: Parameters<typeof actual.createRateLimiter>) => {
const limiters = actual.createRateLimiter(...args)

for (const limiter of Object.values(limiters)) {
limiter.check = vi.fn().mockResolvedValue({
ok: true,
limit: Number.MAX_SAFE_INTEGER,
remaining: Number.MAX_SAFE_INTEGER,
resetAt: Date.now() + 60000,
retryAfter: 0,
toResponse: () => new Response(),
})
}

return limiters
},
}
})

describe("updateSession action", () => {
test("invalid session", async () => {
Expand Down
35 changes: 1 addition & 34 deletions packages/core/test/actions/signIn/signIn/stateless.test.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
import { describe, test, expect, vi, beforeEach, afterEach } from "vitest"
import { describe, test, expect } from "vitest"
import { createAuth } from "@/createAuth.ts"
import { getSetCookie } from "@/cookie.ts"
import { GET, oauthCustomService } from "@test/presets.ts"

beforeEach(() => {
vi.stubEnv("BASE_URL", undefined)
})

afterEach(() => {
vi.unstubAllEnvs()
vi.restoreAllMocks()
vi.unstubAllGlobals()
})

vi.mock("@aura-stack/rate-limiter", async () => {
const actual = await vi.importActual<typeof import("@aura-stack/rate-limiter")>("@aura-stack/rate-limiter")
return {
...actual,
createRateLimiter: (...args: Parameters<typeof actual.createRateLimiter>) => {
const limiters = actual.createRateLimiter(...args)

for (const limiter of Object.values(limiters)) {
limiter.check = vi.fn().mockResolvedValue({
ok: true,
limit: Number.MAX_SAFE_INTEGER,
remaining: Number.MAX_SAFE_INTEGER,
resetAt: Date.now() + 60000,
retryAfter: 0,
toResponse: () => new Response(),
})
}

return limiters
},
}
})

describe("signIn action", () => {
test("default signIn", async () => {
const signIn = await GET(new Request("https://example.com/auth/signIn/oauth-provider"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
import { describe, test, expect, beforeEach, vi, afterEach } from "vitest"
import { describe, test, expect, vi } from "vitest"
import { authInstance, jose, sessionEntityWithUser, userEntity } from "@test/presets.ts"
import { createCSRF } from "@/shared/crypto.ts"
import { createSchemaRegistry } from "@/validator/registry.ts"

beforeEach(() => {
vi.stubEnv("BASE_URL", undefined)
})

afterEach(() => {
vi.unstubAllEnvs()
vi.restoreAllMocks()
vi.unstubAllGlobals()
})

vi.mock("@aura-stack/rate-limiter", async () => {
const actual = await vi.importActual<typeof import("@aura-stack/rate-limiter")>("@aura-stack/rate-limiter")
return {
...actual,
createRateLimiter: (...args: Parameters<typeof actual.createRateLimiter>) => {
const limiters = actual.createRateLimiter(...args)

for (const limiter of Object.values(limiters)) {
limiter.check = vi.fn().mockResolvedValue({
ok: true,
limit: Number.MAX_SAFE_INTEGER,
remaining: Number.MAX_SAFE_INTEGER,
resetAt: Date.now() + 60000,
retryAfter: 0,
toResponse: () => new Response(),
})
}

return limiters
},
}
})

describe("signInCredentials action", async () => {
const csrfToken = await createCSRF(jose)

Expand Down
Loading
Loading