@@ -129,6 +129,18 @@ func TestOapiRequestValidator(t *testing.T) {
129
129
called = true
130
130
return nil
131
131
})
132
+ // add a Handler for an encoded path parameter
133
+ // this needs to be installed before calling the first doGet
134
+ // because of echo internals (maxParam)
135
+ e .GET ("/resource/maxlength/:encoded" , func (c echo.Context ) error {
136
+ called = true
137
+ return c .NoContent (http .StatusNoContent )
138
+ })
139
+ e .GET ("/resource/pattern/:encoded" , func (c echo.Context ) error {
140
+ called = true
141
+ return c .NoContent (http .StatusNoContent )
142
+ })
143
+
132
144
// Let's send the request to the wrong server, this should return 404
133
145
{
134
146
rec := doGet (t , e , "http://not.deepmap.ai/resource" )
@@ -231,6 +243,43 @@ func TestOapiRequestValidator(t *testing.T) {
231
243
assert .False (t , called , "Handler should not have been called" )
232
244
called = false
233
245
}
246
+
247
+ // Let's send a request with an encoded parameter
248
+ // It should pass validation even though the parameter is encoded
249
+ // to 3 chars and the parameter is limited to maxLength: 1
250
+ {
251
+ rec := doGet (t , e , "http://deepmap.ai/resource/maxlength/%2B" )
252
+ assert .Equal (t , http .StatusNoContent , rec .Code )
253
+ assert .True (t , called , "Handler should have been called" )
254
+ called = false
255
+ }
256
+
257
+ // Let's send a request with an unencoded parameter
258
+ // It should pass as well
259
+ {
260
+ rec := doGet (t , e , "http://deepmap.ai/resource/maxlength/+" )
261
+ assert .Equal (t , http .StatusNoContent , rec .Code )
262
+ assert .True (t , called , "Handler should have been called" )
263
+ called = false
264
+ }
265
+
266
+ // Let's send a request with an encoded parameter
267
+ // It should pass validation
268
+ {
269
+ rec := doGet (t , e , "http://deepmap.ai/resource/pattern/%2B1234" )
270
+ assert .Equal (t , http .StatusNoContent , rec .Code )
271
+ assert .True (t , called , "Handler should have been called" )
272
+ called = false
273
+ }
274
+
275
+ // Let's send a request with an unencoded parameter
276
+ // It should pass as well
277
+ {
278
+ rec := doGet (t , e , "http://deepmap.ai/resource/pattern/+1234" )
279
+ assert .Equal (t , http .StatusNoContent , rec .Code )
280
+ assert .True (t , called , "Handler should have been called" )
281
+ called = false
282
+ }
234
283
}
235
284
236
285
func TestOapiRequestValidatorWithOptionsMultiError (t * testing.T ) {
0 commit comments