File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
packages/angular/build/src
builders/application/tests/behavior Expand file tree Collapse file tree 2 files changed +37
-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.dev/license
7
+ */
8
+
9
+ import { buildApplication } from '../../index' ;
10
+ import { APPLICATION_BUILDER_INFO , BASE_OPTIONS , describeBuilder } from '../setup' ;
11
+
12
+ describeBuilder ( buildApplication , APPLICATION_BUILDER_INFO , ( harness ) => {
13
+ describe ( 'Behavior: "CSP Nonce"' , ( ) => {
14
+ it ( 'should add CSP nonce to scripts when optimization is disabled' , async ( ) => {
15
+ await harness . modifyFile ( 'src/index.html' , ( content ) =>
16
+ content . replace ( / < a p p - r o o t / g, '<app-root ngCspNonce="{% nonce %}" ' ) ,
17
+ ) ;
18
+
19
+ harness . useTarget ( 'build' , {
20
+ ...BASE_OPTIONS ,
21
+ polyfills : [ ] ,
22
+ optimization : false ,
23
+ } ) ;
24
+
25
+ const { result } = await harness . executeOnce ( ) ;
26
+ expect ( result ?. success ) . toBeTrue ( ) ;
27
+
28
+ const indexFileContent = harness . expectFile ( 'dist/browser/index.html' ) . content ;
29
+ indexFileContent . toContain (
30
+ '<script src="main.js" type="module" nonce="{% nonce %}"></script>' ,
31
+ ) ;
32
+ indexFileContent . toContain ( '<app-root ngcspnonce="{% nonce %}"' ) ;
33
+ } ) ;
34
+ } ) ;
35
+ } ) ;
Original file line number Diff line number Diff line change @@ -78,6 +78,8 @@ export class IndexHtmlGenerator {
78
78
this . csrPlugins . push ( inlineCriticalCssPlugin ( this ) ) ;
79
79
}
80
80
81
+ this . csrPlugins . push ( addNoncePlugin ( ) ) ;
82
+
81
83
// SSR plugins
82
84
if ( options . generateDedicatedSSRContent ) {
83
85
this . ssrPlugins . push ( addEventDispatchContractPlugin ( ) , addNoncePlugin ( ) ) ;
You can’t perform that action at this time.
0 commit comments