@@ -177,6 +177,94 @@ describe('CspHtmlWebpackPlugin', () => {
177177 ) ;
178178 } ) ;
179179
180+ describe ( "when the user-specified script-src policy contains 'unsafe-inline'" , ( ) => {
181+ it ( 'skips the hashing of the scripts it finds' , done => {
182+ const webpackConfig = {
183+ entry : path . join ( __dirname , 'fixtures/index.js' ) ,
184+ output : {
185+ path : OUTPUT_DIR ,
186+ filename : 'index.bundle.js'
187+ } ,
188+ mode : 'none' ,
189+ plugins : [
190+ new HtmlWebpackPlugin ( {
191+ filename : path . join ( OUTPUT_DIR , 'index.html' ) ,
192+ template : path . join ( __dirname , 'fixtures' , 'with-js.html' ) ,
193+ inject : 'body'
194+ } ) ,
195+ new CspHtmlWebpackPlugin ( {
196+ 'base-uri' : [ "'self'" , 'https://slack.com' ] ,
197+ 'font-src' : [ "'self'" , "'https://a-slack-edge.com'" ] ,
198+ 'script-src' : [ "'self'" , "'unsafe-inline'" ] ,
199+ 'style-src' : [ "'self'" ]
200+ } )
201+ ]
202+ } ;
203+
204+ testCspHtmlWebpackPlugin (
205+ webpackConfig ,
206+ 'index.html' ,
207+ ( cspPolicy , _ , doneFn ) => {
208+ const expected =
209+ "base-uri 'self' https://slack.com;" +
210+ " object-src 'none';" +
211+ " script-src 'self' 'unsafe-inline';" +
212+ " style-src 'self';" +
213+ " font-src 'self' 'https://a-slack-edge.com'" ;
214+
215+ expect ( cspPolicy ) . toEqual ( expected ) ;
216+
217+ doneFn ( ) ;
218+ } ,
219+ done
220+ ) ;
221+ } ) ;
222+ } ) ;
223+
224+ describe ( "when the user-specified style-src policy contains 'unsafe-inline'" , ( ) => {
225+ it ( 'skips the hashing of the styles it finds' , done => {
226+ const webpackConfig = {
227+ entry : path . join ( __dirname , 'fixtures/index.js' ) ,
228+ output : {
229+ path : OUTPUT_DIR ,
230+ filename : 'index.bundle.js'
231+ } ,
232+ mode : 'none' ,
233+ plugins : [
234+ new HtmlWebpackPlugin ( {
235+ filename : path . join ( OUTPUT_DIR , 'index.html' ) ,
236+ template : path . join ( __dirname , 'fixtures' , 'with-css.html' ) ,
237+ inject : 'body'
238+ } ) ,
239+ new CspHtmlWebpackPlugin ( {
240+ 'base-uri' : [ "'self'" , 'https://slack.com' ] ,
241+ 'font-src' : [ "'self'" , "'https://a-slack-edge.com'" ] ,
242+ 'script-src' : [ "'self'" ] ,
243+ 'style-src' : [ "'self'" , "'unsafe-inline'" ]
244+ } )
245+ ]
246+ } ;
247+
248+ testCspHtmlWebpackPlugin (
249+ webpackConfig ,
250+ 'index.html' ,
251+ ( cspPolicy , _ , doneFn ) => {
252+ const expected =
253+ "base-uri 'self' https://slack.com;" +
254+ " object-src 'none';" +
255+ " script-src 'self';" +
256+ " style-src 'self' 'unsafe-inline';" +
257+ " font-src 'self' 'https://a-slack-edge.com'" ;
258+
259+ expect ( cspPolicy ) . toEqual ( expected ) ;
260+
261+ doneFn ( ) ;
262+ } ,
263+ done
264+ ) ;
265+ } ) ;
266+ } ) ;
267+
180268 it ( 'removes the empty Content Security Policy meta tag if enabled is the bool false' , done => {
181269 const webpackConfig = {
182270 entry : path . join ( __dirname , 'fixtures/index.js' ) ,
0 commit comments