|
7 | 7 | */
|
8 | 8 |
|
9 | 9 | import { executeDevServer } from '../../index';
|
10 |
| -import { executeOnceAndFetch } from '../execute-fetch'; |
| 10 | +import { executeOnceAndGet } from '../execute-fetch'; |
11 | 11 | import { describeServeBuilder } from '../jasmine-helpers';
|
12 | 12 | import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup';
|
13 | 13 |
|
14 | 14 | const FETCH_HEADERS = Object.freeze({ host: 'example.com' });
|
15 | 15 |
|
16 |
| -describeServeBuilder( |
17 |
| - executeDevServer, |
18 |
| - DEV_SERVER_BUILDER_INFO, |
19 |
| - (harness, setupTarget, isViteRun) => { |
20 |
| - // TODO(fix-vite): currently this is broken in vite. |
21 |
| - (isViteRun ? xdescribe : describe)('option: "allowedHosts"', () => { |
22 |
| - beforeEach(async () => { |
23 |
| - setupTarget(harness); |
| 16 | +describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget, isVite) => { |
| 17 | + describe('option: "allowedHosts"', () => { |
| 18 | + beforeEach(async () => { |
| 19 | + setupTarget(harness); |
24 | 20 |
|
25 |
| - // Application code is not needed for these tests |
26 |
| - await harness.writeFile('src/main.ts', ''); |
27 |
| - }); |
28 |
| - |
29 |
| - it('does not allow an invalid host when option is not present', async () => { |
30 |
| - harness.useTarget('serve', { |
31 |
| - ...BASE_OPTIONS, |
32 |
| - }); |
| 21 | + // Application code is not needed for these tests |
| 22 | + await harness.writeFile('src/main.ts', ''); |
| 23 | + }); |
33 | 24 |
|
34 |
| - const { result, response } = await executeOnceAndFetch(harness, '/', { |
35 |
| - request: { headers: FETCH_HEADERS }, |
36 |
| - }); |
| 25 | + it('does not allow an invalid host when option is not present', async () => { |
| 26 | + harness.useTarget('serve', { ...BASE_OPTIONS }); |
37 | 27 |
|
38 |
| - expect(result?.success).toBeTrue(); |
39 |
| - expect(await response?.text()).toBe('Invalid Host header'); |
| 28 | + const { result, response, content } = await executeOnceAndGet(harness, '/', { |
| 29 | + request: { headers: FETCH_HEADERS }, |
40 | 30 | });
|
41 | 31 |
|
42 |
| - it('does not allow an invalid host when option is an empty array', async () => { |
43 |
| - harness.useTarget('serve', { |
44 |
| - ...BASE_OPTIONS, |
45 |
| - allowedHosts: [], |
46 |
| - }); |
| 32 | + expect(result?.success).toBeTrue(); |
| 33 | + if (isVite) { |
| 34 | + expect(response?.statusCode).toBe(403); |
| 35 | + } else { |
| 36 | + expect(content).toBe('Invalid Host header'); |
| 37 | + } |
| 38 | + }); |
47 | 39 |
|
48 |
| - const { result, response } = await executeOnceAndFetch(harness, '/', { |
49 |
| - request: { headers: FETCH_HEADERS }, |
50 |
| - }); |
| 40 | + it('does not allow an invalid host when option is an empty array', async () => { |
| 41 | + harness.useTarget('serve', { ...BASE_OPTIONS, allowedHosts: [] }); |
51 | 42 |
|
52 |
| - expect(result?.success).toBeTrue(); |
53 |
| - expect(await response?.text()).toBe('Invalid Host header'); |
| 43 | + const { result, response, content } = await executeOnceAndGet(harness, '/', { |
| 44 | + request: { headers: FETCH_HEADERS }, |
54 | 45 | });
|
55 | 46 |
|
56 |
| - it('allows a host when specified in the option', async () => { |
57 |
| - harness.useTarget('serve', { |
58 |
| - ...BASE_OPTIONS, |
59 |
| - allowedHosts: ['example.com'], |
60 |
| - }); |
| 47 | + expect(result?.success).toBeTrue(); |
| 48 | + if (isVite) { |
| 49 | + expect(response?.statusCode).toBe(403); |
| 50 | + } else { |
| 51 | + expect(content).toBe('Invalid Host header'); |
| 52 | + } |
| 53 | + }); |
61 | 54 |
|
62 |
| - const { result, response } = await executeOnceAndFetch(harness, '/', { |
63 |
| - request: { headers: FETCH_HEADERS }, |
64 |
| - }); |
| 55 | + it('allows a host when specified in the option', async () => { |
| 56 | + harness.useTarget('serve', { ...BASE_OPTIONS, allowedHosts: ['example.com'] }); |
65 | 57 |
|
66 |
| - expect(result?.success).toBeTrue(); |
67 |
| - expect(await response?.text()).toContain('<title>'); |
| 58 | + const { result, content } = await executeOnceAndGet(harness, '/', { |
| 59 | + request: { headers: FETCH_HEADERS }, |
68 | 60 | });
|
| 61 | + |
| 62 | + expect(result?.success).toBeTrue(); |
| 63 | + expect(content).toContain('<title>'); |
69 | 64 | });
|
70 |
| - }, |
71 |
| -); |
| 65 | + }); |
| 66 | +}); |
0 commit comments