From: Vladimír Čunát Date: Mon, 3 Jun 2019 13:42:02 +0000 (+0200) Subject: modules/http: test connection to an AF_UNIX socket X-Git-Tag: v4.1.0~23^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=88f2e482f341f103ab4ae457ce8fffbd15929205;p=thirdparty%2Fknot-resolver.git modules/http: test connection to an AF_UNIX socket --- diff --git a/modules/http/http.test.lua b/modules/http/http.test.lua index 960288aae..968de3b1d 100644 --- a/modules/http/http.test.lua +++ b/modules/http/http.test.lua @@ -94,10 +94,29 @@ else same(code, 400, '/trace requires name') end + -- AF_UNIX tests (very basic ATM) + local function test_unix_socket() + local s_path = os.tmpname() + os.remove(s_path) -- on POSIX .tmpname() (usually) creates a file :-/ + ok(net.listen(s_path, nil, { kind = 'webmgmt' }), 'AF_UNIX net.listen() on ' .. s_path) + -- Unfortunately we can't use standard functions for fetching http:// + local socket = require("cqueues.socket") + local sock = socket.connect({ path = s_path }) + local connection = require('http.h2_connection') + local conn = connection.new(sock, 'client') + local _, err = conn:connect() + os.remove(s_path) -- don't leave garbage around, hopefully not even on errors + same(err, nil, 'AF_UNIX connect(): ' .. (err or 'OK')) + same(conn:ping(), true, 'AF_UNIX http ping') + -- here we might do `conn:new_stream()` and some real queries + same(conn:close(), true, 'AF_UNIX close') + end + -- plan tests local tests = { start_server, test_builtin_pages, + test_unix_socket, } return tests