@@ -92,6 +92,17 @@ func TestKeyAuthWithConfig(t *testing.T) {
92
92
expectHandlerCalled : false ,
93
93
expectError : "code=400, message=missing key in request header" ,
94
94
},
95
+ {
96
+ name : "ok, custom key lookup from multiple places, query and header" ,
97
+ givenRequest : func (req * http.Request ) {
98
+ req .URL .RawQuery = "key=invalid-key"
99
+ req .Header .Set ("API-Key" , "valid-key" )
100
+ },
101
+ whenConfig : func (conf * KeyAuthConfig ) {
102
+ conf .KeyLookup = "query:key,header:API-Key"
103
+ },
104
+ expectHandlerCalled : true ,
105
+ },
95
106
{
96
107
name : "ok, custom key lookup, header" ,
97
108
givenRequest : func (req * http.Request ) {
@@ -289,42 +300,42 @@ func TestKeyAuthWithConfig_panicsOnEmptyValidator(t *testing.T) {
289
300
)
290
301
}
291
302
292
- func TestKeyAuthWithConfig_NoErrorContinuesExecution (t * testing.T ) {
303
+ func TestKeyAuthWithConfig_ContinueOnIgnoredError (t * testing.T ) {
293
304
var testCases = []struct {
294
- name string
295
- whenNoErrorContinuesExecution bool
296
- givenKey string
297
- expectStatus int
298
- expectBody string
305
+ name string
306
+ whenContinueOnIgnoredError bool
307
+ givenKey string
308
+ expectStatus int
309
+ expectBody string
299
310
}{
300
311
{
301
- name : "no error handler is called" ,
302
- whenNoErrorContinuesExecution : true ,
303
- givenKey : "valid-key" ,
304
- expectStatus : http .StatusTeapot ,
305
- expectBody : "" ,
312
+ name : "no error handler is called" ,
313
+ whenContinueOnIgnoredError : true ,
314
+ givenKey : "valid-key" ,
315
+ expectStatus : http .StatusTeapot ,
316
+ expectBody : "" ,
306
317
},
307
318
{
308
- name : "NoErrorContinuesExecution is false and error handler is called for missing token" ,
309
- whenNoErrorContinuesExecution : false ,
310
- givenKey : "" ,
319
+ name : "ContinueOnIgnoredError is false and error handler is called for missing token" ,
320
+ whenContinueOnIgnoredError : false ,
321
+ givenKey : "" ,
311
322
// empty response with 200. This emulates previous behaviour when error handler swallowed the error
312
323
expectStatus : http .StatusOK ,
313
324
expectBody : "" ,
314
325
},
315
326
{
316
- name : "error handler is called for missing token" ,
317
- whenNoErrorContinuesExecution : true ,
318
- givenKey : "" ,
319
- expectStatus : http .StatusTeapot ,
320
- expectBody : "public-auth" ,
327
+ name : "error handler is called for missing token" ,
328
+ whenContinueOnIgnoredError : true ,
329
+ givenKey : "" ,
330
+ expectStatus : http .StatusTeapot ,
331
+ expectBody : "public-auth" ,
321
332
},
322
333
{
323
- name : "error handler is called for invalid token" ,
324
- whenNoErrorContinuesExecution : true ,
325
- givenKey : "x.x.x" ,
326
- expectStatus : http .StatusUnauthorized ,
327
- expectBody : "{\" message\" :\" Unauthorized\" }\n " ,
334
+ name : "error handler is called for invalid token" ,
335
+ whenContinueOnIgnoredError : true ,
336
+ givenKey : "x.x.x" ,
337
+ expectStatus : http .StatusUnauthorized ,
338
+ expectBody : "{\" message\" :\" Unauthorized\" }\n " ,
328
339
},
329
340
}
330
341
@@ -346,8 +357,8 @@ func TestKeyAuthWithConfig_NoErrorContinuesExecution(t *testing.T) {
346
357
}
347
358
return echo .ErrUnauthorized
348
359
},
349
- KeyLookup : "header:X-API-Key" ,
350
- NoErrorContinuesExecution : tc .whenNoErrorContinuesExecution ,
360
+ KeyLookup : "header:X-API-Key" ,
361
+ ContinueOnIgnoredError : tc .whenContinueOnIgnoredError ,
351
362
}))
352
363
353
364
req := httptest .NewRequest (http .MethodGet , "/" , nil )
0 commit comments