forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallowed-hosts_spec.ts
More file actions
83 lines (67 loc) · 2.51 KB
/
allowed-hosts_spec.ts
File metadata and controls
83 lines (67 loc) · 2.51 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
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { executeDevServer } from '../../index';
import { executeOnceAndGet } from '../execute-fetch';
import { describeServeBuilder } from '../jasmine-helpers';
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup';
import { text } from 'node:stream/consumers';
const FETCH_HEADERS = Object.freeze({ Host: 'example.com' });
describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget) => {
describe('option: "allowedHosts"', () => {
beforeEach(async () => {
setupTarget(harness);
// Application code is not needed for these tests
await harness.writeFile('src/main.ts', '');
});
it('does not allow an invalid host when option is not present', async () => {
harness.useTarget('serve', {
...BASE_OPTIONS,
});
const { result, response } = await executeOnceAndGet(harness, '/', {
request: { headers: FETCH_HEADERS },
});
expect(result?.success).toBeTrue();
expect(response?.statusCode).toBe(403);
expect(response && text(response)).toContain('angular.json');
});
it('does not allow an invalid host when option is an empty array', async () => {
harness.useTarget('serve', {
...BASE_OPTIONS,
allowedHosts: [],
});
const { result, response } = await executeOnceAndGet(harness, '/', {
request: { headers: FETCH_HEADERS },
});
expect(result?.success).toBeTrue();
expect(response?.statusCode).toBe(403);
expect(response && text(response)).toContain('angular.json');
});
it('allows a host when specified in the option', async () => {
harness.useTarget('serve', {
...BASE_OPTIONS,
allowedHosts: ['example.com'],
});
const { result, content } = await executeOnceAndGet(harness, '/', {
request: { headers: FETCH_HEADERS },
});
expect(result?.success).toBeTrue();
expect(content).toContain('<title>');
});
it('allows a host when option is true', async () => {
harness.useTarget('serve', {
...BASE_OPTIONS,
allowedHosts: true,
});
const { result, content } = await executeOnceAndGet(harness, '/', {
request: { headers: FETCH_HEADERS },
});
expect(result?.success).toBeTrue();
expect(content).toContain('<title>');
});
});
});