-
Notifications
You must be signed in to change notification settings - Fork 481
Expand file tree
/
Copy pathurl.test.ts
More file actions
70 lines (58 loc) · 2.69 KB
/
Copy pathurl.test.ts
File metadata and controls
70 lines (58 loc) · 2.69 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { isLocalURL } from 'firefox-profiler/utils/url';
describe('isLocalURL', () => {
it('should return true for localhost', () => {
expect(isLocalURL('http://localhost')).toBe(true);
expect(isLocalURL('http://localhost:3000')).toBe(true);
});
it('should return true for 127.0.0.1', () => {
expect(isLocalURL('http://127.0.0.1')).toBe(true);
});
it('should return true for ::1', () => {
expect(isLocalURL('http://[::1]')).toBe(true);
});
it('should return true for IPv6 local addresses', () => {
expect(isLocalURL('http://[fe80::1]')).toBe(true);
expect(isLocalURL('http://[fd00::1]')).toBe(true);
expect(isLocalURL('http://[fc00::1]')).toBe(true);
expect(isLocalURL('http://[ff00::1]')).toBe(false);
expect(isLocalURL('http://[::ffff:1.1.1.1]')).toBe(false);
});
it('should return true for LAN addresses', () => {
expect(isLocalURL('http://10.0.0.1')).toBe(true);
expect(isLocalURL('http://10.255.255.255')).toBe(true);
expect(isLocalURL('http://172.16.0.1')).toBe(true);
expect(isLocalURL('http://172.31.255.255')).toBe(true);
expect(isLocalURL('http://192.168.1.1')).toBe(true);
expect(isLocalURL('http://100.100.100.100')).toBe(true);
expect(isLocalURL('http://169.254.1.1')).toBe(true);
expect(isLocalURL('http://198.18.0.1')).toBe(true);
expect(isLocalURL('http://127.0.0.2')).toBe(true);
});
it('should return false for other public IP addresses', () => {
expect(isLocalURL('http://8.8.8.8')).toBe(false);
expect(isLocalURL('http://172.15.255.255')).toBe(false);
expect(isLocalURL('http://172.32.0.0')).toBe(false);
});
it('should return true for .local domains', () => {
expect(isLocalURL('http://myserver.local')).toBe(true);
expect(isLocalURL('http://test.local:8080')).toBe(true);
});
it('should return true for hostnames without dots', () => {
expect(isLocalURL('http://mycomputer')).toBe(true);
expect(isLocalURL('http://dev-server:8000')).toBe(true);
});
it('should return false for public domains', () => {
expect(isLocalURL('https://firefox.com')).toBe(false);
expect(isLocalURL('https://profiler.firefox.com')).toBe(false);
});
it('should return false for hostnames that look like IPv4 but have more labels', () => {
expect(isLocalURL('http://192.168.1.1.foo.com')).toBe(false);
expect(isLocalURL('http://10.0.0.1.example.org')).toBe(false);
});
it('should return false for invalid URLs', () => {
expect(isLocalURL('not-a-url')).toBe(false);
});
});