Skip to content

Commit

Permalink
test(schemas) fix plugins after moving schemas to the new dao
Browse files Browse the repository at this point in the history
  • Loading branch information
kikito committed Oct 3, 2018
1 parent 82c571d commit d0f00b4
Show file tree
Hide file tree
Showing 43 changed files with 401 additions and 793 deletions.
10 changes: 8 additions & 2 deletions kong/plugins/basic-auth/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ local realm = 'Basic realm="' .. _KONG._NAME .. '"'

local _M = {}


local function is_present(str)
return str and str ~= "" and str ~= ngx.null
end


-- Fast lookup for credential retrieval depending on the type of the authentication
--
-- All methods must respect:
Expand Down Expand Up @@ -165,15 +171,15 @@ end

function _M.execute(conf)

if ngx.ctx.authenticated_credential and conf.anonymous ~= "" then
if ngx.ctx.authenticated_credential and is_present(conf.anonymous) then
-- we're already authenticated, and we're configured for using anonymous,
-- hence we're in a logical OR between auth methods and we're already done.
return
end

local ok, err = do_authentication(conf)
if not ok then
if conf.anonymous ~= "" then
if is_present(conf.anonymous) then
-- get anonymous user
local consumer_cache_key = kong.db.consumers:cache_key(conf.anonymous)
local consumer, err = kong.cache:get(consumer_cache_key, nil,
Expand Down
9 changes: 7 additions & 2 deletions kong/plugins/hmac-auth/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ do
end
end


local _M = {}

local hmac = {
Expand All @@ -63,6 +64,10 @@ local function list_as_set(list)
return set
end

local function is_present(str)
return str and str ~= "" and str ~= ngx.null
end

local function validate_params(params, conf)
-- check username and signature are present
if not params.username and params.signature then
Expand Down Expand Up @@ -315,15 +320,15 @@ end

function _M.execute(conf)

if ngx.ctx.authenticated_credential and conf.anonymous ~= "" then
if ngx.ctx.authenticated_credential and is_present(conf.anonymous) then
-- we're already authenticated, and we're configured for using anonymous,
-- hence we're in a logical OR between auth methods and we're already done.
return
end

local ok, err = do_authentication(conf)
if not ok then
if conf.anonymous ~= "" then
if is_present(conf.anonymous) then
-- get anonymous user
local consumer_cache_key = kong.db.consumers:cache_key(conf.anonymous)
local consumer, err = kong.cache:get(consumer_cache_key, nil,
Expand Down
8 changes: 6 additions & 2 deletions kong/plugins/jwt/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ local JwtHandler = BasePlugin:extend()
JwtHandler.PRIORITY = 1005
JwtHandler.VERSION = "0.1.0"

local function is_present(str)
return str and str ~= "" and str ~= ngx.null
end

--- Retrieve a JWT in a request.
-- Checks for the JWT in URI parameters, then in cookies, and finally
-- in the `Authorization` header.
Expand Down Expand Up @@ -201,15 +205,15 @@ function JwtHandler:access(conf)
return
end

if ngx.ctx.authenticated_credential and conf.anonymous ~= "" then
if ngx.ctx.authenticated_credential and is_present(conf.anonymous) then
-- we're already authenticated, and we're configured for using anonymous,
-- hence we're in a logical OR between auth methods and we're already done.
return
end

local ok, err = do_authentication(conf)
if not ok then
if conf.anonymous ~= "" then
if is_present(conf.anonymous) then
-- get anonymous user
local consumer_cache_key = kong.db.consumers:cache_key(conf.anonymous)
local consumer, err = kong.cache:get(consumer_cache_key, nil,
Expand Down
7 changes: 5 additions & 2 deletions kong/plugins/key-auth/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ local KeyAuthHandler = BasePlugin:extend()
KeyAuthHandler.PRIORITY = 1003
KeyAuthHandler.VERSION = "0.2.0"

local function is_present(str)
return str and str ~= "" and str ~= ngx.null
end

function KeyAuthHandler:new()
KeyAuthHandler.super.new(self, "key-auth")
Expand Down Expand Up @@ -176,15 +179,15 @@ function KeyAuthHandler:access(conf)
-- checking both old and new ctx for backward and forward compatibility
local authenticated_credential = kong.ctx.shared.authenticated_credential
or ngx.ctx.authenticated_credential
if authenticated_credential and conf.anonymous ~= "" then
if authenticated_credential and is_present(conf.anonymous) then
-- we're already authenticated, and we're configured for using anonymous,
-- hence we're in a logical OR between auth methods and we're already done.
return
end

local ok, err = do_authentication(conf)
if not ok then
if conf.anonymous ~= "" then
if is_present(conf.anonymous) then
-- get anonymous user
local consumer_cache_key = kong.db.consumers:cache_key(conf.anonymous)
local consumer, err = kong.cache:get(consumer_cache_key, nil,
Expand Down
9 changes: 7 additions & 2 deletions kong/plugins/ldap-auth/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ local PROXY_AUTHORIZATION = "proxy-authorization"
local ldap_config_cache = setmetatable({}, { __mode = "k" })


local function is_present(str)
return str and str ~= "" and str ~= ngx.null
end


local _M = {}

local function retrieve_credentials(authorization_header_value, conf)
Expand Down Expand Up @@ -203,15 +208,15 @@ end

function _M.execute(conf)

if ngx.ctx.authenticated_credential and conf.anonymous ~= "" then
if ngx.ctx.authenticated_credential and is_present(conf.anonymous) then
-- we're already authenticated, and we're configured for using anonymous,
-- hence we're in a logical OR between auth methods and we're already done.
return
end

local ok, err = do_authentication(conf)
if not ok then
if conf.anonymous ~= "" then
if is_present(conf.anonymous) then
-- get anonymous user
local consumer_cache_key = singletons.db.consumers:cache_key(conf.anonymous)
local consumer, err = singletons.cache:get(consumer_cache_key, nil,
Expand Down
8 changes: 6 additions & 2 deletions kong/plugins/oauth2/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ local GRANT_PASSWORD = "password"
local ERROR = "error"
local AUTHENTICATED_USERID = "authenticated_userid"

local function is_present(str)
return str and str ~= "" and str ~= ngx.null
end

local function generate_token(conf, service, api, credential, authenticated_userid, scope, state, expiration, disable_refresh)
local token_expiration = expiration or conf.token_expiration

Expand Down Expand Up @@ -604,7 +608,7 @@ end
function _M.execute(conf)


if ngx.ctx.authenticated_credential and conf.anonymous ~= "" then
if ngx.ctx.authenticated_credential and is_present(conf.anonymous) then
-- we're already authenticated, and we're configured for using anonymous,
-- hence we're in a logical OR between auth methods and we're already done.
return
Expand All @@ -626,7 +630,7 @@ function _M.execute(conf)

local ok, err = do_authentication(conf)
if not ok then
if conf.anonymous ~= "" then
if is_present(conf.anonymous) then
-- get anonymous user
local consumer_cache_key = kong.db.consumers:cache_key(conf.anonymous)
local consumer, err = kong.cache:get(consumer_cache_key, nil,
Expand Down
9 changes: 7 additions & 2 deletions kong/plugins/rate-limiting/policies/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ local fmt = string.format
local NULL_UUID = "00000000-0000-0000-0000-000000000000"


local function is_present(str)
return str and str ~= "" and str ~= ngx.null
end


local function get_ids(conf)
conf = conf or {}

Expand Down Expand Up @@ -148,7 +153,7 @@ return {
return nil, err
end

if times == 0 and conf.redis_password and conf.redis_password ~= "" then
if times == 0 and is_present(conf.redis_password) then
local ok, err = red:auth(conf.redis_password)
if not ok then
ngx_log(ngx.ERR, "failed to auth Redis: ", err)
Expand Down Expand Up @@ -229,7 +234,7 @@ return {
return nil, err
end

if times == 0 and conf.redis_password and conf.redis_password ~= "" then
if times == 0 and is_present(conf.redis_password) then
local ok, err = red:auth(conf.redis_password)
if not ok then
ngx_log(ngx.ERR, "failed to connect to Redis: ", err)
Expand Down
9 changes: 7 additions & 2 deletions kong/plugins/response-ratelimiting/policies/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ local fmt = string.format
local NULL_UUID = "00000000-0000-0000-0000-000000000000"


local function is_present(str)
return str and str ~= "" and str ~= ngx.null
end


local function get_ids(conf)
conf = conf or {}

Expand Down Expand Up @@ -149,7 +154,7 @@ return {
return nil, err
end

if times == 0 and conf.redis_password and conf.redis_password ~= "" then
if times == 0 and is_present(conf.redis_password) then
local ok, err = red:auth(conf.redis_password)
if not ok then
ngx_log(ngx.ERR, "failed to auth Redis: ", err)
Expand Down Expand Up @@ -228,7 +233,7 @@ return {
return nil, err
end

if times == 0 and conf.redis_password and conf.redis_password ~= "" then
if times == 0 and is_present(conf.redis_password) then
local ok, err = red:auth(conf.redis_password)
if not ok then
ngx_log(ngx.ERR, "failed to auth Redis: ", err)
Expand Down
2 changes: 0 additions & 2 deletions spec-old-api/02-integration/03-dao/04-constraints_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ for _, strategy in helpers.each_strategy() do
run_on_preflight = true,
hide_credentials = false,
key_names = {"apikey"},
anonymous = "",
key_in_body = false,
}, plugin.config)
end)
Expand All @@ -64,7 +63,6 @@ for _, strategy in helpers.each_strategy() do
run_on_preflight = true,
hide_credentials = false,
key_names = {"api-key"},
anonymous = "",
key_in_body = false,
}, plugin.config)
end)
Expand Down
114 changes: 0 additions & 114 deletions spec-old-api/03-plugins/06-statsd/02-schema_spec.lua

This file was deleted.

5 changes: 2 additions & 3 deletions spec-old-api/03-plugins/10-key-auth/01-api_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,8 @@ describe("Plugin: key-auth (API)", function()
})
assert.response(res).has.status(400)
local body = assert.response(res).has.jsonbody()
assert.equal("'hello\\world' is illegal: bad header name " ..
"'hello\\world', allowed characters are A-Z, a-z, 0-9," ..
" '_', and '-'", body.fields.config.key_names)
assert.equal("bad header name 'hello\\world', allowed characters are A-Z, a-z, 0-9, '_', and '-'",
body.fields.config.key_names)
end)
it("succeeds with valid key_names", function()
local key_name = "hello-world"
Expand Down
Loading

0 comments on commit d0f00b4

Please sign in to comment.