Files
envbao-admin/src/model/connectionUrl.test.ts
T
mattandClaude Sonnet 5.5 fd20caa525 Config: show each database connection's URL and allowed roles
The connections table reads each connection and lists its URL and
allowed roles. Literal passwords in a URL are masked; templated
{{password}} URLs are shown as-is.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 14:09:42 +00:00

25 lines
1.1 KiB
TypeScript

import { expect, test } from 'vitest'
import { maskConnectionUrl } from './connectionUrl'
test('keeps templated credentials', () => {
const u = 'postgresql://{{username}}:{{password}}@db:5432/app?sslmode=disable'
expect(maskConnectionUrl(u)).toBe(u)
})
test('hides a literal password in the userinfo', () => {
expect(maskConnectionUrl('postgresql://bao:hunter2@db:5432/app')).toBe('postgresql://bao:••••@db:5432/app')
expect(maskConnectionUrl('mongodb+srv://u:p%40ss@cluster.example.test/x')).toBe('mongodb+srv://u:••••@cluster.example.test/x')
})
test('hides a literal password parameter, in either style', () => {
expect(maskConnectionUrl('postgresql://db/app?user=bao&password=hunter2&sslmode=disable')).toBe(
'postgresql://db/app?user=bao&password=••••&sslmode=disable',
)
expect(maskConnectionUrl('host=db user=bao password=hunter2 dbname=app')).toBe('host=db user=bao password=•••• dbname=app')
})
test('leaves URLs without credentials alone', () => {
expect(maskConnectionUrl('postgresql://db:5432/app')).toBe('postgresql://db:5432/app')
expect(maskConnectionUrl('')).toBe('')
})