4cddfcf2f3
Backend Tests / Tests (other) (push) Failing after 1s
Backend Tests / Static Checks (push) Failing after 2s
Backend Tests / Tests (internal) (push) Failing after 2s
Backend Tests / Tests (server) (push) Failing after 1s
Backend Tests / Tests (store) (push) Failing after 1s
Build Canary Image / build-frontend (push) Failing after 1s
Frontend Tests / Lint (push) Failing after 1s
Build Canary Image / build-push (linux/amd64) (push) Has been skipped
Build Canary Image / build-push (linux/arm64) (push) Has been skipped
Build Canary Image / merge (push) Has been skipped
Frontend Tests / Build (push) Failing after 1s
Release Please / release-please (push) Failing after 0s
Proto Linter / Lint Protos (push) Failing after 2s
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
import { storeOAuthState, validateOAuthState } from "@/utils/oauth";
|
|
|
|
describe("oauth state", () => {
|
|
beforeEach(() => {
|
|
sessionStorage.clear();
|
|
});
|
|
|
|
afterEach(() => {
|
|
sessionStorage.clear();
|
|
});
|
|
|
|
it("round-trips the linking user for link flows", async () => {
|
|
const { state } = await storeOAuthState("identity-providers/google", "link", "/settings", "users/alice");
|
|
|
|
expect(validateOAuthState(state)).toEqual({
|
|
identityProviderName: "identity-providers/google",
|
|
flowMode: "link",
|
|
returnUrl: "/settings",
|
|
linkingUserName: "users/alice",
|
|
codeVerifier: expect.any(String),
|
|
});
|
|
});
|
|
|
|
it("defaults older states to signin without a linking user", () => {
|
|
sessionStorage.setItem(
|
|
"oauth_state",
|
|
JSON.stringify({
|
|
state: "legacy-state",
|
|
identityProviderName: "identity-providers/google",
|
|
timestamp: Date.now(),
|
|
returnUrl: "/auth",
|
|
}),
|
|
);
|
|
|
|
expect(validateOAuthState("legacy-state")).toEqual({
|
|
identityProviderName: "identity-providers/google",
|
|
flowMode: "signin",
|
|
returnUrl: "/auth",
|
|
linkingUserName: undefined,
|
|
codeVerifier: undefined,
|
|
});
|
|
});
|
|
});
|