Add subdomain proxy on unix socket and test

This commit is contained in:
2025-06-25 15:45:29 -07:00
parent 6de5e6b847
commit 50bb79533d
5 changed files with 56 additions and 2 deletions

View File

@@ -19,8 +19,30 @@ describe "https://domain.abc", ->
assert.same request\body!\match("<body>%s+(.-)%s+</body>"), "hello world!"
describe "http://domain.abc", ->
it "redirects to https", ->
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"

15
spec/unixstreamsrvr.moon Normal file
View File

@@ -0,0 +1,15 @@
-- modified from
-- https://github.com/lunarmodules/luasocket/blob/4844a48fbf76b0400fd7b7e4d15d244484019df1/test/unixstreamsrvr.lua
socket = require "socket"
socket.unix = require "socket.unix"
u = assert socket.unix.stream!
assert u\bind "/run/gitea/gitea.socket"
assert u\listen!
assert u\settimeout 1
c = assert u\accept!
while true
m = assert c\receive!
break if m == ""
print m