35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import { describe, expect, test } from 'bun:test';
|
|||
|
|
import { redactSensitiveUrl, resolveDesktopHostUrl } from './desktopHosts';
|
||
|
|
|
||
|
|
describe('resolveDesktopHostUrl', () => {
|
||
|
|
test('keeps regular host URLs unchanged', () => {
|
||
|
|
expect(resolveDesktopHostUrl('https://example.com/app?x=1')).toEqual({
|
||
|
|
persistedUrl: 'https://example.com/app?x=1',
|
||
|
|
redeemUrl: null,
|
||
|
|
kind: 'normal-host',
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
test('detects tunnel connect links and stores only origin', () => {
|
||
|
|
expect(resolveDesktopHostUrl('https://example.trycloudflare.com/connect?t=secret-token')).toEqual({
|
||
|
|
persistedUrl: 'https://example.trycloudflare.com',
|
||
|
|
redeemUrl: 'https://example.trycloudflare.com/connect?t=secret-token',
|
||
|
|
kind: 'tunnel-connect-link',
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
test('detects tunnel connect links with trailing slash', () => {
|
||
|
|
expect(resolveDesktopHostUrl('https://example.trycloudflare.com/connect/?t=secret-token#section')).toEqual({
|
||
|
|
persistedUrl: 'https://example.trycloudflare.com',
|
||
|
|
redeemUrl: 'https://example.trycloudflare.com/connect/?t=secret-token',
|
||
|
|
kind: 'tunnel-connect-link',
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
test('redacts tunnel tokens from labels', () => {
|
||
|
|
expect(redactSensitiveUrl('https://example.trycloudflare.com/connect?t=secret-token')).toBe(
|
||
|
|
'https://example.trycloudflare.com/connect?t=%5BREDACTED%5D',
|
||
|
|
);
|
||
|
|
});
|
||
|
|
});
|