Files
web-terminal/control-panel/test/pairing.test.ts
Yaojia Wang 675de771c7 feat(control-panel): web admin UI for the zero-touch tunnel
Loopback Fastify auth-broker + esbuild SPA. Operator password login (constant-time,
signed HttpOnly session cookie, per-forwarded-IP rate-limit) → session-gated proxy
that mints a fresh 60s manage capability token per call to the control-plane admin
API: list hosts, mint pairing codes (with QR + pair command), revoke hosts. Security
headers + CSP, CP_URL pinned loopback (anti-SSRF), hostId dot-segment guard. 55 tests
pass; security-reviewed. Deployed behind nginx panel.terminal.yaojia.wang.
2026-07-19 19:47:51 +02:00

28 lines
1.2 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { buildPairCommand, buildQrDataUrl, buildPairingArtifacts } from '../src/pairing.js'
describe('pairing artifacts', () => {
it('builds the ready-to-run pair command with the code and zone', () => {
const cmd = buildPairCommand('ABCD-EFGH', 'terminal.yaojia.wang')
expect(cmd).toBe('web-terminal-agent pair ABCD-EFGH --install --zone terminal.yaojia.wang')
})
it('renders a PNG data URL for the code', async () => {
const url = await buildQrDataUrl('ABCD-EFGH')
expect(url.startsWith('data:image/png;base64,')).toBe(true)
expect(url.length).toBeGreaterThan(100)
})
it('combines an issued code into the full artifacts payload', async () => {
const artifacts = await buildPairingArtifacts(
{ code: 'WXYZ-1234', expiresAt: '2026-05-01T00:00:00.000Z' },
'z.example',
)
expect(artifacts.code).toBe('WXYZ-1234')
expect(artifacts.expiresAt).toBe('2026-05-01T00:00:00.000Z')
expect(artifacts.pairCommand).toContain('WXYZ-1234')
expect(artifacts.pairCommand).toContain('z.example')
expect(artifacts.qrDataUrl.startsWith('data:image/png;base64,')).toBe(true)
})
})