Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing null pointer exception on DAO update when config is missing #571

Merged
merged 1 commit into from
Sep 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kong/dao/schemas_validation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function _M.validate_entity(tbl, schema, options)
if type(v.default) == "function" then
t[column] = v.default(t)
else
t[column] = v.default
t[column] = utils.deep_copy(v.default)
end
end
-- [INSERT_VALUE]
Expand Down
20 changes: 19 additions & 1 deletion spec/integration/dao/cassandra/base_dao_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,24 @@ describe("Cassandra", function()
inserted_plugin.consumer_id = nil
end)

it("should insert a plugin with an empty config if none is specified", function()
local api_t = faker:fake_entity("api")
local api, err = dao_factory.apis:insert(api_t)
assert.falsy(err)
assert.truthy(api)

local plugin, err = dao_factory.plugins:insert({
name = "request-transformer",
api_id = api.id
})

assert.falsy(err)
assert.truthy(plugin)
assert.falsy(plugin.consumer_id)
assert.same("request-transformer", plugin.name)
assert.same({}, plugin.config)
end)

it("should select a plugin configuration by 'null' uuid consumer_id and remove the column", function()
-- Now we should be able to select this plugin
local rows, err = dao_factory.plugins:find_by_keys {
Expand All @@ -602,7 +620,7 @@ describe("Cassandra", function()
}
assert.falsy(err)
assert.truthy(rows[1])
assert.are.same(inserted_plugin, rows[1])
assert.same(inserted_plugin, rows[1])
assert.falsy(rows[1].consumer_id)
end)
end)
Expand Down
14 changes: 14 additions & 0 deletions spec/unit/dao/entities_schemas_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,20 @@ describe("Entities Schemas", function()
assert.equal("second is not a number", errors["config.second"])
end)

it("should have an empty config if none is specified and if the config schema does not have default", function()
-- Insert key-auth, whose config has some default values that should be set
local plugin = {name = "key-auth", api_id = "stub"}
local valid = validate_entity(plugin, plugins_schema, {dao = dao_stub})
assert.same({key_names = {"apikey"}, hide_credentials = false}, plugin.config)
assert.True(valid)

-- Insert reauest-transformer, whose default config has no default values, and should be empty
local plugin2 = {name = "response-transformer", api_id = "stub"}
valid = validate_entity(plugin2, plugins_schema, {dao = dao_stub})
assert.same({}, plugin2.config)
assert.True(valid)
end)

describe("self_check", function()
it("should refuse `consumer_id` if specified in the config schema", function()
local stub_config_schema = {
Expand Down