@@ -186,6 +186,72 @@ describe('CspHtmlWebpackPlugin', () => {
186
186
} ) ;
187
187
} ) ;
188
188
189
+ it ( 'only inserts hashes for linked scripts and styles from the same HtmlWebpackPlugin instance' , ( done ) => {
190
+ const config = createWebpackConfig (
191
+ [
192
+ new HtmlWebpackPlugin ( {
193
+ filename : path . join ( WEBPACK_OUTPUT_DIR , 'index-1.html' ) ,
194
+ template : path . join (
195
+ __dirname ,
196
+ 'test-utils' ,
197
+ 'fixtures' ,
198
+ 'external-scripts-styles.html'
199
+ ) ,
200
+ chunks : [ '1' ] ,
201
+ } ) ,
202
+ new HtmlWebpackPlugin ( {
203
+ filename : path . join ( WEBPACK_OUTPUT_DIR , 'index-2.html' ) ,
204
+ template : path . join (
205
+ __dirname ,
206
+ 'test-utils' ,
207
+ 'fixtures' ,
208
+ 'external-scripts-styles.html'
209
+ ) ,
210
+ chunks : [ '2' ] ,
211
+ } ) ,
212
+ new MiniCssExtractPlugin ( ) ,
213
+ new CspHtmlWebpackPlugin ( ) ,
214
+ ] ,
215
+ undefined ,
216
+ undefined ,
217
+ {
218
+ entry : {
219
+ '1' : path . join ( __dirname , 'test-utils' , 'fixtures' , 'index-1.js' ) ,
220
+ '2' : path . join ( __dirname , 'test-utils' , 'fixtures' , 'index-2.js' ) ,
221
+ } ,
222
+ module : {
223
+ rules : [
224
+ {
225
+ test : / \. c s s $ / ,
226
+ use : [ MiniCssExtractPlugin . loader , 'css-loader' ] ,
227
+ } ,
228
+ ] ,
229
+ } ,
230
+ output : {
231
+ path : WEBPACK_OUTPUT_DIR ,
232
+ filename : 'index-[name].bundle.js' ,
233
+ } ,
234
+ }
235
+ ) ;
236
+
237
+ webpackCompile ( config , ( csps ) => {
238
+ const expected1 =
239
+ "base-uri 'self';" +
240
+ " object-src 'none';" +
241
+ " script-src 'unsafe-inline' 'self' 'unsafe-eval' 'sha256-Y3RBVJzjgMLd/3xbsXMQc/ZEfadYzG3ndisG/ogf+jQ=' 'nonce-mockedbase64string-1' 'nonce-mockedbase64string-2';" +
242
+ " style-src 'unsafe-inline' 'self' 'unsafe-eval' 'nonce-mockedbase64string-3'" ;
243
+ const expected2 =
244
+ "base-uri 'self';" +
245
+ " object-src 'none';" +
246
+ " script-src 'unsafe-inline' 'self' 'unsafe-eval' 'sha256-npoLW6kyIiQHrDdOzxWCi7oMbea1fUsMVFlclhuByTY=' 'nonce-mockedbase64string-4' 'nonce-mockedbase64string-5';" +
247
+ " style-src 'unsafe-inline' 'self' 'unsafe-eval' 'nonce-mockedbase64string-6'" ;
248
+
249
+ expect ( csps [ 'index-1.html' ] ) . toEqual ( expected1 ) ;
250
+ expect ( csps [ 'index-2.html' ] ) . toEqual ( expected2 ) ;
251
+ done ( ) ;
252
+ } ) ;
253
+ } ) ;
254
+
189
255
it ( 'inserts a custom policy if one is defined' , ( done ) => {
190
256
const config = createWebpackConfig ( [
191
257
new HtmlWebpackPlugin ( {
0 commit comments