Files
openclaw/src/plugin-sdk/provider-auth-runtime.test.ts
2026-05-08 05:28:12 +01:00

33 lines
1.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import * as providerAuthRuntime from "./provider-auth-runtime.js";
describe("plugin-sdk provider-auth-runtime", () => {
it("exports the runtime-ready auth helper", () => {
expect(providerAuthRuntime).toEqual(
expect.objectContaining({
getRuntimeAuthForModel: expect.any(Function),
}),
);
});
it("generates random OAuth state tokens", () => {
const first = providerAuthRuntime.generateOAuthState();
const second = providerAuthRuntime.generateOAuthState();
expect(first).toMatch(/^[a-f0-9]{64}$/);
expect(second).toMatch(/^[a-f0-9]{64}$/);
expect(second).not.toBe(first);
});
it("parses OAuth callback URLs and rejects bare codes", () => {
expect(
providerAuthRuntime.parseOAuthCallbackInput(
"http://127.0.0.1:3000/callback?code=abc&state=state-1",
),
).toEqual({ code: "abc", state: "state-1" });
expect(providerAuthRuntime.parseOAuthCallbackInput("abc")).toEqual({
error: "Paste the full redirect URL, not just the code.",
});
});
});