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

tests(wasm): add test for new dns client #13725

Merged
merged 1 commit into from
Oct 8, 2024
Merged
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
133 changes: 95 additions & 38 deletions spec/02-integration/20-wasm/04-proxy-wasm_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ 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()
local function setup_entities()
require("kong.runloop.wasm").enable({
{ name = "tests",
path = helpers.test_conf.wasm_filters_path .. "/tests.wasm",
Expand All @@ -33,6 +32,7 @@ describe("proxy-wasm filters (#wasm) (#" .. strategy .. ")", function()
"routes",
"services",
"filter_chains",
"plugins",
})

mock_service = assert(bp.services:insert {
Expand Down Expand Up @@ -126,33 +126,32 @@ describe("proxy-wasm filters (#wasm) (#" .. strategy .. ")", function()
},
},
})
end


-- 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",
}))
before_each(function()
helpers.clean_logfile()
end)

lazy_teardown(function()
helpers.stop_kong()
os.remove(hosts_file)
end)

before_each(function()
helpers.clean_logfile()
helpers.clean_prefix()
end)

describe("runs a filter chain", function()
lazy_setup(function()
setup_entities()

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)
Expand Down Expand Up @@ -183,6 +182,20 @@ describe("proxy-wasm filters (#wasm) (#" .. strategy .. ")", function()
end)

describe("filters can", function()
lazy_setup(function()
setup_entities()
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)
Expand Down Expand Up @@ -788,6 +801,52 @@ 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"))

setup_entities()
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)
Expand Down Expand Up @@ -818,26 +877,24 @@ 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()
setup_entities()
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)
Expand Down
Loading