Files
wg-easy-ca-lose/src/test/unit/prometheus.spec.ts
T
0b97cf6d23 fix: escape Prometheus label values (#2702)
fix: escape Prometheus label values (#2699)

Co-authored-by: potatosips <potatosips@users.noreply.github.com>
2026-07-21 09:38:53 +02:00

27 lines
836 B
TypeScript

import { describe, expect, test } from 'vitest';
import {
escapePrometheusLabelValue,
formatPrometheusLabels,
} from '#server/utils/prometheus';
describe('Prometheus label formatting', () => {
test('escapes quotes, backslashes, and newlines in label values', () => {
expect(escapePrometheusLabelValue('vpn"client')).toBe('vpn\\"client');
expect(escapePrometheusLabelValue('path\\client')).toBe('path\\\\client');
expect(escapePrometheusLabelValue('line one\nline two')).toBe(
'line one\\nline two'
);
});
test('formats escaped values without changing scalar values', () => {
expect(
formatPrometheusLabels({
interface: 'wg"0',
enabled: true,
name: 'home\\office\npeer',
})
).toBe('interface="wg\\"0",enabled="true",name="home\\\\office\\npeer"');
});
});