openpencil/tests/engine/mcp/auth.test.ts
Danila Poyarkov 5e8d189f2e fix(mcp): harden local file and token access
- Resolve configured root paths through symlinks before file operations

- Compare authentication tokens through fixed-length digests
2026-07-25 21:03:29 +03:00

24 lines
955 B
TypeScript

import { describe, expect, test } from 'bun:test'
import { bearerToken, isAuthorized, mcpRequestToken } from '#mcp/auth'
describe('MCP authentication', () => {
test('accepts exact tokens and rejects mismatches', () => {
expect(isAuthorized('secret-token', 'secret-token')).toBe(true)
expect(isAuthorized('secret-token-x', 'secret-token')).toBe(false)
expect(isAuthorized(null, 'secret-token')).toBe(false)
})
test('allows requests when authentication is disabled', () => {
expect(isAuthorized(null, null)).toBe(true)
expect(isAuthorized('unused', null)).toBe(true)
})
test('extracts bearer and fallback MCP tokens', () => {
expect(bearerToken('Bearer secret-token')).toBe('secret-token')
expect(bearerToken('Basic secret-token')).toBeNull()
expect(mcpRequestToken('Bearer bearer-token', 'header-token')).toBe('bearer-token')
expect(mcpRequestToken(undefined, 'header-token')).toBe('header-token')
})
})