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

fix(schema): schema validation to handle potential nil field case #13861

Merged
merged 2 commits into from
Nov 13, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "Fixed a 500 error triggered by unhandled nil fields during schema validation."
type: bugfix
scope: Core
2 changes: 1 addition & 1 deletion kong/db/schema/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ local function run_entity_check(self, name, input, arg, full_check, errors)

-- Don't run if any of the values is a reference in a referenceable field
local field = get_schema_field(self, fname)
if field.type == "string" and field.referenceable and is_reference(value) then
if field and field.type == "string" and field.referenceable and is_reference(value) then
return
end
end
Expand Down
31 changes: 31 additions & 0 deletions spec/01-unit/01-db/01-schema/06-routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1800,3 +1800,34 @@ describe("routes schema (flavor = expressions)", function()
end
end)
end)


describe("routes schema (flavor = traditional_compatible)", function()
local a_valid_uuid = "cbb297c0-a956-486d-ad1d-f9b42df9465a"
local another_uuid = "64a8670b-900f-44e7-a900-6ec7ef5aa4d3"

reload_flavor("traditional_compatible")
setup_global_env()

it("validates a route with only expression field", function()
local route = {
id = a_valid_uuid,
name = "my_route",
protocols = { "http" },
hosts = { "example.com" },
expression = [[(http.method == "GET")]],
priority = 100,
service = { id = another_uuid },
}
route = Routes:process_auto_fields(route, "insert")
assert.truthy(route.created_at)
assert.truthy(route.updated_at)
assert.same(route.created_at, route.updated_at)
local ok, errs = Routes:validate(route)
assert.falsy(ok)
assert.same({
["expression"] = 'unknown field',
["priority"] = 'unknown field'
}, errs)
end)
end)
Loading