Adds tests to make sure all the `nginx.conf` directives (the redirects and rewrites and such) are all correct. - Uses the `busted` framework - The tests are run in a Docker container by the bash script `test.sh` - Self-signed certs are generated in `Dockerfile` for all the domain names - Adds new `Makefile` commands: `test`, `image-build` and `image-rm` Reviewed-on: #1 Co-authored-by: Catalin Mititiuc <webdevcat@proton.me> Co-committed-by: Catalin Mititiuc <webdevcat@proton.me>
139 lines
5.5 KiB
Plaintext
139 lines
5.5 KiB
Plaintext
http = require "luajit-curl-helper.http"
|
|
index_title = "miti.sh · Catalin Constantin Mititiuc"
|
|
|
|
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 "http://miti.sh", ->
|
|
it "redirects to https", ->
|
|
request = req "http://miti.sh"
|
|
assert.same request\statusCode!, 301
|
|
assert.same request\statusMessage!, "Moved Permanently"
|
|
assert.same request\header!.Location, "https://miti.sh/"
|
|
|
|
describe "https://webdevcat.me", ->
|
|
it "permanently redirects to https://miti.sh", ->
|
|
request = req "https://webdevcat.me"
|
|
assert.same request\statusCode!, 301
|
|
assert.same request\statusMessage!, "Moved Permanently"
|
|
assert.same request\header!.Location, "https://miti.sh/"
|
|
|
|
describe "https://webdevcat.me/git", ->
|
|
it "permanently redirects to https://git.miti.sh/ccm/", ->
|
|
request = req "https://webdevcat.me/git"
|
|
assert.same request\statusCode!, 301
|
|
assert.same request\statusMessage!, "Moved Permanently"
|
|
assert.same request\header!.Location, "https://git.miti.sh/ccm/"
|
|
|
|
describe "https://webdevcat.me/git/", ->
|
|
it "permanently redirects to https://git.miti.sh", ->
|
|
request = req "https://webdevcat.me/git"
|
|
assert.same request\statusCode!, 301
|
|
assert.same request\statusMessage!, "Moved Permanently"
|
|
assert.same request\header!.Location, "https://git.miti.sh/ccm/"
|
|
|
|
describe "https://webdevcat.me/git/pandoc", ->
|
|
it "permanently redirects to https://git.miti.sh/ccm/pandoc", ->
|
|
request = req "https://webdevcat.me/git/pandoc"
|
|
assert.same request\statusCode!, 301
|
|
assert.same request\statusMessage!, "Moved Permanently"
|
|
assert.same request\header!.Location, "https://git.miti.sh/ccm/pandoc"
|
|
|
|
describe "https://git.webdevcat.me", ->
|
|
it "permanently redirects to https://git.miti.sh/", ->
|
|
request = req "https://git.webdevcat.me"
|
|
assert.same request\statusCode!, 301
|
|
assert.same request\statusMessage!, "Moved Permanently"
|
|
assert.same request\header!.Location, "https://git.miti.sh/"
|
|
|
|
describe "https://webdevcat.me/apps/btroops", ->
|
|
it "permanently redirects to https://apps.miti.sh/btroops", ->
|
|
request = req "https://webdevcat.me/apps/btroops"
|
|
assert.same request\statusCode!, 301
|
|
assert.same request\statusMessage!, "Moved Permanently"
|
|
assert.same request\header!.Location, "https://apps.miti.sh/btroops"
|
|
|
|
describe "https://apps.webdevcat.me", ->
|
|
it "permanently redirects to https://apps.miti.sh/", ->
|
|
request = req "https://apps.webdevcat.me"
|
|
assert.same request\statusCode!, 301
|
|
assert.same request\statusMessage!, "Moved Permanently"
|
|
assert.same request\header!.Location, "https://apps.miti.sh/"
|
|
|
|
describe "https://apps.webdevcat.me/btroops", ->
|
|
it "permanently redirects to https://apps.miti.sh/btroops", ->
|
|
request = req "https://apps.webdevcat.me/btroops"
|
|
assert.same request\statusCode!, 301
|
|
assert.same request\statusMessage!, "Moved Permanently"
|
|
assert.same request\header!.Location, "https://apps.miti.sh/btroops"
|
|
|
|
describe "https://miti.sh", ->
|
|
it "sends /index.html", ->
|
|
request = req "https://miti.sh"
|
|
assert.same request\statusCode!, 200
|
|
assert.same request\statusMessage!, "OK"
|
|
assert.same request\body!\match("<title>(.*)</title>"), index_title
|
|
|
|
describe "https://miti.sh/index", ->
|
|
it "sends /index.html", ->
|
|
request = req "https://miti.sh/index"
|
|
assert.same request\statusCode!, 200
|
|
assert.same request\statusMessage!, "OK"
|
|
assert.same request\body!\match("<title>(.*)</title>"), index_title
|
|
|
|
describe "https://miti.sh/index.html", ->
|
|
it "sends /index.html", ->
|
|
request = req "https://miti.sh/index.html"
|
|
assert.same request\statusCode!, 200
|
|
assert.same request\statusMessage!, "OK"
|
|
assert.same request\body!\match("<title>(.*)</title>"), index_title
|
|
|
|
describe "https://miti.sh/posts/", ->
|
|
it "permanently redirects to http://miti.sh/posts", ->
|
|
request = req "https://miti.sh/posts/"
|
|
assert.same request\statusCode!, 301
|
|
assert.same request\statusMessage!, "Moved Permanently"
|
|
assert.same request\header!.Location, "https://miti.sh/posts"
|
|
|
|
describe "https://miti.sh/posts", ->
|
|
it "sends /posts/index.html", ->
|
|
request = req "https://miti.sh/posts"
|
|
assert.same request\statusCode!, 200
|
|
assert.same request\statusMessage!, "OK"
|
|
assert.same request\body!\match("<title>(.*)</title>"), "miti.sh · Posts"
|
|
|
|
describe "https://git.miti.sh", ->
|
|
it "reverse-proxies request to a gitea unix socket", ->
|
|
Path = require "sitegen.path"
|
|
socket_fname = "unixstreamsrvr.moon"
|
|
socket_dir = "/run/gitea"
|
|
socket_owner = "nobody"
|
|
basepath = Path.basepath debug.getinfo(1).short_src
|
|
|
|
Path.exec "install", "-o", socket_owner, "-d", socket_dir
|
|
cmd = "su -s /bin/bash -c 'moon %s' %s"
|
|
server = io.popen cmd\format Path.join(basepath, socket_fname), socket_owner
|
|
Path.exec "sleep", "0.1"
|
|
result = Path.read_exec "find", socket_dir, "-type", "s", "-ls"
|
|
assert.truthy result\match "nobody%s+nogroup.+" .. Path.join(socket_dir, "gitea.socket")
|
|
|
|
req "https://git.miti.sh"
|
|
|
|
reqheader = with server\read "*a"
|
|
server\close!
|
|
|
|
assert.truthy reqheader\match "Host: git.miti.sh"
|
|
|
|
describe "https://apps.miti.sh", ->
|
|
it "doesn't find it", ->
|
|
request = req "https://apps.miti.sh"
|
|
assert.same request\statusCode!, 404
|
|
assert.same request\statusMessage!, "Not Found"
|