Skip to content

Commit

Permalink
fix missing info
Browse files Browse the repository at this point in the history
  • Loading branch information
lhanjian committed Dec 20, 2024
1 parent 14b1bf9 commit da087f8
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
message: |
Fixed an issue where declarative flattened errors missed useful info when fields were absent.
type: bugfix
scope: Core
4 changes: 4 additions & 0 deletions kong/db/errors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,10 @@ do
local field_entity_type = ref.reference
local field_err_t = err_t[field_name]

if type(field_err_t) == "string" then
field_err_t = entity_type..":"..field_err_t..":"..ref.field
end

-- if the foreign value is _not_ a table, attempting to treat it like
-- an entity or array of entities will only yield confusion.
--
Expand Down
109 changes: 109 additions & 0 deletions spec/02-integration/04-admin_api/15-off_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2323,6 +2323,115 @@ R6InCcH2Wh8wSeY5AuDXvu2tv9g/PW9wIJmPuKSHMA==
}, post_config(input))
end)

it("snis in certificates without certificate", function()
local res = assert(client:send {
method = "POST",
path = "/config?flatten_errors=1",
body = {
_format_version = "1.1",
consumers = {
{
username = "x",
basicauth_credentials = {
username = "x",
password = "x",
}
}
},
certificates = {
{
cert = ssl_fixtures.cert,
id = "d83994d2-c24c-4315-b431-ee76b6611dcb",
key = ssl_fixtures.key,
snis = {
{
name = "foo.example",
id = "1c6e83b7-c9ad-40ac-94e8-52f5ee7bde44",
},
}
}
},
},
headers = {
["Content-Type"] = "application/json"
}
})

local body = assert.response(res).has.status(400)
local entities = cjson.decode(body)
assert.equals("snis:required field missing:certificate", entities.flattened_errors[1].errors[1].message)
end)

it("flatten_errors1 when conflicting inputs", function()
local conflicting_input = {
_format_version = "3.0",
consumers = {
{
username = "username1",
tags = {
"k8s-group:configuration.konghq.com",
"k8s-version:v1",
"k8s-kind:KongConsumer",
"k8s-namespace:default",
"k8s-name:consumer1"
},
basicauth_credentials = {
{
username = "username1",
password = "password",
tags = {
"k8s-group:",
"k8s-version:v1",
"k8s-kind:Secret",
"k8s-namespace:default",
"k8s-name:basic-1"
}
},
{
username = "username1",
password = "password",
tags = {
"k8s-group:",
"k8s-version:v1",
"k8s-kind:Secret",
"k8s-namespace:default",
"k8s-name:basic-2"
}
},
}
}
}
}
validate({
{
entity = {
username = "username1",
password = "password",
tags = {
"k8s-group:",
"k8s-version:v1",
"k8s-kind:Secret",
"k8s-namespace:default",
"k8s-name:basic-2"
}
},
entity_tags = {
"k8s-group:",
"k8s-version:v1",
"k8s-kind:Secret",
"k8s-namespace:default",
"k8s-name:basic-2"
},
entity_type = "basicauth_credential",
errors = { {
message = "uniqueness violation: 'basicauth_credentials' entity with username set to 'username1' already declared",
type = "entity",
}
}
},
}, post_config(conflicting_input))
end)

it("correctly handles nested entity errors", function()
local consumers = {
{
Expand Down

0 comments on commit da087f8

Please sign in to comment.