oauth-callback.test.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { test, expect, describe, afterEach } from "bun:test"
  2. import { McpOAuthCallback } from "../../src/mcp/oauth-callback"
  3. import { parseRedirectUri } from "../../src/mcp/oauth-provider"
  4. describe("parseRedirectUri", () => {
  5. test("returns defaults when no URI provided", () => {
  6. const result = parseRedirectUri()
  7. expect(result.port).toBe(19876)
  8. expect(result.path).toBe("/mcp/oauth/callback")
  9. })
  10. test("parses port and path from URI", () => {
  11. const result = parseRedirectUri("http://127.0.0.1:8080/oauth/callback")
  12. expect(result.port).toBe(8080)
  13. expect(result.path).toBe("/oauth/callback")
  14. })
  15. test("returns defaults for invalid URI", () => {
  16. const result = parseRedirectUri("not-a-valid-url")
  17. expect(result.port).toBe(19876)
  18. expect(result.path).toBe("/mcp/oauth/callback")
  19. })
  20. })
  21. describe("McpOAuthCallback.ensureRunning", () => {
  22. afterEach(async () => {
  23. await McpOAuthCallback.stop()
  24. })
  25. test("starts server with custom redirectUri port and path", async () => {
  26. await McpOAuthCallback.ensureRunning("http://127.0.0.1:18000/custom/callback")
  27. expect(McpOAuthCallback.isRunning()).toBe(true)
  28. })
  29. })