Skip to content

Commit 27a3f33

Browse files
committed
fix missing info
1 parent 59118e2 commit 27a3f33

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
message: |
2+
Fixed an issue where declarative flattened errors missed useful info when fields were absent.
3+
type: bugfix
4+
scope: Core

kong/db/errors.lua

+4
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,10 @@ do
868868
local field_entity_type = ref.reference
869869
local field_err_t = err_t[field_name]
870870

871+
if type(field_err_t) == "string" then
872+
field_err_t = entity_type..":"..field_err_t..":"..ref.field
873+
end
874+
871875
-- if the foreign value is _not_ a table, attempting to treat it like
872876
-- an entity or array of entities will only yield confusion.
873877
--

spec/02-integration/04-admin_api/15-off_spec.lua

+109
Original file line numberDiff line numberDiff line change
@@ -2323,6 +2323,115 @@ R6InCcH2Wh8wSeY5AuDXvu2tv9g/PW9wIJmPuKSHMA==
23232323
}, post_config(input))
23242324
end)
23252325

2326+
it("snis in certificates without certificate", function()
2327+
local res = assert(client:send {
2328+
method = "POST",
2329+
path = "/config?flatten_errors=1",
2330+
body = {
2331+
_format_version = "1.1",
2332+
consumers = {
2333+
{
2334+
username = "x",
2335+
basicauth_credentials = {
2336+
username = "x",
2337+
password = "x",
2338+
}
2339+
}
2340+
},
2341+
certificates = {
2342+
{
2343+
cert = ssl_fixtures.cert,
2344+
id = "d83994d2-c24c-4315-b431-ee76b6611dcb",
2345+
key = ssl_fixtures.key,
2346+
snis = {
2347+
{
2348+
name = "foo.example",
2349+
id = "1c6e83b7-c9ad-40ac-94e8-52f5ee7bde44",
2350+
},
2351+
}
2352+
}
2353+
},
2354+
},
2355+
headers = {
2356+
["Content-Type"] = "application/json"
2357+
}
2358+
})
2359+
2360+
local body = assert.response(res).has.status(400)
2361+
local entities = cjson.decode(body)
2362+
assert.equals("snis:required field missing:certificate", entities.flattened_errors[1].errors[1].message)
2363+
end)
2364+
2365+
it("flatten_errors1 when conflicting inputs", function()
2366+
local conflicting_input = {
2367+
_format_version = "3.0",
2368+
consumers = {
2369+
{
2370+
username = "username1",
2371+
tags = {
2372+
"k8s-group:configuration.konghq.com",
2373+
"k8s-version:v1",
2374+
"k8s-kind:KongConsumer",
2375+
"k8s-namespace:default",
2376+
"k8s-name:consumer1"
2377+
},
2378+
basicauth_credentials = {
2379+
{
2380+
username = "username1",
2381+
password = "password",
2382+
tags = {
2383+
"k8s-group:",
2384+
"k8s-version:v1",
2385+
"k8s-kind:Secret",
2386+
"k8s-namespace:default",
2387+
"k8s-name:basic-1"
2388+
}
2389+
},
2390+
{
2391+
username = "username1",
2392+
password = "password",
2393+
tags = {
2394+
"k8s-group:",
2395+
"k8s-version:v1",
2396+
"k8s-kind:Secret",
2397+
"k8s-namespace:default",
2398+
"k8s-name:basic-2"
2399+
}
2400+
},
2401+
}
2402+
}
2403+
}
2404+
}
2405+
validate({
2406+
{
2407+
entity = {
2408+
username = "username1",
2409+
password = "password",
2410+
tags = {
2411+
"k8s-group:",
2412+
"k8s-version:v1",
2413+
"k8s-kind:Secret",
2414+
"k8s-namespace:default",
2415+
"k8s-name:basic-2"
2416+
}
2417+
},
2418+
entity_tags = {
2419+
"k8s-group:",
2420+
"k8s-version:v1",
2421+
"k8s-kind:Secret",
2422+
"k8s-namespace:default",
2423+
"k8s-name:basic-2"
2424+
},
2425+
entity_type = "basicauth_credential",
2426+
errors = { {
2427+
message = "uniqueness violation: 'basicauth_credentials' entity with username set to 'username1' already declared",
2428+
type = "entity",
2429+
}
2430+
}
2431+
},
2432+
}, post_config(conflicting_input))
2433+
end)
2434+
23262435
it("correctly handles nested entity errors", function()
23272436
local consumers = {
23282437
{

0 commit comments

Comments
 (0)