From ab894e605bc38316631b61441d125803d65d15f0 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 28 Dec 2023 09:40:34 +0800 Subject: [PATCH 01/10] fix 01-helpers_spec.lua --- spec/02-integration/01-helpers/01-helpers_spec.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/02-integration/01-helpers/01-helpers_spec.lua b/spec/02-integration/01-helpers/01-helpers_spec.lua index fa00dbd313aa..c4e383ffd236 100644 --- a/spec/02-integration/01-helpers/01-helpers_spec.lua +++ b/spec/02-integration/01-helpers/01-helpers_spec.lua @@ -26,6 +26,7 @@ for _, strategy in helpers.each_strategy() do bp.routes:insert { hosts = { "mock_upstream" }, protocols = { "http" }, + paths = { "/" }, service = service } From bb8f8267167d846254f3b03fd9a2e5d0dd6aa491 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 28 Dec 2023 09:42:44 +0800 Subject: [PATCH 02/10] fix 03-upstream_headers_spec.lua --- spec/02-integration/05-proxy/03-upstream_headers_spec.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/02-integration/05-proxy/03-upstream_headers_spec.lua b/spec/02-integration/05-proxy/03-upstream_headers_spec.lua index 3132d0a6bfd0..c78203d3b5f5 100644 --- a/spec/02-integration/05-proxy/03-upstream_headers_spec.lua +++ b/spec/02-integration/05-proxy/03-upstream_headers_spec.lua @@ -278,6 +278,7 @@ for _, strategy in helpers.each_strategy() do assert(bp.routes:insert { hosts = { "headers-charset.test" }, + paths = { "/" }, service = service, }) From 57a8143296774968a563663c0d8c891f074c9c3b Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 28 Dec 2023 09:50:22 +0800 Subject: [PATCH 03/10] fix 14-server_tokens_spec.lua --- spec/02-integration/05-proxy/14-server_tokens_spec.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/02-integration/05-proxy/14-server_tokens_spec.lua b/spec/02-integration/05-proxy/14-server_tokens_spec.lua index 6cee745a1354..3de5077db9dd 100644 --- a/spec/02-integration/05-proxy/14-server_tokens_spec.lua +++ b/spec/02-integration/05-proxy/14-server_tokens_spec.lua @@ -291,6 +291,7 @@ describe("headers [#" .. strategy .. "]", function() return function() bp.routes:insert { hosts = { "headers-inspect.test" }, + paths = { "/" }, } local service = bp.services:insert({ From 37fd79734a7d3e3a1ad92dd9551b66694dd3bd0d Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 28 Dec 2023 10:24:00 +0800 Subject: [PATCH 04/10] fix 31-stream_tls_spec.lua --- kong/router/atc.lua | 6 ++++++ kong/router/fields.lua | 21 ++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/kong/router/atc.lua b/kong/router/atc.lua index f05053f8eb0b..a03acb1c1b5c 100644 --- a/kong/router/atc.lua +++ b/kong/router/atc.lua @@ -11,6 +11,7 @@ local tb_new = require("table.new") local fields = require("kong.router.fields") local utils = require("kong.router.utils") local yield = require("kong.tools.yield").yield +local server_name = require("ngx.ssl").server_name local type = type @@ -655,6 +656,11 @@ function _M:exec(ctx) else route_match_stat(ctx, "pos") + + -- preserve_host logic, modify cache result + if match_t.route.preserve_host then + match_t.upstream_host = fields.get_value("tls.sni", CACHE_PARAMS) + end end return match_t diff --git a/kong/router/fields.lua b/kong/router/fields.lua index a33b27c8fcd5..59d4cee86ec4 100644 --- a/kong/router/fields.lua +++ b/kong/router/fields.lua @@ -218,15 +218,20 @@ if is_http then end -- is_http -local function fields_visitor(fields, params, ctx, cb) - for _, field in ipairs(fields) do - local func = FIELDS_FUNCS[field] +local function get_value(field, params, ctx) + local func = FIELDS_FUNCS[field] + + if not func then -- unknown field + error("unknown router matching schema field: " .. field) + end -- if func + + return func(params, ctx) +end - if not func then -- unknown field - error("unknown router matching schema field: " .. field) - end -- if func - local value = func(params, ctx) +local function fields_visitor(fields, params, ctx, cb) + for _, field in ipairs(fields) do + local value = get_value(field, params, ctx) local res, err = cb(field, value) if not res then @@ -352,6 +357,8 @@ end return { + get_value = get_value, + get_cache_key = get_cache_key, fill_atc_context = fill_atc_context, From 3e40bd98e7cb115a30cd16e517685b98f039b379 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 28 Dec 2023 10:34:35 +0800 Subject: [PATCH 05/10] fix 02-router_spec.lua --- spec/02-integration/05-proxy/02-router_spec.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/02-integration/05-proxy/02-router_spec.lua b/spec/02-integration/05-proxy/02-router_spec.lua index 855e64ebfe9d..26ba41a46176 100644 --- a/spec/02-integration/05-proxy/02-router_spec.lua +++ b/spec/02-integration/05-proxy/02-router_spec.lua @@ -877,15 +877,16 @@ for _, strategy in helpers.each_strategy() do describe("URI arguments (querystring)", function() local routes - before_each(function() + lazy_setup(function() routes = insert_routes(bp, { { hosts = { "mock_upstream" }, + paths = { "/" }, }, }) end) - after_each(function() + lazy_teardown(function() remove_routes(strategy, routes) end) @@ -1301,6 +1302,7 @@ for _, strategy in helpers.each_strategy() do routes = insert_routes(bp, { { protocols = { "https" }, + paths = { "/" }, snis = { "www.example.org" }, service = { name = "service_behind_www.example.org" @@ -1343,7 +1345,7 @@ for _, strategy in helpers.each_strategy() do path = "/status/201", headers = { ["kong-debug"] = 1 }, }) - assert.res_status(flavor == "traditional" and 201 or 200, res) + assert.res_status(201, res) assert.equal("service_behind_www.example.org", res.headers["kong-service-name"]) @@ -1365,7 +1367,7 @@ for _, strategy in helpers.each_strategy() do path = "/status/201", headers = { ["kong-debug"] = 1 }, }) - assert.res_status(flavor == "traditional" and 201 or 200, res) + assert.res_status(201, res) assert.equal("service_behind_example.org", res.headers["kong-service-name"]) end) From 2c28e151fd74fe11efa9d1b09f03e74b8d65081e Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 28 Dec 2023 10:38:19 +0800 Subject: [PATCH 06/10] lint fix --- kong/router/atc.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/kong/router/atc.lua b/kong/router/atc.lua index a03acb1c1b5c..16caac44f559 100644 --- a/kong/router/atc.lua +++ b/kong/router/atc.lua @@ -11,7 +11,6 @@ local tb_new = require("table.new") local fields = require("kong.router.fields") local utils = require("kong.router.utils") local yield = require("kong.tools.yield").yield -local server_name = require("ngx.ssl").server_name local type = type From 351ad5ec8c7a1d22c4a24fa2ff5b967cfd09ebe7 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 28 Dec 2023 10:47:00 +0800 Subject: [PATCH 07/10] fix 01-log_spec.lua --- spec/03-plugins/07-loggly/01-log_spec.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/03-plugins/07-loggly/01-log_spec.lua b/spec/03-plugins/07-loggly/01-log_spec.lua index dd5e35a0199d..4987cbb1d9ab 100644 --- a/spec/03-plugins/07-loggly/01-log_spec.lua +++ b/spec/03-plugins/07-loggly/01-log_spec.lua @@ -19,6 +19,7 @@ for _, strategy in helpers.each_strategy() do local route1 = bp.routes:insert { hosts = { "logging.test" }, + paths = { "/" }, } local route2 = bp.routes:insert { From 5c7ec57f0093dca8c161b7617f71255c6f243b69 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 28 Dec 2023 10:49:48 +0800 Subject: [PATCH 08/10] fix 04-invalidations_spec.lua --- spec/03-plugins/25-oauth2/04-invalidations_spec.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/03-plugins/25-oauth2/04-invalidations_spec.lua b/spec/03-plugins/25-oauth2/04-invalidations_spec.lua index 90f7b25bf858..d4de5cb0d50b 100644 --- a/spec/03-plugins/25-oauth2/04-invalidations_spec.lua +++ b/spec/03-plugins/25-oauth2/04-invalidations_spec.lua @@ -43,6 +43,7 @@ for _, strategy in helpers.each_strategy() do route = assert(admin_api.routes:insert { hosts = { "oauth2.com" }, protocols = { "http", "https" }, + paths = { "/" } service = service, }) From 059ce1a923e392fede8dc00f43e67e6ad38dd4e8 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 28 Dec 2023 10:58:11 +0800 Subject: [PATCH 09/10] fix 02-access_spec.lua --- spec/03-plugins/31-proxy-cache/02-access_spec.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/03-plugins/31-proxy-cache/02-access_spec.lua b/spec/03-plugins/31-proxy-cache/02-access_spec.lua index aa8b350773d7..67e026d9e326 100644 --- a/spec/03-plugins/31-proxy-cache/02-access_spec.lua +++ b/spec/03-plugins/31-proxy-cache/02-access_spec.lua @@ -38,6 +38,7 @@ do local route1 = assert(bp.routes:insert { hosts = { "route-1.test" }, + paths = { "/" }, }) local route2 = assert(bp.routes:insert { hosts = { "route-2.test" }, From 943ea268e2dc03c71124a98921590d6a298ecb5f Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 28 Dec 2023 11:04:32 +0800 Subject: [PATCH 10/10] fix mistake --- spec/03-plugins/25-oauth2/04-invalidations_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/03-plugins/25-oauth2/04-invalidations_spec.lua b/spec/03-plugins/25-oauth2/04-invalidations_spec.lua index d4de5cb0d50b..18218b6cfdb6 100644 --- a/spec/03-plugins/25-oauth2/04-invalidations_spec.lua +++ b/spec/03-plugins/25-oauth2/04-invalidations_spec.lua @@ -43,7 +43,7 @@ for _, strategy in helpers.each_strategy() do route = assert(admin_api.routes:insert { hosts = { "oauth2.com" }, protocols = { "http", "https" }, - paths = { "/" } + paths = { "/" }, service = service, })