@@ -286,6 +286,85 @@ describe('CspHtmlWebpackPlugin', () => {
286286 ) ;
287287 } ) ;
288288
289+ it ( 'adds meta tag with completed policy when no meta tag is specified' , done => {
290+ const webpackConfig = {
291+ entry : path . join ( __dirname , 'fixtures/index.js' ) ,
292+ output : {
293+ path : OUTPUT_DIR ,
294+ filename : 'index.bundle.js'
295+ } ,
296+ plugins : [
297+ new HtmlWebpackPlugin ( {
298+ filename : path . join ( OUTPUT_DIR , 'index.html' ) ,
299+ template : path . join ( __dirname , 'fixtures' , 'with-no-meta-tag.html' ) ,
300+ inject : 'body'
301+ } ) ,
302+ new CspHtmlWebpackPlugin ( {
303+ 'base-uri' : [ "'self'" , 'https://slack.com' ] ,
304+ 'object-src' : [ "'self'" ] ,
305+ 'script-src' : [ "'self'" ] ,
306+ 'style-src' : [ "'self'" ]
307+ } )
308+ ]
309+ } ;
310+
311+ testCspHtmlWebpackPlugin (
312+ webpackConfig ,
313+ 'index.html' ,
314+ ( cspPolicy , _ , doneFn ) => {
315+ const expected =
316+ "base-uri 'self' https://slack.com;" +
317+ " object-src 'self';" +
318+ " script-src 'self';" +
319+ " style-src 'self'" ;
320+
321+ expect ( cspPolicy ) . toEqual ( expected ) ;
322+
323+ doneFn ( ) ;
324+ } ,
325+ done
326+ ) ;
327+ } ) ;
328+
329+ it ( 'adds meta tag with completed policy when no template is specified' , done => {
330+ const webpackConfig = {
331+ entry : path . join ( __dirname , 'fixtures/index.js' ) ,
332+ output : {
333+ path : OUTPUT_DIR ,
334+ filename : 'index.bundle.js'
335+ } ,
336+ plugins : [
337+ new HtmlWebpackPlugin ( {
338+ filename : path . join ( OUTPUT_DIR , 'index.html' ) ,
339+ inject : 'body'
340+ } ) ,
341+ new CspHtmlWebpackPlugin ( {
342+ 'base-uri' : [ "'self'" , 'https://slack.com' ] ,
343+ 'object-src' : [ "'self'" ] ,
344+ 'script-src' : [ "'self'" ] ,
345+ 'style-src' : [ "'self'" ]
346+ } )
347+ ]
348+ } ;
349+
350+ testCspHtmlWebpackPlugin (
351+ webpackConfig ,
352+ 'index.html' ,
353+ ( cspPolicy , _ , doneFn ) => {
354+ const expected =
355+ "base-uri 'self' https://slack.com;" +
356+ " object-src 'self';" +
357+ " script-src 'self';" +
358+ " style-src 'self'" ;
359+
360+ expect ( cspPolicy ) . toEqual ( expected ) ;
361+
362+ doneFn ( ) ;
363+ } ,
364+ done
365+ ) ;
366+ } ) ;
367+
289368 it ( 'throws an error if an invalid hashing method is used' , ( ) => {
290369 expect ( ( ) => {
291370 // eslint-disable-next-line no-new
0 commit comments