From: Tomas Krizek Date: Thu, 1 Oct 2020 15:07:23 +0000 (+0200) Subject: tests/config: modify doh tests for doh2 X-Git-Tag: v5.2.0~15^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=251310ea2a644ec93fa53675b4c41d5f57131a1f;p=thirdparty%2Fknot-resolver.git tests/config: modify doh tests for doh2 Test only supported test-cases. Extend list of lua dependencies for config tests. --- diff --git a/tests/config/doh2.test.lua b/tests/config/doh2.test.lua index c66bef267..8461db50b 100644 --- a/tests/config/doh2.test.lua +++ b/tests/config/doh2.test.lua @@ -1,4 +1,7 @@ -- SPDX-License-Identifier: GPL-3.0-or-later +local basexx = require('basexx') +local ffi = require('ffi') + local function gen_huge_answer(_, req) local answer = req.answer ffi.C.kr_pkt_make_auth_header(answer) @@ -70,41 +73,34 @@ local function check_err(req, exp_status, desc) end -- check prerequisites -local has_doh2, err = pcall(net.listen, '127.0.0.1', math.random(30000, 39999), { kind = 'doh2'}) -if not has_doh2 then - -- skipping doh2 tests (failure to bind may be cause by missing support during build) +local bound +local host = '127.0.0.1' +local port +for _ = 1,10 do + port = math.random(30000, 39999) + bound = pcall(net.listen, host, port, { kind = 'doh2'}) + if bound then + break + end +end + +if not bound then + -- skipping doh2 tests (failure to bind may be caused by missing support during build) os.exit(77) else policy.add(policy.suffix(policy.DROP, policy.todnames({'servfail.test.'}))) policy.add(policy.suffix(policy.DENY, policy.todnames({'nxdomain.test.'}))) policy.add(policy.suffix(gen_varying_ttls, policy.todnames({'noerror.test.'}))) - modules.load('http') - http.config({ - tls = false, - }, 'doh') - - local bound - for _ = 1,1000 do - bound, _err = pcall(net.listen, '127.0.0.1', math.random(30000, 39999), { kind = 'doh' }) - if bound then - break - end - end - assert(bound, 'unable to bind a port for HTTP module (1000 attempts)') - - local _, host, port, req_templ, uri_templ + local _, req_templ, uri_templ local function start_server() local request = require('http.request') - local server_fd = next(http.servers) - assert(server_fd) - local server = http.servers[server_fd].server - ok(server ~= nil, 'creates server instance') - _, host, port = server:localname() - ok(host and port, 'binds to an interface') - uri_templ = string.format('http://%s:%d/doh', host, port) + local ssl_ctx = require('openssl.ssl.context') + uri_templ = string.format('https://%s:%d/dns_query', host, port) req_templ = assert(request.new_from_uri(uri_templ)) req_templ.headers:upsert('content-type', 'application/dns-message') + req_templ.ctx = ssl_ctx.new() + req_templ.ctx:setVerify(ssl_ctx.VERIFY_NONE) end @@ -120,7 +116,7 @@ else return end -- uncacheable - same(headers:get('cache-control'), 'max-age=0', desc .. ': TTL 0') + -- same(headers:get('cache-control'), 'max-age=0', desc .. ': TTL 0') TODO: implement same(pkt:rcode(), kres.rcode.SERVFAIL, desc .. ': rcode matches') end @@ -135,7 +131,7 @@ else return end -- HTTP TTL is minimum from all RRs in the answer - same(headers:get('cache-control'), 'max-age=300', desc .. ': TTL 900') + -- same(headers:get('cache-control'), 'max-age=300', desc .. ': TTL 900') TODO: implement same(pkt:rcode(), kres.rcode.NOERROR, desc .. ': rcode matches') same(pkt:ancount(), 3, desc .. ': ANSWER is present') same(pkt:nscount(), 1, desc .. ': AUTHORITY is present') @@ -152,7 +148,7 @@ else if not (headers and pkt) then return end - same(headers:get('cache-control'), 'max-age=10800', desc .. ': TTL 10800') + -- same(headers:get('cache-control'), 'max-age=10800', desc .. ': TTL 10800') TODO: implement same(pkt:rcode(), kres.rcode.NXDOMAIN, desc .. ': rcode matches') same(pkt:nscount(), 1, desc .. ': AUTHORITY is present') end @@ -213,7 +209,7 @@ else return end -- uncacheable - same(headers:get('cache-control'), 'max-age=0', desc .. ': TTL 0') + -- same(headers:get('cache-control'), 'max-age=0', desc .. ': TTL 0') TODO: implement same(pkt:rcode(), kres.rcode.SERVFAIL, desc .. ': rcode matches') end @@ -228,7 +224,7 @@ else return end -- HTTP TTL is minimum from all RRs in the answer - same(headers:get('cache-control'), 'max-age=300', desc .. ': TTL 900') + -- same(headers:get('cache-control'), 'max-age=300', desc .. ': TTL 900') TODO: implement same(pkt:rcode(), kres.rcode.NOERROR, desc .. ': rcode matches') same(pkt:ancount(), 3, desc .. ': ANSWER is present') same(pkt:nscount(), 1, desc .. ': AUTHORITY is present') @@ -245,7 +241,7 @@ else if not (headers and pkt) then return end - same(headers:get('cache-control'), 'max-age=10800', desc .. ': TTL 10800') + -- same(headers:get('cache-control'), 'max-age=10800', desc .. ': TTL 10800') TODO: implement same(pkt:rcode(), kres.rcode.NXDOMAIN, desc .. ': rcode matches') same(pkt:nscount(), 1, desc .. ': AUTHORITY is present') end @@ -367,28 +363,29 @@ else -- end -- plan tests + -- TODO: implement (some) of the error status codes local tests = { start_server, test_post_servfail, test_post_noerror, test_post_nxdomain, test_huge_answer, - test_post_short_input, - test_post_long_input, - test_post_unparseable_input, - test_post_unsupp_type, + --test_post_short_input, + --test_post_long_input, + --test_post_unparseable_input, + --test_post_unsupp_type, test_get_servfail, test_get_noerror, test_get_nxdomain, test_get_other_params_before_dns, test_get_other_params_after_dns, test_get_other_params, - test_get_long_input, - test_get_no_dns_param, - test_get_unparseable, - test_get_invalid_b64, - test_get_invalid_chars, - test_unsupp_method, + --test_get_long_input, + --test_get_no_dns_param, + --test_get_unparseable, + --test_get_invalid_b64, + --test_get_invalid_chars, + --test_unsupp_method, test_dstaddr, test_srcaddr } diff --git a/tests/meson.build b/tests/meson.build index c4b332c73..edc64947e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -26,6 +26,14 @@ if build_config_tests if cqueues.returncode() != 0 error('missing luajit package: cqueues') endif + basexx = run_command('luajit', '-l', 'basexx', '-e', 'os.exit(0)') # luajit -l $(1) -e "os.exit(0)" + if basexx.returncode() != 0 + error('missing luajit package: basexx') + endif + ffi = run_command('luajit', '-l', 'ffi', '-e', 'os.exit(0)') # luajit -l $(1) -e "os.exit(0)" + if ffi.returncode() != 0 + error('missing luajit package: ffi') + endif message('---------------------------------') subdir('config')