Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lhanjian committed Jan 22, 2025
1 parent 22a59c7 commit b353adf
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion kong/clustering/compat/removed_fields.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ return {
-- Any dataplane older than 3.10.0
[3010000000] = {
cors = {
"skip_cors_when_origin_is_empty",
"allow_origin_absent",
},
session = {
"hash_subject",
Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/cors/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function CorsHandler:header_filter(conf)
end

local req_origin = kong.request.get_header("origin")
if not req_origin and conf.skip_cors_when_origin_is_empty then
if not req_origin and not conf.allow_origin_absent then
return
end

Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/cors/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ return {
{ credentials = { description = "Flag to determine whether the `Access-Control-Allow-Credentials` header should be sent with `true` as the value.", type = "boolean", required = true, default = false }, },
{ private_network = { description = "Flag to determine whether the `Access-Control-Allow-Private-Network` header should be sent with `true` as the value.", type = "boolean", required = true, default = false }, },
{ preflight_continue = { description = "A boolean value that instructs the plugin to proxy the `OPTIONS` preflight request to the Upstream service.", type = "boolean", required = true, default = false }, },
{ skip_cors_when_origin_is_empty = { description = "A boolean value that skip cors response headers when origin header of request is empty", type = "boolean", required = true, default = false }, },
{ allow_origin_absent = { description = "A boolean value that skip cors response headers when origin header of request is empty", type = "boolean", required = true, default = true }, },
}, }, },
},
}
10 changes: 5 additions & 5 deletions spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,18 @@ describe("CP/DP config compat transformations #" .. strategy, function()
enabled = true,
config = {
-- [[ new fields 3.10.0
skip_cors_when_origin_is_empty = false,
allow_origin_absent = true,
-- ]]
-- [[ new fields 3.5.0
private_network = false
-- ]]
}
}

assert.not_nil(cors.config.skip_cors_when_origin_is_empty)
assert.not_nil(cors.config.allow_origin_absent)
local expected_cors = cycle_aware_deep_copy(cors)
do_assert(uuid(), "3.10.0", expected_cors)
expected_cors.config.skip_cors_when_origin_is_empty = nil
expected_cors.config.allow_origin_absent = nil

assert.not_nil(cors.config.private_network)
expected_cors = cycle_aware_deep_copy(expected_cors)
Expand All @@ -235,15 +235,15 @@ describe("CP/DP config compat transformations #" .. strategy, function()
enabled = true,
config = {
-- [[ new fields 3.10.0
skip_cors_when_origin_is_empty = false,
allow_origin_absent = true,
-- ]]
-- [[ new fields 3.5.0
private_network = false
-- ]]
}
}
do_assert(uuid(), "3.10.0", cors)
cors.config.skip_cors_when_origin_is_empty = nil
cors.config.allow_origin_absent = nil

do_assert(uuid(), "3.5.0", cors)

Expand Down
8 changes: 4 additions & 4 deletions spec/03-plugins/13-cors/01-access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ for _, strategy in helpers.each_strategy() do
name = "cors",
route = { id = route15.id },
config = {
skip_cors_when_origin_is_empty = true,
allow_origin_absent = false,
origins = { "foo.bar" },
exposed_headers = { "x-auth-token" },
credentials = true
Expand All @@ -487,7 +487,7 @@ for _, strategy in helpers.each_strategy() do
name = "cors",
route = { id = route16.id },
config = {
skip_cors_when_origin_is_empty = false,
allow_origin_absent = true,
origins = { "foo.bar" },
exposed_headers = { "x-auth-token" },
credentials = true
Expand Down Expand Up @@ -1161,7 +1161,7 @@ for _, strategy in helpers.each_strategy() do
assert.equal("disallowed-domain.test", json.headers["origin"])
end)

it("when enable skip_cors_when_origin_is_empty, no ACAO", function()
it("when disable allow_origin_absent, no ACAO", function()
local res = assert(proxy_client:send {
method = "GET",
headers = {
Expand All @@ -1174,7 +1174,7 @@ for _, strategy in helpers.each_strategy() do
assert.is_nil(res.headers["Access-Control-Expose-Headers"])
end)

it("when disable skip_cors_when_origin_is_empty, ACAO is returned", function()
it("when enable allow_origin_absent, ACAO is returned", function()
local res = assert(proxy_client:send {
method = "GET",
headers = {
Expand Down

0 comments on commit b353adf

Please sign in to comment.