78ef64a / test/webui.sh
diff --git a/test/webui.sh b/test/webui.sh
index fc696c5..bf3138a 100755
--- a/test/webui.sh
+++ b/test/webui.sh
@@ -38,7 +38,10 @@ change=$(git -C "$scratch/source" rev-parse HEAD~2)
root=$(git -C "$scratch/source" rev-parse HEAD~3)
node "$cli" publish --data "$scratch/node" --source "$scratch/source" --branch main --name webui --port "$port" >/dev/null
-node "$cli" serve --data "$scratch/node" --port "$port" >"$scratch/url" &
+author=$(node "$cli" identity --data "$scratch/agent")
+other=$(node "$cli" identity --data "$scratch/peer")
+printf '%s\n%s\n' "$author" "$other" >"$scratch/allowlist"
+node "$cli" serve --data "$scratch/node" --port "$port" --push-allowlist "$scratch/allowlist" >"$scratch/url" &
server=$!
for attempt in 1 2 3 4 5; do
if test -s "$scratch/url"; then break; fi
@@ -53,13 +56,28 @@ const response = await fetch(process.argv[2] + '/feed')
assert.equal(response.status, 200)
assert.match(await response.text(), /No posts yet/)
JS
-author=$(node "$cli" identity --data "$scratch/node")
-other=$(node "$cli" identity --data "$scratch/peer")
-post=$(node "$cli" post --data "$scratch/node" --text 'Hello <script>alert(1)</script>
+post=$(node "$cli" post --data "$scratch/agent" --url "$base" --text 'Hello <script>alert(1)</script>
Second line' |
node -pe 'JSON.parse(require("node:fs").readFileSync(0)).id')
-node "$cli" post --data "$scratch/peer" --reply-to "$post" --text 'Reply from another author' >/dev/null
-cp "$scratch/peer/posts/"* "$scratch/node/posts/"
+node "$cli" post --data "$scratch/peer" --url "$base" --reply-to "$post" --text 'Reply from another author' >/dev/null
+node "$cli" post --data "$scratch/agent" --url "$base" --id "$post" >/dev/null
+test "$(find "$scratch/node/posts" -type f | wc -l | tr -d ' ')" -eq 2
+node "$cli" identity --data "$scratch/outsider" >/dev/null
+if node "$cli" post --data "$scratch/outsider" --url "$base" --text 'Blocked author'; then exit 1; fi
+test "$(find "$scratch/outsider/posts" -type f | wc -l | tr -d ' ')" -eq 1
+
+node --input-type=module - "$base" "$scratch/agent/posts/"* <<'JS'
+import assert from 'node:assert/strict'
+import { readFileSync } from 'node:fs'
+const [, , base, path] = process.argv
+const record = readFileSync(path, 'utf8')
+const submit = body => fetch(base + '/posts', {
+ method: 'POST', headers: { 'Content-Type': 'application/json' }, body
+})
+assert.equal((await submit(record)).status, 200)
+assert.equal((await submit(record.replace('Hello', 'Forged'))).status, 400)
+assert.equal((await submit(' '.repeat(32769))).status, 413)
+JS
if node "$cli" post --data "$scratch/node" --text ' ' >/dev/null 2>&1; then exit 1; fi
if node "$cli" post --data "$scratch/node" --text 'Bad reply' --reply-to 'invalid' >/dev/null 2>&1; then exit 1; fi
@@ -185,6 +203,7 @@ assert.match(liveScript.type, /^text\/javascript/)
assert.match(feed.text, /<h1>ANBot feed<\/h1>/)
assert.doesNotMatch(feed.text, /<style|\sstyle=|<form|ANBot repository|<table/)
assert.match(feed.text, /Hello <script>alert\(1\)<\/script><br>\nSecond line/)
+assert.doesNotMatch(feed.text, /Blocked author|Forged/)
assert.ok(feed.text.includes(`?author=${encodeURIComponent(author)}`))
assert.ok(feed.text.includes(`?post=${encodeURIComponent(post)}`))
assert.ok(feed.text.indexOf('Reply from another author') < feed.text.indexOf('Hello'))
Git ยท Social feed