Files
api/services/edge-broker/test/config.test.mjs
T

34 lines
2.7 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
const composeSource = readFileSync(new URL("../../../docker-compose.yml", import.meta.url), "utf8");
const composeProdSource = readFileSync(new URL("../../../docker-compose.prod.yml", import.meta.url), "utf8");
const traefikSource = readFileSync(new URL("../../../services/traefik/traefik.yml", import.meta.url), "utf8");
const traefikProdSource = readFileSync(new URL("../../../services/traefik/traefik.prod.yml", import.meta.url), "utf8");
test("traefik does not expose a dedicated public edge broker port", () => {
assert.doesNotMatch(traefikSource, /edge-broker:\s*\n\s*address:\s*":4300"/);
assert.doesNotMatch(traefikProdSource, /edge-broker:\s*\n\s*address:\s*":4300"/);
assert.doesNotMatch(composeSource, /traefik:[\s\S]*ports:[\s\S]*"4300:4300"/);
assert.doesNotMatch(composeProdSource, /ports:[\s\S]*"4300:4300"/);
});
test("edge broker websocket paths are routed through the standard api entrypoints", () => {
assert.match(composeSource, /edge-broker:[\s\S]*traefik\.http\.routers\.edge-broker-dk\.rule=Host\(`api\.truckwash\.dk`\) && \(PathPrefix\(`\/ws\/agent`\) \|\| PathPrefix\(`\/ws\/browser-shell`\)\)/);
assert.match(composeSource, /edge-broker:[\s\S]*traefik\.http\.routers\.edge-broker-dk\.entrypoints=websecure/);
assert.match(composeSource, /edge-broker:[\s\S]*traefik\.http\.routers\.edge-broker-io\.rule=Host\(`api\.truckwash\.io`\) && \(PathPrefix\(`\/ws\/agent`\) \|\| PathPrefix\(`\/ws\/browser-shell`\)\)/);
assert.match(composeSource, /edge-broker:[\s\S]*traefik\.http\.routers\.edge-broker-io\.entrypoints=websecure/);
assert.match(composeSource, /edge-broker:[\s\S]*traefik\.http\.routers\.edge-broker-staging\.entrypoints=websecure-staging/);
assert.match(composeSource, /edge-broker:[\s\S]*traefik\.http\.routers\.edge-broker-local\.entrypoints=web/);
assert.match(composeSource, /edge-broker:[\s\S]*traefik\.http\.routers\.edge-broker-local-secure\.entrypoints=websecure/);
assert.match(composeSource, /edge-broker:[\s\S]*traefik\.http\.services\.edge-broker\.loadbalancer\.server\.port=4300/);
});
test("php services receive the broker url and shared secret defaults", () => {
assert.match(composeSource, /php1:[\s\S]*EDGE_BROKER_URL:\s*\$\{EDGE_BROKER_URL:-http:\/\/edge-broker:4300\}/);
assert.match(composeSource, /php1:[\s\S]*EDGE_BROKER_SHARED_SECRET:\s*\$\{EDGE_BROKER_SHARED_SECRET:-truckwash-edge-dev\}/);
assert.match(composeSource, /php-staging:[\s\S]*EDGE_BROKER_URL:\s*\$\{EDGE_BROKER_URL:-http:\/\/edge-broker:4300\}/);
assert.match(composeSource, /php-cron:[\s\S]*EDGE_BROKER_SHARED_SECRET:\s*\$\{EDGE_BROKER_SHARED_SECRET:-truckwash-edge-dev\}/);
});