@@ -655,31 +655,40 @@ describe('Parse.File testing', () => {
655
655
} ) ;
656
656
657
657
describe ( 'getting files' , ( ) => {
658
- it ( 'can get invalid file' , async ( ) => {
659
- const getFile = async ( ) => {
660
- try {
661
- await request ( { url : 'http://localhost:8378/1/files/invalid-id/invalid-file.txt' } ) ;
662
- } catch ( e ) {
663
- throw new Parse . Error ( e . data . code , e . data . error ) ;
664
- }
665
- } ;
666
- await expectAsync ( getFile ( ) ) . toBeRejectedWith (
667
- new Parse . Error ( Parse . Error . OPERATION_FORBIDDEN , 'Invalid appId.' )
668
- ) ;
669
- const { status, data } = await request ( { url : 'http://localhost:8378/1/health' } ) ;
670
- expect ( status ) . toEqual ( 200 ) ;
671
- expect ( data ) . toEqual ( { status : 'ok' } ) ;
658
+ it ( 'does not crash on file request with invalid app ID' , async ( ) => {
659
+ const res1 = await request ( {
660
+ url : 'http://localhost:8378/1/files/invalid-id/invalid-file.txt' ,
661
+ } ) . catch ( e => e ) ;
662
+ expect ( res1 . status ) . toBe ( 403 ) ;
663
+ expect ( res1 . data ) . toEqual ( { code : 119 , error : 'Invalid application ID.' } ) ;
664
+ // Ensure server did not crash
665
+ const res2 = await request ( { url : 'http://localhost:8378/1/health' } ) ;
666
+ expect ( res2 . status ) . toEqual ( 200 ) ;
667
+ expect ( res2 . data ) . toEqual ( { status : 'ok' } ) ;
668
+ } ) ;
669
+
670
+ it ( 'does not crash on file request with invalid path' , async ( ) => {
671
+ const res1 = await request ( {
672
+ url : 'http://localhost:8378/1/files/invalid-id//invalid-path/%20/invalid-file.txt' ,
673
+ } ) . catch ( e => e ) ;
674
+ expect ( res1 . status ) . toBe ( 403 ) ;
675
+ expect ( res1 . data ) . toEqual ( { error : 'unauthorized' } ) ;
676
+ // Ensure server did not crash
677
+ const res2 = await request ( { url : 'http://localhost:8378/1/health' } ) ;
678
+ expect ( res2 . status ) . toEqual ( 200 ) ;
679
+ expect ( res2 . data ) . toEqual ( { status : 'ok' } ) ;
672
680
} ) ;
673
681
674
- it ( 'can get invalid metadata' , async ( ) => {
675
- const metadata = await request ( {
682
+ it ( 'does not crash on file metadata request with invalid app ID ' , async ( ) => {
683
+ const res1 = await request ( {
676
684
url : `http://localhost:8378/1/files/invalid-id/metadata/invalid-file.txt` ,
677
685
} ) ;
678
- expect ( metadata . status ) . toBe ( 200 ) ;
679
- expect ( metadata . data ) . toEqual ( { } ) ;
680
- const { status, data } = await request ( { url : 'http://localhost:8378/1/health' } ) ;
681
- expect ( status ) . toEqual ( 200 ) ;
682
- expect ( data ) . toEqual ( { status : 'ok' } ) ;
686
+ expect ( res1 . status ) . toBe ( 200 ) ;
687
+ expect ( res1 . data ) . toEqual ( { } ) ;
688
+ // Ensure server did not crash
689
+ const res2 = await request ( { url : 'http://localhost:8378/1/health' } ) ;
690
+ expect ( res2 . status ) . toEqual ( 200 ) ;
691
+ expect ( res2 . data ) . toEqual ( { status : 'ok' } ) ;
683
692
} ) ;
684
693
} ) ;
685
694
0 commit comments