The AI trust layer between agents: identity, agreements, safeguards, and outcome intelligence for A2A.

Viewing files at commit 5239911501a5Commit detailsView latest

tests/hosted-auth.test.ts 38 lines · 1.6 KB · typescript
1
import { describe, expect, it } from 'vitest';
2
import { POST as mcpHandler } from '../api/mcp.js';
3
import { GET as metadataHandler } from '../api/oauth-protected-resource.js';
4
import { dashboardTokenFromCookie } from '../api/auth0.js';
5
6
describe('hosted MCP authorization', () => {
7
  it('reads only the named dashboard session cookie', () => {
8
    expect(dashboardTokenFromCookie('other=x; openclasp_session=token%2Evalue; last=y')).toBe(
9
      'token.value',
10
    );
11
    expect(dashboardTokenFromCookie('other=x')).toBeUndefined();
12
  });
13
  it('challenges unauthenticated remote MCP requests', async () => {
14
    const response = await mcpHandler(
15
      new Request('https://openclasp.example/mcp', {
16
        method: 'POST',
17
        headers: { 'content-type': 'application/json' },
18
        body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/list' }),
19
      }),
20
    );
21
    expect(response.status).toBe(401);
22
    expect(response.headers.get('www-authenticate')).toContain(
23
      'resource_metadata="https://openclasp.example/.well-known/oauth-protected-resource"',
24
    );
25
  });
26
27
  it('publishes Auth0 protected-resource metadata', async () => {
28
    const response = metadataHandler(
29
      new Request('https://openclasp.example/.well-known/oauth-protected-resource'),
30
    );
31
    expect(response.status).toBe(200);
32
    await expect(response.json()).resolves.toMatchObject({
33
      resource: 'https://openclasp.example/mcp',
34
      authorization_servers: ['https://icfg-0ua6bab8d4omtfolx72mrhzo.us.auth0.com/'],
35
      scopes_supported: ['openid', 'profile', 'email', 'mcp:access'],
36
    });
37
  });
38
});