mirror of
https://github.com/davidkaya/aryx.git
synced 2026-08-03 10:28:43 +02:00
Some MCP servers place .well-known metadata at the appended path (e.g. /v1/.well-known/oauth-protected-resource) instead of the RFC 9728 compliant inserted path. Now tries the RFC-compliant URL first and falls back to the appended form. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
53 lines
2.4 KiB
TypeScript
53 lines
2.4 KiB
TypeScript
import { describe, expect, test } from 'bun:test';
|
|
|
|
import { buildWellKnownUrl, buildWellKnownUrlFallback } from '@main/services/mcpTokenStore';
|
|
|
|
describe('buildWellKnownUrl', () => {
|
|
test('inserts well-known segment after origin for URL with path', () => {
|
|
expect(buildWellKnownUrl('https://api.githubcopilot.com/mcp/', 'oauth-protected-resource'))
|
|
.toBe('https://api.githubcopilot.com/.well-known/oauth-protected-resource/mcp/');
|
|
});
|
|
|
|
test('inserts well-known segment for URL with multi-level path', () => {
|
|
expect(buildWellKnownUrl('https://example.com/v1/mcp/api', 'oauth-protected-resource'))
|
|
.toBe('https://example.com/.well-known/oauth-protected-resource/v1/mcp/api');
|
|
});
|
|
|
|
test('handles origin-only URL without path', () => {
|
|
expect(buildWellKnownUrl('https://auth.example.com', 'oauth-authorization-server'))
|
|
.toBe('https://auth.example.com/.well-known/oauth-authorization-server');
|
|
});
|
|
|
|
test('handles origin-only URL with trailing slash', () => {
|
|
expect(buildWellKnownUrl('https://auth.example.com/', 'oauth-authorization-server'))
|
|
.toBe('https://auth.example.com/.well-known/oauth-authorization-server');
|
|
});
|
|
|
|
test('handles URL with port', () => {
|
|
expect(buildWellKnownUrl('https://mcp.example.com:8443/v1/', 'oauth-protected-resource'))
|
|
.toBe('https://mcp.example.com:8443/.well-known/oauth-protected-resource/v1/');
|
|
});
|
|
|
|
test('preserves path without trailing slash', () => {
|
|
expect(buildWellKnownUrl('https://example.com/mcp', 'oauth-protected-resource'))
|
|
.toBe('https://example.com/.well-known/oauth-protected-resource/mcp');
|
|
});
|
|
});
|
|
|
|
describe('buildWellKnownUrlFallback', () => {
|
|
test('appends well-known segment to the full URL path', () => {
|
|
expect(buildWellKnownUrlFallback('https://icm-mcp-prod.azure-api.net/v1/', 'oauth-protected-resource'))
|
|
.toBe('https://icm-mcp-prod.azure-api.net/v1/.well-known/oauth-protected-resource');
|
|
});
|
|
|
|
test('handles URL without trailing slash', () => {
|
|
expect(buildWellKnownUrlFallback('https://example.com/mcp', 'oauth-protected-resource'))
|
|
.toBe('https://example.com/mcp/.well-known/oauth-protected-resource');
|
|
});
|
|
|
|
test('handles origin-only URL', () => {
|
|
expect(buildWellKnownUrlFallback('https://auth.example.com/', 'oauth-authorization-server'))
|
|
.toBe('https://auth.example.com/.well-known/oauth-authorization-server');
|
|
});
|
|
});
|