forked from bai/curriculum-project-hub
feat: add deployable alpha silo
This commit is contained in:
@@ -2,6 +2,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
buildAuthorizeUrl,
|
||||
exchangeCodeForUser,
|
||||
FeishuOAuthError,
|
||||
type FeishuOAuthConfig,
|
||||
} from "../../src/admin/auth/feishuOAuth.js";
|
||||
|
||||
@@ -75,13 +76,18 @@ describe("exchangeCodeForUser", () => {
|
||||
|
||||
it("throws on token exchange failure", async () => {
|
||||
const fetchImpl = vi.fn(async () =>
|
||||
new Response(JSON.stringify({ code: 20003, error: "invalid_grant", error_description: "bad code" }), {
|
||||
new Response(JSON.stringify({
|
||||
code: 20003,
|
||||
error: "invalid_grant",
|
||||
error_description: "echoed app secret s and authorization code bad",
|
||||
}), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
}),
|
||||
);
|
||||
await expect(
|
||||
exchangeCodeForUser(
|
||||
let failure: unknown;
|
||||
try {
|
||||
await exchangeCodeForUser(
|
||||
{
|
||||
appId: "cli",
|
||||
appSecret: "s",
|
||||
@@ -90,7 +96,17 @@ describe("exchangeCodeForUser", () => {
|
||||
fetchImpl: fetchImpl as unknown as typeof fetch,
|
||||
},
|
||||
"bad",
|
||||
),
|
||||
).rejects.toThrow(/token exchange failed/);
|
||||
);
|
||||
} catch (error) {
|
||||
failure = error;
|
||||
}
|
||||
expect(failure).toBeInstanceOf(FeishuOAuthError);
|
||||
expect(failure).toMatchObject({
|
||||
code: "feishu_oauth_rejected",
|
||||
category: "provider_rejection",
|
||||
upstreamStatus: 200,
|
||||
});
|
||||
expect(String(failure)).not.toContain("secret s");
|
||||
expect(String(failure)).not.toContain("authorization code bad");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user