@@ -4,6 +4,9 @@ var cache = require('../src/cache');
4
4
var Config = require ( '../src/Config' ) ;
5
5
var rest = require ( '../src/rest' ) ;
6
6
7
+ var querystring = require ( 'querystring' ) ;
8
+ var request = require ( 'request' ) ;
9
+
7
10
var config = new Config ( 'test' ) ;
8
11
var nobody = auth . nobody ( config ) ;
9
12
@@ -92,4 +95,49 @@ describe('rest query', () => {
92
95
} ) . catch ( ( error ) => { console . log ( error ) ; } ) ;
93
96
} ) ;
94
97
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
+
95
143
} ) ;
0 commit comments