@@ -92,6 +92,17 @@ func TestKeyAuthWithConfig(t *testing.T) {
9292 expectHandlerCalled : false ,
9393 expectError : "code=400, message=missing key in request header" ,
9494 },
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+ },
95106 {
96107 name : "ok, custom key lookup, header" ,
97108 givenRequest : func (req * http.Request ) {
@@ -289,42 +300,42 @@ func TestKeyAuthWithConfig_panicsOnEmptyValidator(t *testing.T) {
289300 )
290301}
291302
292- func TestKeyAuthWithConfig_NoErrorContinuesExecution (t * testing.T ) {
303+ func TestKeyAuthWithConfig_ContinueOnIgnoredError (t * testing.T ) {
293304 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
299310 }{
300311 {
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 : "" ,
306317 },
307318 {
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 : "" ,
311322 // empty response with 200. This emulates previous behaviour when error handler swallowed the error
312323 expectStatus : http .StatusOK ,
313324 expectBody : "" ,
314325 },
315326 {
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" ,
321332 },
322333 {
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 " ,
328339 },
329340 }
330341
@@ -346,8 +357,8 @@ func TestKeyAuthWithConfig_NoErrorContinuesExecution(t *testing.T) {
346357 }
347358 return echo .ErrUnauthorized
348359 },
349- KeyLookup : "header:X-API-Key" ,
350- NoErrorContinuesExecution : tc .whenNoErrorContinuesExecution ,
360+ KeyLookup : "header:X-API-Key" ,
361+ ContinueOnIgnoredError : tc .whenContinueOnIgnoredError ,
351362 }))
352363
353364 req := httptest .NewRequest (http .MethodGet , "/" , nil )
0 commit comments