Repository navigation
Expand file tree
/
Copy pathroutes-stack.test.ts
More file actions
52 lines (43 loc) · 1.9 KB
/
Copy pathroutes-stack.test.ts
File metadata and controls
52 lines (43 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Contract test: verify expected HTTP routes are registered without invoking handlers
import test from 'node:test'
import assert from 'node:assert'
import { createRoutes } from '../../dist/app/routes.js'
import { TEST_SECRET } from '../test-constants.js'
const minimalConfig = {
ssh: { host: 'example.com', port: 22, term: 'xterm-256color' },
http: { origins: ['*:*'] },
user: { name: null, password: null },
session: { secret: TEST_SECRET, name: 'y' },
sso: { enabled: false, csrfProtection: false, trustedProxies: [], headerMapping: {} },
options: { challengeButton: true, autoLog: false, allowReplay: true, allowReconnect: true, allowReauth: true },
}
function getRouteMap(router: any) {
const layers = router.stack || []
const byPath: Record<string, Set<string>> = {}
for (const l of layers) {
if (!l.route) continue
const p = l.route.path
const methods = Object.keys(l.route.methods)
byPath[p] = byPath[p] || new Set()
for (const m of methods) byPath[p].add(m)
}
return Object.fromEntries(Object.entries(byPath).map(([p, s]) => [p, Array.from(s).sort()]))
}
test('router registers expected paths and methods', () => {
const router = createRoutes(minimalConfig)
const byPath = getRouteMap(router)
assert.ok(byPath['/'], 'GET / present')
assert.ok(byPath['/'].includes('get'))
assert.ok(byPath['/host/'], 'GET /host/ present')
assert.ok(byPath['/host/'].includes('get'))
assert.ok(byPath['/host/:host'], 'GET /host/:host present')
assert.ok(byPath['/host/:host'].includes('get'))
// POST endpoints
assert.ok(byPath['/'], 'POST / present')
assert.ok(byPath['/'].includes('post'))
// Utility endpoints
assert.ok(byPath['/clear-credentials'], 'GET /clear-credentials present')
assert.ok(byPath['/clear-credentials'].includes('get'))
assert.ok(byPath['/force-reconnect'], 'GET /force-reconnect present')
assert.ok(byPath['/force-reconnect'].includes('get'))
})