@@ -4,6 +4,9 @@ var cache = require('../src/cache');
44var Config = require ( '../src/Config' ) ;
55var rest = require ( '../src/rest' ) ;
66
7+ var querystring = require ( 'querystring' ) ;
8+ var request = require ( 'request' ) ;
9+
710var config = new Config ( 'test' ) ;
811var nobody = auth . nobody ( config ) ;
912
@@ -92,4 +95,49 @@ describe('rest query', () => {
9295 } ) . catch ( ( error ) => { console . log ( error ) ; } ) ;
9396 } ) ;
9497
98+ it ( 'query with wrongly encoded parameter' , ( done ) => {
99+ rest . create ( config , nobody , 'TestParameterEncode' , { foo : 'bar' }
100+ ) . then ( ( ) => {
101+ return rest . create ( config , nobody ,
102+ 'TestParameterEncode' , { foo : 'baz' } ) ;
103+ } ) . then ( ( ) => {
104+ var headers = {
105+ 'X-Parse-Application-Id' : 'test' ,
106+ 'X-Parse-REST-API-Key' : 'rest'
107+ } ;
108+ request . get ( {
109+ headers : headers ,
110+ url : 'http://localhost:8378/1/classes/TestParameterEncode?'
111+ + querystring . stringify ( {
112+ where : '{"foo":{"$ne": "baz"}}' ,
113+ limit : 1
114+ } ) . replace ( '=' , '%3D' ) ,
115+ } , ( error , response , body ) => {
116+ expect ( error ) . toBe ( null ) ;
117+ var b = JSON . parse ( body ) ;
118+ expect ( b . code ) . toEqual ( Parse . Error . INVALID_QUERY ) ;
119+ expect ( b . error ) . toEqual ( 'Improper encode of parameter' ) ;
120+ done ( ) ;
121+ } ) ;
122+ } ) . then ( ( ) => {
123+ var headers = {
124+ 'X-Parse-Application-Id' : 'test' ,
125+ 'X-Parse-REST-API-Key' : 'rest'
126+ } ;
127+ request . get ( {
128+ headers : headers ,
129+ url : 'http://localhost:8378/1/classes/TestParameterEncode?'
130+ + querystring . stringify ( {
131+ limit : 1
132+ } ) . replace ( '=' , '%3D' ) ,
133+ } , ( error , response , body ) => {
134+ expect ( error ) . toBe ( null ) ;
135+ var b = JSON . parse ( body ) ;
136+ expect ( b . code ) . toEqual ( Parse . Error . INVALID_QUERY ) ;
137+ expect ( b . error ) . toEqual ( 'Improper encode of parameter' ) ;
138+ done ( ) ;
139+ } ) ;
140+ } ) ;
141+ } ) ;
142+
95143} ) ;
0 commit comments