Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a7965bd75 |
No files matched your search
@@ -1,53 +0,0 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { NextRequest } from "next/server";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { getTicket } from "@/lib/auth/ticketClient";
|
||||
import { GET } from "./route";
|
||||
|
||||
vi.mock("@/lib/auth", () => ({ auth: vi.fn() }));
|
||||
vi.mock("@/lib/auth/ticketClient", () => ({ getTicket: vi.fn() }));
|
||||
vi.mock("@/core/edition", () => ({ isAuthEnabled: true }));
|
||||
|
||||
describe("GET /api/auth/ticket", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("returns 401 when no session exists", async () => {
|
||||
vi.mocked(auth).mockResolvedValue(null);
|
||||
const req = new NextRequest("http://localhost/api/auth/ticket?pluginId=aviation");
|
||||
const res = await GET(req);
|
||||
expect(res.status).toBe(401);
|
||||
expect(await res.json()).toEqual({ error: "Unauthorized" });
|
||||
});
|
||||
|
||||
it("returns 400 when pluginId query param is missing", async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(auth).mockResolvedValue({ user: { id: "u1" } } as any);
|
||||
const req = new NextRequest("http://localhost/api/auth/ticket");
|
||||
const res = await GET(req);
|
||||
expect(res.status).toBe(400);
|
||||
expect(await res.json()).toEqual({ error: "Missing pluginId" });
|
||||
});
|
||||
|
||||
it("returns 500 when getTicket throws", async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(auth).mockResolvedValue({ user: { id: "u1" } } as any);
|
||||
vi.mocked(getTicket).mockRejectedValue(new Error("Marketplace unreachable"));
|
||||
const req = new NextRequest("http://localhost/api/auth/ticket?pluginId=aviation");
|
||||
const res = await GET(req);
|
||||
expect(res.status).toBe(500);
|
||||
expect(await res.json()).toEqual({ error: "Failed to obtain plugin ticket" });
|
||||
});
|
||||
|
||||
it("returns 200 with token on success", async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(auth).mockResolvedValue({ user: { id: "u1" } } as any);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(getTicket).mockResolvedValue("plugin-ticket-abc" as any);
|
||||
const req = new NextRequest("http://localhost/api/auth/ticket?pluginId=aviation");
|
||||
const res = await GET(req);
|
||||
expect(res.status).toBe(200);
|
||||
expect(await res.json()).toEqual({ token: "plugin-ticket-abc" });
|
||||
});
|
||||
});
|
||||
@@ -1,32 +0,0 @@
|
||||
import { describe, it, expect, vi, afterEach } from "vitest";
|
||||
import { ticketAuthEnabledForPlugin } from "./edition";
|
||||
|
||||
describe("ticketAuthEnabledForPlugin", () => {
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
it("returns false when env var is empty (dormant default)", () => {
|
||||
vi.stubEnv("NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS", "");
|
||||
expect(ticketAuthEnabledForPlugin("aviation")).toBe(false);
|
||||
expect(ticketAuthEnabledForPlugin("maritime")).toBe(false);
|
||||
});
|
||||
|
||||
it("returns true only for plugin IDs in the comma-separated list", () => {
|
||||
vi.stubEnv("NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS", "aviation,maritime");
|
||||
expect(ticketAuthEnabledForPlugin("aviation")).toBe(true);
|
||||
expect(ticketAuthEnabledForPlugin("maritime")).toBe(true);
|
||||
expect(ticketAuthEnabledForPlugin("wildfire")).toBe(false);
|
||||
});
|
||||
|
||||
it("trims whitespace around plugin IDs", () => {
|
||||
vi.stubEnv("NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS", " aviation , maritime ");
|
||||
expect(ticketAuthEnabledForPlugin("aviation")).toBe(true);
|
||||
expect(ticketAuthEnabledForPlugin("maritime")).toBe(true);
|
||||
});
|
||||
|
||||
it("returns false for a partial match (no substring matching)", () => {
|
||||
vi.stubEnv("NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS", "aviation");
|
||||
expect(ticketAuthEnabledForPlugin("avi")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,43 +0,0 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
|
||||
vi.mock("@sentry/nextjs", () => ({ captureRequestError: vi.fn() }));
|
||||
vi.mock("./sentry.server.config", () => ({}));
|
||||
vi.mock("./sentry.edge.config", () => ({}));
|
||||
|
||||
import { register } from "./instrumentation";
|
||||
|
||||
describe("instrumentation — register()", () => {
|
||||
beforeEach(() => {
|
||||
vi.stubEnv("NEXT_RUNTIME", "nodejs");
|
||||
vi.stubEnv("ENCRYPTION_MASTER_KEY", "test-key-64-chars-abcdef1234567890abcdef");
|
||||
vi.stubEnv("AUTH_SECRET", "test-auth-secret");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
it("throws when ENCRYPTION_MASTER_KEY is not set", async () => {
|
||||
vi.stubEnv("ENCRYPTION_MASTER_KEY", "");
|
||||
await expect(register()).rejects.toThrow(
|
||||
"[startup] ENCRYPTION_MASTER_KEY is not set. The server cannot start without it."
|
||||
);
|
||||
});
|
||||
|
||||
it("throws when AUTH_SECRET is not set", async () => {
|
||||
vi.stubEnv("AUTH_SECRET", "");
|
||||
await expect(register()).rejects.toThrow(
|
||||
"[startup] AUTH_SECRET is not set. The server cannot start without it."
|
||||
);
|
||||
});
|
||||
|
||||
it("resolves without throwing when both secrets are set", async () => {
|
||||
await expect(register()).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not throw when NEXT_RUNTIME is edge (skips nodejs checks)", async () => {
|
||||
vi.stubEnv("NEXT_RUNTIME", "edge");
|
||||
vi.stubEnv("ENCRYPTION_MASTER_KEY", "");
|
||||
await expect(register()).resolves.toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user