@useatlas/create 0.0.1
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/README.md +231 -0
- package/index.ts +829 -0
- package/package.json +38 -0
- package/templates/docker/.env.example +67 -0
- package/templates/docker/Dockerfile +52 -0
- package/templates/docker/bin/__tests__/benchmark.test.ts +598 -0
- package/templates/docker/bin/__tests__/duckdb-ingest.test.ts +171 -0
- package/templates/docker/bin/__tests__/eval.test.ts +434 -0
- package/templates/docker/bin/__tests__/matview-partition.test.ts +615 -0
- package/templates/docker/bin/__tests__/multi-source.test.ts +113 -0
- package/templates/docker/bin/__tests__/plugin-cli.test.ts +322 -0
- package/templates/docker/bin/__tests__/profiler-heuristics.test.ts +608 -0
- package/templates/docker/bin/__tests__/query.test.ts +240 -0
- package/templates/docker/bin/__tests__/schema-drift.test.ts +542 -0
- package/templates/docker/bin/__tests__/view-yaml-generation.test.ts +146 -0
- package/templates/docker/bin/atlas.ts +5044 -0
- package/templates/docker/bin/benchmark.ts +695 -0
- package/templates/docker/bin/enrich.ts +559 -0
- package/templates/docker/bin/eval.ts +770 -0
- package/templates/docker/bin/smoke.ts +438 -0
- package/templates/docker/data/.gitkeep +0 -0
- package/templates/docker/data/cybersec.sql +1961 -0
- package/templates/docker/data/demo-semantic/catalog.yml +40 -0
- package/templates/docker/data/demo-semantic/entities/accounts.yml +170 -0
- package/templates/docker/data/demo-semantic/entities/companies.yml +207 -0
- package/templates/docker/data/demo-semantic/entities/people.yml +145 -0
- package/templates/docker/data/demo-semantic/glossary.yml +22 -0
- package/templates/docker/data/demo-semantic/metrics/accounts.yml +38 -0
- package/templates/docker/data/demo-semantic/metrics/companies.yml +89 -0
- package/templates/docker/data/demo.sql +373 -0
- package/templates/docker/data/ecommerce.sql +1690 -0
- package/templates/docker/data/init-demo-db.sql +8 -0
- package/templates/docker/docker-compose.yml +34 -0
- package/templates/docker/docs/deploy.md +390 -0
- package/templates/docker/eslint.config.mjs +18 -0
- package/templates/docker/gitignore +5 -0
- package/templates/docker/next.config.ts +9 -0
- package/templates/docker/package.json +59 -0
- package/templates/docker/postcss.config.mjs +8 -0
- package/templates/docker/public/.gitkeep +0 -0
- package/templates/docker/public/favicon.svg +4 -0
- package/templates/docker/railway.json +13 -0
- package/templates/docker/render.yaml +34 -0
- package/templates/docker/semantic/catalog.yml +5 -0
- package/templates/docker/semantic/entities/.gitkeep +0 -0
- package/templates/docker/semantic/glossary.yml +6 -0
- package/templates/docker/semantic/metrics/.gitkeep +0 -0
- package/templates/docker/sidecar/Dockerfile +28 -0
- package/templates/docker/sidecar/railway.json +14 -0
- package/templates/docker/sidecar/server.ts +188 -0
- package/templates/docker/src/api/__tests__/actions.test.ts +683 -0
- package/templates/docker/src/api/__tests__/admin.test.ts +820 -0
- package/templates/docker/src/api/__tests__/auth.test.ts +165 -0
- package/templates/docker/src/api/__tests__/chat.test.ts +376 -0
- package/templates/docker/src/api/__tests__/conversations.test.ts +555 -0
- package/templates/docker/src/api/__tests__/cors.test.ts +135 -0
- package/templates/docker/src/api/__tests__/health-plugin.test.ts +169 -0
- package/templates/docker/src/api/__tests__/health.test.ts +261 -0
- package/templates/docker/src/api/__tests__/query.test.ts +891 -0
- package/templates/docker/src/api/__tests__/scheduled-tasks.test.ts +601 -0
- package/templates/docker/src/api/__tests__/slack.test.ts +847 -0
- package/templates/docker/src/api/index.ts +117 -0
- package/templates/docker/src/api/routes/actions.ts +274 -0
- package/templates/docker/src/api/routes/admin.ts +757 -0
- package/templates/docker/src/api/routes/auth.ts +48 -0
- package/templates/docker/src/api/routes/chat.ts +465 -0
- package/templates/docker/src/api/routes/conversations.ts +266 -0
- package/templates/docker/src/api/routes/health.ts +287 -0
- package/templates/docker/src/api/routes/openapi.ts +390 -0
- package/templates/docker/src/api/routes/query.ts +318 -0
- package/templates/docker/src/api/routes/scheduled-tasks.ts +467 -0
- package/templates/docker/src/api/routes/slack.ts +611 -0
- package/templates/docker/src/api/server.ts +226 -0
- package/templates/docker/src/app/api/[...route]/route.ts +33 -0
- package/templates/docker/src/app/error.tsx +24 -0
- package/templates/docker/src/app/globals.css +126 -0
- package/templates/docker/src/app/layout.tsx +19 -0
- package/templates/docker/src/app/page.tsx +14 -0
- package/templates/docker/src/global.d.ts +1 -0
- package/templates/docker/src/lib/__tests__/agent-cache.test.ts +437 -0
- package/templates/docker/src/lib/__tests__/agent-dialect.test.ts +114 -0
- package/templates/docker/src/lib/__tests__/agent-health-annotations.test.ts +164 -0
- package/templates/docker/src/lib/__tests__/agent-integration.test.ts +514 -0
- package/templates/docker/src/lib/__tests__/config-actions.test.ts +166 -0
- package/templates/docker/src/lib/__tests__/config.test.ts +1063 -0
- package/templates/docker/src/lib/__tests__/conversations.test.ts +589 -0
- package/templates/docker/src/lib/__tests__/errors.test.ts +256 -0
- package/templates/docker/src/lib/__tests__/logger.test.ts +200 -0
- package/templates/docker/src/lib/__tests__/providers.test.ts +99 -0
- package/templates/docker/src/lib/__tests__/rls.test.ts +435 -0
- package/templates/docker/src/lib/__tests__/scheduled-task-types.test.ts +124 -0
- package/templates/docker/src/lib/__tests__/scheduled-tasks.test.ts +550 -0
- package/templates/docker/src/lib/__tests__/semantic-index.test.ts +547 -0
- package/templates/docker/src/lib/__tests__/semantic-multisource.test.ts +544 -0
- package/templates/docker/src/lib/__tests__/semantic.test.ts +363 -0
- package/templates/docker/src/lib/__tests__/startup-actions.test.ts +452 -0
- package/templates/docker/src/lib/__tests__/startup.test.ts +465 -0
- package/templates/docker/src/lib/__tests__/tracing.test.ts +28 -0
- package/templates/docker/src/lib/action-types.ts +95 -0
- package/templates/docker/src/lib/agent-query.ts +178 -0
- package/templates/docker/src/lib/agent.ts +505 -0
- package/templates/docker/src/lib/api-url.ts +2 -0
- package/templates/docker/src/lib/auth/__tests__/audit.test.ts +418 -0
- package/templates/docker/src/lib/auth/__tests__/byot-integration.test.ts +222 -0
- package/templates/docker/src/lib/auth/__tests__/byot.test.ts +366 -0
- package/templates/docker/src/lib/auth/__tests__/detect.test.ts +190 -0
- package/templates/docker/src/lib/auth/__tests__/managed.test.ts +173 -0
- package/templates/docker/src/lib/auth/__tests__/middleware.test.ts +456 -0
- package/templates/docker/src/lib/auth/__tests__/migrate.test.ts +201 -0
- package/templates/docker/src/lib/auth/__tests__/permissions.test.ts +225 -0
- package/templates/docker/src/lib/auth/__tests__/server.test.ts +34 -0
- package/templates/docker/src/lib/auth/__tests__/simple-key.test.ts +176 -0
- package/templates/docker/src/lib/auth/__tests__/types.test.ts +44 -0
- package/templates/docker/src/lib/auth/audit.ts +89 -0
- package/templates/docker/src/lib/auth/byot.ts +158 -0
- package/templates/docker/src/lib/auth/client.ts +35 -0
- package/templates/docker/src/lib/auth/detect.ts +83 -0
- package/templates/docker/src/lib/auth/managed.ts +73 -0
- package/templates/docker/src/lib/auth/middleware.ts +208 -0
- package/templates/docker/src/lib/auth/migrate.ts +111 -0
- package/templates/docker/src/lib/auth/permissions.ts +156 -0
- package/templates/docker/src/lib/auth/server.ts +142 -0
- package/templates/docker/src/lib/auth/simple-key.ts +92 -0
- package/templates/docker/src/lib/auth/types.ts +49 -0
- package/templates/docker/src/lib/config.ts +704 -0
- package/templates/docker/src/lib/conversation-types.ts +29 -0
- package/templates/docker/src/lib/conversations.ts +270 -0
- package/templates/docker/src/lib/db/__tests__/connection.test.ts +69 -0
- package/templates/docker/src/lib/db/__tests__/duckdb.test.ts +141 -0
- package/templates/docker/src/lib/db/__tests__/internal.test.ts +387 -0
- package/templates/docker/src/lib/db/__tests__/registry-health.test.ts +207 -0
- package/templates/docker/src/lib/db/__tests__/registry-pool-limits.test.ts +156 -0
- package/templates/docker/src/lib/db/__tests__/registry.test.ts +595 -0
- package/templates/docker/src/lib/db/__tests__/salesforce.test.ts +339 -0
- package/templates/docker/src/lib/db/__tests__/snowflake.test.ts +217 -0
- package/templates/docker/src/lib/db/__tests__/source-rate-limit.test.ts +130 -0
- package/templates/docker/src/lib/db/connection.ts +753 -0
- package/templates/docker/src/lib/db/duckdb.ts +122 -0
- package/templates/docker/src/lib/db/internal.ts +273 -0
- package/templates/docker/src/lib/db/salesforce.ts +342 -0
- package/templates/docker/src/lib/db/source-rate-limit.ts +191 -0
- package/templates/docker/src/lib/errors.ts +154 -0
- package/templates/docker/src/lib/logger.ts +98 -0
- package/templates/docker/src/lib/plugins/__tests__/hooks-integration.test.ts +202 -0
- package/templates/docker/src/lib/plugins/__tests__/hooks.test.ts +529 -0
- package/templates/docker/src/lib/plugins/__tests__/migrate.test.ts +521 -0
- package/templates/docker/src/lib/plugins/__tests__/registry.test.ts +346 -0
- package/templates/docker/src/lib/plugins/__tests__/tools.test.ts +49 -0
- package/templates/docker/src/lib/plugins/__tests__/wiring.test.ts +585 -0
- package/templates/docker/src/lib/plugins/hooks.ts +162 -0
- package/templates/docker/src/lib/plugins/index.ts +9 -0
- package/templates/docker/src/lib/plugins/migrate.ts +309 -0
- package/templates/docker/src/lib/plugins/registry.ts +231 -0
- package/templates/docker/src/lib/plugins/tools.ts +39 -0
- package/templates/docker/src/lib/plugins/wiring.ts +291 -0
- package/templates/docker/src/lib/providers.ts +102 -0
- package/templates/docker/src/lib/rls.ts +321 -0
- package/templates/docker/src/lib/scheduled-task-types.ts +132 -0
- package/templates/docker/src/lib/scheduled-tasks.ts +475 -0
- package/templates/docker/src/lib/scheduler/__tests__/delivery.test.ts +192 -0
- package/templates/docker/src/lib/scheduler/__tests__/engine.test.ts +248 -0
- package/templates/docker/src/lib/scheduler/__tests__/format-email.test.ts +96 -0
- package/templates/docker/src/lib/scheduler/__tests__/format-slack.test.ts +78 -0
- package/templates/docker/src/lib/scheduler/__tests__/format-webhook.test.ts +78 -0
- package/templates/docker/src/lib/scheduler/delivery.ts +248 -0
- package/templates/docker/src/lib/scheduler/engine.ts +317 -0
- package/templates/docker/src/lib/scheduler/executor.ts +73 -0
- package/templates/docker/src/lib/scheduler/format-email.ts +109 -0
- package/templates/docker/src/lib/scheduler/format-slack.ts +35 -0
- package/templates/docker/src/lib/scheduler/format-webhook.ts +37 -0
- package/templates/docker/src/lib/scheduler/index.ts +7 -0
- package/templates/docker/src/lib/security.ts +11 -0
- package/templates/docker/src/lib/semantic-index.ts +503 -0
- package/templates/docker/src/lib/semantic.ts +387 -0
- package/templates/docker/src/lib/sidecar-types.ts +16 -0
- package/templates/docker/src/lib/slack/__tests__/api.test.ts +160 -0
- package/templates/docker/src/lib/slack/__tests__/format.test.ts +237 -0
- package/templates/docker/src/lib/slack/__tests__/store.test.ts +188 -0
- package/templates/docker/src/lib/slack/__tests__/threads.test.ts +112 -0
- package/templates/docker/src/lib/slack/__tests__/verify.test.ts +111 -0
- package/templates/docker/src/lib/slack/api.ts +102 -0
- package/templates/docker/src/lib/slack/format.ts +209 -0
- package/templates/docker/src/lib/slack/store.ts +107 -0
- package/templates/docker/src/lib/slack/threads.ts +64 -0
- package/templates/docker/src/lib/slack/verify.ts +71 -0
- package/templates/docker/src/lib/startup.ts +730 -0
- package/templates/docker/src/lib/tools/__tests__/action-permissions.test.ts +594 -0
- package/templates/docker/src/lib/tools/__tests__/custom-validation.test.ts +238 -0
- package/templates/docker/src/lib/tools/__tests__/explore-backend.test.ts +267 -0
- package/templates/docker/src/lib/tools/__tests__/explore-nsjail.test.ts +492 -0
- package/templates/docker/src/lib/tools/__tests__/explore-plugin.test.ts +374 -0
- package/templates/docker/src/lib/tools/__tests__/explore-sdk-compat.test.ts +82 -0
- package/templates/docker/src/lib/tools/__tests__/explore-sidecar.test.ts +208 -0
- package/templates/docker/src/lib/tools/__tests__/registry-actions.test.ts +144 -0
- package/templates/docker/src/lib/tools/__tests__/registry.test.ts +235 -0
- package/templates/docker/src/lib/tools/__tests__/salesforce-tool.test.ts +154 -0
- package/templates/docker/src/lib/tools/__tests__/soql-validation.test.ts +303 -0
- package/templates/docker/src/lib/tools/__tests__/sql-audit.test.ts +225 -0
- package/templates/docker/src/lib/tools/__tests__/sql-connection-whitelist.test.ts +98 -0
- package/templates/docker/src/lib/tools/__tests__/sql-duckdb.test.ts +233 -0
- package/templates/docker/src/lib/tools/__tests__/sql-ratelimit.test.ts +225 -0
- package/templates/docker/src/lib/tools/__tests__/sql.test.ts +1012 -0
- package/templates/docker/src/lib/tools/actions/__tests__/audit.test.ts +211 -0
- package/templates/docker/src/lib/tools/actions/__tests__/email.test.ts +378 -0
- package/templates/docker/src/lib/tools/actions/__tests__/handler.test.ts +681 -0
- package/templates/docker/src/lib/tools/actions/__tests__/jira.test.ts +427 -0
- package/templates/docker/src/lib/tools/actions/audit.ts +47 -0
- package/templates/docker/src/lib/tools/actions/email.ts +191 -0
- package/templates/docker/src/lib/tools/actions/handler.ts +591 -0
- package/templates/docker/src/lib/tools/actions/index.ts +23 -0
- package/templates/docker/src/lib/tools/actions/jira.ts +220 -0
- package/templates/docker/src/lib/tools/explore-nsjail.ts +343 -0
- package/templates/docker/src/lib/tools/explore-sandbox.ts +264 -0
- package/templates/docker/src/lib/tools/explore-sidecar.ts +163 -0
- package/templates/docker/src/lib/tools/explore.ts +379 -0
- package/templates/docker/src/lib/tools/registry.ts +221 -0
- package/templates/docker/src/lib/tools/salesforce.ts +138 -0
- package/templates/docker/src/lib/tools/soql-validation.ts +172 -0
- package/templates/docker/src/lib/tools/sql.ts +680 -0
- package/templates/docker/src/lib/tracing.ts +40 -0
- package/templates/docker/src/lib/utils.ts +6 -0
- package/templates/docker/src/test-setup.ts +38 -0
- package/templates/docker/src/types/vercel-sandbox.d.ts +54 -0
- package/templates/docker/src/ui/components/actions/action-approval-card.tsx +295 -0
- package/templates/docker/src/ui/components/actions/action-status-badge.tsx +50 -0
- package/templates/docker/src/ui/components/admin/admin-layout.tsx +26 -0
- package/templates/docker/src/ui/components/admin/admin-sidebar.tsx +96 -0
- package/templates/docker/src/ui/components/admin/empty-state.tsx +24 -0
- package/templates/docker/src/ui/components/admin/entity-detail.tsx +233 -0
- package/templates/docker/src/ui/components/admin/entity-list.tsx +96 -0
- package/templates/docker/src/ui/components/admin/error-banner.tsx +22 -0
- package/templates/docker/src/ui/components/admin/feature-disabled.tsx +44 -0
- package/templates/docker/src/ui/components/admin/health-badge.tsx +30 -0
- package/templates/docker/src/ui/components/admin/loading-state.tsx +14 -0
- package/templates/docker/src/ui/components/admin/stat-card.tsx +32 -0
- package/templates/docker/src/ui/components/atlas-chat.tsx +370 -0
- package/templates/docker/src/ui/components/chart/chart-detection.ts +261 -0
- package/templates/docker/src/ui/components/chart/result-chart.tsx +375 -0
- package/templates/docker/src/ui/components/chat/api-key-bar.tsx +66 -0
- package/templates/docker/src/ui/components/chat/copy-button.tsx +25 -0
- package/templates/docker/src/ui/components/chat/data-table.tsx +102 -0
- package/templates/docker/src/ui/components/chat/error-banner.tsx +32 -0
- package/templates/docker/src/ui/components/chat/explore-card.tsx +41 -0
- package/templates/docker/src/ui/components/chat/loading-card.tsx +10 -0
- package/templates/docker/src/ui/components/chat/managed-auth-card.tsx +116 -0
- package/templates/docker/src/ui/components/chat/markdown.tsx +72 -0
- package/templates/docker/src/ui/components/chat/sql-block.tsx +30 -0
- package/templates/docker/src/ui/components/chat/sql-result-card.tsx +144 -0
- package/templates/docker/src/ui/components/chat/starter-prompts.ts +6 -0
- package/templates/docker/src/ui/components/chat/tool-part.tsx +40 -0
- package/templates/docker/src/ui/components/chat/typing-indicator.tsx +19 -0
- package/templates/docker/src/ui/components/conversations/conversation-item.tsx +120 -0
- package/templates/docker/src/ui/components/conversations/conversation-list.tsx +66 -0
- package/templates/docker/src/ui/components/conversations/conversation-sidebar.tsx +78 -0
- package/templates/docker/src/ui/components/conversations/delete-confirmation.tsx +27 -0
- package/templates/docker/src/ui/context.tsx +78 -0
- package/templates/docker/src/ui/hooks/use-admin-fetch.ts +104 -0
- package/templates/docker/src/ui/hooks/use-conversations.ts +184 -0
- package/templates/docker/src/ui/hooks/use-dark-mode.ts +17 -0
- package/templates/docker/src/ui/lib/action-types.ts +63 -0
- package/templates/docker/src/ui/lib/helpers.ts +104 -0
- package/templates/docker/src/ui/lib/types.ts +145 -0
- package/templates/docker/tsconfig.json +41 -0
- package/templates/docker/vercel.json +3 -0
- package/templates/nextjs-standalone/.env.example +68 -0
- package/templates/nextjs-standalone/bin/__tests__/benchmark.test.ts +598 -0
- package/templates/nextjs-standalone/bin/__tests__/duckdb-ingest.test.ts +171 -0
- package/templates/nextjs-standalone/bin/__tests__/eval.test.ts +434 -0
- package/templates/nextjs-standalone/bin/__tests__/matview-partition.test.ts +615 -0
- package/templates/nextjs-standalone/bin/__tests__/multi-source.test.ts +113 -0
- package/templates/nextjs-standalone/bin/__tests__/plugin-cli.test.ts +322 -0
- package/templates/nextjs-standalone/bin/__tests__/profiler-heuristics.test.ts +608 -0
- package/templates/nextjs-standalone/bin/__tests__/query.test.ts +240 -0
- package/templates/nextjs-standalone/bin/__tests__/schema-drift.test.ts +542 -0
- package/templates/nextjs-standalone/bin/__tests__/view-yaml-generation.test.ts +146 -0
- package/templates/nextjs-standalone/bin/atlas.ts +5044 -0
- package/templates/nextjs-standalone/bin/benchmark.ts +695 -0
- package/templates/nextjs-standalone/bin/enrich.ts +559 -0
- package/templates/nextjs-standalone/bin/eval.ts +770 -0
- package/templates/nextjs-standalone/bin/smoke.ts +438 -0
- package/templates/nextjs-standalone/data/.gitkeep +0 -0
- package/templates/nextjs-standalone/data/cybersec.sql +1961 -0
- package/templates/nextjs-standalone/data/demo-semantic/catalog.yml +40 -0
- package/templates/nextjs-standalone/data/demo-semantic/entities/accounts.yml +170 -0
- package/templates/nextjs-standalone/data/demo-semantic/entities/companies.yml +207 -0
- package/templates/nextjs-standalone/data/demo-semantic/entities/people.yml +145 -0
- package/templates/nextjs-standalone/data/demo-semantic/glossary.yml +22 -0
- package/templates/nextjs-standalone/data/demo-semantic/metrics/accounts.yml +38 -0
- package/templates/nextjs-standalone/data/demo-semantic/metrics/companies.yml +89 -0
- package/templates/nextjs-standalone/data/demo.sql +373 -0
- package/templates/nextjs-standalone/data/ecommerce.sql +1690 -0
- package/templates/nextjs-standalone/data/init-demo-db.sql +8 -0
- package/templates/nextjs-standalone/docs/deploy.md +390 -0
- package/templates/nextjs-standalone/eslint.config.mjs +18 -0
- package/templates/nextjs-standalone/gitignore +5 -0
- package/templates/nextjs-standalone/next.config.ts +10 -0
- package/templates/nextjs-standalone/package.json +63 -0
- package/templates/nextjs-standalone/postcss.config.mjs +8 -0
- package/templates/nextjs-standalone/semantic/catalog.yml +5 -0
- package/templates/nextjs-standalone/semantic/entities/.gitkeep +0 -0
- package/templates/nextjs-standalone/semantic/glossary.yml +6 -0
- package/templates/nextjs-standalone/semantic/metrics/.gitkeep +0 -0
- package/templates/nextjs-standalone/src/api/__tests__/actions.test.ts +683 -0
- package/templates/nextjs-standalone/src/api/__tests__/admin.test.ts +820 -0
- package/templates/nextjs-standalone/src/api/__tests__/auth.test.ts +165 -0
- package/templates/nextjs-standalone/src/api/__tests__/chat.test.ts +376 -0
- package/templates/nextjs-standalone/src/api/__tests__/conversations.test.ts +555 -0
- package/templates/nextjs-standalone/src/api/__tests__/cors.test.ts +135 -0
- package/templates/nextjs-standalone/src/api/__tests__/health-plugin.test.ts +169 -0
- package/templates/nextjs-standalone/src/api/__tests__/health.test.ts +261 -0
- package/templates/nextjs-standalone/src/api/__tests__/query.test.ts +891 -0
- package/templates/nextjs-standalone/src/api/__tests__/scheduled-tasks.test.ts +601 -0
- package/templates/nextjs-standalone/src/api/__tests__/slack.test.ts +847 -0
- package/templates/nextjs-standalone/src/api/index.ts +117 -0
- package/templates/nextjs-standalone/src/api/routes/actions.ts +274 -0
- package/templates/nextjs-standalone/src/api/routes/admin.ts +757 -0
- package/templates/nextjs-standalone/src/api/routes/auth.ts +48 -0
- package/templates/nextjs-standalone/src/api/routes/chat.ts +465 -0
- package/templates/nextjs-standalone/src/api/routes/conversations.ts +266 -0
- package/templates/nextjs-standalone/src/api/routes/health.ts +287 -0
- package/templates/nextjs-standalone/src/api/routes/openapi.ts +390 -0
- package/templates/nextjs-standalone/src/api/routes/query.ts +318 -0
- package/templates/nextjs-standalone/src/api/routes/scheduled-tasks.ts +467 -0
- package/templates/nextjs-standalone/src/api/routes/slack.ts +611 -0
- package/templates/nextjs-standalone/src/api/server.ts +226 -0
- package/templates/nextjs-standalone/src/app/api/[...route]/route.ts +33 -0
- package/templates/nextjs-standalone/src/app/error.tsx +24 -0
- package/templates/nextjs-standalone/src/app/global-error.tsx +68 -0
- package/templates/nextjs-standalone/src/app/globals.css +126 -0
- package/templates/nextjs-standalone/src/app/layout.tsx +19 -0
- package/templates/nextjs-standalone/src/app/page.tsx +14 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-cache.test.ts +437 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-dialect.test.ts +114 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-health-annotations.test.ts +164 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-integration.test.ts +514 -0
- package/templates/nextjs-standalone/src/lib/__tests__/config-actions.test.ts +166 -0
- package/templates/nextjs-standalone/src/lib/__tests__/config.test.ts +1063 -0
- package/templates/nextjs-standalone/src/lib/__tests__/conversations.test.ts +589 -0
- package/templates/nextjs-standalone/src/lib/__tests__/errors.test.ts +256 -0
- package/templates/nextjs-standalone/src/lib/__tests__/logger.test.ts +200 -0
- package/templates/nextjs-standalone/src/lib/__tests__/providers.test.ts +99 -0
- package/templates/nextjs-standalone/src/lib/__tests__/rls.test.ts +435 -0
- package/templates/nextjs-standalone/src/lib/__tests__/scheduled-task-types.test.ts +124 -0
- package/templates/nextjs-standalone/src/lib/__tests__/scheduled-tasks.test.ts +550 -0
- package/templates/nextjs-standalone/src/lib/__tests__/semantic-index.test.ts +547 -0
- package/templates/nextjs-standalone/src/lib/__tests__/semantic-multisource.test.ts +544 -0
- package/templates/nextjs-standalone/src/lib/__tests__/semantic.test.ts +363 -0
- package/templates/nextjs-standalone/src/lib/__tests__/startup-actions.test.ts +452 -0
- package/templates/nextjs-standalone/src/lib/__tests__/startup.test.ts +465 -0
- package/templates/nextjs-standalone/src/lib/__tests__/tracing.test.ts +28 -0
- package/templates/nextjs-standalone/src/lib/action-types.ts +95 -0
- package/templates/nextjs-standalone/src/lib/agent-query.ts +178 -0
- package/templates/nextjs-standalone/src/lib/agent.ts +505 -0
- package/templates/nextjs-standalone/src/lib/api-url.ts +3 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/audit.test.ts +418 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/byot-integration.test.ts +222 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/byot.test.ts +366 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/detect.test.ts +190 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/managed.test.ts +173 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/middleware.test.ts +456 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/migrate.test.ts +201 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/permissions.test.ts +225 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/server.test.ts +34 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/simple-key.test.ts +176 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/types.test.ts +44 -0
- package/templates/nextjs-standalone/src/lib/auth/audit.ts +89 -0
- package/templates/nextjs-standalone/src/lib/auth/byot.ts +158 -0
- package/templates/nextjs-standalone/src/lib/auth/client.ts +23 -0
- package/templates/nextjs-standalone/src/lib/auth/detect.ts +83 -0
- package/templates/nextjs-standalone/src/lib/auth/managed.ts +73 -0
- package/templates/nextjs-standalone/src/lib/auth/middleware.ts +208 -0
- package/templates/nextjs-standalone/src/lib/auth/migrate.ts +111 -0
- package/templates/nextjs-standalone/src/lib/auth/permissions.ts +156 -0
- package/templates/nextjs-standalone/src/lib/auth/server.ts +142 -0
- package/templates/nextjs-standalone/src/lib/auth/simple-key.ts +92 -0
- package/templates/nextjs-standalone/src/lib/auth/types.ts +49 -0
- package/templates/nextjs-standalone/src/lib/config.ts +704 -0
- package/templates/nextjs-standalone/src/lib/conversation-types.ts +29 -0
- package/templates/nextjs-standalone/src/lib/conversations.ts +270 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/connection.test.ts +69 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/duckdb.test.ts +141 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/internal.test.ts +387 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry-health.test.ts +207 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry-pool-limits.test.ts +156 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry.test.ts +595 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/salesforce.test.ts +339 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/snowflake.test.ts +217 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/source-rate-limit.test.ts +130 -0
- package/templates/nextjs-standalone/src/lib/db/connection.ts +753 -0
- package/templates/nextjs-standalone/src/lib/db/duckdb.ts +122 -0
- package/templates/nextjs-standalone/src/lib/db/internal.ts +273 -0
- package/templates/nextjs-standalone/src/lib/db/salesforce.ts +342 -0
- package/templates/nextjs-standalone/src/lib/db/source-rate-limit.ts +191 -0
- package/templates/nextjs-standalone/src/lib/errors.ts +154 -0
- package/templates/nextjs-standalone/src/lib/logger.ts +98 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/hooks-integration.test.ts +202 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/hooks.test.ts +529 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/migrate.test.ts +521 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/registry.test.ts +346 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/tools.test.ts +49 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/wiring.test.ts +585 -0
- package/templates/nextjs-standalone/src/lib/plugins/hooks.ts +162 -0
- package/templates/nextjs-standalone/src/lib/plugins/index.ts +9 -0
- package/templates/nextjs-standalone/src/lib/plugins/migrate.ts +309 -0
- package/templates/nextjs-standalone/src/lib/plugins/registry.ts +231 -0
- package/templates/nextjs-standalone/src/lib/plugins/tools.ts +39 -0
- package/templates/nextjs-standalone/src/lib/plugins/wiring.ts +291 -0
- package/templates/nextjs-standalone/src/lib/providers.ts +102 -0
- package/templates/nextjs-standalone/src/lib/rls.ts +321 -0
- package/templates/nextjs-standalone/src/lib/scheduled-task-types.ts +132 -0
- package/templates/nextjs-standalone/src/lib/scheduled-tasks.ts +475 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/delivery.test.ts +192 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/engine.test.ts +248 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-email.test.ts +96 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-slack.test.ts +78 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-webhook.test.ts +78 -0
- package/templates/nextjs-standalone/src/lib/scheduler/delivery.ts +248 -0
- package/templates/nextjs-standalone/src/lib/scheduler/engine.ts +317 -0
- package/templates/nextjs-standalone/src/lib/scheduler/executor.ts +73 -0
- package/templates/nextjs-standalone/src/lib/scheduler/format-email.ts +109 -0
- package/templates/nextjs-standalone/src/lib/scheduler/format-slack.ts +35 -0
- package/templates/nextjs-standalone/src/lib/scheduler/format-webhook.ts +37 -0
- package/templates/nextjs-standalone/src/lib/scheduler/index.ts +7 -0
- package/templates/nextjs-standalone/src/lib/security.ts +11 -0
- package/templates/nextjs-standalone/src/lib/semantic-index.ts +503 -0
- package/templates/nextjs-standalone/src/lib/semantic.ts +387 -0
- package/templates/nextjs-standalone/src/lib/sidecar-types.ts +16 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/api.test.ts +160 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/format.test.ts +237 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/store.test.ts +188 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/threads.test.ts +112 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/verify.test.ts +111 -0
- package/templates/nextjs-standalone/src/lib/slack/api.ts +102 -0
- package/templates/nextjs-standalone/src/lib/slack/format.ts +209 -0
- package/templates/nextjs-standalone/src/lib/slack/store.ts +107 -0
- package/templates/nextjs-standalone/src/lib/slack/threads.ts +64 -0
- package/templates/nextjs-standalone/src/lib/slack/verify.ts +71 -0
- package/templates/nextjs-standalone/src/lib/startup.ts +730 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/action-permissions.test.ts +594 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/custom-validation.test.ts +238 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-backend.test.ts +267 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-nsjail.test.ts +492 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-plugin.test.ts +374 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-sdk-compat.test.ts +82 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-sidecar.test.ts +208 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/registry-actions.test.ts +144 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/registry.test.ts +235 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/salesforce-tool.test.ts +154 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/soql-validation.test.ts +303 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-audit.test.ts +225 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-connection-whitelist.test.ts +98 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-duckdb.test.ts +233 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-ratelimit.test.ts +225 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql.test.ts +1012 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/audit.test.ts +211 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/email.test.ts +378 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/handler.test.ts +681 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/jira.test.ts +427 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/audit.ts +47 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/email.ts +191 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/handler.ts +591 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/index.ts +23 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/jira.ts +220 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-nsjail.ts +343 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-sandbox.ts +264 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-sidecar.ts +163 -0
- package/templates/nextjs-standalone/src/lib/tools/explore.ts +379 -0
- package/templates/nextjs-standalone/src/lib/tools/registry.ts +221 -0
- package/templates/nextjs-standalone/src/lib/tools/salesforce.ts +138 -0
- package/templates/nextjs-standalone/src/lib/tools/soql-validation.ts +172 -0
- package/templates/nextjs-standalone/src/lib/tools/sql.ts +680 -0
- package/templates/nextjs-standalone/src/lib/tracing.ts +40 -0
- package/templates/nextjs-standalone/src/lib/utils.ts +6 -0
- package/templates/nextjs-standalone/src/test-setup.ts +38 -0
- package/templates/nextjs-standalone/src/ui/components/actions/action-approval-card.tsx +295 -0
- package/templates/nextjs-standalone/src/ui/components/actions/action-status-badge.tsx +50 -0
- package/templates/nextjs-standalone/src/ui/components/admin/admin-layout.tsx +26 -0
- package/templates/nextjs-standalone/src/ui/components/admin/admin-sidebar.tsx +96 -0
- package/templates/nextjs-standalone/src/ui/components/admin/empty-state.tsx +24 -0
- package/templates/nextjs-standalone/src/ui/components/admin/entity-detail.tsx +233 -0
- package/templates/nextjs-standalone/src/ui/components/admin/entity-list.tsx +96 -0
- package/templates/nextjs-standalone/src/ui/components/admin/error-banner.tsx +22 -0
- package/templates/nextjs-standalone/src/ui/components/admin/feature-disabled.tsx +44 -0
- package/templates/nextjs-standalone/src/ui/components/admin/health-badge.tsx +30 -0
- package/templates/nextjs-standalone/src/ui/components/admin/loading-state.tsx +14 -0
- package/templates/nextjs-standalone/src/ui/components/admin/stat-card.tsx +32 -0
- package/templates/nextjs-standalone/src/ui/components/atlas-chat.tsx +370 -0
- package/templates/nextjs-standalone/src/ui/components/chart/chart-detection.ts +261 -0
- package/templates/nextjs-standalone/src/ui/components/chart/result-chart.tsx +375 -0
- package/templates/nextjs-standalone/src/ui/components/chat/api-key-bar.tsx +66 -0
- package/templates/nextjs-standalone/src/ui/components/chat/copy-button.tsx +25 -0
- package/templates/nextjs-standalone/src/ui/components/chat/data-table.tsx +102 -0
- package/templates/nextjs-standalone/src/ui/components/chat/error-banner.tsx +32 -0
- package/templates/nextjs-standalone/src/ui/components/chat/explore-card.tsx +41 -0
- package/templates/nextjs-standalone/src/ui/components/chat/loading-card.tsx +10 -0
- package/templates/nextjs-standalone/src/ui/components/chat/managed-auth-card.tsx +116 -0
- package/templates/nextjs-standalone/src/ui/components/chat/markdown.tsx +72 -0
- package/templates/nextjs-standalone/src/ui/components/chat/sql-block.tsx +30 -0
- package/templates/nextjs-standalone/src/ui/components/chat/sql-result-card.tsx +144 -0
- package/templates/nextjs-standalone/src/ui/components/chat/starter-prompts.ts +6 -0
- package/templates/nextjs-standalone/src/ui/components/chat/tool-part.tsx +40 -0
- package/templates/nextjs-standalone/src/ui/components/chat/typing-indicator.tsx +19 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-item.tsx +120 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-list.tsx +66 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-sidebar.tsx +78 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/delete-confirmation.tsx +27 -0
- package/templates/nextjs-standalone/src/ui/context.tsx +78 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-admin-fetch.ts +104 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-conversations.ts +184 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-dark-mode.ts +17 -0
- package/templates/nextjs-standalone/src/ui/lib/action-types.ts +63 -0
- package/templates/nextjs-standalone/src/ui/lib/helpers.ts +104 -0
- package/templates/nextjs-standalone/src/ui/lib/types.ts +145 -0
- package/templates/nextjs-standalone/tsconfig.json +32 -0
- package/templates/nextjs-standalone/vercel.json +4 -0
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from "bun:test";
|
|
2
|
+
import { withRequestContext } from "@atlas/api/lib/logger";
|
|
3
|
+
import { _resetPool, type InternalPool } from "@atlas/api/lib/db/internal";
|
|
4
|
+
import type { AtlasUser } from "../types";
|
|
5
|
+
import { logQueryAudit } from "../audit";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Audit tests use _resetPool() to inject a mock pg.Pool into the real
|
|
9
|
+
* internal.ts module. This avoids mock.module which is unreliable in
|
|
10
|
+
* bun's full test suite (module caching across files).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Capture pool.query calls for assertion
|
|
14
|
+
let queryCalls: Array<{ sql: string; params?: unknown[] }> = [];
|
|
15
|
+
let queryThrow: Error | null = null;
|
|
16
|
+
|
|
17
|
+
const mockPool: InternalPool = {
|
|
18
|
+
query: async (sql: string, params?: unknown[]) => {
|
|
19
|
+
if (queryThrow) throw queryThrow;
|
|
20
|
+
queryCalls.push({ sql, params });
|
|
21
|
+
return { rows: [] };
|
|
22
|
+
},
|
|
23
|
+
end: async () => {},
|
|
24
|
+
on: () => {},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
describe("logQueryAudit()", () => {
|
|
28
|
+
const origDbUrl = process.env.DATABASE_URL;
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
queryCalls = [];
|
|
32
|
+
queryThrow = null;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
// Restore original state
|
|
37
|
+
if (origDbUrl) {
|
|
38
|
+
process.env.DATABASE_URL = origDbUrl;
|
|
39
|
+
} else {
|
|
40
|
+
delete process.env.DATABASE_URL;
|
|
41
|
+
}
|
|
42
|
+
_resetPool(null);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/** Enable the internal DB path by setting env var + injecting mock pool */
|
|
46
|
+
function enableInternalDB() {
|
|
47
|
+
process.env.DATABASE_URL = "postgresql://test:test@localhost:5432/test";
|
|
48
|
+
_resetPool(mockPool);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
it("inserts into audit_log with correct params when internal DB is available", () => {
|
|
52
|
+
enableInternalDB();
|
|
53
|
+
const user: AtlasUser = { id: "u1", label: "test@example.com", mode: "managed" };
|
|
54
|
+
|
|
55
|
+
withRequestContext({ requestId: "req-1", user }, () => {
|
|
56
|
+
logQueryAudit({
|
|
57
|
+
sql: "SELECT 1",
|
|
58
|
+
durationMs: 42,
|
|
59
|
+
rowCount: 1,
|
|
60
|
+
success: true,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
expect(queryCalls).toHaveLength(1);
|
|
65
|
+
expect(queryCalls[0].sql).toContain("INSERT INTO audit_log");
|
|
66
|
+
expect(queryCalls[0].params).toEqual([
|
|
67
|
+
"u1",
|
|
68
|
+
"test@example.com",
|
|
69
|
+
"managed",
|
|
70
|
+
"SELECT 1",
|
|
71
|
+
42,
|
|
72
|
+
1,
|
|
73
|
+
true,
|
|
74
|
+
null,
|
|
75
|
+
null, // source_id
|
|
76
|
+
null, // source_type
|
|
77
|
+
null, // target_host
|
|
78
|
+
]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("includes source fields in audit insert when provided", () => {
|
|
82
|
+
enableInternalDB();
|
|
83
|
+
|
|
84
|
+
logQueryAudit({
|
|
85
|
+
sql: "SELECT 1",
|
|
86
|
+
durationMs: 10,
|
|
87
|
+
rowCount: 1,
|
|
88
|
+
success: true,
|
|
89
|
+
sourceId: "warehouse",
|
|
90
|
+
sourceType: "postgres",
|
|
91
|
+
targetHost: "db.example.com",
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
expect(queryCalls).toHaveLength(1);
|
|
95
|
+
const params = queryCalls[0].params!;
|
|
96
|
+
expect(params[8]).toBe("warehouse"); // source_id
|
|
97
|
+
expect(params[9]).toBe("postgres"); // source_type
|
|
98
|
+
expect(params[10]).toBe("db.example.com"); // target_host
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("does not insert when internal DB is not available", () => {
|
|
102
|
+
delete process.env.DATABASE_URL;
|
|
103
|
+
_resetPool(null);
|
|
104
|
+
|
|
105
|
+
expect(() =>
|
|
106
|
+
logQueryAudit({
|
|
107
|
+
sql: "SELECT 1",
|
|
108
|
+
durationMs: 10,
|
|
109
|
+
rowCount: 1,
|
|
110
|
+
success: true,
|
|
111
|
+
}),
|
|
112
|
+
).not.toThrow();
|
|
113
|
+
|
|
114
|
+
expect(queryCalls).toHaveLength(0);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("does not throw when DB insert fails", () => {
|
|
118
|
+
enableInternalDB();
|
|
119
|
+
queryThrow = new Error("connection lost");
|
|
120
|
+
|
|
121
|
+
expect(() =>
|
|
122
|
+
logQueryAudit({
|
|
123
|
+
sql: "SELECT 1",
|
|
124
|
+
durationMs: 5,
|
|
125
|
+
rowCount: null,
|
|
126
|
+
success: false,
|
|
127
|
+
error: "timeout",
|
|
128
|
+
}),
|
|
129
|
+
).not.toThrow();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("preserves full SQL for DB insert when under 2000 chars", () => {
|
|
133
|
+
enableInternalDB();
|
|
134
|
+
const longSql = "SELECT " + "x".repeat(600); // 607 chars
|
|
135
|
+
|
|
136
|
+
logQueryAudit({ sql: longSql, durationMs: 10, rowCount: 5, success: true });
|
|
137
|
+
|
|
138
|
+
expect(queryCalls[0].params![3]).toBe(longSql);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("truncates SQL to 2000 chars for DB when over limit", () => {
|
|
142
|
+
enableInternalDB();
|
|
143
|
+
const longSql = "SELECT " + "x".repeat(2500); // 2507 chars
|
|
144
|
+
|
|
145
|
+
logQueryAudit({ sql: longSql, durationMs: 10, rowCount: 5, success: true });
|
|
146
|
+
|
|
147
|
+
expect((queryCalls[0].params![3] as string).length).toBe(2000);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("scrubs errors containing 'password' in DB insert", () => {
|
|
151
|
+
enableInternalDB();
|
|
152
|
+
|
|
153
|
+
logQueryAudit({
|
|
154
|
+
sql: "SELECT 1",
|
|
155
|
+
durationMs: 10,
|
|
156
|
+
rowCount: null,
|
|
157
|
+
success: false,
|
|
158
|
+
error: "password authentication failed for user 'atlas'",
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
expect(queryCalls[0].params![7]).toBe("[scrubbed]");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("scrubs errors containing 'secret' in DB insert", () => {
|
|
165
|
+
enableInternalDB();
|
|
166
|
+
|
|
167
|
+
logQueryAudit({
|
|
168
|
+
sql: "SELECT 1",
|
|
169
|
+
durationMs: 10,
|
|
170
|
+
rowCount: null,
|
|
171
|
+
success: false,
|
|
172
|
+
error: "missing secret key",
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
expect(queryCalls[0].params![7]).toBe("[scrubbed]");
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("scrubs errors containing 'credential' in DB insert", () => {
|
|
179
|
+
enableInternalDB();
|
|
180
|
+
|
|
181
|
+
logQueryAudit({
|
|
182
|
+
sql: "SELECT 1",
|
|
183
|
+
durationMs: 10,
|
|
184
|
+
rowCount: null,
|
|
185
|
+
success: false,
|
|
186
|
+
error: "invalid credential provided",
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
expect(queryCalls[0].params![7]).toBe("[scrubbed]");
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("scrubs errors containing 'connection_string' or 'connectionstring'", () => {
|
|
193
|
+
enableInternalDB();
|
|
194
|
+
|
|
195
|
+
logQueryAudit({
|
|
196
|
+
sql: "SELECT 1",
|
|
197
|
+
durationMs: 10,
|
|
198
|
+
rowCount: null,
|
|
199
|
+
success: false,
|
|
200
|
+
error: "invalid connection_string format",
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
expect(queryCalls[0].params![7]).toBe("[scrubbed]");
|
|
204
|
+
|
|
205
|
+
logQueryAudit({
|
|
206
|
+
sql: "SELECT 1",
|
|
207
|
+
durationMs: 10,
|
|
208
|
+
rowCount: null,
|
|
209
|
+
success: false,
|
|
210
|
+
error: "bad connectionstring provided",
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
expect(queryCalls[1].params![7]).toBe("[scrubbed]");
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("scrubs case-insensitively (uppercase sensitive keywords)", () => {
|
|
217
|
+
enableInternalDB();
|
|
218
|
+
|
|
219
|
+
logQueryAudit({
|
|
220
|
+
sql: "SELECT 1",
|
|
221
|
+
durationMs: 10,
|
|
222
|
+
rowCount: null,
|
|
223
|
+
success: false,
|
|
224
|
+
error: "AUTHENTICATION PASSWORD FAILED",
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
expect(queryCalls[0].params![7]).toBe("[scrubbed]");
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("scrubs MySQL 'Access denied for user' errors", () => {
|
|
231
|
+
enableInternalDB();
|
|
232
|
+
|
|
233
|
+
logQueryAudit({
|
|
234
|
+
sql: "SELECT 1",
|
|
235
|
+
durationMs: 10,
|
|
236
|
+
rowCount: null,
|
|
237
|
+
success: false,
|
|
238
|
+
error: "Access denied for user 'root'@'localhost' (using password: YES)",
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
expect(queryCalls[0].params![7]).toBe("[scrubbed]");
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("scrubs MySQL ER_ACCESS_DENIED_ERROR", () => {
|
|
245
|
+
enableInternalDB();
|
|
246
|
+
|
|
247
|
+
logQueryAudit({
|
|
248
|
+
sql: "SELECT 1",
|
|
249
|
+
durationMs: 10,
|
|
250
|
+
rowCount: null,
|
|
251
|
+
success: false,
|
|
252
|
+
error: "ER_ACCESS_DENIED_ERROR: Access denied",
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
expect(queryCalls[0].params![7]).toBe("[scrubbed]");
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("scrubs MySQL PROTOCOL_CONNECTION_LOST", () => {
|
|
259
|
+
enableInternalDB();
|
|
260
|
+
|
|
261
|
+
logQueryAudit({
|
|
262
|
+
sql: "SELECT 1",
|
|
263
|
+
durationMs: 10,
|
|
264
|
+
rowCount: null,
|
|
265
|
+
success: false,
|
|
266
|
+
error: "PROTOCOL_CONNECTION_LOST: server closed the connection unexpectedly",
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
expect(queryCalls[0].params![7]).toBe("[scrubbed]");
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("scrubs ClickHouse UNKNOWN_USER error", () => {
|
|
273
|
+
enableInternalDB();
|
|
274
|
+
|
|
275
|
+
logQueryAudit({
|
|
276
|
+
sql: "SELECT 1",
|
|
277
|
+
durationMs: 10,
|
|
278
|
+
rowCount: null,
|
|
279
|
+
success: false,
|
|
280
|
+
error: "UNKNOWN_USER: no user with such name: analyst",
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
expect(queryCalls[0].params![7]).toBe("[scrubbed]");
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it("scrubs ClickHouse WRONG_PASSWORD error", () => {
|
|
287
|
+
enableInternalDB();
|
|
288
|
+
|
|
289
|
+
logQueryAudit({
|
|
290
|
+
sql: "SELECT 1",
|
|
291
|
+
durationMs: 10,
|
|
292
|
+
rowCount: null,
|
|
293
|
+
success: false,
|
|
294
|
+
error: "WRONG_PASSWORD: password is incorrect for user default",
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
expect(queryCalls[0].params![7]).toBe("[scrubbed]");
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("scrubs ClickHouse IP_ADDRESS_NOT_ALLOWED error", () => {
|
|
301
|
+
enableInternalDB();
|
|
302
|
+
|
|
303
|
+
logQueryAudit({
|
|
304
|
+
sql: "SELECT 1",
|
|
305
|
+
durationMs: 10,
|
|
306
|
+
rowCount: null,
|
|
307
|
+
success: false,
|
|
308
|
+
error: "IP_ADDRESS_NOT_ALLOWED: 10.0.0.5 is not allowed to connect",
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
expect(queryCalls[0].params![7]).toBe("[scrubbed]");
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("scrubs ClickHouse ALL_CONNECTION_TRIES_FAILED error", () => {
|
|
315
|
+
enableInternalDB();
|
|
316
|
+
|
|
317
|
+
logQueryAudit({
|
|
318
|
+
sql: "SELECT 1",
|
|
319
|
+
durationMs: 10,
|
|
320
|
+
rowCount: null,
|
|
321
|
+
success: false,
|
|
322
|
+
error: "ALL_CONNECTION_TRIES_FAILED: could not connect to clickhouse-server:9000",
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
expect(queryCalls[0].params![7]).toBe("[scrubbed]");
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("does not scrub non-sensitive errors", () => {
|
|
329
|
+
enableInternalDB();
|
|
330
|
+
|
|
331
|
+
logQueryAudit({
|
|
332
|
+
sql: "SELECT 1",
|
|
333
|
+
durationMs: 10,
|
|
334
|
+
rowCount: null,
|
|
335
|
+
success: false,
|
|
336
|
+
error: "column bad_col does not exist",
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
expect(queryCalls[0].params![7]).toBe("column bad_col does not exist");
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it("pulls user identity from request context", () => {
|
|
343
|
+
enableInternalDB();
|
|
344
|
+
const user: AtlasUser = { id: "user-abc", label: "admin@co.com", mode: "simple-key" };
|
|
345
|
+
|
|
346
|
+
withRequestContext({ requestId: "req-42", user }, () => {
|
|
347
|
+
logQueryAudit({ sql: "SELECT 1", durationMs: 5, rowCount: 1, success: true });
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
expect(queryCalls[0].params![0]).toBe("user-abc");
|
|
351
|
+
expect(queryCalls[0].params![1]).toBe("admin@co.com");
|
|
352
|
+
expect(queryCalls[0].params![2]).toBe("simple-key");
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it("uses auth_mode 'none' when no request context exists", () => {
|
|
356
|
+
enableInternalDB();
|
|
357
|
+
|
|
358
|
+
logQueryAudit({ sql: "SELECT 1", durationMs: 5, rowCount: 1, success: true });
|
|
359
|
+
|
|
360
|
+
expect(queryCalls[0].params![0]).toBeNull(); // user_id
|
|
361
|
+
expect(queryCalls[0].params![1]).toBeNull(); // user_label
|
|
362
|
+
expect(queryCalls[0].params![2]).toBe("none"); // auth_mode
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it("records success=false and error for failed queries", () => {
|
|
366
|
+
enableInternalDB();
|
|
367
|
+
|
|
368
|
+
logQueryAudit({
|
|
369
|
+
sql: "SELECT bad_col FROM t",
|
|
370
|
+
durationMs: 3,
|
|
371
|
+
rowCount: null,
|
|
372
|
+
success: false,
|
|
373
|
+
error: "column bad_col does not exist",
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
expect(queryCalls[0].params![5]).toBeNull(); // row_count
|
|
377
|
+
expect(queryCalls[0].params![6]).toBe(false); // success
|
|
378
|
+
expect(queryCalls[0].params![7]).toBe("column bad_col does not exist");
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it("records null error for successful queries", () => {
|
|
382
|
+
enableInternalDB();
|
|
383
|
+
|
|
384
|
+
logQueryAudit({ sql: "SELECT 1", durationMs: 5, rowCount: 10, success: true });
|
|
385
|
+
|
|
386
|
+
expect(queryCalls[0].params![5]).toBe(10); // row_count
|
|
387
|
+
expect(queryCalls[0].params![6]).toBe(true); // success
|
|
388
|
+
expect(queryCalls[0].params![7]).toBeNull(); // error
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it("treats empty string error as no error (null in DB)", () => {
|
|
392
|
+
enableInternalDB();
|
|
393
|
+
|
|
394
|
+
logQueryAudit({
|
|
395
|
+
sql: "SELECT 1",
|
|
396
|
+
durationMs: 10,
|
|
397
|
+
rowCount: null,
|
|
398
|
+
success: false,
|
|
399
|
+
error: "",
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
expect(queryCalls[0].params![7]).toBeNull();
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it("treats explicit undefined error as null in DB", () => {
|
|
406
|
+
enableInternalDB();
|
|
407
|
+
|
|
408
|
+
logQueryAudit({
|
|
409
|
+
sql: "SELECT 1",
|
|
410
|
+
durationMs: 10,
|
|
411
|
+
rowCount: null,
|
|
412
|
+
success: false,
|
|
413
|
+
error: undefined,
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
expect(queryCalls[0].params![7]).toBeNull();
|
|
417
|
+
});
|
|
418
|
+
});
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BYOT integration test — validates JWT auth against a real JWKS HTTP server.
|
|
3
|
+
*
|
|
4
|
+
* Separate from byot.test.ts because that file uses mock.module("jose", ...)
|
|
5
|
+
* which is sticky within its module graph. This file imports jose and byot.ts
|
|
6
|
+
* without any mocking.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach } from "bun:test";
|
|
10
|
+
import { generateKeyPair, exportJWK, SignJWT } from "jose";
|
|
11
|
+
import { validateBYOT, resetJWKSCache } from "../byot";
|
|
12
|
+
|
|
13
|
+
const TEST_ISSUER = "https://auth.integration-test.example.com";
|
|
14
|
+
const TEST_AUDIENCE = "atlas-integration";
|
|
15
|
+
|
|
16
|
+
let publicKey: CryptoKey;
|
|
17
|
+
let privateKey: CryptoKey;
|
|
18
|
+
let wrongPrivateKey: CryptoKey;
|
|
19
|
+
let server: ReturnType<typeof Bun.serve>;
|
|
20
|
+
let jwksUrl: string;
|
|
21
|
+
|
|
22
|
+
// Env vars to restore after tests
|
|
23
|
+
const origJwksUrl = process.env.ATLAS_AUTH_JWKS_URL;
|
|
24
|
+
const origIssuer = process.env.ATLAS_AUTH_ISSUER;
|
|
25
|
+
const origAudience = process.env.ATLAS_AUTH_AUDIENCE;
|
|
26
|
+
|
|
27
|
+
beforeAll(async () => {
|
|
28
|
+
// Generate two RS256 key pairs — one for the JWKS server, one to simulate wrong-key signing
|
|
29
|
+
const primary = await generateKeyPair("RS256");
|
|
30
|
+
publicKey = primary.publicKey;
|
|
31
|
+
privateKey = primary.privateKey;
|
|
32
|
+
|
|
33
|
+
const wrong = await generateKeyPair("RS256");
|
|
34
|
+
wrongPrivateKey = wrong.privateKey;
|
|
35
|
+
|
|
36
|
+
const publicJwk = await exportJWK(publicKey);
|
|
37
|
+
publicJwk.kid = "integration-key-1";
|
|
38
|
+
publicJwk.alg = "RS256";
|
|
39
|
+
publicJwk.use = "sig";
|
|
40
|
+
|
|
41
|
+
const jwksPayload = JSON.stringify({ keys: [publicJwk] });
|
|
42
|
+
|
|
43
|
+
// Start an ephemeral HTTP server serving the JWKS endpoint
|
|
44
|
+
server = Bun.serve({
|
|
45
|
+
port: 0, // OS-assigned ephemeral port
|
|
46
|
+
fetch(req) {
|
|
47
|
+
const url = new URL(req.url);
|
|
48
|
+
if (url.pathname === "/.well-known/jwks.json") {
|
|
49
|
+
return new Response(jwksPayload, {
|
|
50
|
+
headers: { "Content-Type": "application/json" },
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return new Response("Not Found", { status: 404 });
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
jwksUrl = `http://localhost:${server.port}/.well-known/jwks.json`;
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
afterAll(() => {
|
|
61
|
+
if (server) server.stop(true);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
process.env.ATLAS_AUTH_JWKS_URL = jwksUrl;
|
|
66
|
+
process.env.ATLAS_AUTH_ISSUER = TEST_ISSUER;
|
|
67
|
+
process.env.ATLAS_AUTH_AUDIENCE = TEST_AUDIENCE;
|
|
68
|
+
resetJWKSCache();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
afterEach(() => {
|
|
72
|
+
if (origJwksUrl !== undefined) process.env.ATLAS_AUTH_JWKS_URL = origJwksUrl;
|
|
73
|
+
else delete process.env.ATLAS_AUTH_JWKS_URL;
|
|
74
|
+
|
|
75
|
+
if (origIssuer !== undefined) process.env.ATLAS_AUTH_ISSUER = origIssuer;
|
|
76
|
+
else delete process.env.ATLAS_AUTH_ISSUER;
|
|
77
|
+
|
|
78
|
+
if (origAudience !== undefined) process.env.ATLAS_AUTH_AUDIENCE = origAudience;
|
|
79
|
+
else delete process.env.ATLAS_AUTH_AUDIENCE;
|
|
80
|
+
|
|
81
|
+
resetJWKSCache();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
/** Sign a JWT with the given key (defaults to the primary private key). */
|
|
85
|
+
async function signJWT(
|
|
86
|
+
claims: Record<string, unknown> = {},
|
|
87
|
+
opts: { expiresIn?: string; issuer?: string; audience?: string; key?: CryptoKey } = {},
|
|
88
|
+
): Promise<string> {
|
|
89
|
+
return new SignJWT(claims)
|
|
90
|
+
.setProtectedHeader({ alg: "RS256", kid: "integration-key-1" })
|
|
91
|
+
.setSubject((claims.sub as string) ?? "user_integ_1")
|
|
92
|
+
.setIssuedAt()
|
|
93
|
+
.setExpirationTime(opts.expiresIn ?? "1h")
|
|
94
|
+
.setIssuer(opts.issuer ?? TEST_ISSUER)
|
|
95
|
+
.setAudience(opts.audience ?? TEST_AUDIENCE)
|
|
96
|
+
.sign(opts.key ?? privateKey);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function makeRequest(headers?: Record<string, string>): Request {
|
|
100
|
+
return new Request("http://localhost/api/chat", {
|
|
101
|
+
method: "POST",
|
|
102
|
+
headers: headers ?? {},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
describe("BYOT integration (real JWKS server)", () => {
|
|
107
|
+
it("valid JWT authenticates successfully via real JWKS fetch", async () => {
|
|
108
|
+
const token = await signJWT({ sub: "user_integ_1", email: "alice@corp.com" });
|
|
109
|
+
const result = await validateBYOT(
|
|
110
|
+
makeRequest({ Authorization: `Bearer ${token}` }),
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
expect(result).toMatchObject({
|
|
114
|
+
authenticated: true,
|
|
115
|
+
mode: "byot",
|
|
116
|
+
user: {
|
|
117
|
+
id: "user_integ_1",
|
|
118
|
+
mode: "byot",
|
|
119
|
+
label: "alice@corp.com",
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
// Verify claims populated from JWT payload
|
|
123
|
+
if (result.authenticated && result.user) {
|
|
124
|
+
expect(result.user.claims).toBeDefined();
|
|
125
|
+
expect(result.user.claims!.sub).toBe("user_integ_1");
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("expired JWT returns 401", async () => {
|
|
130
|
+
const token = await signJWT({ sub: "user_integ_1" }, { expiresIn: "-1h" });
|
|
131
|
+
const result = await validateBYOT(
|
|
132
|
+
makeRequest({ Authorization: `Bearer ${token}` }),
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
expect(result.authenticated).toBe(false);
|
|
136
|
+
if (!result.authenticated) {
|
|
137
|
+
expect(result.status).toBe(401);
|
|
138
|
+
expect(result.error).toContain("Invalid or expired");
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("wrong issuer returns 401", async () => {
|
|
143
|
+
const token = await signJWT(
|
|
144
|
+
{ sub: "user_integ_1" },
|
|
145
|
+
{ issuer: "https://evil.example.com" },
|
|
146
|
+
);
|
|
147
|
+
const result = await validateBYOT(
|
|
148
|
+
makeRequest({ Authorization: `Bearer ${token}` }),
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
expect(result.authenticated).toBe(false);
|
|
152
|
+
if (!result.authenticated) {
|
|
153
|
+
expect(result.status).toBe(401);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("wrong audience returns 401", async () => {
|
|
158
|
+
const token = await signJWT(
|
|
159
|
+
{ sub: "user_integ_1" },
|
|
160
|
+
{ audience: "wrong-audience" },
|
|
161
|
+
);
|
|
162
|
+
const result = await validateBYOT(
|
|
163
|
+
makeRequest({ Authorization: `Bearer ${token}` }),
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
expect(result.authenticated).toBe(false);
|
|
167
|
+
if (!result.authenticated) {
|
|
168
|
+
expect(result.status).toBe(401);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("token signed with wrong key returns 401", async () => {
|
|
173
|
+
const token = await signJWT(
|
|
174
|
+
{ sub: "user_integ_1" },
|
|
175
|
+
{ key: wrongPrivateKey },
|
|
176
|
+
);
|
|
177
|
+
const result = await validateBYOT(
|
|
178
|
+
makeRequest({ Authorization: `Bearer ${token}` }),
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
expect(result.authenticated).toBe(false);
|
|
182
|
+
if (!result.authenticated) {
|
|
183
|
+
expect(result.status).toBe(401);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("empty ATLAS_AUTH_AUDIENCE skips audience check (accepts any audience)", async () => {
|
|
188
|
+
process.env.ATLAS_AUTH_AUDIENCE = "";
|
|
189
|
+
resetJWKSCache();
|
|
190
|
+
|
|
191
|
+
const token = await signJWT(
|
|
192
|
+
{ sub: "user_integ_1" },
|
|
193
|
+
{ audience: "any-audience-should-work" },
|
|
194
|
+
);
|
|
195
|
+
const result = await validateBYOT(
|
|
196
|
+
makeRequest({ Authorization: `Bearer ${token}` }),
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
expect(result.authenticated).toBe(true);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("JWT missing sub claim returns 401", async () => {
|
|
203
|
+
const token = await new SignJWT({ email: "nosub@example.com" })
|
|
204
|
+
.setProtectedHeader({ alg: "RS256", kid: "integration-key-1" })
|
|
205
|
+
.setIssuedAt()
|
|
206
|
+
.setExpirationTime("1h")
|
|
207
|
+
.setIssuer(TEST_ISSUER)
|
|
208
|
+
.setAudience(TEST_AUDIENCE)
|
|
209
|
+
.sign(privateKey);
|
|
210
|
+
|
|
211
|
+
const result = await validateBYOT(
|
|
212
|
+
makeRequest({ Authorization: `Bearer ${token}` }),
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
expect(result).toEqual({
|
|
216
|
+
authenticated: false,
|
|
217
|
+
mode: "byot",
|
|
218
|
+
status: 401,
|
|
219
|
+
error: "JWT missing sub claim",
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
});
|