Skip to content

Commit

Permalink
[configuration] fix error when loading empty policy chain
Browse files Browse the repository at this point in the history
> src/apicast/configuration.lua:62: attempt to get length of local 'policies' (a userdata value)
  • Loading branch information
mikz committed Feb 27, 2018
1 parent 985a24a commit fc22d86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion gateway/src/apicast/configuration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local next = next
local lower = string.lower
local insert = table.insert
local setmetatable = setmetatable
local null = ngx.null

local re = require 'ngx.re'
local env = require 'resty.env'
Expand Down Expand Up @@ -55,7 +56,7 @@ local function backend_endpoint(proxy)
end

local function build_policy_chain(policies)
if not policies then return nil, 'no policy chain' end
if not policies or policies == null then return nil, 'no policy chain' end

local chain = {}

Expand Down
10 changes: 10 additions & 0 deletions spec/configuration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ describe('Configuration object', function()
assert.equals(429, config.limits_exceeded_status)
end)


describe('policy_chain', function()

it('works with null', function()
local config = configuration.parse_service({ proxy = { policy_chain = ngx.null }})

assert(config)
end)
end)

describe('backend', function()
it('defaults to fake backend', function()
local config = configuration.parse_service({ proxy = {
Expand Down

0 comments on commit fc22d86

Please sign in to comment.