File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
tests/legacy-cli/e2e/tests/misc Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+
9
+ import { ng } from '../../utils/process' ;
10
+ import { updateJsonFile } from '../../utils/project' ;
11
+
12
+ export default async function ( ) {
13
+ // This test ensures that ng e2e serves the HTTP headers that are configured
14
+ // in the 'headers' field of the serve options. We do this by serving the
15
+ // strictest possible CSP headers (default-src 'none') which blocks loading of
16
+ // any resources (including scripts, styles and images) and should cause ng
17
+ // e2e to fail with a CSP-related error, which is asserted below.
18
+
19
+ await updateJsonFile ( 'angular.json' , ( json ) => {
20
+ const serve = json [ 'projects' ] [ 'test-project' ] [ 'architect' ] [ 'serve' ] ;
21
+ if ( ! serve [ 'options' ] ) serve [ 'options' ] = { } ;
22
+ serve [ 'options' ] [ 'headers' ] = {
23
+ 'Content-Security-Policy' : "default-src 'none'" ,
24
+ } ;
25
+ } ) ;
26
+
27
+ let errorMessage = null ;
28
+ try {
29
+ await ng ( 'e2e' ) ;
30
+ } catch ( error ) {
31
+ errorMessage = error . message ;
32
+ }
33
+
34
+ if ( ! errorMessage ) {
35
+ throw new Error (
36
+ 'Application loaded successfully, indicating that the CSP headers were not served.' ,
37
+ ) ;
38
+ }
39
+ if ( ! errorMessage . match ( / R e f u s e d t o l o a d / ) ) {
40
+ throw new Error ( 'Expected to see CSP loading failure in error logs.' ) ;
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments