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(certificates):fix missing info when fields was absent #14032

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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,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
lhanjian marked this conversation as resolved.
Show resolved Hide resolved
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()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only add a test, not about errors.lua change

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
Loading