mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-17 13:54:59 +00:00
test: adapt caddy testing environment into a smoke test
Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
10
test/anubis_configs/less_paranoid.yaml
Normal file
10
test/anubis_configs/less_paranoid.yaml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
bots:
|
||||||
|
- name: challenge
|
||||||
|
user_agent_regex: Mozilla
|
||||||
|
action: WEIGH
|
||||||
|
weight:
|
||||||
|
adjust: 10
|
||||||
|
|
||||||
|
status_codes:
|
||||||
|
CHALLENGE: 401
|
||||||
|
DENY: 403
|
||||||
@@ -9,14 +9,14 @@ services:
|
|||||||
- "../pki/caddy.local.cetacean.club:/etc/techaro/pki/caddy.local.cetacean.club/"
|
- "../pki/caddy.local.cetacean.club:/etc/techaro/pki/caddy.local.cetacean.club/"
|
||||||
|
|
||||||
anubis:
|
anubis:
|
||||||
image: ghcr.io/techarohq/anubis:main
|
image: ko.local/anubis
|
||||||
environment:
|
environment:
|
||||||
BIND: ":3000"
|
BIND: ":3000"
|
||||||
TARGET: http://httpdebug:3000
|
TARGET: http://httpdebug:3000
|
||||||
POLICY_FNAME: /etc/techaro/anubis/less_paranoid.yaml
|
POLICY_FNAME: /cfg/less_paranoid.yaml
|
||||||
|
SLOG_LEVEL: DEBUG
|
||||||
volumes:
|
volumes:
|
||||||
- ../anubis_configs:/etc/techaro/anubis
|
- ../anubis_configs:/cfg
|
||||||
|
|
||||||
httpdebug:
|
httpdebug:
|
||||||
image: ghcr.io/xe/x/httpdebug
|
image: ghcr.io/xe/x/httpdebug
|
||||||
pull_policy: always
|
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# If the transient local TLS certificate doesn't exist, mint a new one
|
|
||||||
if [ ! -f ../pki/caddy.local.cetacean.club/cert.pem ]; then
|
|
||||||
# Subshell to contain the directory change
|
|
||||||
(
|
|
||||||
cd ../pki \
|
|
||||||
&& mkdir -p caddy.local.cetacean.club \
|
|
||||||
&& \
|
|
||||||
# Try using https://github.com/FiloSottile/mkcert for better DevEx,
|
|
||||||
# but fall back to using https://github.com/jsha/minica in case
|
|
||||||
# you don't have that installed.
|
|
||||||
(
|
|
||||||
mkcert \
|
|
||||||
--cert-file ./caddy.local.cetacean.club/cert.pem \
|
|
||||||
--key-file ./caddy.local.cetacean.club/key.pem caddy.local.cetacean.club \
|
|
||||||
|| go tool minica -domains caddy.local.cetacean.club
|
|
||||||
)
|
|
||||||
)
|
|
||||||
fi
|
|
||||||
|
|
||||||
docker compose up --build
|
|
||||||
27
test/caddy/test.mjs
Normal file
27
test/caddy/test.mjs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
async function testWithUserAgent(userAgent) {
|
||||||
|
const statusCode =
|
||||||
|
await fetch("https://relayd.local.cetacean.club:8443/reqmeta", {
|
||||||
|
headers: {
|
||||||
|
"User-Agent": userAgent,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(resp => resp.status);
|
||||||
|
return statusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const codes = {
|
||||||
|
Mozilla: await testWithUserAgent("Mozilla"),
|
||||||
|
curl: await testWithUserAgent("curl"),
|
||||||
|
}
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
Mozilla: 401,
|
||||||
|
curl: 200,
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("Mozilla:", codes.Mozilla);
|
||||||
|
console.log("curl: ", codes.curl);
|
||||||
|
|
||||||
|
if (JSON.stringify(codes) !== JSON.stringify(expected)) {
|
||||||
|
throw new Error(`wanted ${JSON.stringify(expected)}, got: ${JSON.stringify(codes)}`);
|
||||||
|
}
|
||||||
13
test/caddy/test.sh
Executable file
13
test/caddy/test.sh
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
source ../lib/lib.sh
|
||||||
|
|
||||||
|
build_anubis_ko
|
||||||
|
|
||||||
|
docker compose up -d --build
|
||||||
|
|
||||||
|
export NODE_TLS_REJECT_UNAUTHORIZED=0
|
||||||
|
|
||||||
|
backoff-retry node test.mjs
|
||||||
54
test/lib/lib.sh
Normal file
54
test/lib/lib.sh
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
REPO_ROOT=$(git rev-parse --show-toplevel)
|
||||||
|
(cd $REPO_ROOT && go install ./utils/cmd/...)
|
||||||
|
|
||||||
|
function cleanup() {
|
||||||
|
pkill -P $$
|
||||||
|
|
||||||
|
if [ -f "docker-compose.yaml" ]; then
|
||||||
|
docker compose down
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
trap cleanup EXIT SIGINT
|
||||||
|
|
||||||
|
function build_anubis_ko() {
|
||||||
|
(
|
||||||
|
cd ../.. &&
|
||||||
|
VERSION=devel ko build \
|
||||||
|
--platform=all \
|
||||||
|
--base-import-paths \
|
||||||
|
--tags="latest" \
|
||||||
|
--image-user=1000 \
|
||||||
|
--image-annotation="" \
|
||||||
|
--image-label="" \
|
||||||
|
./cmd/anubis \
|
||||||
|
-L
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function mint_cert() {
|
||||||
|
if [ "$#" -ne 1 ]; then
|
||||||
|
echo "Usage: mint_cert <domain.name>"
|
||||||
|
fi
|
||||||
|
|
||||||
|
domainName="$1"
|
||||||
|
|
||||||
|
# If the transient local TLS certificate doesn't exist, mint a new one
|
||||||
|
if [ ! -f "../pki/${domainName}/cert.pem" ]; then
|
||||||
|
# Subshell to contain the directory change
|
||||||
|
(
|
||||||
|
cd ../pki &&
|
||||||
|
mkdir -p "${domainName}" &&
|
||||||
|
# Try using https://github.com/FiloSottile/mkcert for better DevEx,
|
||||||
|
# but fall back to using https://github.com/jsha/minica in case
|
||||||
|
# you don't have that installed.
|
||||||
|
(
|
||||||
|
mkcert \
|
||||||
|
--cert-file ./"${domainName}"/cert.pem \
|
||||||
|
--key-file ./"${domainName}"/key.pem \
|
||||||
|
"${domainName}" ||
|
||||||
|
go tool minica -domains "${domainName}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user