palaryn 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +716 -0
- package/dist/sdk/typescript/src/client.d.ts +71 -0
- package/dist/sdk/typescript/src/client.d.ts.map +1 -0
- package/dist/sdk/typescript/src/client.js +176 -0
- package/dist/sdk/typescript/src/client.js.map +1 -0
- package/dist/sdk/typescript/src/errors.d.ts +50 -0
- package/dist/sdk/typescript/src/errors.d.ts.map +1 -0
- package/dist/sdk/typescript/src/errors.js +103 -0
- package/dist/sdk/typescript/src/errors.js.map +1 -0
- package/dist/sdk/typescript/src/index.d.ts +4 -0
- package/dist/sdk/typescript/src/index.d.ts.map +1 -0
- package/dist/sdk/typescript/src/index.js +15 -0
- package/dist/sdk/typescript/src/index.js.map +1 -0
- package/dist/sdk/typescript/src/types.d.ts +101 -0
- package/dist/sdk/typescript/src/types.d.ts.map +1 -0
- package/dist/sdk/typescript/src/types.js +6 -0
- package/dist/sdk/typescript/src/types.js.map +1 -0
- package/dist/src/admin/index.d.ts +2 -0
- package/dist/src/admin/index.d.ts.map +1 -0
- package/dist/src/admin/index.js +6 -0
- package/dist/src/admin/index.js.map +1 -0
- package/dist/src/admin/routes.d.ts +5 -0
- package/dist/src/admin/routes.d.ts.map +1 -0
- package/dist/src/admin/routes.js +471 -0
- package/dist/src/admin/routes.js.map +1 -0
- package/dist/src/admin/templates.d.ts +51 -0
- package/dist/src/admin/templates.d.ts.map +1 -0
- package/dist/src/admin/templates.js +500 -0
- package/dist/src/admin/templates.js.map +1 -0
- package/dist/src/anomaly/detector.d.ts +141 -0
- package/dist/src/anomaly/detector.d.ts.map +1 -0
- package/dist/src/anomaly/detector.js +554 -0
- package/dist/src/anomaly/detector.js.map +1 -0
- package/dist/src/anomaly/index.d.ts +2 -0
- package/dist/src/anomaly/index.d.ts.map +1 -0
- package/dist/src/anomaly/index.js +7 -0
- package/dist/src/anomaly/index.js.map +1 -0
- package/dist/src/approval/manager.d.ts +147 -0
- package/dist/src/approval/manager.d.ts.map +1 -0
- package/dist/src/approval/manager.js +511 -0
- package/dist/src/approval/manager.js.map +1 -0
- package/dist/src/approval/webhook.d.ts +36 -0
- package/dist/src/approval/webhook.d.ts.map +1 -0
- package/dist/src/approval/webhook.js +135 -0
- package/dist/src/approval/webhook.js.map +1 -0
- package/dist/src/audit/logger.d.ts +70 -0
- package/dist/src/audit/logger.d.ts.map +1 -0
- package/dist/src/audit/logger.js +440 -0
- package/dist/src/audit/logger.js.map +1 -0
- package/dist/src/auth/index.d.ts +6 -0
- package/dist/src/auth/index.d.ts.map +1 -0
- package/dist/src/auth/index.js +22 -0
- package/dist/src/auth/index.js.map +1 -0
- package/dist/src/auth/password.d.ts +3 -0
- package/dist/src/auth/password.d.ts.map +1 -0
- package/dist/src/auth/password.js +25 -0
- package/dist/src/auth/password.js.map +1 -0
- package/dist/src/auth/pkce.d.ts +13 -0
- package/dist/src/auth/pkce.d.ts.map +1 -0
- package/dist/src/auth/pkce.js +58 -0
- package/dist/src/auth/pkce.js.map +1 -0
- package/dist/src/auth/providers.d.ts +28 -0
- package/dist/src/auth/providers.d.ts.map +1 -0
- package/dist/src/auth/providers.js +198 -0
- package/dist/src/auth/providers.js.map +1 -0
- package/dist/src/auth/routes.d.ts +14 -0
- package/dist/src/auth/routes.d.ts.map +1 -0
- package/dist/src/auth/routes.js +431 -0
- package/dist/src/auth/routes.js.map +1 -0
- package/dist/src/auth/session.d.ts +24 -0
- package/dist/src/auth/session.d.ts.map +1 -0
- package/dist/src/auth/session.js +105 -0
- package/dist/src/auth/session.js.map +1 -0
- package/dist/src/billing/index.d.ts +7 -0
- package/dist/src/billing/index.d.ts.map +1 -0
- package/dist/src/billing/index.js +14 -0
- package/dist/src/billing/index.js.map +1 -0
- package/dist/src/billing/plan-enforcer.d.ts +44 -0
- package/dist/src/billing/plan-enforcer.d.ts.map +1 -0
- package/dist/src/billing/plan-enforcer.js +110 -0
- package/dist/src/billing/plan-enforcer.js.map +1 -0
- package/dist/src/billing/routes.d.ts +15 -0
- package/dist/src/billing/routes.d.ts.map +1 -0
- package/dist/src/billing/routes.js +193 -0
- package/dist/src/billing/routes.js.map +1 -0
- package/dist/src/billing/stripe-client.d.ts +14 -0
- package/dist/src/billing/stripe-client.d.ts.map +1 -0
- package/dist/src/billing/stripe-client.js +51 -0
- package/dist/src/billing/stripe-client.js.map +1 -0
- package/dist/src/billing/webhook-handler.d.ts +19 -0
- package/dist/src/billing/webhook-handler.d.ts.map +1 -0
- package/dist/src/billing/webhook-handler.js +169 -0
- package/dist/src/billing/webhook-handler.js.map +1 -0
- package/dist/src/billing/webhook-routes.d.ts +5 -0
- package/dist/src/billing/webhook-routes.d.ts.map +1 -0
- package/dist/src/billing/webhook-routes.js +30 -0
- package/dist/src/billing/webhook-routes.js.map +1 -0
- package/dist/src/budget/manager.d.ts +95 -0
- package/dist/src/budget/manager.d.ts.map +1 -0
- package/dist/src/budget/manager.js +547 -0
- package/dist/src/budget/manager.js.map +1 -0
- package/dist/src/budget/usage-extractor.d.ts +38 -0
- package/dist/src/budget/usage-extractor.d.ts.map +1 -0
- package/dist/src/budget/usage-extractor.js +165 -0
- package/dist/src/budget/usage-extractor.js.map +1 -0
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +115 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/config/defaults.d.ts +3 -0
- package/dist/src/config/defaults.d.ts.map +1 -0
- package/dist/src/config/defaults.js +243 -0
- package/dist/src/config/defaults.js.map +1 -0
- package/dist/src/config/validate.d.ts +15 -0
- package/dist/src/config/validate.d.ts.map +1 -0
- package/dist/src/config/validate.js +105 -0
- package/dist/src/config/validate.js.map +1 -0
- package/dist/src/dlp/composite-scanner.d.ts +47 -0
- package/dist/src/dlp/composite-scanner.d.ts.map +1 -0
- package/dist/src/dlp/composite-scanner.js +186 -0
- package/dist/src/dlp/composite-scanner.js.map +1 -0
- package/dist/src/dlp/index.d.ts +10 -0
- package/dist/src/dlp/index.d.ts.map +1 -0
- package/dist/src/dlp/index.js +26 -0
- package/dist/src/dlp/index.js.map +1 -0
- package/dist/src/dlp/interfaces.d.ts +33 -0
- package/dist/src/dlp/interfaces.d.ts.map +1 -0
- package/dist/src/dlp/interfaces.js +3 -0
- package/dist/src/dlp/interfaces.js.map +1 -0
- package/dist/src/dlp/patterns.d.ts +9 -0
- package/dist/src/dlp/patterns.d.ts.map +1 -0
- package/dist/src/dlp/patterns.js +25 -0
- package/dist/src/dlp/patterns.js.map +1 -0
- package/dist/src/dlp/prompt-injection-backend.d.ts +68 -0
- package/dist/src/dlp/prompt-injection-backend.d.ts.map +1 -0
- package/dist/src/dlp/prompt-injection-backend.js +148 -0
- package/dist/src/dlp/prompt-injection-backend.js.map +1 -0
- package/dist/src/dlp/prompt-injection-patterns.d.ts +32 -0
- package/dist/src/dlp/prompt-injection-patterns.d.ts.map +1 -0
- package/dist/src/dlp/prompt-injection-patterns.js +290 -0
- package/dist/src/dlp/prompt-injection-patterns.js.map +1 -0
- package/dist/src/dlp/regex-backend.d.ts +32 -0
- package/dist/src/dlp/regex-backend.d.ts.map +1 -0
- package/dist/src/dlp/regex-backend.js +153 -0
- package/dist/src/dlp/regex-backend.js.map +1 -0
- package/dist/src/dlp/scanner.d.ts +122 -0
- package/dist/src/dlp/scanner.d.ts.map +1 -0
- package/dist/src/dlp/scanner.js +444 -0
- package/dist/src/dlp/scanner.js.map +1 -0
- package/dist/src/dlp/text-normalizer.d.ts +41 -0
- package/dist/src/dlp/text-normalizer.d.ts.map +1 -0
- package/dist/src/dlp/text-normalizer.js +203 -0
- package/dist/src/dlp/text-normalizer.js.map +1 -0
- package/dist/src/dlp/trufflehog-backend.d.ts +64 -0
- package/dist/src/dlp/trufflehog-backend.d.ts.map +1 -0
- package/dist/src/dlp/trufflehog-backend.js +151 -0
- package/dist/src/dlp/trufflehog-backend.js.map +1 -0
- package/dist/src/executor/http-executor.d.ts +25 -0
- package/dist/src/executor/http-executor.d.ts.map +1 -0
- package/dist/src/executor/http-executor.js +333 -0
- package/dist/src/executor/http-executor.js.map +1 -0
- package/dist/src/executor/index.d.ts +6 -0
- package/dist/src/executor/index.d.ts.map +1 -0
- package/dist/src/executor/index.js +12 -0
- package/dist/src/executor/index.js.map +1 -0
- package/dist/src/executor/interfaces.d.ts +11 -0
- package/dist/src/executor/interfaces.d.ts.map +1 -0
- package/dist/src/executor/interfaces.js +3 -0
- package/dist/src/executor/interfaces.js.map +1 -0
- package/dist/src/executor/noop-executor.d.ts +13 -0
- package/dist/src/executor/noop-executor.d.ts.map +1 -0
- package/dist/src/executor/noop-executor.js +21 -0
- package/dist/src/executor/noop-executor.js.map +1 -0
- package/dist/src/executor/registry.d.ts +30 -0
- package/dist/src/executor/registry.d.ts.map +1 -0
- package/dist/src/executor/registry.js +62 -0
- package/dist/src/executor/registry.js.map +1 -0
- package/dist/src/executor/slack-executor.d.ts +24 -0
- package/dist/src/executor/slack-executor.d.ts.map +1 -0
- package/dist/src/executor/slack-executor.js +147 -0
- package/dist/src/executor/slack-executor.js.map +1 -0
- package/dist/src/index.d.ts +25 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +74 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mcp/auth-verifier.d.ts +23 -0
- package/dist/src/mcp/auth-verifier.d.ts.map +1 -0
- package/dist/src/mcp/auth-verifier.js +162 -0
- package/dist/src/mcp/auth-verifier.js.map +1 -0
- package/dist/src/mcp/bridge.d.ts +132 -0
- package/dist/src/mcp/bridge.d.ts.map +1 -0
- package/dist/src/mcp/bridge.js +734 -0
- package/dist/src/mcp/bridge.js.map +1 -0
- package/dist/src/mcp/http-transport.d.ts +32 -0
- package/dist/src/mcp/http-transport.d.ts.map +1 -0
- package/dist/src/mcp/http-transport.js +538 -0
- package/dist/src/mcp/http-transport.js.map +1 -0
- package/dist/src/mcp/index.d.ts +10 -0
- package/dist/src/mcp/index.d.ts.map +1 -0
- package/dist/src/mcp/index.js +17 -0
- package/dist/src/mcp/index.js.map +1 -0
- package/dist/src/mcp/oauth-pages.d.ts +23 -0
- package/dist/src/mcp/oauth-pages.d.ts.map +1 -0
- package/dist/src/mcp/oauth-pages.js +121 -0
- package/dist/src/mcp/oauth-pages.js.map +1 -0
- package/dist/src/mcp/oauth-postgres-stores.d.ts +55 -0
- package/dist/src/mcp/oauth-postgres-stores.d.ts.map +1 -0
- package/dist/src/mcp/oauth-postgres-stores.js +226 -0
- package/dist/src/mcp/oauth-postgres-stores.js.map +1 -0
- package/dist/src/mcp/oauth-provider.d.ts +95 -0
- package/dist/src/mcp/oauth-provider.d.ts.map +1 -0
- package/dist/src/mcp/oauth-provider.js +360 -0
- package/dist/src/mcp/oauth-provider.js.map +1 -0
- package/dist/src/mcp/oauth-stores.d.ts +62 -0
- package/dist/src/mcp/oauth-stores.d.ts.map +1 -0
- package/dist/src/mcp/oauth-stores.js +154 -0
- package/dist/src/mcp/oauth-stores.js.map +1 -0
- package/dist/src/mcp/server.d.ts +18 -0
- package/dist/src/mcp/server.d.ts.map +1 -0
- package/dist/src/mcp/server.js +51 -0
- package/dist/src/mcp/server.js.map +1 -0
- package/dist/src/metrics/collector.d.ts +106 -0
- package/dist/src/metrics/collector.d.ts.map +1 -0
- package/dist/src/metrics/collector.js +311 -0
- package/dist/src/metrics/collector.js.map +1 -0
- package/dist/src/metrics/index.d.ts +2 -0
- package/dist/src/metrics/index.d.ts.map +1 -0
- package/dist/src/metrics/index.js +6 -0
- package/dist/src/metrics/index.js.map +1 -0
- package/dist/src/middleware/auth.d.ts +77 -0
- package/dist/src/middleware/auth.d.ts.map +1 -0
- package/dist/src/middleware/auth.js +720 -0
- package/dist/src/middleware/auth.js.map +1 -0
- package/dist/src/middleware/session.d.ts +18 -0
- package/dist/src/middleware/session.d.ts.map +1 -0
- package/dist/src/middleware/session.js +67 -0
- package/dist/src/middleware/session.js.map +1 -0
- package/dist/src/middleware/validate.d.ts +3 -0
- package/dist/src/middleware/validate.d.ts.map +1 -0
- package/dist/src/middleware/validate.js +85 -0
- package/dist/src/middleware/validate.js.map +1 -0
- package/dist/src/policy/engine.d.ts +107 -0
- package/dist/src/policy/engine.d.ts.map +1 -0
- package/dist/src/policy/engine.js +646 -0
- package/dist/src/policy/engine.js.map +1 -0
- package/dist/src/policy/index.d.ts +3 -0
- package/dist/src/policy/index.d.ts.map +1 -0
- package/dist/src/policy/index.js +8 -0
- package/dist/src/policy/index.js.map +1 -0
- package/dist/src/policy/opa-engine.d.ts +176 -0
- package/dist/src/policy/opa-engine.d.ts.map +1 -0
- package/dist/src/policy/opa-engine.js +790 -0
- package/dist/src/policy/opa-engine.js.map +1 -0
- package/dist/src/proxy/forward-proxy.d.ts +30 -0
- package/dist/src/proxy/forward-proxy.d.ts.map +1 -0
- package/dist/src/proxy/forward-proxy.js +580 -0
- package/dist/src/proxy/forward-proxy.js.map +1 -0
- package/dist/src/proxy/index.d.ts +2 -0
- package/dist/src/proxy/index.d.ts.map +1 -0
- package/dist/src/proxy/index.js +8 -0
- package/dist/src/proxy/index.js.map +1 -0
- package/dist/src/ratelimit/limiter.d.ts +45 -0
- package/dist/src/ratelimit/limiter.d.ts.map +1 -0
- package/dist/src/ratelimit/limiter.js +158 -0
- package/dist/src/ratelimit/limiter.js.map +1 -0
- package/dist/src/replay/engine.d.ts +40 -0
- package/dist/src/replay/engine.d.ts.map +1 -0
- package/dist/src/replay/engine.js +106 -0
- package/dist/src/replay/engine.js.map +1 -0
- package/dist/src/replay/index.d.ts +2 -0
- package/dist/src/replay/index.d.ts.map +1 -0
- package/dist/src/replay/index.js +6 -0
- package/dist/src/replay/index.js.map +1 -0
- package/dist/src/saas/index.d.ts +2 -0
- package/dist/src/saas/index.d.ts.map +1 -0
- package/dist/src/saas/index.js +18 -0
- package/dist/src/saas/index.js.map +1 -0
- package/dist/src/saas/routes.d.ts +18 -0
- package/dist/src/saas/routes.d.ts.map +1 -0
- package/dist/src/saas/routes.js +1566 -0
- package/dist/src/saas/routes.js.map +1 -0
- package/dist/src/server/app.d.ts +44 -0
- package/dist/src/server/app.d.ts.map +1 -0
- package/dist/src/server/app.js +854 -0
- package/dist/src/server/app.js.map +1 -0
- package/dist/src/server/errors.d.ts +32 -0
- package/dist/src/server/errors.d.ts.map +1 -0
- package/dist/src/server/errors.js +39 -0
- package/dist/src/server/errors.js.map +1 -0
- package/dist/src/server/gateway.d.ts +165 -0
- package/dist/src/server/gateway.d.ts.map +1 -0
- package/dist/src/server/gateway.js +964 -0
- package/dist/src/server/gateway.js.map +1 -0
- package/dist/src/server/index.d.ts +2 -0
- package/dist/src/server/index.d.ts.map +1 -0
- package/dist/src/server/index.js +295 -0
- package/dist/src/server/index.js.map +1 -0
- package/dist/src/server/logger.d.ts +33 -0
- package/dist/src/server/logger.d.ts.map +1 -0
- package/dist/src/server/logger.js +230 -0
- package/dist/src/server/logger.js.map +1 -0
- package/dist/src/server/stream-proxy.d.ts +32 -0
- package/dist/src/server/stream-proxy.d.ts.map +1 -0
- package/dist/src/server/stream-proxy.js +184 -0
- package/dist/src/server/stream-proxy.js.map +1 -0
- package/dist/src/storage/file-persistence.d.ts +48 -0
- package/dist/src/storage/file-persistence.d.ts.map +1 -0
- package/dist/src/storage/file-persistence.js +280 -0
- package/dist/src/storage/file-persistence.js.map +1 -0
- package/dist/src/storage/index.d.ts +5 -0
- package/dist/src/storage/index.d.ts.map +1 -0
- package/dist/src/storage/index.js +21 -0
- package/dist/src/storage/index.js.map +1 -0
- package/dist/src/storage/interfaces.d.ts +237 -0
- package/dist/src/storage/interfaces.d.ts.map +1 -0
- package/dist/src/storage/interfaces.js +3 -0
- package/dist/src/storage/interfaces.js.map +1 -0
- package/dist/src/storage/memory.d.ts +162 -0
- package/dist/src/storage/memory.d.ts.map +1 -0
- package/dist/src/storage/memory.js +603 -0
- package/dist/src/storage/memory.js.map +1 -0
- package/dist/src/storage/postgres.d.ts +267 -0
- package/dist/src/storage/postgres.d.ts.map +1 -0
- package/dist/src/storage/postgres.js +1555 -0
- package/dist/src/storage/postgres.js.map +1 -0
- package/dist/src/storage/redis.d.ts +202 -0
- package/dist/src/storage/redis.d.ts.map +1 -0
- package/dist/src/storage/redis.js +629 -0
- package/dist/src/storage/redis.js.map +1 -0
- package/dist/src/tracing/index.d.ts +2 -0
- package/dist/src/tracing/index.d.ts.map +1 -0
- package/dist/src/tracing/index.js +6 -0
- package/dist/src/tracing/index.js.map +1 -0
- package/dist/src/tracing/provider.d.ts +43 -0
- package/dist/src/tracing/provider.d.ts.map +1 -0
- package/dist/src/tracing/provider.js +74 -0
- package/dist/src/tracing/provider.js.map +1 -0
- package/dist/src/trust/calculator.d.ts +54 -0
- package/dist/src/trust/calculator.d.ts.map +1 -0
- package/dist/src/trust/calculator.js +102 -0
- package/dist/src/trust/calculator.js.map +1 -0
- package/dist/src/trust/index.d.ts +2 -0
- package/dist/src/trust/index.d.ts.map +1 -0
- package/dist/src/trust/index.js +7 -0
- package/dist/src/trust/index.js.map +1 -0
- package/dist/src/types/budget.d.ts +30 -0
- package/dist/src/types/budget.d.ts.map +1 -0
- package/dist/src/types/budget.js +3 -0
- package/dist/src/types/budget.js.map +1 -0
- package/dist/src/types/config.d.ts +176 -0
- package/dist/src/types/config.d.ts.map +1 -0
- package/dist/src/types/config.js +3 -0
- package/dist/src/types/config.js.map +1 -0
- package/dist/src/types/events.d.ts +24 -0
- package/dist/src/types/events.d.ts.map +1 -0
- package/dist/src/types/events.js +3 -0
- package/dist/src/types/events.js.map +1 -0
- package/dist/src/types/index.d.ts +8 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +24 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/policy.d.ts +60 -0
- package/dist/src/types/policy.d.ts.map +1 -0
- package/dist/src/types/policy.js +3 -0
- package/dist/src/types/policy.js.map +1 -0
- package/dist/src/types/stripe-config.d.ts +12 -0
- package/dist/src/types/stripe-config.d.ts.map +1 -0
- package/dist/src/types/stripe-config.js +3 -0
- package/dist/src/types/stripe-config.js.map +1 -0
- package/dist/src/types/subscription.d.ts +24 -0
- package/dist/src/types/subscription.d.ts.map +1 -0
- package/dist/src/types/subscription.js +38 -0
- package/dist/src/types/subscription.js.map +1 -0
- package/dist/src/types/tool-call.d.ts +42 -0
- package/dist/src/types/tool-call.d.ts.map +1 -0
- package/dist/src/types/tool-call.js +3 -0
- package/dist/src/types/tool-call.js.map +1 -0
- package/dist/src/types/tool-result.d.ts +58 -0
- package/dist/src/types/tool-result.d.ts.map +1 -0
- package/dist/src/types/tool-result.js +3 -0
- package/dist/src/types/tool-result.js.map +1 -0
- package/dist/src/types/user.d.ts +101 -0
- package/dist/src/types/user.d.ts.map +1 -0
- package/dist/src/types/user.js +6 -0
- package/dist/src/types/user.js.map +1 -0
- package/dist/tests/integration/api.test.d.ts +2 -0
- package/dist/tests/integration/api.test.d.ts.map +1 -0
- package/dist/tests/integration/api.test.js +1199 -0
- package/dist/tests/integration/api.test.js.map +1 -0
- package/dist/tests/integration/proxy.test.d.ts +2 -0
- package/dist/tests/integration/proxy.test.d.ts.map +1 -0
- package/dist/tests/integration/proxy.test.js +251 -0
- package/dist/tests/integration/proxy.test.js.map +1 -0
- package/dist/tests/integration/storage.test.d.ts +16 -0
- package/dist/tests/integration/storage.test.d.ts.map +1 -0
- package/dist/tests/integration/storage.test.js +826 -0
- package/dist/tests/integration/storage.test.js.map +1 -0
- package/dist/tests/unit/admin.test.d.ts +2 -0
- package/dist/tests/unit/admin.test.d.ts.map +1 -0
- package/dist/tests/unit/admin.test.js +698 -0
- package/dist/tests/unit/admin.test.js.map +1 -0
- package/dist/tests/unit/anomaly-detector.test.d.ts +2 -0
- package/dist/tests/unit/anomaly-detector.test.d.ts.map +1 -0
- package/dist/tests/unit/anomaly-detector.test.js +903 -0
- package/dist/tests/unit/anomaly-detector.test.js.map +1 -0
- package/dist/tests/unit/approval-manager.test.d.ts +2 -0
- package/dist/tests/unit/approval-manager.test.d.ts.map +1 -0
- package/dist/tests/unit/approval-manager.test.js +528 -0
- package/dist/tests/unit/approval-manager.test.js.map +1 -0
- package/dist/tests/unit/approval-webhook.test.d.ts +2 -0
- package/dist/tests/unit/approval-webhook.test.d.ts.map +1 -0
- package/dist/tests/unit/approval-webhook.test.js +355 -0
- package/dist/tests/unit/approval-webhook.test.js.map +1 -0
- package/dist/tests/unit/audit-logger.test.d.ts +2 -0
- package/dist/tests/unit/audit-logger.test.d.ts.map +1 -0
- package/dist/tests/unit/audit-logger.test.js +635 -0
- package/dist/tests/unit/audit-logger.test.js.map +1 -0
- package/dist/tests/unit/auth-routes.test.d.ts +2 -0
- package/dist/tests/unit/auth-routes.test.d.ts.map +1 -0
- package/dist/tests/unit/auth-routes.test.js +281 -0
- package/dist/tests/unit/auth-routes.test.js.map +1 -0
- package/dist/tests/unit/auth.test.d.ts +2 -0
- package/dist/tests/unit/auth.test.d.ts.map +1 -0
- package/dist/tests/unit/auth.test.js +1382 -0
- package/dist/tests/unit/auth.test.js.map +1 -0
- package/dist/tests/unit/billing.test.d.ts +2 -0
- package/dist/tests/unit/billing.test.d.ts.map +1 -0
- package/dist/tests/unit/billing.test.js +579 -0
- package/dist/tests/unit/billing.test.js.map +1 -0
- package/dist/tests/unit/budget-manager.test.d.ts +2 -0
- package/dist/tests/unit/budget-manager.test.d.ts.map +1 -0
- package/dist/tests/unit/budget-manager.test.js +778 -0
- package/dist/tests/unit/budget-manager.test.js.map +1 -0
- package/dist/tests/unit/budget-race.test.d.ts +2 -0
- package/dist/tests/unit/budget-race.test.d.ts.map +1 -0
- package/dist/tests/unit/budget-race.test.js +58 -0
- package/dist/tests/unit/budget-race.test.js.map +1 -0
- package/dist/tests/unit/cli.test.d.ts +2 -0
- package/dist/tests/unit/cli.test.d.ts.map +1 -0
- package/dist/tests/unit/cli.test.js +93 -0
- package/dist/tests/unit/cli.test.js.map +1 -0
- package/dist/tests/unit/concurrency.test.d.ts +2 -0
- package/dist/tests/unit/concurrency.test.d.ts.map +1 -0
- package/dist/tests/unit/concurrency.test.js +1270 -0
- package/dist/tests/unit/concurrency.test.js.map +1 -0
- package/dist/tests/unit/config-validate.test.d.ts +2 -0
- package/dist/tests/unit/config-validate.test.d.ts.map +1 -0
- package/dist/tests/unit/config-validate.test.js +230 -0
- package/dist/tests/unit/config-validate.test.js.map +1 -0
- package/dist/tests/unit/defaults.test.d.ts +2 -0
- package/dist/tests/unit/defaults.test.d.ts.map +1 -0
- package/dist/tests/unit/defaults.test.js +364 -0
- package/dist/tests/unit/defaults.test.js.map +1 -0
- package/dist/tests/unit/dlp-backends.test.d.ts +2 -0
- package/dist/tests/unit/dlp-backends.test.d.ts.map +1 -0
- package/dist/tests/unit/dlp-backends.test.js +563 -0
- package/dist/tests/unit/dlp-backends.test.js.map +1 -0
- package/dist/tests/unit/dlp-scanner.test.d.ts +2 -0
- package/dist/tests/unit/dlp-scanner.test.d.ts.map +1 -0
- package/dist/tests/unit/dlp-scanner.test.js +739 -0
- package/dist/tests/unit/dlp-scanner.test.js.map +1 -0
- package/dist/tests/unit/error-responses.test.d.ts +2 -0
- package/dist/tests/unit/error-responses.test.d.ts.map +1 -0
- package/dist/tests/unit/error-responses.test.js +101 -0
- package/dist/tests/unit/error-responses.test.js.map +1 -0
- package/dist/tests/unit/executor-registry.test.d.ts +2 -0
- package/dist/tests/unit/executor-registry.test.d.ts.map +1 -0
- package/dist/tests/unit/executor-registry.test.js +390 -0
- package/dist/tests/unit/executor-registry.test.js.map +1 -0
- package/dist/tests/unit/forward-proxy.test.d.ts +2 -0
- package/dist/tests/unit/forward-proxy.test.d.ts.map +1 -0
- package/dist/tests/unit/forward-proxy.test.js +621 -0
- package/dist/tests/unit/forward-proxy.test.js.map +1 -0
- package/dist/tests/unit/gateway-features.test.d.ts +2 -0
- package/dist/tests/unit/gateway-features.test.d.ts.map +1 -0
- package/dist/tests/unit/gateway-features.test.js +753 -0
- package/dist/tests/unit/gateway-features.test.js.map +1 -0
- package/dist/tests/unit/http-executor.test.d.ts +2 -0
- package/dist/tests/unit/http-executor.test.d.ts.map +1 -0
- package/dist/tests/unit/http-executor.test.js +310 -0
- package/dist/tests/unit/http-executor.test.js.map +1 -0
- package/dist/tests/unit/mcp-bridge.test.d.ts +2 -0
- package/dist/tests/unit/mcp-bridge.test.d.ts.map +1 -0
- package/dist/tests/unit/mcp-bridge.test.js +1136 -0
- package/dist/tests/unit/mcp-bridge.test.js.map +1 -0
- package/dist/tests/unit/mcp-http-transport.test.d.ts +2 -0
- package/dist/tests/unit/mcp-http-transport.test.d.ts.map +1 -0
- package/dist/tests/unit/mcp-http-transport.test.js +899 -0
- package/dist/tests/unit/mcp-http-transport.test.js.map +1 -0
- package/dist/tests/unit/mcp-oauth.test.d.ts +2 -0
- package/dist/tests/unit/mcp-oauth.test.d.ts.map +1 -0
- package/dist/tests/unit/mcp-oauth.test.js +759 -0
- package/dist/tests/unit/mcp-oauth.test.js.map +1 -0
- package/dist/tests/unit/mcp-server.test.d.ts +15 -0
- package/dist/tests/unit/mcp-server.test.d.ts.map +1 -0
- package/dist/tests/unit/mcp-server.test.js +158 -0
- package/dist/tests/unit/mcp-server.test.js.map +1 -0
- package/dist/tests/unit/metrics.test.d.ts +2 -0
- package/dist/tests/unit/metrics.test.d.ts.map +1 -0
- package/dist/tests/unit/metrics.test.js +208 -0
- package/dist/tests/unit/metrics.test.js.map +1 -0
- package/dist/tests/unit/oauth.test.d.ts +2 -0
- package/dist/tests/unit/oauth.test.d.ts.map +1 -0
- package/dist/tests/unit/oauth.test.js +281 -0
- package/dist/tests/unit/oauth.test.js.map +1 -0
- package/dist/tests/unit/opa-circuit-breaker.test.d.ts +2 -0
- package/dist/tests/unit/opa-circuit-breaker.test.d.ts.map +1 -0
- package/dist/tests/unit/opa-circuit-breaker.test.js +297 -0
- package/dist/tests/unit/opa-circuit-breaker.test.js.map +1 -0
- package/dist/tests/unit/opa-engine.test.d.ts +2 -0
- package/dist/tests/unit/opa-engine.test.d.ts.map +1 -0
- package/dist/tests/unit/opa-engine.test.js +1813 -0
- package/dist/tests/unit/opa-engine.test.js.map +1 -0
- package/dist/tests/unit/pipeline-timing.test.d.ts +2 -0
- package/dist/tests/unit/pipeline-timing.test.d.ts.map +1 -0
- package/dist/tests/unit/pipeline-timing.test.js +528 -0
- package/dist/tests/unit/pipeline-timing.test.js.map +1 -0
- package/dist/tests/unit/policy-engine.test.d.ts +2 -0
- package/dist/tests/unit/policy-engine.test.d.ts.map +1 -0
- package/dist/tests/unit/policy-engine.test.js +1345 -0
- package/dist/tests/unit/policy-engine.test.js.map +1 -0
- package/dist/tests/unit/policy-store.test.d.ts +2 -0
- package/dist/tests/unit/policy-store.test.d.ts.map +1 -0
- package/dist/tests/unit/policy-store.test.js +60 -0
- package/dist/tests/unit/policy-store.test.js.map +1 -0
- package/dist/tests/unit/postgres-storage.test.d.ts +2 -0
- package/dist/tests/unit/postgres-storage.test.d.ts.map +1 -0
- package/dist/tests/unit/postgres-storage.test.js +614 -0
- package/dist/tests/unit/postgres-storage.test.js.map +1 -0
- package/dist/tests/unit/prompt-injection-backend.test.d.ts +2 -0
- package/dist/tests/unit/prompt-injection-backend.test.d.ts.map +1 -0
- package/dist/tests/unit/prompt-injection-backend.test.js +621 -0
- package/dist/tests/unit/prompt-injection-backend.test.js.map +1 -0
- package/dist/tests/unit/proxy-hardening.test.d.ts +2 -0
- package/dist/tests/unit/proxy-hardening.test.d.ts.map +1 -0
- package/dist/tests/unit/proxy-hardening.test.js +166 -0
- package/dist/tests/unit/proxy-hardening.test.js.map +1 -0
- package/dist/tests/unit/rate-limiter.test.d.ts +2 -0
- package/dist/tests/unit/rate-limiter.test.d.ts.map +1 -0
- package/dist/tests/unit/rate-limiter.test.js +443 -0
- package/dist/tests/unit/rate-limiter.test.js.map +1 -0
- package/dist/tests/unit/redis-storage.test.d.ts +2 -0
- package/dist/tests/unit/redis-storage.test.d.ts.map +1 -0
- package/dist/tests/unit/redis-storage.test.js +766 -0
- package/dist/tests/unit/redis-storage.test.js.map +1 -0
- package/dist/tests/unit/replay-engine.test.d.ts +2 -0
- package/dist/tests/unit/replay-engine.test.d.ts.map +1 -0
- package/dist/tests/unit/replay-engine.test.js +371 -0
- package/dist/tests/unit/replay-engine.test.js.map +1 -0
- package/dist/tests/unit/saas-routes.test.d.ts +2 -0
- package/dist/tests/unit/saas-routes.test.d.ts.map +1 -0
- package/dist/tests/unit/saas-routes.test.js +1399 -0
- package/dist/tests/unit/saas-routes.test.js.map +1 -0
- package/dist/tests/unit/session.test.d.ts +2 -0
- package/dist/tests/unit/session.test.d.ts.map +1 -0
- package/dist/tests/unit/session.test.js +532 -0
- package/dist/tests/unit/session.test.js.map +1 -0
- package/dist/tests/unit/slack-executor.test.d.ts +2 -0
- package/dist/tests/unit/slack-executor.test.d.ts.map +1 -0
- package/dist/tests/unit/slack-executor.test.js +209 -0
- package/dist/tests/unit/slack-executor.test.js.map +1 -0
- package/dist/tests/unit/storage-hardening.test.d.ts +2 -0
- package/dist/tests/unit/storage-hardening.test.d.ts.map +1 -0
- package/dist/tests/unit/storage-hardening.test.js +165 -0
- package/dist/tests/unit/storage-hardening.test.js.map +1 -0
- package/dist/tests/unit/storage.test.d.ts +2 -0
- package/dist/tests/unit/storage.test.d.ts.map +1 -0
- package/dist/tests/unit/storage.test.js +698 -0
- package/dist/tests/unit/storage.test.js.map +1 -0
- package/dist/tests/unit/text-normalizer.test.d.ts +2 -0
- package/dist/tests/unit/text-normalizer.test.d.ts.map +1 -0
- package/dist/tests/unit/text-normalizer.test.js +229 -0
- package/dist/tests/unit/text-normalizer.test.js.map +1 -0
- package/dist/tests/unit/tracing.test.d.ts +2 -0
- package/dist/tests/unit/tracing.test.d.ts.map +1 -0
- package/dist/tests/unit/tracing.test.js +611 -0
- package/dist/tests/unit/tracing.test.js.map +1 -0
- package/dist/tests/unit/trust-calculator.test.d.ts +2 -0
- package/dist/tests/unit/trust-calculator.test.d.ts.map +1 -0
- package/dist/tests/unit/trust-calculator.test.js +497 -0
- package/dist/tests/unit/trust-calculator.test.js.map +1 -0
- package/dist/tests/unit/ts-sdk.test.d.ts +2 -0
- package/dist/tests/unit/ts-sdk.test.d.ts.map +1 -0
- package/dist/tests/unit/ts-sdk.test.js +421 -0
- package/dist/tests/unit/ts-sdk.test.js.map +1 -0
- package/dist/tests/unit/usage-extractor-llm.test.d.ts +2 -0
- package/dist/tests/unit/usage-extractor-llm.test.d.ts.map +1 -0
- package/dist/tests/unit/usage-extractor-llm.test.js +139 -0
- package/dist/tests/unit/usage-extractor-llm.test.js.map +1 -0
- package/dist/tests/unit/usage-extractor.test.d.ts +2 -0
- package/dist/tests/unit/usage-extractor.test.d.ts.map +1 -0
- package/dist/tests/unit/usage-extractor.test.js +271 -0
- package/dist/tests/unit/usage-extractor.test.js.map +1 -0
- package/dist/tests/unit/user-stores.test.d.ts +2 -0
- package/dist/tests/unit/user-stores.test.d.ts.map +1 -0
- package/dist/tests/unit/user-stores.test.js +687 -0
- package/dist/tests/unit/user-stores.test.js.map +1 -0
- package/dist/tests/unit/validate.test.d.ts +2 -0
- package/dist/tests/unit/validate.test.d.ts.map +1 -0
- package/dist/tests/unit/validate.test.js +545 -0
- package/dist/tests/unit/validate.test.js.map +1 -0
- package/package.json +86 -0
- package/policy-packs/README.md +42 -0
- package/policy-packs/default.yaml +46 -0
- package/policy-packs/dev_fast.yaml +54 -0
- package/policy-packs/prod_strict.yaml +83 -0
|
@@ -0,0 +1,759 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Mock SaaS stores
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
function createMockStores() {
|
|
7
|
+
const users = new Map();
|
|
8
|
+
const workspaces = new Map();
|
|
9
|
+
const members = [];
|
|
10
|
+
const sessions = new Map();
|
|
11
|
+
return {
|
|
12
|
+
userStore: {
|
|
13
|
+
create(u) { users.set(u.id, u); },
|
|
14
|
+
getById(id) { return users.get(id); },
|
|
15
|
+
getByEmail(email) { for (const u of users.values()) {
|
|
16
|
+
if (u.email === email)
|
|
17
|
+
return u;
|
|
18
|
+
} return undefined; },
|
|
19
|
+
update(id, updates) { const u = users.get(id); if (!u)
|
|
20
|
+
return undefined; Object.assign(u, updates); return u; },
|
|
21
|
+
delete(id) { return users.delete(id); },
|
|
22
|
+
list() { return Array.from(users.values()); },
|
|
23
|
+
},
|
|
24
|
+
workspaceStore: {
|
|
25
|
+
create(w) { workspaces.set(w.id, w); },
|
|
26
|
+
getById(id) { return workspaces.get(id); },
|
|
27
|
+
getBySlug(slug) { for (const w of workspaces.values()) {
|
|
28
|
+
if (w.slug === slug)
|
|
29
|
+
return w;
|
|
30
|
+
} return undefined; },
|
|
31
|
+
getByOwner(userId) { return Array.from(workspaces.values()).filter(w => w.owner_user_id === userId); },
|
|
32
|
+
update(id, updates) { const w = workspaces.get(id); if (!w)
|
|
33
|
+
return undefined; Object.assign(w, updates); return w; },
|
|
34
|
+
delete(id) { return workspaces.delete(id); },
|
|
35
|
+
list() { return Array.from(workspaces.values()); },
|
|
36
|
+
},
|
|
37
|
+
workspaceMemberStore: {
|
|
38
|
+
create(m) { members.push(m); },
|
|
39
|
+
getById(id) { return members.find(m => m.id === id); },
|
|
40
|
+
getByWorkspace(wsId) { return members.filter(m => m.workspace_id === wsId); },
|
|
41
|
+
getByUser(userId) { return members.filter(m => m.user_id === userId); },
|
|
42
|
+
getByWorkspaceAndUser(wsId, userId) { return members.find(m => m.workspace_id === wsId && m.user_id === userId); },
|
|
43
|
+
update(id, updates) { const m = members.find(x => x.id === id); if (!m)
|
|
44
|
+
return undefined; Object.assign(m, updates); return m; },
|
|
45
|
+
delete(id) { const idx = members.findIndex(m => m.id === id); if (idx >= 0) {
|
|
46
|
+
members.splice(idx, 1);
|
|
47
|
+
return true;
|
|
48
|
+
} return false; },
|
|
49
|
+
},
|
|
50
|
+
sessionStore: {
|
|
51
|
+
create(s) { sessions.set(s.id, s); },
|
|
52
|
+
getById(id) { return sessions.get(id); },
|
|
53
|
+
getByUserId(userId) { return Array.from(sessions.values()).filter(s => s.user_id === userId); },
|
|
54
|
+
update(id, updates) { const s = sessions.get(id); if (!s)
|
|
55
|
+
return undefined; Object.assign(s, updates); return s; },
|
|
56
|
+
delete(id) { return sessions.delete(id); },
|
|
57
|
+
deleteExpired() { return 0; },
|
|
58
|
+
deleteByUserId(userId) { let count = 0; for (const [id, s] of sessions) {
|
|
59
|
+
if (s.user_id === userId) {
|
|
60
|
+
sessions.delete(id);
|
|
61
|
+
count++;
|
|
62
|
+
}
|
|
63
|
+
} return count; },
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function seedTestData(stores) {
|
|
68
|
+
const now = new Date().toISOString();
|
|
69
|
+
stores.userStore.create({
|
|
70
|
+
id: 'usr_test1',
|
|
71
|
+
email: 'alice@test.com',
|
|
72
|
+
display_name: 'Alice',
|
|
73
|
+
status: 'active',
|
|
74
|
+
onboarding_completed: true,
|
|
75
|
+
created_at: now,
|
|
76
|
+
updated_at: now,
|
|
77
|
+
});
|
|
78
|
+
stores.workspaceStore.create({
|
|
79
|
+
id: 'ws_prod',
|
|
80
|
+
name: 'Production',
|
|
81
|
+
slug: 'production',
|
|
82
|
+
owner_user_id: 'usr_test1',
|
|
83
|
+
plan: 'free',
|
|
84
|
+
settings: {},
|
|
85
|
+
created_at: now,
|
|
86
|
+
updated_at: now,
|
|
87
|
+
});
|
|
88
|
+
stores.workspaceMemberStore.create({
|
|
89
|
+
id: 'wm_1',
|
|
90
|
+
workspace_id: 'ws_prod',
|
|
91
|
+
user_id: 'usr_test1',
|
|
92
|
+
role: 'owner',
|
|
93
|
+
joined_at: now,
|
|
94
|
+
});
|
|
95
|
+
stores.sessionStore.create({
|
|
96
|
+
id: 'sess_abc123',
|
|
97
|
+
user_id: 'usr_test1',
|
|
98
|
+
workspace_id: 'ws_prod',
|
|
99
|
+
expires_at: new Date(Date.now() + 3600000).toISOString(),
|
|
100
|
+
last_active_at: now,
|
|
101
|
+
created_at: now,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
// Imports
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
const oauth_stores_1 = require("../../src/mcp/oauth-stores");
|
|
108
|
+
const oauth_provider_1 = require("../../src/mcp/oauth-provider");
|
|
109
|
+
const auth_verifier_1 = require("../../src/mcp/auth-verifier");
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
// OAuth Stores
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
describe('OAuthClientsStore', () => {
|
|
114
|
+
let store;
|
|
115
|
+
beforeEach(() => { store = new oauth_stores_1.OAuthClientsStore(); });
|
|
116
|
+
it('registers a client with generated ID and secret', () => {
|
|
117
|
+
const client = store.registerClient({
|
|
118
|
+
redirect_uris: [new URL('http://localhost:3000/callback')],
|
|
119
|
+
client_name: 'Test Client',
|
|
120
|
+
});
|
|
121
|
+
expect(client.client_id).toMatch(/^pn_client_/);
|
|
122
|
+
expect(client.client_secret).toBeDefined();
|
|
123
|
+
expect(client.client_secret.length).toBe(64); // 32 bytes hex
|
|
124
|
+
expect(client.client_id_issued_at).toBeGreaterThan(0);
|
|
125
|
+
expect(client.client_name).toBe('Test Client');
|
|
126
|
+
});
|
|
127
|
+
it('retrieves a registered client by ID', () => {
|
|
128
|
+
const client = store.registerClient({
|
|
129
|
+
redirect_uris: [new URL('http://localhost:3000/callback')],
|
|
130
|
+
});
|
|
131
|
+
const found = store.getClient(client.client_id);
|
|
132
|
+
expect(found).toBeDefined();
|
|
133
|
+
expect(found.client_id).toBe(client.client_id);
|
|
134
|
+
});
|
|
135
|
+
it('returns undefined for unknown client ID', () => {
|
|
136
|
+
expect(store.getClient('nonexistent')).toBeUndefined();
|
|
137
|
+
});
|
|
138
|
+
it('serializes and loads entries for persistence', () => {
|
|
139
|
+
const client = store.registerClient({
|
|
140
|
+
redirect_uris: [new URL('http://localhost:3000/callback')],
|
|
141
|
+
client_name: 'Persistent',
|
|
142
|
+
});
|
|
143
|
+
const entries = store.entries();
|
|
144
|
+
expect(entries.length).toBe(1);
|
|
145
|
+
const newStore = new oauth_stores_1.OAuthClientsStore();
|
|
146
|
+
newStore.load(entries);
|
|
147
|
+
const found = newStore.getClient(client.client_id);
|
|
148
|
+
expect(found).toBeDefined();
|
|
149
|
+
expect(found.client_name).toBe('Persistent');
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
describe('AuthCodeStore', () => {
|
|
153
|
+
let store;
|
|
154
|
+
beforeEach(() => { store = new oauth_stores_1.AuthCodeStore(10000); }); // 10s TTL
|
|
155
|
+
afterEach(() => { store.destroy(); });
|
|
156
|
+
it('saves and retrieves an auth code', () => {
|
|
157
|
+
store.save({
|
|
158
|
+
code: 'code_123',
|
|
159
|
+
clientId: 'client_1',
|
|
160
|
+
codeChallenge: 'challenge',
|
|
161
|
+
redirectUri: 'http://localhost/callback',
|
|
162
|
+
scopes: ['mcp:tools'],
|
|
163
|
+
userId: 'usr_1',
|
|
164
|
+
workspaceId: 'ws_1',
|
|
165
|
+
expiresAt: Date.now() + 60000,
|
|
166
|
+
});
|
|
167
|
+
const entry = store.get('code_123');
|
|
168
|
+
expect(entry).toBeDefined();
|
|
169
|
+
expect(entry.clientId).toBe('client_1');
|
|
170
|
+
});
|
|
171
|
+
it('returns undefined for unknown code', () => {
|
|
172
|
+
expect(store.get('nonexistent')).toBeUndefined();
|
|
173
|
+
});
|
|
174
|
+
it('returns undefined for expired code', () => {
|
|
175
|
+
store.save({
|
|
176
|
+
code: 'expired',
|
|
177
|
+
clientId: 'client_1',
|
|
178
|
+
codeChallenge: 'challenge',
|
|
179
|
+
redirectUri: 'http://localhost/callback',
|
|
180
|
+
scopes: [],
|
|
181
|
+
userId: 'usr_1',
|
|
182
|
+
workspaceId: 'ws_1',
|
|
183
|
+
expiresAt: Date.now() - 1000, // Already expired
|
|
184
|
+
});
|
|
185
|
+
expect(store.get('expired')).toBeUndefined();
|
|
186
|
+
});
|
|
187
|
+
it('consume removes the code after retrieval', () => {
|
|
188
|
+
store.save({
|
|
189
|
+
code: 'one_time',
|
|
190
|
+
clientId: 'client_1',
|
|
191
|
+
codeChallenge: 'challenge',
|
|
192
|
+
redirectUri: 'http://localhost/callback',
|
|
193
|
+
scopes: [],
|
|
194
|
+
userId: 'usr_1',
|
|
195
|
+
workspaceId: 'ws_1',
|
|
196
|
+
expiresAt: Date.now() + 60000,
|
|
197
|
+
});
|
|
198
|
+
const entry = store.consume('one_time');
|
|
199
|
+
expect(entry).toBeDefined();
|
|
200
|
+
expect(store.get('one_time')).toBeUndefined(); // Gone after consume
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
describe('OAuthTokenStore', () => {
|
|
204
|
+
let store;
|
|
205
|
+
beforeEach(() => { store = new oauth_stores_1.OAuthTokenStore(3600, 86400); }); // 1h access, 24h refresh
|
|
206
|
+
afterEach(() => { store.destroy(); });
|
|
207
|
+
it('saves and retrieves access tokens', () => {
|
|
208
|
+
const nowSec = Math.floor(Date.now() / 1000);
|
|
209
|
+
store.saveAccessToken({
|
|
210
|
+
token: 'access_abc',
|
|
211
|
+
clientId: 'client_1',
|
|
212
|
+
userId: 'usr_1',
|
|
213
|
+
workspaceId: 'ws_1',
|
|
214
|
+
scopes: ['mcp:tools'],
|
|
215
|
+
expiresAt: nowSec + 3600,
|
|
216
|
+
createdAt: nowSec,
|
|
217
|
+
});
|
|
218
|
+
const entry = store.getAccessToken('access_abc');
|
|
219
|
+
expect(entry).toBeDefined();
|
|
220
|
+
expect(entry.workspaceId).toBe('ws_1');
|
|
221
|
+
});
|
|
222
|
+
it('returns undefined for expired access token', () => {
|
|
223
|
+
store.saveAccessToken({
|
|
224
|
+
token: 'expired_token',
|
|
225
|
+
clientId: 'client_1',
|
|
226
|
+
userId: 'usr_1',
|
|
227
|
+
workspaceId: 'ws_1',
|
|
228
|
+
scopes: [],
|
|
229
|
+
expiresAt: Math.floor(Date.now() / 1000) - 1,
|
|
230
|
+
createdAt: Math.floor(Date.now() / 1000) - 3601,
|
|
231
|
+
});
|
|
232
|
+
expect(store.getAccessToken('expired_token')).toBeUndefined();
|
|
233
|
+
});
|
|
234
|
+
it('revokes access tokens', () => {
|
|
235
|
+
const nowSec = Math.floor(Date.now() / 1000);
|
|
236
|
+
store.saveAccessToken({
|
|
237
|
+
token: 'revoke_me',
|
|
238
|
+
clientId: 'client_1',
|
|
239
|
+
userId: 'usr_1',
|
|
240
|
+
workspaceId: 'ws_1',
|
|
241
|
+
scopes: [],
|
|
242
|
+
expiresAt: nowSec + 3600,
|
|
243
|
+
createdAt: nowSec,
|
|
244
|
+
});
|
|
245
|
+
store.revokeAccessToken('revoke_me');
|
|
246
|
+
expect(store.getAccessToken('revoke_me')).toBeUndefined();
|
|
247
|
+
});
|
|
248
|
+
it('saves and retrieves refresh tokens', () => {
|
|
249
|
+
const nowSec = Math.floor(Date.now() / 1000);
|
|
250
|
+
store.saveRefreshToken({
|
|
251
|
+
token: 'refresh_xyz',
|
|
252
|
+
clientId: 'client_1',
|
|
253
|
+
userId: 'usr_1',
|
|
254
|
+
workspaceId: 'ws_1',
|
|
255
|
+
scopes: ['mcp:tools'],
|
|
256
|
+
expiresAt: nowSec + 86400,
|
|
257
|
+
createdAt: nowSec,
|
|
258
|
+
});
|
|
259
|
+
const entry = store.getRefreshToken('refresh_xyz');
|
|
260
|
+
expect(entry).toBeDefined();
|
|
261
|
+
});
|
|
262
|
+
it('exposes TTL values', () => {
|
|
263
|
+
expect(store.accessTtlSeconds).toBe(3600);
|
|
264
|
+
expect(store.refreshTtlSeconds).toBe(86400);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
// ---------------------------------------------------------------------------
|
|
268
|
+
// PalarynOAuthProvider
|
|
269
|
+
// ---------------------------------------------------------------------------
|
|
270
|
+
describe('PalarynOAuthProvider', () => {
|
|
271
|
+
let stores;
|
|
272
|
+
let clientsStore;
|
|
273
|
+
let authCodeStore;
|
|
274
|
+
let tokenStore;
|
|
275
|
+
let provider;
|
|
276
|
+
beforeEach(() => {
|
|
277
|
+
stores = createMockStores();
|
|
278
|
+
seedTestData(stores);
|
|
279
|
+
clientsStore = new oauth_stores_1.OAuthClientsStore();
|
|
280
|
+
authCodeStore = new oauth_stores_1.AuthCodeStore();
|
|
281
|
+
tokenStore = new oauth_stores_1.OAuthTokenStore(3600, 86400);
|
|
282
|
+
provider = new oauth_provider_1.PalarynOAuthProvider({
|
|
283
|
+
clientsStore,
|
|
284
|
+
authCodeStore,
|
|
285
|
+
tokenStore,
|
|
286
|
+
userStore: stores.userStore,
|
|
287
|
+
workspaceStore: stores.workspaceStore,
|
|
288
|
+
workspaceMemberStore: stores.workspaceMemberStore,
|
|
289
|
+
sessionStore: stores.sessionStore,
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
afterEach(() => {
|
|
293
|
+
authCodeStore.destroy();
|
|
294
|
+
tokenStore.destroy();
|
|
295
|
+
});
|
|
296
|
+
it('exposes the clients store', () => {
|
|
297
|
+
expect(provider.clientsStore).toBe(clientsStore);
|
|
298
|
+
});
|
|
299
|
+
describe('authorize', () => {
|
|
300
|
+
it('redirects to login when no session cookie', async () => {
|
|
301
|
+
const client = clientsStore.registerClient({
|
|
302
|
+
redirect_uris: [new URL('http://localhost/callback')],
|
|
303
|
+
client_name: 'Test',
|
|
304
|
+
});
|
|
305
|
+
const res = {
|
|
306
|
+
req: { cookies: {} },
|
|
307
|
+
redirect: jest.fn(),
|
|
308
|
+
setHeader: jest.fn(),
|
|
309
|
+
status: jest.fn().mockReturnThis(),
|
|
310
|
+
type: jest.fn().mockReturnThis(),
|
|
311
|
+
send: jest.fn(),
|
|
312
|
+
};
|
|
313
|
+
await provider.authorize(client, { codeChallenge: 'test', redirectUri: 'http://localhost/callback', scopes: ['mcp:tools'] }, res);
|
|
314
|
+
expect(res.redirect).toHaveBeenCalled();
|
|
315
|
+
const redirectUrl = res.redirect.mock.calls[0][0];
|
|
316
|
+
expect(redirectUrl).toContain('/login');
|
|
317
|
+
expect(redirectUrl).toContain('return_to=');
|
|
318
|
+
});
|
|
319
|
+
it('renders consent page when session is valid', async () => {
|
|
320
|
+
const client = clientsStore.registerClient({
|
|
321
|
+
redirect_uris: [new URL('http://localhost/callback')],
|
|
322
|
+
client_name: 'Claude Code',
|
|
323
|
+
});
|
|
324
|
+
const res = {
|
|
325
|
+
req: { cookies: { pn_session: 'sess_abc123' } },
|
|
326
|
+
redirect: jest.fn(),
|
|
327
|
+
setHeader: jest.fn(),
|
|
328
|
+
status: jest.fn().mockReturnThis(),
|
|
329
|
+
type: jest.fn().mockReturnThis(),
|
|
330
|
+
send: jest.fn(),
|
|
331
|
+
};
|
|
332
|
+
await provider.authorize(client, { codeChallenge: 'test_challenge', redirectUri: 'http://localhost/callback', scopes: ['mcp:tools'] }, res);
|
|
333
|
+
expect(res.status).toHaveBeenCalledWith(200);
|
|
334
|
+
expect(res.type).toHaveBeenCalledWith('html');
|
|
335
|
+
const html = res.send.mock.calls[0][0];
|
|
336
|
+
expect(html).toContain('Claude Code');
|
|
337
|
+
expect(html).toContain('ws_prod'); // Single workspace → hidden input with workspace ID
|
|
338
|
+
expect(html).toContain('Approve');
|
|
339
|
+
expect(html).toContain('Deny');
|
|
340
|
+
});
|
|
341
|
+
it('shows error when user has no workspaces', async () => {
|
|
342
|
+
// Create a user with no workspace memberships
|
|
343
|
+
stores.userStore.create({
|
|
344
|
+
id: 'usr_lonely',
|
|
345
|
+
email: 'lonely@test.com',
|
|
346
|
+
display_name: 'Lonely',
|
|
347
|
+
status: 'active',
|
|
348
|
+
onboarding_completed: true,
|
|
349
|
+
created_at: new Date().toISOString(),
|
|
350
|
+
updated_at: new Date().toISOString(),
|
|
351
|
+
});
|
|
352
|
+
stores.sessionStore.create({
|
|
353
|
+
id: 'sess_lonely',
|
|
354
|
+
user_id: 'usr_lonely',
|
|
355
|
+
expires_at: new Date(Date.now() + 3600000).toISOString(),
|
|
356
|
+
last_active_at: new Date().toISOString(),
|
|
357
|
+
created_at: new Date().toISOString(),
|
|
358
|
+
});
|
|
359
|
+
const client = clientsStore.registerClient({
|
|
360
|
+
redirect_uris: [new URL('http://localhost/callback')],
|
|
361
|
+
});
|
|
362
|
+
const res = {
|
|
363
|
+
req: { cookies: { pn_session: 'sess_lonely' } },
|
|
364
|
+
redirect: jest.fn(),
|
|
365
|
+
setHeader: jest.fn(),
|
|
366
|
+
status: jest.fn().mockReturnThis(),
|
|
367
|
+
type: jest.fn().mockReturnThis(),
|
|
368
|
+
send: jest.fn(),
|
|
369
|
+
};
|
|
370
|
+
await provider.authorize(client, { codeChallenge: 'test', redirectUri: 'http://localhost/callback' }, res);
|
|
371
|
+
expect(res.status).toHaveBeenCalledWith(403);
|
|
372
|
+
const html = res.send.mock.calls[0][0];
|
|
373
|
+
expect(html).toContain('No workspaces');
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
describe('handleConsentDecision', () => {
|
|
377
|
+
let client;
|
|
378
|
+
let csrfToken;
|
|
379
|
+
beforeEach(async () => {
|
|
380
|
+
client = clientsStore.registerClient({
|
|
381
|
+
redirect_uris: [new URL('http://localhost/callback')],
|
|
382
|
+
client_name: 'Test',
|
|
383
|
+
});
|
|
384
|
+
// Trigger authorize to create CSRF token
|
|
385
|
+
const res = {
|
|
386
|
+
req: { cookies: { pn_session: 'sess_abc123' } },
|
|
387
|
+
redirect: jest.fn(),
|
|
388
|
+
setHeader: jest.fn(),
|
|
389
|
+
status: jest.fn().mockReturnThis(),
|
|
390
|
+
type: jest.fn().mockReturnThis(),
|
|
391
|
+
send: jest.fn(),
|
|
392
|
+
};
|
|
393
|
+
await provider.authorize(client, { codeChallenge: 'test_challenge', redirectUri: 'http://localhost/callback', scopes: ['mcp:tools'] }, res);
|
|
394
|
+
// Extract CSRF token from HTML
|
|
395
|
+
const html = res.send.mock.calls[0][0];
|
|
396
|
+
const csrfMatch = html.match(/name="csrf_token" value="([^"]+)"/);
|
|
397
|
+
csrfToken = csrfMatch[1];
|
|
398
|
+
});
|
|
399
|
+
it('generates auth code on approve', async () => {
|
|
400
|
+
const result = await provider.handleConsentDecision({
|
|
401
|
+
client_id: client.client_id,
|
|
402
|
+
redirect_uri: 'http://localhost/callback',
|
|
403
|
+
state: 'test_state',
|
|
404
|
+
code_challenge: 'test_challenge',
|
|
405
|
+
scopes: 'mcp:tools',
|
|
406
|
+
csrf_token: csrfToken,
|
|
407
|
+
workspace_id: 'ws_prod',
|
|
408
|
+
decision: 'approve',
|
|
409
|
+
}, 'usr_test1');
|
|
410
|
+
expect('redirectUrl' in result).toBe(true);
|
|
411
|
+
const url = new URL(result.redirectUrl);
|
|
412
|
+
expect(url.searchParams.get('code')).toBeTruthy();
|
|
413
|
+
expect(url.searchParams.get('state')).toBe('test_state');
|
|
414
|
+
});
|
|
415
|
+
it('returns access_denied on deny', async () => {
|
|
416
|
+
const result = await provider.handleConsentDecision({
|
|
417
|
+
client_id: client.client_id,
|
|
418
|
+
redirect_uri: 'http://localhost/callback',
|
|
419
|
+
state: 'test_state',
|
|
420
|
+
code_challenge: 'test_challenge',
|
|
421
|
+
scopes: 'mcp:tools',
|
|
422
|
+
csrf_token: csrfToken,
|
|
423
|
+
workspace_id: 'ws_prod',
|
|
424
|
+
decision: 'deny',
|
|
425
|
+
}, 'usr_test1');
|
|
426
|
+
expect('redirectUrl' in result).toBe(true);
|
|
427
|
+
const url = new URL(result.redirectUrl);
|
|
428
|
+
expect(url.searchParams.get('error')).toBe('access_denied');
|
|
429
|
+
});
|
|
430
|
+
it('rejects invalid CSRF token', async () => {
|
|
431
|
+
const result = await provider.handleConsentDecision({
|
|
432
|
+
client_id: client.client_id,
|
|
433
|
+
redirect_uri: 'http://localhost/callback',
|
|
434
|
+
code_challenge: 'test_challenge',
|
|
435
|
+
scopes: 'mcp:tools',
|
|
436
|
+
csrf_token: 'bad_token',
|
|
437
|
+
workspace_id: 'ws_prod',
|
|
438
|
+
decision: 'approve',
|
|
439
|
+
}, 'usr_test1');
|
|
440
|
+
expect('error' in result).toBe(true);
|
|
441
|
+
expect(result.status).toBe(403);
|
|
442
|
+
});
|
|
443
|
+
it('rejects wrong workspace', async () => {
|
|
444
|
+
const result = await provider.handleConsentDecision({
|
|
445
|
+
client_id: client.client_id,
|
|
446
|
+
redirect_uri: 'http://localhost/callback',
|
|
447
|
+
code_challenge: 'test_challenge',
|
|
448
|
+
scopes: 'mcp:tools',
|
|
449
|
+
csrf_token: csrfToken,
|
|
450
|
+
workspace_id: 'ws_nonexistent',
|
|
451
|
+
decision: 'approve',
|
|
452
|
+
}, 'usr_test1');
|
|
453
|
+
expect('error' in result).toBe(true);
|
|
454
|
+
expect(result.status).toBe(403);
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
describe('full token exchange flow', () => {
|
|
458
|
+
it('exchanges auth code for tokens', async () => {
|
|
459
|
+
const client = clientsStore.registerClient({
|
|
460
|
+
redirect_uris: [new URL('http://localhost/callback')],
|
|
461
|
+
});
|
|
462
|
+
// Save an auth code directly
|
|
463
|
+
authCodeStore.save({
|
|
464
|
+
code: 'test_code',
|
|
465
|
+
clientId: client.client_id,
|
|
466
|
+
codeChallenge: 'challenge123',
|
|
467
|
+
redirectUri: 'http://localhost/callback',
|
|
468
|
+
scopes: ['mcp:tools'],
|
|
469
|
+
userId: 'usr_test1',
|
|
470
|
+
workspaceId: 'ws_prod',
|
|
471
|
+
expiresAt: Date.now() + 60000,
|
|
472
|
+
});
|
|
473
|
+
const tokens = await provider.exchangeAuthorizationCode(client, 'test_code');
|
|
474
|
+
expect(tokens.access_token).toBeTruthy();
|
|
475
|
+
expect(tokens.refresh_token).toBeTruthy();
|
|
476
|
+
expect(tokens.token_type).toBe('Bearer');
|
|
477
|
+
expect(tokens.expires_in).toBe(3600);
|
|
478
|
+
expect(tokens.scope).toBe('mcp:tools');
|
|
479
|
+
});
|
|
480
|
+
it('rejects mismatched client ID', async () => {
|
|
481
|
+
const client1 = clientsStore.registerClient({ redirect_uris: [new URL('http://localhost/cb')] });
|
|
482
|
+
const client2 = clientsStore.registerClient({ redirect_uris: [new URL('http://localhost/cb')] });
|
|
483
|
+
authCodeStore.save({
|
|
484
|
+
code: 'code_for_client1',
|
|
485
|
+
clientId: client1.client_id,
|
|
486
|
+
codeChallenge: 'c',
|
|
487
|
+
redirectUri: 'http://localhost/cb',
|
|
488
|
+
scopes: [],
|
|
489
|
+
userId: 'usr_test1',
|
|
490
|
+
workspaceId: 'ws_prod',
|
|
491
|
+
expiresAt: Date.now() + 60000,
|
|
492
|
+
});
|
|
493
|
+
await expect(provider.exchangeAuthorizationCode(client2, 'code_for_client1')).rejects.toThrow('Client ID mismatch');
|
|
494
|
+
});
|
|
495
|
+
it('auth code is single-use', async () => {
|
|
496
|
+
const client = clientsStore.registerClient({ redirect_uris: [new URL('http://localhost/cb')] });
|
|
497
|
+
authCodeStore.save({
|
|
498
|
+
code: 'single_use',
|
|
499
|
+
clientId: client.client_id,
|
|
500
|
+
codeChallenge: 'c',
|
|
501
|
+
redirectUri: 'http://localhost/cb',
|
|
502
|
+
scopes: [],
|
|
503
|
+
userId: 'usr_test1',
|
|
504
|
+
workspaceId: 'ws_prod',
|
|
505
|
+
expiresAt: Date.now() + 60000,
|
|
506
|
+
});
|
|
507
|
+
await provider.exchangeAuthorizationCode(client, 'single_use');
|
|
508
|
+
await expect(provider.exchangeAuthorizationCode(client, 'single_use')).rejects.toThrow('not found');
|
|
509
|
+
});
|
|
510
|
+
});
|
|
511
|
+
describe('verifyAccessToken', () => {
|
|
512
|
+
it('returns AuthInfo with Palaryn context', async () => {
|
|
513
|
+
const client = clientsStore.registerClient({ redirect_uris: [new URL('http://localhost/cb')] });
|
|
514
|
+
authCodeStore.save({
|
|
515
|
+
code: 'code_verify',
|
|
516
|
+
clientId: client.client_id,
|
|
517
|
+
codeChallenge: 'c',
|
|
518
|
+
redirectUri: 'http://localhost/cb',
|
|
519
|
+
scopes: ['mcp:tools'],
|
|
520
|
+
userId: 'usr_test1',
|
|
521
|
+
workspaceId: 'ws_prod',
|
|
522
|
+
expiresAt: Date.now() + 60000,
|
|
523
|
+
});
|
|
524
|
+
const tokens = await provider.exchangeAuthorizationCode(client, 'code_verify');
|
|
525
|
+
const authInfo = await provider.verifyAccessToken(tokens.access_token);
|
|
526
|
+
expect(authInfo.token).toBe(tokens.access_token);
|
|
527
|
+
expect(authInfo.clientId).toBe(client.client_id);
|
|
528
|
+
expect(authInfo.scopes).toEqual(['mcp:tools']);
|
|
529
|
+
expect(authInfo.expiresAt).toBeGreaterThan(Date.now() / 1000);
|
|
530
|
+
expect(authInfo.extra).toBeDefined();
|
|
531
|
+
expect(authInfo.extra.workspace_id).toBe('ws_prod');
|
|
532
|
+
expect(authInfo.extra.actor_id).toBe('user:usr_test1');
|
|
533
|
+
expect(authInfo.extra.auth_method).toBe('oauth');
|
|
534
|
+
expect(authInfo.extra.roles).toEqual(['admin']); // owner maps to admin
|
|
535
|
+
});
|
|
536
|
+
it('rejects invalid token', async () => {
|
|
537
|
+
await expect(provider.verifyAccessToken('nonexistent_token')).rejects.toThrow('Invalid or expired');
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
describe('exchangeRefreshToken', () => {
|
|
541
|
+
it('rotates refresh token', async () => {
|
|
542
|
+
const client = clientsStore.registerClient({ redirect_uris: [new URL('http://localhost/cb')] });
|
|
543
|
+
authCodeStore.save({
|
|
544
|
+
code: 'code_refresh',
|
|
545
|
+
clientId: client.client_id,
|
|
546
|
+
codeChallenge: 'c',
|
|
547
|
+
redirectUri: 'http://localhost/cb',
|
|
548
|
+
scopes: ['mcp:tools'],
|
|
549
|
+
userId: 'usr_test1',
|
|
550
|
+
workspaceId: 'ws_prod',
|
|
551
|
+
expiresAt: Date.now() + 60000,
|
|
552
|
+
});
|
|
553
|
+
const tokens1 = await provider.exchangeAuthorizationCode(client, 'code_refresh');
|
|
554
|
+
const tokens2 = await provider.exchangeRefreshToken(client, tokens1.refresh_token);
|
|
555
|
+
// New tokens issued
|
|
556
|
+
expect(tokens2.access_token).toBeTruthy();
|
|
557
|
+
expect(tokens2.refresh_token).toBeTruthy();
|
|
558
|
+
expect(tokens2.access_token).not.toBe(tokens1.access_token);
|
|
559
|
+
expect(tokens2.refresh_token).not.toBe(tokens1.refresh_token);
|
|
560
|
+
// Old refresh token revoked
|
|
561
|
+
await expect(provider.exchangeRefreshToken(client, tokens1.refresh_token)).rejects.toThrow('Invalid refresh token');
|
|
562
|
+
// New access token works
|
|
563
|
+
const authInfo = await provider.verifyAccessToken(tokens2.access_token);
|
|
564
|
+
expect(authInfo.extra.workspace_id).toBe('ws_prod');
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
describe('revokeToken', () => {
|
|
568
|
+
it('revokes access token', async () => {
|
|
569
|
+
const client = clientsStore.registerClient({ redirect_uris: [new URL('http://localhost/cb')] });
|
|
570
|
+
authCodeStore.save({
|
|
571
|
+
code: 'code_revoke',
|
|
572
|
+
clientId: client.client_id,
|
|
573
|
+
codeChallenge: 'c',
|
|
574
|
+
redirectUri: 'http://localhost/cb',
|
|
575
|
+
scopes: [],
|
|
576
|
+
userId: 'usr_test1',
|
|
577
|
+
workspaceId: 'ws_prod',
|
|
578
|
+
expiresAt: Date.now() + 60000,
|
|
579
|
+
});
|
|
580
|
+
const tokens = await provider.exchangeAuthorizationCode(client, 'code_revoke');
|
|
581
|
+
await provider.revokeToken(client, { token: tokens.access_token });
|
|
582
|
+
await expect(provider.verifyAccessToken(tokens.access_token)).rejects.toThrow();
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
describe('challengeForAuthorizationCode', () => {
|
|
586
|
+
it('returns the stored code challenge', async () => {
|
|
587
|
+
const client = clientsStore.registerClient({ redirect_uris: [new URL('http://localhost/cb')] });
|
|
588
|
+
authCodeStore.save({
|
|
589
|
+
code: 'code_pkce',
|
|
590
|
+
clientId: client.client_id,
|
|
591
|
+
codeChallenge: 'S256_challenge_value',
|
|
592
|
+
redirectUri: 'http://localhost/cb',
|
|
593
|
+
scopes: [],
|
|
594
|
+
userId: 'usr_test1',
|
|
595
|
+
workspaceId: 'ws_prod',
|
|
596
|
+
expiresAt: Date.now() + 60000,
|
|
597
|
+
});
|
|
598
|
+
const challenge = await provider.challengeForAuthorizationCode(client, 'code_pkce');
|
|
599
|
+
expect(challenge).toBe('S256_challenge_value');
|
|
600
|
+
});
|
|
601
|
+
it('throws for unknown code', async () => {
|
|
602
|
+
const client = clientsStore.registerClient({ redirect_uris: [new URL('http://localhost/cb')] });
|
|
603
|
+
await expect(provider.challengeForAuthorizationCode(client, 'nonexistent')).rejects.toThrow('not found');
|
|
604
|
+
});
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
// ---------------------------------------------------------------------------
|
|
608
|
+
// HybridTokenVerifier
|
|
609
|
+
// ---------------------------------------------------------------------------
|
|
610
|
+
describe('HybridTokenVerifier', () => {
|
|
611
|
+
let stores;
|
|
612
|
+
let clientsStore;
|
|
613
|
+
let authCodeStore;
|
|
614
|
+
let tokenStore;
|
|
615
|
+
let oauthProvider;
|
|
616
|
+
beforeEach(() => {
|
|
617
|
+
stores = createMockStores();
|
|
618
|
+
seedTestData(stores);
|
|
619
|
+
clientsStore = new oauth_stores_1.OAuthClientsStore();
|
|
620
|
+
authCodeStore = new oauth_stores_1.AuthCodeStore();
|
|
621
|
+
tokenStore = new oauth_stores_1.OAuthTokenStore(3600, 86400);
|
|
622
|
+
oauthProvider = new oauth_provider_1.PalarynOAuthProvider({
|
|
623
|
+
clientsStore,
|
|
624
|
+
authCodeStore,
|
|
625
|
+
tokenStore,
|
|
626
|
+
userStore: stores.userStore,
|
|
627
|
+
workspaceStore: stores.workspaceStore,
|
|
628
|
+
workspaceMemberStore: stores.workspaceMemberStore,
|
|
629
|
+
sessionStore: stores.sessionStore,
|
|
630
|
+
});
|
|
631
|
+
});
|
|
632
|
+
afterEach(() => {
|
|
633
|
+
authCodeStore.destroy();
|
|
634
|
+
tokenStore.destroy();
|
|
635
|
+
});
|
|
636
|
+
it('verifies OAuth tokens first', async () => {
|
|
637
|
+
const client = clientsStore.registerClient({ redirect_uris: [new URL('http://localhost/cb')] });
|
|
638
|
+
authCodeStore.save({
|
|
639
|
+
code: 'code_hybrid',
|
|
640
|
+
clientId: client.client_id,
|
|
641
|
+
codeChallenge: 'c',
|
|
642
|
+
redirectUri: 'http://localhost/cb',
|
|
643
|
+
scopes: ['mcp:tools'],
|
|
644
|
+
userId: 'usr_test1',
|
|
645
|
+
workspaceId: 'ws_prod',
|
|
646
|
+
expiresAt: Date.now() + 60000,
|
|
647
|
+
});
|
|
648
|
+
const tokens = await oauthProvider.exchangeAuthorizationCode(client, 'code_hybrid');
|
|
649
|
+
const verifier = new auth_verifier_1.HybridTokenVerifier({
|
|
650
|
+
oauthProvider,
|
|
651
|
+
authConfig: { enabled: true, api_keys: {} },
|
|
652
|
+
});
|
|
653
|
+
const authInfo = await verifier.verifyAccessToken(tokens.access_token);
|
|
654
|
+
expect(authInfo.extra.auth_method).toBe('oauth');
|
|
655
|
+
expect(authInfo.extra.workspace_id).toBe('ws_prod');
|
|
656
|
+
});
|
|
657
|
+
it('falls back to config API keys', async () => {
|
|
658
|
+
const verifier = new auth_verifier_1.HybridTokenVerifier({
|
|
659
|
+
oauthProvider,
|
|
660
|
+
authConfig: {
|
|
661
|
+
enabled: true,
|
|
662
|
+
api_keys: {
|
|
663
|
+
'test-api-key-123': {
|
|
664
|
+
workspace_id: 'ws_config',
|
|
665
|
+
description: 'Test key',
|
|
666
|
+
roles: [],
|
|
667
|
+
},
|
|
668
|
+
},
|
|
669
|
+
},
|
|
670
|
+
});
|
|
671
|
+
const authInfo = await verifier.verifyAccessToken('test-api-key-123');
|
|
672
|
+
expect(authInfo.extra.auth_method).toBe('api_key');
|
|
673
|
+
expect(authInfo.extra.workspace_id).toBe('ws_config');
|
|
674
|
+
});
|
|
675
|
+
it('rejects expired config API keys', async () => {
|
|
676
|
+
const verifier = new auth_verifier_1.HybridTokenVerifier({
|
|
677
|
+
authConfig: {
|
|
678
|
+
enabled: true,
|
|
679
|
+
api_keys: {
|
|
680
|
+
'expired-key': {
|
|
681
|
+
workspace_id: 'ws_1',
|
|
682
|
+
expires_at: new Date(Date.now() - 1000).toISOString(),
|
|
683
|
+
},
|
|
684
|
+
},
|
|
685
|
+
},
|
|
686
|
+
});
|
|
687
|
+
await expect(verifier.verifyAccessToken('expired-key')).rejects.toThrow('expired');
|
|
688
|
+
});
|
|
689
|
+
it('rejects revoked config API keys', async () => {
|
|
690
|
+
const verifier = new auth_verifier_1.HybridTokenVerifier({
|
|
691
|
+
authConfig: {
|
|
692
|
+
enabled: true,
|
|
693
|
+
api_keys: {
|
|
694
|
+
'revoked-key': {
|
|
695
|
+
workspace_id: 'ws_1',
|
|
696
|
+
revoked: true,
|
|
697
|
+
},
|
|
698
|
+
},
|
|
699
|
+
},
|
|
700
|
+
});
|
|
701
|
+
await expect(verifier.verifyAccessToken('revoked-key')).rejects.toThrow('Invalid');
|
|
702
|
+
});
|
|
703
|
+
it('returns anonymous AuthInfo when auth disabled', async () => {
|
|
704
|
+
const verifier = new auth_verifier_1.HybridTokenVerifier({
|
|
705
|
+
authConfig: { enabled: false, api_keys: {} },
|
|
706
|
+
});
|
|
707
|
+
const authInfo = await verifier.verifyAccessToken('anything');
|
|
708
|
+
expect(authInfo.extra.auth_method).toBe('none');
|
|
709
|
+
expect(authInfo.extra.workspace_id).toBe('ws_default');
|
|
710
|
+
});
|
|
711
|
+
it('rejects unknown tokens when auth enabled and no OAuth', async () => {
|
|
712
|
+
const verifier = new auth_verifier_1.HybridTokenVerifier({
|
|
713
|
+
authConfig: { enabled: true, api_keys: {} },
|
|
714
|
+
});
|
|
715
|
+
await expect(verifier.verifyAccessToken('unknown')).rejects.toThrow('Invalid');
|
|
716
|
+
});
|
|
717
|
+
});
|
|
718
|
+
// ---------------------------------------------------------------------------
|
|
719
|
+
// resolveIdentity with OAuth AuthInfo shape
|
|
720
|
+
// ---------------------------------------------------------------------------
|
|
721
|
+
describe('resolveIdentity with OAuth AuthInfo', () => {
|
|
722
|
+
// We test this indirectly through the http-transport module.
|
|
723
|
+
// The key behavior: identity is extracted from extra.workspace_id when
|
|
724
|
+
// top-level workspace_id is absent (OAuth shape).
|
|
725
|
+
it('extracts identity from extra field (OAuth shape)', () => {
|
|
726
|
+
// Simulate what requireBearerAuth sets on req.auth
|
|
727
|
+
const authInfo = {
|
|
728
|
+
token: 'abc',
|
|
729
|
+
clientId: 'pn_client_123',
|
|
730
|
+
scopes: ['mcp:tools'],
|
|
731
|
+
expiresAt: Math.floor(Date.now() / 1000) + 3600,
|
|
732
|
+
extra: {
|
|
733
|
+
workspace_id: 'ws_oauth',
|
|
734
|
+
actor_id: 'user:usr_1',
|
|
735
|
+
roles: ['admin'],
|
|
736
|
+
permissions: ['tool:execute'],
|
|
737
|
+
auth_method: 'oauth',
|
|
738
|
+
},
|
|
739
|
+
};
|
|
740
|
+
// Use the exported function from http-transport
|
|
741
|
+
// We can't easily import the private function, so we verify via integration
|
|
742
|
+
// by checking the extra field structure matches what resolveIdentity expects
|
|
743
|
+
expect(authInfo.extra.workspace_id).toBe('ws_oauth');
|
|
744
|
+
expect(authInfo.extra.actor_id).toBe('user:usr_1');
|
|
745
|
+
});
|
|
746
|
+
it('checkCapabilityPermission reads permissions from extra', () => {
|
|
747
|
+
// Same verification — the extra field has the right shape
|
|
748
|
+
const authInfo = {
|
|
749
|
+
token: 'abc',
|
|
750
|
+
clientId: 'pn_client_123',
|
|
751
|
+
scopes: ['mcp:tools'],
|
|
752
|
+
extra: {
|
|
753
|
+
permissions: ['tool:execute', 'tool:execute:read', 'tool:execute:write'],
|
|
754
|
+
},
|
|
755
|
+
};
|
|
756
|
+
expect(authInfo.extra.permissions).toContain('tool:execute');
|
|
757
|
+
});
|
|
758
|
+
});
|
|
759
|
+
//# sourceMappingURL=mcp-oauth.test.js.map
|