@@ -1374,18 +1374,60 @@ describe('Parse.File testing', () => {
1374
1374
'X-Parse-Application-Id' : 'test' ,
1375
1375
'X-Parse-REST-API-Key' : 'rest' ,
1376
1376
} ;
1377
- await expectAsync (
1378
- request ( {
1379
- method : 'POST' ,
1380
- headers : headers ,
1381
- url : 'http://localhost:8378/1/files/file.png.html' ,
1382
- body : '<html></html>\n' ,
1383
- } ) . catch ( e => {
1384
- throw new Error ( e . data . error ) ;
1385
- } )
1386
- ) . toBeRejectedWith (
1387
- new Parse . Error ( Parse . Error . FILE_SAVE_ERROR , `File upload of extension html is disabled.` )
1388
- ) ;
1377
+
1378
+ const values = [ 'file.png.html' , 'file.txt.png.html' , 'file.png.txt.html' ] ;
1379
+
1380
+ for ( const value of values ) {
1381
+ await expectAsync (
1382
+ request ( {
1383
+ method : 'POST' ,
1384
+ headers : headers ,
1385
+ url : `http://localhost:8378/1/files/${ value } ` ,
1386
+ body : '<html></html>\n' ,
1387
+ } ) . catch ( e => {
1388
+ throw new Error ( e . data . error ) ;
1389
+ } )
1390
+ ) . toBeRejectedWith (
1391
+ new Parse . Error ( Parse . Error . FILE_SAVE_ERROR , `File upload of extension html is disabled.` )
1392
+ ) ;
1393
+ }
1394
+ } ) ;
1395
+
1396
+ it ( 'works to stop invalid filenames' , async ( ) => {
1397
+ await reconfigureServer ( {
1398
+ fileUpload : {
1399
+ enableForPublic : true ,
1400
+ } ,
1401
+ } ) ;
1402
+ const headers = {
1403
+ 'X-Parse-Application-Id' : 'test' ,
1404
+ 'X-Parse-REST-API-Key' : 'rest' ,
1405
+ } ;
1406
+
1407
+ const values = [
1408
+ '!invalid.png' ,
1409
+ '.png' ,
1410
+ '.html' ,
1411
+ ' .html' ,
1412
+ '.png.html' ,
1413
+ '~invalid.png' ,
1414
+ '-invalid.png' ,
1415
+ ] ;
1416
+
1417
+ for ( const value of values ) {
1418
+ await expectAsync (
1419
+ request ( {
1420
+ method : 'POST' ,
1421
+ headers : headers ,
1422
+ url : `http://localhost:8378/1/files/${ value } ` ,
1423
+ body : '<html></html>\n' ,
1424
+ } ) . catch ( e => {
1425
+ throw new Error ( e . data . error ) ;
1426
+ } )
1427
+ ) . toBeRejectedWith (
1428
+ new Parse . Error ( Parse . Error . INVALID_FILE_NAME , `Filename contains invalid characters.` )
1429
+ ) ;
1430
+ }
1389
1431
} ) ;
1390
1432
1391
1433
it ( 'works with array' , async ( ) => {
0 commit comments