]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
modules/http: test connection to an AF_UNIX socket
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 3 Jun 2019 13:42:02 +0000 (15:42 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 3 Jun 2019 13:43:04 +0000 (15:43 +0200)
modules/http/http.test.lua

index 960288aae831b2d8ddb996828367106f00eadde4..968de3b1d70dc1d2448e3a339a3b0b6c9588bc7f 100644 (file)
@@ -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