From 15358ab883ec2ce880ae5b98a2517f4390312363 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Mon, 30 Sep 2024 10:08:10 -0700 Subject: [PATCH] tests(wasm): add test for new dns client --- .../20-wasm/04-proxy-wasm_spec.lua | 121 ++++++++++++------ 1 file changed, 84 insertions(+), 37 deletions(-) diff --git a/spec/02-integration/20-wasm/04-proxy-wasm_spec.lua b/spec/02-integration/20-wasm/04-proxy-wasm_spec.lua index 4518eb657d53..64b688582cab 100644 --- a/spec/02-integration/20-wasm/04-proxy-wasm_spec.lua +++ b/spec/02-integration/20-wasm/04-proxy-wasm_spec.lua @@ -20,7 +20,6 @@ for _, strategy in helpers.each_strategy({ "postgres", "off" }) do describe("proxy-wasm filters (#wasm) (#" .. strategy .. ")", function() local r_single, mock_service - local hosts_file lazy_setup(function() require("kong.runloop.wasm").enable({ @@ -126,26 +125,6 @@ describe("proxy-wasm filters (#wasm) (#" .. strategy .. ")", function() }, }, }) - - - -- XXX our dns mock fixture doesn't work when called from wasm land - hosts_file = os.tmpname() - assert(helpers.file.write(hosts_file, - "127.0.0.1 " .. DNS_HOSTNAME .. "\n")) - - assert(helpers.start_kong({ - database = strategy, - nginx_conf = "spec/fixtures/custom_nginx.template", - wasm = true, - dns_hostsfile = hosts_file, - resolver_hosts_file = hosts_file, - plugins = "pre-function,post-function", - })) - end) - - lazy_teardown(function() - helpers.stop_kong() - os.remove(hosts_file) end) before_each(function() @@ -153,6 +132,19 @@ describe("proxy-wasm filters (#wasm) (#" .. strategy .. ")", function() end) describe("runs a filter chain", function() + lazy_setup(function() + assert(helpers.start_kong({ + database = strategy, + nginx_conf = "spec/fixtures/custom_nginx.template", + wasm = true, + plugins = "pre-function,post-function", + })) + end) + + lazy_teardown(function() + helpers.stop_kong() + end) + it("with a single filter", function() local client = helpers.proxy_client() finally(function() client:close() end) @@ -183,6 +175,19 @@ describe("proxy-wasm filters (#wasm) (#" .. strategy .. ")", function() end) describe("filters can", function() + lazy_setup(function() + assert(helpers.start_kong({ + database = strategy, + nginx_conf = "spec/fixtures/custom_nginx.template", + wasm = true, + plugins = "pre-function,post-function", + })) + end) + + lazy_teardown(function() + helpers.stop_kong() + end) + it("add request headers", function() local client = helpers.proxy_client() finally(function() client:close() end) @@ -788,6 +793,51 @@ describe("proxy-wasm filters (#wasm) (#" .. strategy .. ")", function() assert.logfile().has.no.line("[crit]", true, 0) end) + pending("start on_tick background timer", function() + -- Pending on internal ngx_wasm_module changes + local client = helpers.proxy_client() + finally(function() client:close() end) + + local res = assert(client:send { + method = "GET", + path = "/single/status/200", + }) + + assert.res_status(200, res) + assert.logfile().has.no.line("[error]", true, 0) + assert.logfile().has.no.line("[crit]", true, 0) + + -- TODO + end) + end) + + for _, new_dns_client in ipairs({"off", "on"}) do + + describe("lua dns bridge (new_dns_client=" .. new_dns_client .. ")", function() + local hosts_file + + lazy_setup(function() + -- XXX our dns mock fixture doesn't work when called from wasm land + hosts_file = os.tmpname() + assert(helpers.file.write(hosts_file, + "127.0.0.1 " .. DNS_HOSTNAME .. "\n")) + + assert(helpers.start_kong({ + database = strategy, + nginx_conf = "spec/fixtures/custom_nginx.template", + wasm = true, + dns_hostsfile = hosts_file, + resolver_hosts_file = hosts_file, + plugins = "pre-function,post-function", + new_dns_client = new_dns_client, + })) + end) + + lazy_teardown(function() + helpers.stop_kong() + os.remove(hosts_file) + end) + it("resolves DNS hostnames to send an http dispatch, return its response body", function() local client = helpers.proxy_client() finally(function() client:close() end) @@ -818,26 +868,23 @@ describe("proxy-wasm filters (#wasm) (#" .. strategy .. ")", function() .. DNS_HOSTNAME .. [[" to "127.0.0.1"]]) end) + end) + end -- each `new_dns_client` - pending("start on_tick background timer", function() - -- Pending on internal ngx_wasm_module changes - local client = helpers.proxy_client() - finally(function() client:close() end) - - local res = assert(client:send { - method = "GET", - path = "/single/status/200", - }) - - assert.res_status(200, res) - assert.logfile().has.no.line("[error]", true, 0) - assert.logfile().has.no.line("[crit]", true, 0) + describe("behavior with", function() + lazy_setup(function() + assert(helpers.start_kong({ + database = strategy, + nginx_conf = "spec/fixtures/custom_nginx.template", + wasm = true, + plugins = "pre-function,post-function", + })) + end) - -- TODO + lazy_teardown(function() + helpers.stop_kong() end) - end) - describe("behavior with", function() pending("multiple filters, one sends a local response", function() local client = helpers.proxy_client() finally(function() client:close() end)