CI / config (push) Canceled after 0s
CI / test-frontend (push) Canceled after 0s
CI / test-rust (push) Canceled after 0s
CI / test-e2e (push) Canceled after 0s
CI / test-e2e-release (push) Canceled after 0s
CI / build (push) Canceled after 0s
CI / release (push) Canceled after 0s
CI / docker (push) Canceled after 0s
CI / docker-website (push) Canceled after 0s
在 401 或 opaque redirect 隐藏登录地址时,直接跳转当前空间登录页,并清理旧 Service Worker,避免停留在空白应用外壳。 Co-Authored-By: Codex <noreply@anthropic.com>
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { expect, test } from "vitest";
|
|
import { authenticationRedirectTarget } from "./auth_redirect.ts";
|
|
|
|
test("uses the server-provided authentication location", () => {
|
|
expect(
|
|
authenticationRedirectTarget(
|
|
{ status: 401, type: "basic" },
|
|
"/.auth?from=%2Fnotes",
|
|
"https://notes.example.com/",
|
|
),
|
|
).toBe("https://notes.example.com/.auth?from=%2Fnotes");
|
|
});
|
|
|
|
test("falls back to the current space login when Safari hides Location", () => {
|
|
expect(
|
|
authenticationRedirectTarget(
|
|
{ status: 401, type: "basic" },
|
|
null,
|
|
"https://notes.example.com/work/",
|
|
),
|
|
).toBe("https://notes.example.com/work/.auth");
|
|
expect(
|
|
authenticationRedirectTarget(
|
|
{ status: 0, type: "opaqueredirect" },
|
|
null,
|
|
"https://notes.example.com/",
|
|
),
|
|
).toBe("https://notes.example.com/.auth");
|
|
});
|
|
|
|
test("does not redirect ordinary responses", () => {
|
|
expect(
|
|
authenticationRedirectTarget(
|
|
{ status: 200, type: "basic" },
|
|
null,
|
|
"https://notes.example.com/",
|
|
),
|
|
).toBeNull();
|
|
});
|