2026-01-29 19:48:36 +09:00
|
|
|
/// <reference types="bun-types" />
|
|
|
|
|
import { describe, expect, test } from "bun:test"
|
|
|
|
|
import { McpOauthSchema } from "./schema"
|
|
|
|
|
|
|
|
|
|
describe("McpOauthSchema", () => {
|
|
|
|
|
test("parses empty oauth config", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given
|
2026-01-29 19:48:36 +09:00
|
|
|
const input = {}
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-29 19:48:36 +09:00
|
|
|
const result = McpOauthSchema.parse(input)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-29 19:48:36 +09:00
|
|
|
expect(result).toEqual({})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("parses oauth config with clientId", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given
|
2026-01-29 19:48:36 +09:00
|
|
|
const input = { clientId: "client-123" }
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-29 19:48:36 +09:00
|
|
|
const result = McpOauthSchema.parse(input)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-29 19:48:36 +09:00
|
|
|
expect(result).toEqual({ clientId: "client-123" })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("parses oauth config with scopes", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given
|
2026-01-29 19:48:36 +09:00
|
|
|
const input = { scopes: ["openid", "profile"] }
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-29 19:48:36 +09:00
|
|
|
const result = McpOauthSchema.parse(input)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-29 19:48:36 +09:00
|
|
|
expect(result).toEqual({ scopes: ["openid", "profile"] })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("rejects non-string clientId", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given
|
2026-01-29 19:48:36 +09:00
|
|
|
const input = { clientId: 123 }
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-29 19:48:36 +09:00
|
|
|
const result = McpOauthSchema.safeParse(input)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-29 19:48:36 +09:00
|
|
|
expect(result.success).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("rejects non-string scopes", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given
|
2026-01-29 19:48:36 +09:00
|
|
|
const input = { scopes: ["openid", 42] }
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-29 19:48:36 +09:00
|
|
|
const result = McpOauthSchema.safeParse(input)
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-29 19:48:36 +09:00
|
|
|
expect(result.success).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
})
|