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 @@
|
|
|
1
|
+
{"version":3,"file":"forward-proxy.test.d.ts","sourceRoot":"","sources":["../../../tests/unit/forward-proxy.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const http = __importStar(require("http"));
|
|
37
|
+
const proxy_1 = require("../../src/proxy");
|
|
38
|
+
const auth_1 = require("../../src/middleware/auth");
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// buildToolCallFromProxy tests
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
describe('buildToolCallFromProxy', () => {
|
|
43
|
+
it('should build a ToolCall from a GET request', () => {
|
|
44
|
+
const tc = (0, proxy_1.buildToolCallFromProxy)('GET', 'http://api.example.com/v1/data?q=test', { 'accept': 'application/json', 'host': 'api.example.com' }, undefined, 'ws_123', 'agent_456');
|
|
45
|
+
expect(tc.tool.name).toBe('http.get');
|
|
46
|
+
expect(tc.tool.capability).toBe('read');
|
|
47
|
+
expect(tc.args.method).toBe('GET');
|
|
48
|
+
expect(tc.args.url).toBe('http://api.example.com/v1/data?q=test');
|
|
49
|
+
expect(tc.workspace_id).toBe('ws_123');
|
|
50
|
+
expect(tc.actor.id).toBe('agent_456');
|
|
51
|
+
expect(tc.actor.type).toBe('agent');
|
|
52
|
+
expect(tc.source.platform).toBe('forward_proxy');
|
|
53
|
+
expect(tc.tool_call_id).toBeDefined();
|
|
54
|
+
expect(tc.task_id).toBeDefined();
|
|
55
|
+
expect(tc.context?.labels).toContain('proxy');
|
|
56
|
+
expect(tc.context?.labels).toContain('api.example.com');
|
|
57
|
+
});
|
|
58
|
+
it('should build a ToolCall from a POST request with JSON body', () => {
|
|
59
|
+
const tc = (0, proxy_1.buildToolCallFromProxy)('POST', 'http://api.example.com/v1/chat', { 'content-type': 'application/json' }, JSON.stringify({ message: 'hello' }), 'ws_123', 'agent_456');
|
|
60
|
+
expect(tc.tool.name).toBe('http.post');
|
|
61
|
+
expect(tc.tool.capability).toBe('write');
|
|
62
|
+
expect(tc.args.method).toBe('POST');
|
|
63
|
+
expect(tc.args.body).toEqual({ message: 'hello' });
|
|
64
|
+
});
|
|
65
|
+
it('should keep non-JSON body as string', () => {
|
|
66
|
+
const tc = (0, proxy_1.buildToolCallFromProxy)('POST', 'http://api.example.com/upload', { 'content-type': 'text/plain' }, 'plain text body', 'ws_123', 'agent_456');
|
|
67
|
+
expect(tc.args.body).toBe('plain text body');
|
|
68
|
+
});
|
|
69
|
+
it('should map DELETE to delete capability', () => {
|
|
70
|
+
const tc = (0, proxy_1.buildToolCallFromProxy)('DELETE', 'http://api.example.com/v1/resource/123', {}, undefined, 'ws_123', 'agent_456');
|
|
71
|
+
expect(tc.tool.name).toBe('http.delete');
|
|
72
|
+
expect(tc.tool.capability).toBe('delete');
|
|
73
|
+
});
|
|
74
|
+
it('should map HEAD and OPTIONS to read capability', () => {
|
|
75
|
+
const head = (0, proxy_1.buildToolCallFromProxy)('HEAD', 'http://example.com', {}, undefined, 'ws', 'a');
|
|
76
|
+
const options = (0, proxy_1.buildToolCallFromProxy)('OPTIONS', 'http://example.com', {}, undefined, 'ws', 'a');
|
|
77
|
+
expect(head.tool.capability).toBe('read');
|
|
78
|
+
expect(options.tool.capability).toBe('read');
|
|
79
|
+
});
|
|
80
|
+
it('should map PUT and PATCH to write capability', () => {
|
|
81
|
+
const put = (0, proxy_1.buildToolCallFromProxy)('PUT', 'http://example.com', {}, undefined, 'ws', 'a');
|
|
82
|
+
const patch = (0, proxy_1.buildToolCallFromProxy)('PATCH', 'http://example.com', {}, undefined, 'ws', 'a');
|
|
83
|
+
expect(put.tool.capability).toBe('write');
|
|
84
|
+
expect(patch.tool.capability).toBe('write');
|
|
85
|
+
});
|
|
86
|
+
it('should strip proxy-specific and sensitive headers from forwarded headers', () => {
|
|
87
|
+
const tc = (0, proxy_1.buildToolCallFromProxy)('GET', 'http://example.com', {
|
|
88
|
+
'proxy-authorization': 'Basic dXNlcjpwYXNz',
|
|
89
|
+
'proxy-connection': 'keep-alive',
|
|
90
|
+
'x-palaryn-workspace': 'ws_override',
|
|
91
|
+
'x-palaryn-actor': 'custom_actor',
|
|
92
|
+
'accept': 'application/json',
|
|
93
|
+
'authorization': 'Bearer token123',
|
|
94
|
+
'cookie': 'session=abc',
|
|
95
|
+
'x-api-key': 'sk-secret',
|
|
96
|
+
}, undefined, 'ws_123', 'agent_456');
|
|
97
|
+
const forwardHeaders = tc.args.headers;
|
|
98
|
+
expect(forwardHeaders['proxy-authorization']).toBeUndefined();
|
|
99
|
+
expect(forwardHeaders['proxy-connection']).toBeUndefined();
|
|
100
|
+
expect(forwardHeaders['x-palaryn-workspace']).toBeUndefined();
|
|
101
|
+
expect(forwardHeaders['x-palaryn-actor']).toBeUndefined();
|
|
102
|
+
expect(forwardHeaders['authorization']).toBeUndefined();
|
|
103
|
+
expect(forwardHeaders['cookie']).toBeUndefined();
|
|
104
|
+
expect(forwardHeaders['x-api-key']).toBeUndefined();
|
|
105
|
+
expect(forwardHeaders['accept']).toBe('application/json');
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
// parseProxyAuth tests
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
describe('parseProxyAuth', () => {
|
|
112
|
+
const baseAuthConfig = {
|
|
113
|
+
enabled: true,
|
|
114
|
+
api_keys: {
|
|
115
|
+
'valid-key-123': { workspace_id: 'ws_1', description: 'Test key' },
|
|
116
|
+
'revoked-key': { workspace_id: 'ws_2', description: 'Revoked', revoked: true },
|
|
117
|
+
'expired-key': { workspace_id: 'ws_3', description: 'Expired', expires_at: '2020-01-01T00:00:00Z' },
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
const baseProxyConfig = {
|
|
121
|
+
enabled: true,
|
|
122
|
+
port: 3128,
|
|
123
|
+
require_auth: true,
|
|
124
|
+
};
|
|
125
|
+
it('should authenticate with valid Proxy-Authorization Basic header', () => {
|
|
126
|
+
const encoded = Buffer.from('ws_1:valid-key-123').toString('base64');
|
|
127
|
+
const result = (0, auth_1.parseProxyAuth)({ 'proxy-authorization': `Basic ${encoded}` }, baseProxyConfig, baseAuthConfig);
|
|
128
|
+
expect(result.authenticated).toBe(true);
|
|
129
|
+
expect(result.workspace_id).toBe('ws_1');
|
|
130
|
+
expect(result.api_key).toBe('valid-key-123');
|
|
131
|
+
});
|
|
132
|
+
it('should reject invalid Proxy-Authorization format', () => {
|
|
133
|
+
const result = (0, auth_1.parseProxyAuth)({ 'proxy-authorization': 'Bearer token123' }, baseProxyConfig, baseAuthConfig);
|
|
134
|
+
expect(result.authenticated).toBe(false);
|
|
135
|
+
expect(result.error).toContain('Invalid Proxy-Authorization format');
|
|
136
|
+
});
|
|
137
|
+
it('should reject missing colon in credentials', () => {
|
|
138
|
+
const encoded = Buffer.from('noColon').toString('base64');
|
|
139
|
+
const result = (0, auth_1.parseProxyAuth)({ 'proxy-authorization': `Basic ${encoded}` }, baseProxyConfig, baseAuthConfig);
|
|
140
|
+
expect(result.authenticated).toBe(false);
|
|
141
|
+
expect(result.error).toContain('Expected: workspace_id:api_key');
|
|
142
|
+
});
|
|
143
|
+
it('should reject empty workspace_id or api_key', () => {
|
|
144
|
+
const encoded = Buffer.from(':api_key').toString('base64');
|
|
145
|
+
const result = (0, auth_1.parseProxyAuth)({ 'proxy-authorization': `Basic ${encoded}` }, baseProxyConfig, baseAuthConfig);
|
|
146
|
+
expect(result.authenticated).toBe(false);
|
|
147
|
+
expect(result.error).toContain('Empty workspace_id or api_key');
|
|
148
|
+
});
|
|
149
|
+
it('should reject invalid API key when auth is enabled', () => {
|
|
150
|
+
const encoded = Buffer.from('ws_1:wrong-key').toString('base64');
|
|
151
|
+
const result = (0, auth_1.parseProxyAuth)({ 'proxy-authorization': `Basic ${encoded}` }, baseProxyConfig, baseAuthConfig);
|
|
152
|
+
expect(result.authenticated).toBe(false);
|
|
153
|
+
expect(result.error).toContain('Invalid API key');
|
|
154
|
+
});
|
|
155
|
+
it('should reject revoked API key', () => {
|
|
156
|
+
const encoded = Buffer.from('ws_2:revoked-key').toString('base64');
|
|
157
|
+
const result = (0, auth_1.parseProxyAuth)({ 'proxy-authorization': `Basic ${encoded}` }, baseProxyConfig, baseAuthConfig);
|
|
158
|
+
expect(result.authenticated).toBe(false);
|
|
159
|
+
expect(result.error).toContain('revoked');
|
|
160
|
+
});
|
|
161
|
+
it('should reject expired API key', () => {
|
|
162
|
+
const encoded = Buffer.from('ws_3:expired-key').toString('base64');
|
|
163
|
+
const result = (0, auth_1.parseProxyAuth)({ 'proxy-authorization': `Basic ${encoded}` }, baseProxyConfig, baseAuthConfig);
|
|
164
|
+
expect(result.authenticated).toBe(false);
|
|
165
|
+
expect(result.error).toContain('expired');
|
|
166
|
+
});
|
|
167
|
+
it('should use sidecar defaults when no auth header present', () => {
|
|
168
|
+
const sidecarConfig = {
|
|
169
|
+
...baseProxyConfig,
|
|
170
|
+
default_workspace_id: 'ws_sidecar',
|
|
171
|
+
default_actor_id: 'agent_sidecar',
|
|
172
|
+
};
|
|
173
|
+
const result = (0, auth_1.parseProxyAuth)({}, sidecarConfig, baseAuthConfig);
|
|
174
|
+
expect(result.authenticated).toBe(true);
|
|
175
|
+
expect(result.workspace_id).toBe('ws_sidecar');
|
|
176
|
+
expect(result.actor_id).toBe('agent_sidecar');
|
|
177
|
+
});
|
|
178
|
+
it('should override sidecar workspace with X-Palaryn-Workspace header', () => {
|
|
179
|
+
const sidecarConfig = {
|
|
180
|
+
...baseProxyConfig,
|
|
181
|
+
default_workspace_id: 'ws_sidecar',
|
|
182
|
+
};
|
|
183
|
+
const result = (0, auth_1.parseProxyAuth)({ 'x-palaryn-workspace': 'ws_override' }, sidecarConfig, baseAuthConfig);
|
|
184
|
+
expect(result.authenticated).toBe(true);
|
|
185
|
+
expect(result.workspace_id).toBe('ws_override');
|
|
186
|
+
});
|
|
187
|
+
it('should use X-Palaryn-Actor header with Proxy-Authorization', () => {
|
|
188
|
+
const encoded = Buffer.from('ws_1:valid-key-123').toString('base64');
|
|
189
|
+
const result = (0, auth_1.parseProxyAuth)({
|
|
190
|
+
'proxy-authorization': `Basic ${encoded}`,
|
|
191
|
+
'x-palaryn-actor': 'custom_agent',
|
|
192
|
+
}, baseProxyConfig, baseAuthConfig);
|
|
193
|
+
expect(result.authenticated).toBe(true);
|
|
194
|
+
expect(result.actor_id).toBe('custom_agent');
|
|
195
|
+
});
|
|
196
|
+
it('should allow unauthenticated requests when require_auth is false', () => {
|
|
197
|
+
const permissiveConfig = {
|
|
198
|
+
...baseProxyConfig,
|
|
199
|
+
require_auth: false,
|
|
200
|
+
};
|
|
201
|
+
const result = (0, auth_1.parseProxyAuth)({}, permissiveConfig, baseAuthConfig);
|
|
202
|
+
expect(result.authenticated).toBe(true);
|
|
203
|
+
expect(result.workspace_id).toBe('ws_default');
|
|
204
|
+
expect(result.actor_id).toBe('proxy:anonymous');
|
|
205
|
+
});
|
|
206
|
+
it('should reject unauthenticated requests when require_auth is true', () => {
|
|
207
|
+
const result = (0, auth_1.parseProxyAuth)({}, baseProxyConfig, baseAuthConfig);
|
|
208
|
+
expect(result.authenticated).toBe(false);
|
|
209
|
+
expect(result.error).toContain('Proxy-Authorization required');
|
|
210
|
+
});
|
|
211
|
+
it('should authenticate via X-Palaryn-Workspace header when require_auth is false', () => {
|
|
212
|
+
const permissiveConfig = {
|
|
213
|
+
...baseProxyConfig,
|
|
214
|
+
require_auth: false,
|
|
215
|
+
};
|
|
216
|
+
const result = (0, auth_1.parseProxyAuth)({ 'x-palaryn-workspace': 'ws_header' }, permissiveConfig, baseAuthConfig);
|
|
217
|
+
expect(result.authenticated).toBe(true);
|
|
218
|
+
expect(result.workspace_id).toBe('ws_header');
|
|
219
|
+
expect(result.actor_id).toBe('proxy:ws_header');
|
|
220
|
+
});
|
|
221
|
+
it('should reject X-Palaryn-Workspace header when require_auth is true', () => {
|
|
222
|
+
const result = (0, auth_1.parseProxyAuth)({ 'x-palaryn-workspace': 'ws_header' }, baseProxyConfig, baseAuthConfig);
|
|
223
|
+
expect(result.authenticated).toBe(false);
|
|
224
|
+
expect(result.error).toContain('Proxy-Authorization required');
|
|
225
|
+
});
|
|
226
|
+
it('should skip API key validation when auth is disabled', () => {
|
|
227
|
+
const disabledAuth = {
|
|
228
|
+
enabled: false,
|
|
229
|
+
api_keys: {},
|
|
230
|
+
};
|
|
231
|
+
const encoded = Buffer.from('ws_any:any-key').toString('base64');
|
|
232
|
+
const result = (0, auth_1.parseProxyAuth)({ 'proxy-authorization': `Basic ${encoded}` }, baseProxyConfig, disabledAuth);
|
|
233
|
+
expect(result.authenticated).toBe(true);
|
|
234
|
+
expect(result.workspace_id).toBe('ws_any');
|
|
235
|
+
expect(result.api_key).toBe('any-key');
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
// ---------------------------------------------------------------------------
|
|
239
|
+
// createForwardProxy tests
|
|
240
|
+
// ---------------------------------------------------------------------------
|
|
241
|
+
describe('createForwardProxy', () => {
|
|
242
|
+
let targetServer;
|
|
243
|
+
let targetPort;
|
|
244
|
+
let proxyServer;
|
|
245
|
+
let proxyPort;
|
|
246
|
+
// Mock gateway
|
|
247
|
+
const mockPreExecute = jest.fn();
|
|
248
|
+
const mockPostExecute = jest.fn();
|
|
249
|
+
const mockRateLimiterCheck = jest.fn().mockReturnValue({ allowed: true, current: 1, limit: 100 });
|
|
250
|
+
const mockAuditLogToolCallReceived = jest.fn();
|
|
251
|
+
const mockGateway = {
|
|
252
|
+
preExecute: mockPreExecute,
|
|
253
|
+
postExecute: mockPostExecute,
|
|
254
|
+
getRateLimiter: () => ({ check: mockRateLimiterCheck }),
|
|
255
|
+
getAuditLogger: () => ({ logToolCallReceived: mockAuditLogToolCallReceived }),
|
|
256
|
+
};
|
|
257
|
+
function testConfig(overrides) {
|
|
258
|
+
return {
|
|
259
|
+
port: 0,
|
|
260
|
+
host: '127.0.0.1',
|
|
261
|
+
auth: {
|
|
262
|
+
enabled: false,
|
|
263
|
+
api_keys: {},
|
|
264
|
+
},
|
|
265
|
+
policy: {
|
|
266
|
+
pack_path: './policy-packs/dev_fast.yaml',
|
|
267
|
+
default_effect: 'ALLOW',
|
|
268
|
+
hot_reload: false,
|
|
269
|
+
},
|
|
270
|
+
dlp: {
|
|
271
|
+
enabled: false,
|
|
272
|
+
scan_args: false,
|
|
273
|
+
scan_output: false,
|
|
274
|
+
secrets_detection: false,
|
|
275
|
+
pii_detection: false,
|
|
276
|
+
default_redaction_method: 'mask',
|
|
277
|
+
},
|
|
278
|
+
budget: {
|
|
279
|
+
task_budget_usd: 100,
|
|
280
|
+
max_steps_per_task: 1000,
|
|
281
|
+
max_retries_per_call: 3,
|
|
282
|
+
max_wall_clock_ms: 300000,
|
|
283
|
+
},
|
|
284
|
+
audit: {
|
|
285
|
+
enabled: false,
|
|
286
|
+
log_dir: '',
|
|
287
|
+
console_output: false,
|
|
288
|
+
retention_days: 30,
|
|
289
|
+
},
|
|
290
|
+
executor: {
|
|
291
|
+
http: { timeout_ms: 15000, max_retries: 3, backoff_base_ms: 1000 },
|
|
292
|
+
cache: { enabled: false, ttl_ms: 0 },
|
|
293
|
+
},
|
|
294
|
+
approval: {
|
|
295
|
+
enabled: false,
|
|
296
|
+
token_secret: 'test-secret',
|
|
297
|
+
default_ttl_seconds: 3600,
|
|
298
|
+
},
|
|
299
|
+
proxy: {
|
|
300
|
+
enabled: true,
|
|
301
|
+
port: 0,
|
|
302
|
+
require_auth: false,
|
|
303
|
+
ssrf_protection: false,
|
|
304
|
+
},
|
|
305
|
+
...overrides,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
beforeAll((done) => {
|
|
309
|
+
// Start a target HTTP server for the proxy to forward to
|
|
310
|
+
targetServer = http.createServer((req, res) => {
|
|
311
|
+
if (req.url === '/api/data' && req.method === 'GET') {
|
|
312
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
313
|
+
res.end(JSON.stringify({ data: 'success', method: 'GET' }));
|
|
314
|
+
}
|
|
315
|
+
else if (req.url === '/api/create' && req.method === 'POST') {
|
|
316
|
+
let body = '';
|
|
317
|
+
req.on('data', (chunk) => (body += chunk));
|
|
318
|
+
req.on('end', () => {
|
|
319
|
+
res.writeHead(201, { 'Content-Type': 'application/json' });
|
|
320
|
+
res.end(JSON.stringify({ created: true, received: body }));
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
else if (req.url === '/api/slow') {
|
|
324
|
+
// Do not respond (simulate timeout)
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
res.writeHead(404);
|
|
328
|
+
res.end('Not found');
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
targetServer.listen(0, '127.0.0.1', () => {
|
|
332
|
+
targetPort = targetServer.address().port;
|
|
333
|
+
done();
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
afterAll((done) => {
|
|
337
|
+
targetServer.close(done);
|
|
338
|
+
});
|
|
339
|
+
beforeEach(() => {
|
|
340
|
+
mockPreExecute.mockReset();
|
|
341
|
+
mockPostExecute.mockReset();
|
|
342
|
+
mockPostExecute.mockResolvedValue({});
|
|
343
|
+
mockRateLimiterCheck.mockReset();
|
|
344
|
+
mockRateLimiterCheck.mockReturnValue({ allowed: true, current: 1, limit: 100 });
|
|
345
|
+
mockAuditLogToolCallReceived.mockReset();
|
|
346
|
+
});
|
|
347
|
+
afterEach((done) => {
|
|
348
|
+
if (proxyServer) {
|
|
349
|
+
proxyServer.close(() => done());
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
done();
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
function startProxy(config) {
|
|
356
|
+
return new Promise((resolve) => {
|
|
357
|
+
proxyServer = (0, proxy_1.createForwardProxy)(mockGateway, testConfig(config));
|
|
358
|
+
proxyServer.listen(0, () => {
|
|
359
|
+
proxyPort = proxyServer.server.address().port;
|
|
360
|
+
resolve(proxyPort);
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
function proxyRequest(method, targetUrl, body, headers) {
|
|
365
|
+
return new Promise((resolve, reject) => {
|
|
366
|
+
let host = '127.0.0.1';
|
|
367
|
+
try {
|
|
368
|
+
const url = new URL(targetUrl);
|
|
369
|
+
host = url.host;
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
// Relative URL — just send as-is
|
|
373
|
+
}
|
|
374
|
+
const options = {
|
|
375
|
+
hostname: '127.0.0.1',
|
|
376
|
+
port: proxyPort,
|
|
377
|
+
method,
|
|
378
|
+
path: targetUrl, // Absolute URL for proxy protocol
|
|
379
|
+
headers: {
|
|
380
|
+
'Host': host,
|
|
381
|
+
...headers,
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
const req = http.request(options, (res) => {
|
|
385
|
+
let data = '';
|
|
386
|
+
res.on('data', (chunk) => (data += chunk));
|
|
387
|
+
res.on('end', () => {
|
|
388
|
+
resolve({ status: res.statusCode || 0, headers: res.headers, body: data });
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
req.on('error', reject);
|
|
392
|
+
if (body)
|
|
393
|
+
req.write(body);
|
|
394
|
+
req.end();
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
it('should return 400 for non-proxy requests (relative URL)', async () => {
|
|
398
|
+
await startProxy();
|
|
399
|
+
const res = await proxyRequest('GET', '/not-a-proxy-request');
|
|
400
|
+
expect(res.status).toBe(400);
|
|
401
|
+
expect(JSON.parse(res.body).error).toContain('Not a proxy request');
|
|
402
|
+
});
|
|
403
|
+
it('should forward allowed GET requests and return response', async () => {
|
|
404
|
+
await startProxy();
|
|
405
|
+
const targetUrl = `http://127.0.0.1:${targetPort}/api/data`;
|
|
406
|
+
mockPreExecute.mockResolvedValue({
|
|
407
|
+
allowed: true,
|
|
408
|
+
stepTimings: {},
|
|
409
|
+
startTime: Date.now(),
|
|
410
|
+
});
|
|
411
|
+
const res = await proxyRequest('GET', targetUrl);
|
|
412
|
+
expect(res.status).toBe(200);
|
|
413
|
+
const parsed = JSON.parse(res.body);
|
|
414
|
+
expect(parsed.data).toBe('success');
|
|
415
|
+
expect(mockPreExecute).toHaveBeenCalledTimes(1);
|
|
416
|
+
// Verify the ToolCall passed to preExecute
|
|
417
|
+
const toolCall = mockPreExecute.mock.calls[0][0];
|
|
418
|
+
expect(toolCall.tool.name).toBe('http.get');
|
|
419
|
+
expect(toolCall.tool.capability).toBe('read');
|
|
420
|
+
expect(toolCall.args.url).toBe(targetUrl);
|
|
421
|
+
expect(toolCall.workspace_id).toBe('ws_default');
|
|
422
|
+
});
|
|
423
|
+
it('should forward POST requests with body', async () => {
|
|
424
|
+
await startProxy();
|
|
425
|
+
const targetUrl = `http://127.0.0.1:${targetPort}/api/create`;
|
|
426
|
+
mockPreExecute.mockResolvedValue({
|
|
427
|
+
allowed: true,
|
|
428
|
+
stepTimings: {},
|
|
429
|
+
startTime: Date.now(),
|
|
430
|
+
});
|
|
431
|
+
const res = await proxyRequest('POST', targetUrl, JSON.stringify({ test: true }), {
|
|
432
|
+
'Content-Type': 'application/json',
|
|
433
|
+
});
|
|
434
|
+
expect(res.status).toBe(201);
|
|
435
|
+
const parsed = JSON.parse(res.body);
|
|
436
|
+
expect(parsed.created).toBe(true);
|
|
437
|
+
});
|
|
438
|
+
it('should return 403 when preExecute denies the request', async () => {
|
|
439
|
+
await startProxy();
|
|
440
|
+
const targetUrl = `http://127.0.0.1:${targetPort}/api/data`;
|
|
441
|
+
mockPreExecute.mockResolvedValue({
|
|
442
|
+
allowed: false,
|
|
443
|
+
result: {
|
|
444
|
+
tool_call_id: 'tc_1',
|
|
445
|
+
task_id: 'task_1',
|
|
446
|
+
status: 'blocked',
|
|
447
|
+
policy: { decision: 'deny', rule_id: 'block_domain', reasons: ['Domain blocked by policy'] },
|
|
448
|
+
dlp: { detected: [], redactions: [], severity: 'low' },
|
|
449
|
+
budget: { estimated_cost_usd: 0, spent_cost_usd_task: 0, remaining_cost_usd_task: 0 },
|
|
450
|
+
timing: { started_at: new Date().toISOString(), duration_ms: 1 },
|
|
451
|
+
},
|
|
452
|
+
stepTimings: {},
|
|
453
|
+
startTime: Date.now(),
|
|
454
|
+
});
|
|
455
|
+
const res = await proxyRequest('GET', targetUrl);
|
|
456
|
+
expect(res.status).toBe(403);
|
|
457
|
+
const parsed = JSON.parse(res.body);
|
|
458
|
+
expect(parsed.status).toBe('blocked');
|
|
459
|
+
expect(parsed.policy.decision).toBe('deny');
|
|
460
|
+
});
|
|
461
|
+
it('should return 202 when preExecute requires approval', async () => {
|
|
462
|
+
await startProxy();
|
|
463
|
+
const targetUrl = `http://127.0.0.1:${targetPort}/api/data`;
|
|
464
|
+
mockPreExecute.mockResolvedValue({
|
|
465
|
+
allowed: false,
|
|
466
|
+
result: {
|
|
467
|
+
tool_call_id: 'tc_1',
|
|
468
|
+
task_id: 'task_1',
|
|
469
|
+
status: 'needs_approval',
|
|
470
|
+
policy: { decision: 'require_approval', rule_id: 'require_human', reasons: ['Requires approval'] },
|
|
471
|
+
dlp: { detected: [], redactions: [], severity: 'low' },
|
|
472
|
+
budget: { estimated_cost_usd: 0, spent_cost_usd_task: 0, remaining_cost_usd_task: 0 },
|
|
473
|
+
timing: { started_at: new Date().toISOString(), duration_ms: 1 },
|
|
474
|
+
approval: { approval_id: 'apr_1', token: 'tok_1' },
|
|
475
|
+
},
|
|
476
|
+
stepTimings: {},
|
|
477
|
+
startTime: Date.now(),
|
|
478
|
+
});
|
|
479
|
+
const res = await proxyRequest('GET', targetUrl);
|
|
480
|
+
expect(res.status).toBe(202);
|
|
481
|
+
});
|
|
482
|
+
it('should return 407 when auth is required but missing', async () => {
|
|
483
|
+
await startProxy({
|
|
484
|
+
auth: { enabled: true, api_keys: { 'test-key': { workspace_id: 'ws_1' } } },
|
|
485
|
+
proxy: { enabled: true, port: 0, require_auth: true, ssrf_protection: false },
|
|
486
|
+
});
|
|
487
|
+
const targetUrl = `http://127.0.0.1:${targetPort}/api/data`;
|
|
488
|
+
const res = await proxyRequest('GET', targetUrl);
|
|
489
|
+
expect(res.status).toBe(407);
|
|
490
|
+
expect(res.headers['proxy-authenticate']).toBe('Basic realm="Palaryn Proxy"');
|
|
491
|
+
});
|
|
492
|
+
it('should authenticate with Proxy-Authorization header', async () => {
|
|
493
|
+
await startProxy({
|
|
494
|
+
auth: { enabled: true, api_keys: { 'my-key': { workspace_id: 'ws_proxy' } } },
|
|
495
|
+
proxy: { enabled: true, port: 0, require_auth: true, ssrf_protection: false },
|
|
496
|
+
});
|
|
497
|
+
const targetUrl = `http://127.0.0.1:${targetPort}/api/data`;
|
|
498
|
+
const encoded = Buffer.from('ws_proxy:my-key').toString('base64');
|
|
499
|
+
mockPreExecute.mockResolvedValue({
|
|
500
|
+
allowed: true,
|
|
501
|
+
stepTimings: {},
|
|
502
|
+
startTime: Date.now(),
|
|
503
|
+
});
|
|
504
|
+
const res = await proxyRequest('GET', targetUrl, undefined, {
|
|
505
|
+
'Proxy-Authorization': `Basic ${encoded}`,
|
|
506
|
+
});
|
|
507
|
+
expect(res.status).toBe(200);
|
|
508
|
+
// Verify workspace was set correctly
|
|
509
|
+
const toolCall = mockPreExecute.mock.calls[0][0];
|
|
510
|
+
expect(toolCall.workspace_id).toBe('ws_proxy');
|
|
511
|
+
});
|
|
512
|
+
it('should call postExecute after successful forwarding', async () => {
|
|
513
|
+
await startProxy();
|
|
514
|
+
const targetUrl = `http://127.0.0.1:${targetPort}/api/data`;
|
|
515
|
+
const pre = {
|
|
516
|
+
allowed: true,
|
|
517
|
+
stepTimings: {},
|
|
518
|
+
startTime: Date.now(),
|
|
519
|
+
policyResult: { decision: 'allow', rule_id: 'default', rule_name: 'Default allow', reasons: [] },
|
|
520
|
+
argsDlp: { detected: [], redactions: [], severity: 'low' },
|
|
521
|
+
budgetCheck: { report: { estimated_cost_usd: 0 }, allowed: true },
|
|
522
|
+
};
|
|
523
|
+
mockPreExecute.mockResolvedValue(pre);
|
|
524
|
+
await proxyRequest('GET', targetUrl);
|
|
525
|
+
// postExecute runs in background, give it a tick
|
|
526
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
527
|
+
expect(mockPostExecute).toHaveBeenCalledTimes(1);
|
|
528
|
+
const [tc, output, passedPre] = mockPostExecute.mock.calls[0];
|
|
529
|
+
expect(tc.tool.name).toBe('http.get');
|
|
530
|
+
expect(output.http_status).toBe(200);
|
|
531
|
+
expect(typeof output.body).toBe('string');
|
|
532
|
+
});
|
|
533
|
+
it('should handle CONNECT tunnel requests', async () => {
|
|
534
|
+
await startProxy();
|
|
535
|
+
// Send CONNECT request
|
|
536
|
+
const result = await new Promise((resolve, reject) => {
|
|
537
|
+
const req = http.request({
|
|
538
|
+
hostname: '127.0.0.1',
|
|
539
|
+
port: proxyPort,
|
|
540
|
+
method: 'CONNECT',
|
|
541
|
+
path: '127.0.0.1:' + targetPort,
|
|
542
|
+
});
|
|
543
|
+
req.on('connect', (res, socket, head) => {
|
|
544
|
+
// We got a tunnel established response
|
|
545
|
+
resolve({ status: res.statusCode?.toString() || '', socket });
|
|
546
|
+
socket.destroy();
|
|
547
|
+
});
|
|
548
|
+
req.on('error', (err) => {
|
|
549
|
+
// CONNECT may fail because we mock gateway - that's fine for unit test
|
|
550
|
+
// The point is the handler ran
|
|
551
|
+
resolve({ status: 'error', socket: null });
|
|
552
|
+
});
|
|
553
|
+
req.end();
|
|
554
|
+
});
|
|
555
|
+
// The CONNECT handler should have been invoked
|
|
556
|
+
// With mock gateway, preExecute should have been called
|
|
557
|
+
expect(mockPreExecute).toHaveBeenCalled();
|
|
558
|
+
});
|
|
559
|
+
// -- S2: Passthrough domains should still run rate limiting and audit ------
|
|
560
|
+
it('should run rate limiting for passthrough domains (S2)', async () => {
|
|
561
|
+
await startProxy({
|
|
562
|
+
proxy: {
|
|
563
|
+
enabled: true,
|
|
564
|
+
port: 0,
|
|
565
|
+
require_auth: false,
|
|
566
|
+
ssrf_protection: false,
|
|
567
|
+
passthrough_domains: ['127.0.0.1'],
|
|
568
|
+
},
|
|
569
|
+
});
|
|
570
|
+
const targetUrl = `http://127.0.0.1:${targetPort}/api/data`;
|
|
571
|
+
const res = await proxyRequest('GET', targetUrl);
|
|
572
|
+
// Request should be forwarded (passthrough skips policy)
|
|
573
|
+
expect(res.status).toBe(200);
|
|
574
|
+
// Rate limiter should have been checked
|
|
575
|
+
expect(mockRateLimiterCheck).toHaveBeenCalledTimes(1);
|
|
576
|
+
// preExecute should NOT have been called (passthrough skips full pipeline)
|
|
577
|
+
expect(mockPreExecute).not.toHaveBeenCalled();
|
|
578
|
+
});
|
|
579
|
+
it('should return 429 when passthrough domain hits rate limit (S2)', async () => {
|
|
580
|
+
await startProxy({
|
|
581
|
+
proxy: {
|
|
582
|
+
enabled: true,
|
|
583
|
+
port: 0,
|
|
584
|
+
require_auth: false,
|
|
585
|
+
ssrf_protection: false,
|
|
586
|
+
passthrough_domains: ['127.0.0.1'],
|
|
587
|
+
},
|
|
588
|
+
});
|
|
589
|
+
mockRateLimiterCheck.mockReturnValue({
|
|
590
|
+
allowed: false,
|
|
591
|
+
current: 101,
|
|
592
|
+
limit: 100,
|
|
593
|
+
blocked_by: 'actor',
|
|
594
|
+
});
|
|
595
|
+
const targetUrl = `http://127.0.0.1:${targetPort}/api/data`;
|
|
596
|
+
const res = await proxyRequest('GET', targetUrl);
|
|
597
|
+
expect(res.status).toBe(429);
|
|
598
|
+
const body = JSON.parse(res.body);
|
|
599
|
+
expect(body.error_code).toBe('RATE_LIMIT_EXCEEDED');
|
|
600
|
+
expect(body.error).toContain('Rate limit exceeded');
|
|
601
|
+
});
|
|
602
|
+
it('should run audit logging for passthrough domains (S2)', async () => {
|
|
603
|
+
await startProxy({
|
|
604
|
+
proxy: {
|
|
605
|
+
enabled: true,
|
|
606
|
+
port: 0,
|
|
607
|
+
require_auth: false,
|
|
608
|
+
ssrf_protection: false,
|
|
609
|
+
passthrough_domains: ['127.0.0.1'],
|
|
610
|
+
},
|
|
611
|
+
});
|
|
612
|
+
const targetUrl = `http://127.0.0.1:${targetPort}/api/data`;
|
|
613
|
+
await proxyRequest('GET', targetUrl);
|
|
614
|
+
// Audit logger should have been called
|
|
615
|
+
expect(mockAuditLogToolCallReceived).toHaveBeenCalledTimes(1);
|
|
616
|
+
const toolCall = mockAuditLogToolCallReceived.mock.calls[0][0];
|
|
617
|
+
expect(toolCall.tool.name).toBe('http.get');
|
|
618
|
+
expect(toolCall.args.url).toBe(targetUrl);
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
//# sourceMappingURL=forward-proxy.test.js.map
|