@@ -33,6 +33,95 @@ describe('Parse.File testing', () => {
3333    } ) ; 
3434  } ) ; 
3535
36+   it ( 'supports REST end-to-end file create, read, delete, read' ,  done  =>  { 
37+     var  headers  =  { 
38+       'Content-Type' : 'image/jpeg' , 
39+       'X-Parse-Application-Id' : 'test' , 
40+       'X-Parse-REST-API-Key' : 'rest' 
41+     } ; 
42+     request . post ( { 
43+       headers : headers , 
44+       url : 'http://localhost:8378/1/files/testfile.txt' , 
45+       body : 'check one two' , 
46+     } ,  ( error ,  response ,  body )  =>  { 
47+       expect ( error ) . toBe ( null ) ; 
48+       var  b  =  JSON . parse ( body ) ; 
49+       expect ( b . name ) . toMatch ( / _ t e s t f i l e .t x t $ / ) ; 
50+       expect ( b . url ) . toMatch ( / ^ h t t p : \/ \/ l o c a l h o s t : 8 3 7 8 \/ 1 \/ f i l e s \/ t e s t \/ .* t e s t f i l e .t x t $ / ) ; 
51+       request . get ( b . url ,  ( error ,  response ,  body )  =>  { 
52+         expect ( error ) . toBe ( null ) ; 
53+         expect ( body ) . toEqual ( 'check one two' ) ; 
54+         request . del ( { 
55+           headers : { 
56+             'X-Parse-Application-Id' : 'test' , 
57+             'X-Parse-REST-API-Key' : 'rest' , 
58+             'X-Parse-Master-Key' : 'test' 
59+           } , 
60+           url : 'http://localhost:8378/1/files/'  +  b . name 
61+         } ,  ( error ,  response ,  body )  =>  { 
62+           expect ( error ) . toBe ( null ) ; 
63+           expect ( response . statusCode ) . toEqual ( 200 ) ; 
64+           request . get ( { 
65+             headers : { 
66+               'X-Parse-Application-Id' : 'test' , 
67+               'X-Parse-REST-API-Key' : 'rest' 
68+             } , 
69+             url : b . url 
70+           } ,  ( error ,  response ,  body )  =>  { 
71+             expect ( error ) . toBe ( null ) ; 
72+             expect ( response . statusCode ) . toEqual ( 404 ) ; 
73+             done ( ) ; 
74+           } ) ; 
75+         } ) ; 
76+       } ) ; 
77+     } ) ; 
78+   } ) ; 
79+ 
80+   it ( 'blocks file deletions with missing or incorrect master-key header' ,  done  =>  { 
81+     var  headers  =  { 
82+       'Content-Type' : 'image/jpeg' , 
83+       'X-Parse-Application-Id' : 'test' , 
84+       'X-Parse-REST-API-Key' : 'rest' 
85+     } ; 
86+     request . post ( { 
87+       headers : headers , 
88+       url : 'http://localhost:8378/1/files/thefile.jpg' , 
89+       body : 'the file body' 
90+     } ,  ( error ,  response ,  body )  =>  { 
91+       expect ( error ) . toBe ( null ) ; 
92+       var  b  =  JSON . parse ( body ) ; 
93+       expect ( b . url ) . toMatch ( / ^ h t t p : \/ \/ l o c a l h o s t : 8 3 7 8 \/ 1 \/ f i l e s \/ t e s t \/ .* t h e f i l e .j p g $ / ) ; 
94+       // missing X-Parse-Master-Key header 
95+       request . del ( { 
96+         headers : { 
97+           'X-Parse-Application-Id' : 'test' , 
98+           'X-Parse-REST-API-Key' : 'rest' 
99+         } , 
100+         url : 'http://localhost:8378/1/files/'  +  b . name 
101+       } ,  ( error ,  response ,  body )  =>  { 
102+         expect ( error ) . toBe ( null ) ; 
103+         var  del_b  =  JSON . parse ( body ) ; 
104+         expect ( response . statusCode ) . toEqual ( 400 ) ; 
105+         expect ( del_b . code ) . toEqual ( 119 ) ; 
106+         // incorrect X-Parse-Master-Key header 
107+         request . del ( { 
108+           headers : { 
109+             'X-Parse-Application-Id' : 'test' , 
110+             'X-Parse-REST-API-Key' : 'rest' , 
111+             'X-Parse-Master-Key' : 'tryagain' 
112+           } , 
113+           url : 'http://localhost:8378/1/files/'  +  b . name 
114+         } ,  ( error ,  response ,  body )  =>  { 
115+           expect ( error ) . toBe ( null ) ; 
116+           var  del_b2  =  JSON . parse ( body ) ; 
117+           expect ( response . statusCode ) . toEqual ( 400 ) ; 
118+           expect ( del_b2 . code ) . toEqual ( 119 ) ; 
119+           done ( ) ; 
120+         } ) ; 
121+       } ) ; 
122+     } ) ; 
123+   } ) ; 
124+ 
36125  it ( 'handles other filetypes' ,  done  =>  { 
37126    var  headers  =  { 
38127      'Content-Type' : 'image/jpeg' , 
0 commit comments