|
| 1 | +import { |
| 2 | + isServerUrl, |
| 3 | + isHttps, |
| 4 | + isDomainWithoutProtocol, |
| 5 | + isLocalhost, |
| 6 | + hasTrailingForwardSlash, |
| 7 | +} from '@shell/utils/validators/setting'; |
| 8 | + |
| 9 | +describe('isServerUrl', () => { |
| 10 | + it.each([ |
| 11 | + ['server-url', true], |
| 12 | + ['SERVER-URL', false], |
| 13 | + ['server-url/', false], |
| 14 | + ['not-server-url', false], |
| 15 | + ['', false], |
| 16 | + ])('should validate that isServerUrl("%s") returns %s', (input, expected) => { |
| 17 | + expect(isServerUrl(input)).toBe(expected); |
| 18 | + }); |
| 19 | +}); |
| 20 | + |
| 21 | +describe('isHttps', () => { |
| 22 | + it.each([ |
| 23 | + ['https://example.com', true], |
| 24 | + ['HTTPS://EXAMPLE.COM', true], |
| 25 | + ['http://example.com', false], |
| 26 | + ['ftp://example.com', false], |
| 27 | + ['example.com', false], |
| 28 | + ['', false], |
| 29 | + ])('should validate that isHttps("%s") returns %s', (input, expected) => { |
| 30 | + expect(isHttps(input)).toBe(expected); |
| 31 | + }); |
| 32 | +}); |
| 33 | + |
| 34 | +describe('isDomainWithoutProtocol (follows domain format, no protocol)', () => { |
| 35 | + it.each([ |
| 36 | + ['ec2.us-west-2.amazonaws.com', true], |
| 37 | + ['ec2.us-west-2.api.aws', true], |
| 38 | + ['ec2.us-west-2.amazonaws.com.cn', true], |
| 39 | + ['s3.eu-central-1.amazonaws.com.cn', true], |
| 40 | + ['my-service.internal.net', true], |
| 41 | + ['db.example.org:5432', true], |
| 42 | + ['ex.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.com', true], |
| 43 | + ['service.company.local/path/to/resource', true], |
| 44 | + ['example.org:443', true], |
| 45 | + ['https://ec2.us-west-2.amazonaws.com', false], |
| 46 | + ['http://example.com', false], |
| 47 | + ['udp://example.com', false], |
| 48 | + ['ftp://example.com', false], |
| 49 | + ['ftps://example.com', false], |
| 50 | + ['example://example.com', false], |
| 51 | + ['example', false], |
| 52 | + ['-bad.example.com', false], |
| 53 | + ['bad-.example.com', false], |
| 54 | + ['example.c', false], |
| 55 | + ['exa mple.com', false], |
| 56 | + ['exa.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.example.com', false], |
| 57 | + ['', false], |
| 58 | + ])('should validate that isDomainWithoutProtocol("%s") returns %s', (input, expected) => { |
| 59 | + expect(isDomainWithoutProtocol(input)).toBe(expected); |
| 60 | + }); |
| 61 | +}); |
| 62 | + |
| 63 | +describe('isLocalhost', () => { |
| 64 | + it.each([ |
| 65 | + ['localhost', true], |
| 66 | + ['LOCALHOST', true], |
| 67 | + ['http://localhost', true], |
| 68 | + ['https://localhost:3000', true], |
| 69 | + ['127.0.0.1', true], |
| 70 | + ['http://127.0.0.1:8080/path', true], |
| 71 | + ['HTTPS://127.0.0.1/Health', true], |
| 72 | + ['127.0.0.2', false], |
| 73 | + ['http://127.0.0.2', false], |
| 74 | + ['mylocalhost', false], |
| 75 | + ])('should validate that isLocalhost("%s") returns %s', (input, expected) => { |
| 76 | + expect(isLocalhost(input)).toBe(expected); |
| 77 | + }); |
| 78 | +}); |
| 79 | + |
| 80 | +describe('hasTrailingForwardSlash', () => { |
| 81 | + it.each([ |
| 82 | + ['https://example.com/', true], |
| 83 | + ['http://example.com/', true], |
| 84 | + ['HTTPS://EXAMPLE.COM/', true], |
| 85 | + ['https://example.com/path/', true], |
| 86 | + ['https://example.com', false], |
| 87 | + ['http://example.com/path', false], |
| 88 | + ['example.com/', false], |
| 89 | + ])('should validate that hasTrailingForwardSlash("%s") returns %s', (input, expected) => { |
| 90 | + expect(hasTrailingForwardSlash(input)).toBe(expected); |
| 91 | + }); |
| 92 | +}); |
0 commit comments