From: Petr Špaček Date: Thu, 18 Apr 2019 08:30:45 +0000 (+0200) Subject: http: fix forgotten doh config tests X-Git-Tag: v4.0.0~4^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b4ee29282aed1e3e42ffb31bccf7fd34e790d98;p=thirdparty%2Fknot-resolver.git http: fix forgotten doh config tests --- diff --git a/modules/http/http_doh.test.lua b/modules/http/http_doh.test.lua index 37c6f6411..f9cd26b32 100644 --- a/modules/http/http_doh.test.lua +++ b/modules/http/http_doh.test.lua @@ -77,28 +77,39 @@ if not has_http then pass('skipping http module test because its not installed') done() else - local request = require('http.request') - local endpoints = require('kres_modules.http').endpoints - - -- setup resolver - modules = { - http = { - port = 0, -- Select random port - cert = false, - endpoints = endpoints, - } - } 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.'}))) - local server = http.servers[1] - ok(server ~= nil, 'creates server instance') - local _, host, port = server:localname() - ok(host and port, 'binds to an interface') - local uri_templ = string.format('http://%s:%d/doh', host, port) - local req_templ = assert(request.new_from_uri(uri_templ)) - req_templ.headers:upsert('content-type', 'application/dns-message') + modules.load('http') + http.config({ + tls = false, + endpoints = http.templates.doh.endpoints + }, 'doh') + + local bound + for i = 1,1000 do + bound = net.listen('127.0.0.1', math.random(1025,65535), { 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 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) + req_templ = assert(request.new_from_uri(uri_templ)) + req_templ.headers:upsert('content-type', 'application/dns-message') + end + -- test a valid DNS query using POST local function test_doh_servfail() @@ -255,6 +266,7 @@ else -- plan tests local tests = { + start_server, test_unsupp_method, test_post_short_input, test_post_long_input,