http = require "luajit-curl-helper.http" req = (url) -> request = http.init url st = request\perform! error request\lastError! if not st request describe "test environment", -> it "can't connect to the internet", -> assert.has_error (-> req "http://example.org"), "Couldn't resolve host name" describe "https://domain.abc", -> it "sends /index.html", -> request = req "https://domain.abc" assert.same request\statusCode!, 200 assert.same request\statusMessage!, "OK" assert.same request\body!\match("%s+(.-)%s+"), "hello world!" describe "http://domain.abc", -> it "redirects to https permanently", -> request = req "http://domain.abc" assert.same request\statusCode!, 301 assert.same request\statusMessage!, "Moved Permanently" assert.same request\header!.Location, "https://domain.abc/" describe "https://git.domain.abc", -> it "reverse-proxy's request to a gitea unix socket", -> socket = fname: "unixstreamsrvr.moon", dir: "/run/gitea", owner: "nobody" basepath = debug.getinfo(1).short_src\match"^(.*)/[^/]*$" or "." seconds = 0.1 os.execute "install -o #{socket.owner} -d #{socket.dir}" cmd = "su -s /bin/bash -c 'moon %s' %s" server = io.popen cmd\format "#{basepath}/#{socket.fname}", socket.owner os.execute "sleep #{seconds}" f = io.popen "find #{socket.dir} -type s -ls", "r" result = with f\read "*a" f\close! assert.truthy result\match "nobody%s+nogroup.+#{socket.dir}/gitea.socket" req "https://git.domain.abc" reqheader = with server\read "*a" server\close! assert.truthy reqheader\match "Host: git.domain.abc"