forked from promptfoo/promptfoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshare.test.ts
39 lines (32 loc) · 1.31 KB
/
share.test.ts
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
import { stripAuthFromUrl } from '../src/share';
jest.mock('../src/logger');
describe('stripAuthFromUrl', () => {
it('removes username and password from URL', () => {
const input = 'https://user:pass@example.com/path?query=value#hash';
const expected = 'https://example.com/path?query=value#hash';
expect(stripAuthFromUrl(input)).toBe(expected);
});
it('handles URLs without auth info', () => {
const input = 'https://example.com/path?query=value#hash';
expect(stripAuthFromUrl(input)).toBe(input);
});
it('handles URLs with only username', () => {
const input = 'https://user@example.com/path';
const expected = 'https://example.com/path';
expect(stripAuthFromUrl(input)).toBe(expected);
});
it('handles URLs with special characters in auth', () => {
const input = 'https://user%40:p@ss@example.com/path';
const expected = 'https://example.com/path';
expect(stripAuthFromUrl(input)).toBe(expected);
});
it('returns original string for invalid URLs', () => {
const input = 'not a valid url';
expect(stripAuthFromUrl(input)).toBe(input);
});
it('handles URLs with IP addresses', () => {
const input = 'http://user:pass@192.168.1.1:8080/path';
const expected = 'http://192.168.1.1:8080/path';
expect(stripAuthFromUrl(input)).toBe(expected);
});
});