@@ -99,6 +99,10 @@ describe.each([
99
99
path . resolve ( outputPath , "image.svg" ) ,
100
100
"svg image" ,
101
101
) ;
102
+ instance . context . outputFileSystem . writeFileSync (
103
+ path . resolve ( outputPath , "image image.svg" ) ,
104
+ "svg image" ,
105
+ ) ;
102
106
instance . context . outputFileSystem . writeFileSync (
103
107
path . resolve ( outputPath , "byte-length.html" ) ,
104
108
"\u00bd + \u00bc = \u00be" ,
@@ -183,6 +187,36 @@ describe.each([
183
187
expect ( response . headers [ "content-type" ] ) . toEqual ( "image/svg+xml" ) ;
184
188
} ) ;
185
189
190
+ it ( 'should return the "200" code for the "GET" request to the "image.svg" file with "/../"' , async ( ) => {
191
+ const fileData = instance . context . outputFileSystem . readFileSync (
192
+ path . resolve ( outputPath , "image.svg" ) ,
193
+ ) ;
194
+
195
+ const response = await req . get ( "/public/../image.svg" ) ;
196
+
197
+ expect ( response . statusCode ) . toEqual ( 200 ) ;
198
+ expect ( response . headers [ "content-length" ] ) . toEqual (
199
+ fileData . byteLength . toString ( ) ,
200
+ ) ;
201
+ expect ( response . headers [ "content-type" ] ) . toEqual ( "image/svg+xml" ) ;
202
+ } ) ;
203
+
204
+ it ( 'should return the "200" code for the "GET" request to the "image.svg" file with "/../../../"' , async ( ) => {
205
+ const fileData = instance . context . outputFileSystem . readFileSync (
206
+ path . resolve ( outputPath , "image.svg" ) ,
207
+ ) ;
208
+
209
+ const response = await req . get (
210
+ "/public/assets/images/../../../image.svg" ,
211
+ ) ;
212
+
213
+ expect ( response . statusCode ) . toEqual ( 200 ) ;
214
+ expect ( response . headers [ "content-length" ] ) . toEqual (
215
+ fileData . byteLength . toString ( ) ,
216
+ ) ;
217
+ expect ( response . headers [ "content-type" ] ) . toEqual ( "image/svg+xml" ) ;
218
+ } ) ;
219
+
186
220
it ( 'should return the "200" code for the "GET" request to the directory' , async ( ) => {
187
221
const fileData = fs . readFileSync (
188
222
path . resolve ( __dirname , "./fixtures/index.html" ) ,
@@ -263,7 +297,7 @@ describe.each([
263
297
`bytes */${ codeLength } ` ,
264
298
) ;
265
299
expect ( response . headers [ "content-type" ] ) . toEqual (
266
- "text/html; charset=UTF -8" ,
300
+ "text/html; charset=utf -8" ,
267
301
) ;
268
302
expect ( response . text ) . toEqual (
269
303
`<!DOCTYPE html>
@@ -447,6 +481,29 @@ describe.each([
447
481
false ,
448
482
) ;
449
483
} ) ;
484
+
485
+ it ( 'should return the "200" code for the "GET" request to the "image image.svg" file' , async ( ) => {
486
+ const fileData = instance . context . outputFileSystem . readFileSync (
487
+ path . resolve ( outputPath , "image image.svg" ) ,
488
+ ) ;
489
+
490
+ const response = await req . get ( "/image image.svg" ) ;
491
+
492
+ expect ( response . statusCode ) . toEqual ( 200 ) ;
493
+ expect ( response . headers [ "content-length" ] ) . toEqual (
494
+ fileData . byteLength . toString ( ) ,
495
+ ) ;
496
+ expect ( response . headers [ "content-type" ] ) . toEqual ( "image/svg+xml" ) ;
497
+ } ) ;
498
+
499
+ it ( 'should return the "404" code for the "GET" request to the "%FF" file' , async ( ) => {
500
+ const response = await req . get ( "/%FF" ) ;
501
+
502
+ expect ( response . statusCode ) . toEqual ( 404 ) ;
503
+ expect ( response . headers [ "content-type" ] ) . toEqual (
504
+ "text/html; charset=utf-8" ,
505
+ ) ;
506
+ } ) ;
450
507
} ) ;
451
508
452
509
describe ( 'should not work with the broken "publicPath" option' , ( ) => {
@@ -2032,7 +2089,7 @@ describe.each([
2032
2089
2033
2090
expect ( response . statusCode ) . toEqual ( 500 ) ;
2034
2091
expect ( response . headers [ "content-type" ] ) . toEqual (
2035
- "text/html; charset=UTF -8" ,
2092
+ "text/html; charset=utf -8" ,
2036
2093
) ;
2037
2094
expect ( response . text ) . toEqual (
2038
2095
"<!DOCTYPE html>\n" +
@@ -2113,7 +2170,7 @@ describe.each([
2113
2170
2114
2171
expect ( response . statusCode ) . toEqual ( 404 ) ;
2115
2172
expect ( response . headers [ "content-type" ] ) . toEqual (
2116
- "text/html; charset=UTF -8" ,
2173
+ "text/html; charset=utf -8" ,
2117
2174
) ;
2118
2175
expect ( response . text ) . toEqual (
2119
2176
"<!DOCTYPE html>\n" +
@@ -2575,6 +2632,7 @@ describe.each([
2575
2632
output : {
2576
2633
filename : "bundle.js" ,
2577
2634
path : path . resolve ( __dirname , "./outputs/write-to-disk-true" ) ,
2635
+ publicPath : "/public/" ,
2578
2636
} ,
2579
2637
} ) ;
2580
2638
@@ -2598,7 +2656,7 @@ describe.each([
2598
2656
2599
2657
it ( "should find the bundle file on disk" , ( done ) => {
2600
2658
request ( app )
2601
- . get ( "/bundle.js" )
2659
+ . get ( "/public/ bundle.js" )
2602
2660
. expect ( 200 , ( error ) => {
2603
2661
if ( error ) {
2604
2662
return done ( error ) ;
@@ -2632,6 +2690,25 @@ describe.each([
2632
2690
) ;
2633
2691
} ) ;
2634
2692
} ) ;
2693
+
2694
+ it ( "should not allow to get files above root" , async ( ) => {
2695
+ const response = await req . get ( "/public/..%2f../middleware.test.js" ) ;
2696
+
2697
+ expect ( response . statusCode ) . toEqual ( 403 ) ;
2698
+ expect ( response . headers [ "content-type" ] ) . toEqual (
2699
+ "text/html; charset=utf-8" ,
2700
+ ) ;
2701
+ expect ( response . text ) . toEqual ( `<!DOCTYPE html>
2702
+ <html lang="en">
2703
+ <head>
2704
+ <meta charset="utf-8">
2705
+ <title>Error</title>
2706
+ </head>
2707
+ <body>
2708
+ <pre>Forbidden</pre>
2709
+ </body>
2710
+ </html>` ) ;
2711
+ } ) ;
2635
2712
} ) ;
2636
2713
2637
2714
describe ( 'should work with "true" value when the `output.clean` is `true`' , ( ) => {
0 commit comments