Add tests for nginx.conf directives #1

Merged
ccm merged 26 commits from ccm-test-nginx-directives into trunk 2025-06-14 21:54:22 +00:00
3 changed files with 30 additions and 19 deletions
Showing only changes of commit 6462ac9968 - Show all commits

View File

@ -106,18 +106,22 @@ describe "http://miti.sh/posts", ->
describe "http://git.miti.sh", -> describe "http://git.miti.sh", ->
it "reverse proxies request to gitea through a unix socket", -> it "reverse proxies request to gitea through a unix socket", ->
Path = require "sitegen.path" Path = require "sitegen.path"
filename = "unixstreamsrvr.lua" socket_fname = "unixstreamsrvr.moon"
socket_dir = "/run/gitea" socket_dir = "/run/gitea"
info = debug.getinfo 1 socket_owner = "nobody"
basepath = Path.basepath info.short_src basepath = Path.basepath debug.getinfo(1).short_src
os.execute "mkdir " .. socket_dir os.execute "mkdir " .. socket_dir
p = io.popen "luajit %s"\format Path.join basepath, filename p = io.popen "moon %s"\format Path.join(basepath, socket_fname)
os.execute "sleep 0" os.execute "sleep 0.1"
os.execute "chown -R nobody " .. socket_dir os.execute "chown -R " .. socket_owner .. " " .. socket_dir
result = Path.read_exec "find", socket_dir, "-type", "s", "-ls"
assert.truthy result\match "nobody%s+root.+" .. Path.join(socket_dir, "gitea.socket")
request = req "http://git.miti.sh" request = req "http://git.miti.sh"
assert.truthy p\read"*a"\match "Host: git.miti.sh" pout = p\read"*a"
p\close!
assert.truthy pout\match "Host: git.miti.sh"
describe "http://apps.miti.sh", -> describe "http://apps.miti.sh", ->
it "doesn't find it", -> it "doesn't find it", ->

View File

@ -1,12 +0,0 @@
socket = require"socket"
socket.unix = require"socket.unix"
u = assert(socket.unix.stream())
assert(u:bind("/run/gitea/gitea.socket"))
assert(u:listen())
c = assert(u:accept())
m = assert(c:receive())
repeat
print(m)
m = assert(c:receive())
until m == ""

19
spec/unixstreamsrvr.moon Normal file
View File

@ -0,0 +1,19 @@
-- 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!
m = assert c\receive!
-- print "RECEIVED"
-- print m
while m != ""
print m
m = assert c\receive!
-- repeat
-- print m
-- m = assert c\receive!
-- until m == ""