Compare commits
4 Commits
365d4a5023
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 784418937d | |||
| 40899d135a | |||
| 62c80ca8d0 | |||
| bb55c658a5 |
@@ -1,4 +1,4 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { authProviderRouter } from "../routes/authProvider.js";
|
import { authProviderRouter } from "../routes/authProvider.js";
|
||||||
|
|
||||||
@@ -227,6 +227,7 @@ describe("PUT /admin/auth-provider", () => {
|
|||||||
|
|
||||||
describe("POST /admin/auth-provider/test", () => {
|
describe("POST /admin/auth-provider/test", () => {
|
||||||
beforeEach(resetMock);
|
beforeEach(resetMock);
|
||||||
|
afterEach(() => vi.restoreAllMocks());
|
||||||
|
|
||||||
it("returns ok=false for unreachable issuer", async () => {
|
it("returns ok=false for unreachable issuer", async () => {
|
||||||
const app = makeApp(mockSuperUser);
|
const app = makeApp(mockSuperUser);
|
||||||
@@ -242,7 +243,12 @@ describe("POST /admin/auth-provider/test", () => {
|
|||||||
expect(body.error).toBeTruthy();
|
expect(body.error).toBeTruthy();
|
||||||
}, 15000); // timeout must exceed the 10s fetch timeout in the route handler
|
}, 15000); // timeout must exceed the 10s fetch timeout in the route handler
|
||||||
|
|
||||||
it("returns 400 for missing clientSecret (not required for test)", async () => {
|
it("returns 200 when clientSecret is omitted (not required by test-connection schema)", async () => {
|
||||||
|
// Mock fetch so the route does not make a real network request.
|
||||||
|
vi.spyOn(global, "fetch").mockResolvedValueOnce({
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({ issuer: "https://auth.example.com" }),
|
||||||
|
} as Response);
|
||||||
const app = makeApp(mockSuperUser);
|
const app = makeApp(mockSuperUser);
|
||||||
const { status } = await post(app, "/admin/auth-provider/test", {
|
const { status } = await post(app, "/admin/auth-provider/test", {
|
||||||
providerId: "authentik",
|
providerId: "authentik",
|
||||||
@@ -250,7 +256,7 @@ describe("POST /admin/auth-provider/test", () => {
|
|||||||
issuerUrl: "https://auth.example.com",
|
issuerUrl: "https://auth.example.com",
|
||||||
clientId: "client",
|
clientId: "client",
|
||||||
}, mockSuperUser);
|
}, mockSuperUser);
|
||||||
expect(status).toBe(200); // clientSecret omitted intentionally for test
|
expect(status).toBe(200);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { authProviderRouter } from "../routes/authProvider.js";
|
import { authProviderRouter } from "../routes/authProvider.js";
|
||||||
|
|
||||||
@@ -227,6 +227,7 @@ describe("PUT /admin/auth-provider", () => {
|
|||||||
|
|
||||||
describe("POST /admin/auth-provider/test", () => {
|
describe("POST /admin/auth-provider/test", () => {
|
||||||
beforeEach(resetMock);
|
beforeEach(resetMock);
|
||||||
|
afterEach(() => vi.restoreAllMocks());
|
||||||
|
|
||||||
it("returns ok=false for unreachable issuer", async () => {
|
it("returns ok=false for unreachable issuer", async () => {
|
||||||
const app = makeApp(mockSuperUser);
|
const app = makeApp(mockSuperUser);
|
||||||
@@ -242,7 +243,12 @@ describe("POST /admin/auth-provider/test", () => {
|
|||||||
expect(body.error).toBeTruthy();
|
expect(body.error).toBeTruthy();
|
||||||
}, 15000); // timeout must exceed the 10s fetch timeout in the route handler
|
}, 15000); // timeout must exceed the 10s fetch timeout in the route handler
|
||||||
|
|
||||||
it("returns 400 for missing clientSecret (not required for test)", async () => {
|
it("returns 200 when clientSecret is omitted (not required by test-connection schema)", async () => {
|
||||||
|
// Mock fetch so the route does not make a real network request.
|
||||||
|
vi.spyOn(global, "fetch").mockResolvedValueOnce({
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({ issuer: "https://auth.example.com" }),
|
||||||
|
} as Response);
|
||||||
const app = makeApp(mockSuperUser);
|
const app = makeApp(mockSuperUser);
|
||||||
const { status } = await post(app, "/admin/auth-provider/test", {
|
const { status } = await post(app, "/admin/auth-provider/test", {
|
||||||
providerId: "authentik",
|
providerId: "authentik",
|
||||||
@@ -250,7 +256,7 @@ describe("POST /admin/auth-provider/test", () => {
|
|||||||
issuerUrl: "https://auth.example.com",
|
issuerUrl: "https://auth.example.com",
|
||||||
clientId: "client",
|
clientId: "client",
|
||||||
}, mockSuperUser);
|
}, mockSuperUser);
|
||||||
expect(status).toBe(200); // clientSecret omitted intentionally for test
|
expect(status).toBe(200);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user