|
| 1 | +import { expect, test } from 'vitest' |
| 2 | +import { defaultAllowedOrigins } from '../constants' |
| 3 | + |
| 4 | +test('defaultAllowedOrigins', () => { |
| 5 | + const allowed = [ |
| 6 | + 'http://localhost', |
| 7 | + 'http://foo.localhost', |
| 8 | + 'http://localhost:3000', |
| 9 | + 'https://localhost:3000', |
| 10 | + 'http://127.0.0.1', |
| 11 | + 'http://[::1]', |
| 12 | + 'http://[::1]:3000', |
| 13 | + ] |
| 14 | + const denied = [ |
| 15 | + 'file:///foo', |
| 16 | + 'http://localhost.example.com', |
| 17 | + 'http://foo.example.com:localhost', |
| 18 | + 'http://', |
| 19 | + 'http://192.0.2', |
| 20 | + 'http://[2001:db8::1]', |
| 21 | + 'http://vite', |
| 22 | + 'http://vite:3000', |
| 23 | + ] |
| 24 | + |
| 25 | + for (const origin of allowed) { |
| 26 | + expect(defaultAllowedOrigins.test(origin), origin).toBe(true) |
| 27 | + } |
| 28 | + |
| 29 | + for (const origin of denied) { |
| 30 | + expect(defaultAllowedOrigins.test(origin), origin).toBe(false) |
| 31 | + } |
| 32 | +}) |
0 commit comments