calendar-bridge-hosted-route.test.mjs
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠ breaking
10 days ago
| 1 | /** |
| 2 | * Hosted bridge calendar route contract tests (step 12 parity). |
| 3 | */ |
| 4 | import { describe, it } from 'node:test'; |
| 5 | import assert from 'node:assert/strict'; |
| 6 | import fs from 'fs'; |
| 7 | import path from 'path'; |
| 8 | import { fileURLToPath } from 'url'; |
| 9 | |
| 10 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 11 | const repoRoot = path.dirname(__dirname); |
| 12 | |
| 13 | function readRepoFile(relativePath) { |
| 14 | return fs.readFileSync(path.join(repoRoot, relativePath), 'utf8'); |
| 15 | } |
| 16 | |
| 17 | describe('hosted bridge calendar routes', () => { |
| 18 | it('unit: registers timeline, agent-context, source-calendars, and import routes', () => { |
| 19 | const bridge = readRepoFile('hub/bridge/server.mjs'); |
| 20 | const gateway = readRepoFile('hub/gateway/server.mjs'); |
| 21 | |
| 22 | assert.match(bridge, /app\.get\('\/api\/v1\/calendar\/timeline', requireBridgeAuth/); |
| 23 | assert.match(bridge, /app\.get\('\/api\/v1\/calendar\/agent-context', requireBridgeAuth/); |
| 24 | assert.match(bridge, /app\.get\('\/api\/v1\/calendar\/source-calendars', requireBridgeAuth/); |
| 25 | assert.match(bridge, /app\.patch\('\/api\/v1\/calendar\/source-calendars\/:id', requireBridgeAuth, requireBridgeEditorOrAdmin/); |
| 26 | assert.match(bridge, /app\.post\('\/api\/v1\/calendar\/events\/import', requireBridgeAuth, requireBridgeEditorOrAdmin/); |
| 27 | assert.match(bridge, /app\.get\('\/api\/v1\/calendar\/connectors\/callback'/); |
| 28 | assert.match(bridge, /app\.post\('\/api\/v1\/calendar\/connectors', requireBridgeAuth, requireBridgeEditorOrAdmin/); |
| 29 | assert.match(bridge, /app\.get\('\/api\/v1\/calendar\/connectors', requireBridgeAuth/); |
| 30 | assert.match(bridge, /app\.post\('\/api\/v1\/calendar\/connectors\/:id\/sync', requireBridgeAuth, requireBridgeEditorOrAdmin/); |
| 31 | assert.match(bridge, /app\.delete\('\/api\/v1\/calendar\/connectors\/:id', requireBridgeAuth, requireBridgeEditorOrAdmin/); |
| 32 | assert.match(bridge, /fetchCanisterNoteRecordsForTimeline/); |
| 33 | |
| 34 | assert.match(gateway, /app\.get\('\/api\/v1\/calendar\/timeline'/); |
| 35 | assert.match(gateway, /app\.get\('\/api\/v1\/calendar\/agent-context'/); |
| 36 | assert.match(gateway, /app\.get\('\/api\/v1\/calendar\/source-calendars'/); |
| 37 | assert.match(gateway, /app\.patch\('\/api\/v1\/calendar\/source-calendars\/:id'/); |
| 38 | assert.match(gateway, /app\.post\('\/api\/v1\/calendar\/events\/import'/); |
| 39 | assert.match(gateway, /app\.get\('\/api\/v1\/calendar\/connectors\/callback'/); |
| 40 | assert.match(gateway, /app\.post\('\/api\/v1\/calendar\/connectors'/); |
| 41 | assert.match(gateway, /app\.get\('\/api\/v1\/calendar\/connectors'/); |
| 42 | assert.match(gateway, /app\.post\('\/api\/v1\/calendar\/connectors\/:id\/sync'/); |
| 43 | assert.match(gateway, /app\.delete\('\/api\/v1\/calendar\/connectors\/:id'/); |
| 44 | }); |
| 45 | |
| 46 | it('security: bridge calendar routes require auth before hosted context resolution', () => { |
| 47 | const bridge = readRepoFile('hub/bridge/server.mjs'); |
| 48 | const timelineBlock = bridge.slice( |
| 49 | bridge.indexOf("app.get('/api/v1/calendar/timeline'"), |
| 50 | bridge.indexOf("app.get('/api/v1/calendar/agent-context'"), |
| 51 | ); |
| 52 | const connectorListBlock = bridge.slice( |
| 53 | bridge.indexOf("app.get('/api/v1/calendar/connectors', requireBridgeAuth"), |
| 54 | bridge.indexOf("app.post('/api/v1/calendar/connectors/:id/sync'"), |
| 55 | ); |
| 56 | |
| 57 | assert.match(timelineBlock, /requireBridgeAuth/); |
| 58 | assert.match(timelineBlock, /resolveHostedBridgeContext/); |
| 59 | assert.doesNotMatch(timelineBlock, /oauth_ref|refresh_token/); |
| 60 | assert.match(connectorListBlock, /requireBridgeAuth/); |
| 61 | assert.doesNotMatch(connectorListBlock, /oauth_ref|refresh_token/); |
| 62 | }); |
| 63 | |
| 64 | it('integration: timeline merge can use canister note records without a local vault path', () => { |
| 65 | const timeline = readRepoFile('lib/calendar/timeline.mjs'); |
| 66 | assert.match(timeline, /noteRecords/); |
| 67 | assert.match(timeline, /input\.noteRecords != null/); |
| 68 | }); |
| 69 | }); |
File History
2 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠
10 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b
fix(7C-L1b): route hosted delegation proposals through cani…
Human
minor
⚠
30 days ago