1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env bash
# Full local flow on the Rust stack: hono-plc + atproto-pds, create account,
# write and list a com.nahdig.cve.nvdV2 record, then optionally run the
# vuln-notif binary once against NVD (skipped when NVD is unreachable).
set -euo pipefail
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
REPO_DIR=$(cd "$SCRIPT_DIR/.." && pwd)
PDS_PORT=${PDS_PORT:-4800}
PDS_URL=http://127.0.0.1:$PDS_PORT
PLC_PORT=${PLC_PORT:-2587}
PLC_URL=http://127.0.0.1:$PLC_PORT
NOTIF_TIMEOUT=${NOTIF_TIMEOUT:-120}
VULN_NOTIF_BIN=${VULN_NOTIF_BIN:-$REPO_DIR/target/release/vuln-notif}
HANDLE=${HANDLE:-cve.test}
EMAIL=${EMAIL:-cve@example.com}
PASSWORD=${PASSWORD:-test-password}
COLLECTION=com.nahdig.cve.nvdV2
RKEY=${RKEY:-CVE-2024-3094}
TMP_ROOT=$(mktemp -d "${TMPDIR:-/tmp}/vuln-notif-e2e.XXXXXX")
PLC_STATE=$TMP_ROOT/plc-state
PDS_STATE=$TMP_ROOT/pds-state
PDS_DATA=$TMP_ROOT/pds-data
ACCOUNT_FILE=$TMP_ROOT/account.json
PLC_STARTED=0
PDS_STARTED=0
note() { printf '\n== %s\n' "$*"; }
die() { printf 'FAIL: %s\n' "$*" >&2; exit 1; }
log() { printf '%s\n' "$*" >&2; }
cleanup() {
local rc=$?
set +e
if [ "$PDS_STARTED" = 1 ]; then
STATE_DIR=$PDS_STATE "$SCRIPT_DIR/local_atproto_pds.sh" stop >/dev/null 2>&1
fi
if [ "$PLC_STARTED" = 1 ]; then
STATE_DIR=$PLC_STATE "$SCRIPT_DIR/local_plc.sh" stop >/dev/null 2>&1
fi
if [ "$rc" -ne 0 ] && [ "${KEEP_TMP:-0}" = 1 ]; then
printf '\ncleanup: kept %s for inspection\n' "$TMP_ROOT" >&2
else
rm -rf "$TMP_ROOT"
fi
exit "$rc"
}
trap cleanup EXIT
run_with_timeout() {
local timeout_s=$1 logfile=$2
shift 2
"$@" >"$TMP_ROOT/notif.stdout" 2>"$logfile" &
local pid=$! waited=0
while kill -0 "$pid" 2>/dev/null && [ "$waited" -lt "$timeout_s" ]; do
sleep 1
waited=$((waited + 1))
done
if kill -0 "$pid" 2>/dev/null; then
kill -TERM "$pid" 2>/dev/null || true
wait "$pid" 2>/dev/null || true
return 124
fi
wait "$pid" || return $?
}
note "starting hono-plc on $PLC_URL"
plc_started_url=$(PORT=$PLC_PORT STATE_DIR=$PLC_STATE "$SCRIPT_DIR/local_plc.sh" start) ||
die "local_plc.sh start failed"
PLC_STARTED=1
[ "$plc_started_url" = "$PLC_URL" ] || die "local_plc.sh reported unexpected URL: $plc_started_url"
note "starting atproto-pds on $PDS_URL"
pds_started_url=$(PDS_PORT=$PDS_PORT PLC_URL=$PLC_URL STATE_DIR=$PDS_STATE \
PDS_DATA_DIRECTORY=$PDS_DATA "$SCRIPT_DIR/local_atproto_pds.sh" start) ||
die "local_atproto_pds.sh start failed"
PDS_STARTED=1
[ "$pds_started_url" = "$PDS_URL" ] || die "local_atproto_pds.sh reported unexpected URL: $pds_started_url"
note "confirming health"
health_body=$(curl -fsS --max-time 5 "$PDS_URL/xrpc/_health") || die "PDS health check failed"
printf 'health: %s\n' "$health_body"
note "creating account $HANDLE"
ACCOUNT_FILE=$ACCOUNT_FILE PDS_URL=$PDS_URL PLC_URL=$PLC_URL \
HANDLE=$HANDLE EMAIL=$EMAIL PASSWORD=$PASSWORD \
"$SCRIPT_DIR/create_local_account.sh" >"$TMP_ROOT/account.env" ||
die "create_local_account.sh failed"
DID=$(jq -er '.did' "$ACCOUNT_FILE") || die "account file missing did"
ACCESS_JWT=$(jq -er '.session.accessJwt' "$ACCOUNT_FILE") || die "account file missing session accessJwt"
ATP_APP_PASSWORD=$(jq -er '.app_password' "$ACCOUNT_FILE") || die "account file missing app_password"
export ATP_PDS_URL="$PDS_URL"
export ATP_HANDLE="$HANDLE"
export ATP_APP_PASSWORD
printf 'did: %s\n' "$DID"
note "writing $COLLECTION/$RKEY"
record_payload=$(jq -nc \
--arg repo "$DID" \
--arg collection "$COLLECTION" \
--arg rkey "$RKEY" \
'{repo:$repo,collection:$collection,rkey:$rkey,record:{"$type":$collection,createdAt:"2026-11-11T00:00:00.000Z",id:$rkey,vulnStatus:"Analyzed"}}')
response=$(curl -sS --max-time 15 -X POST \
-H "Authorization: Bearer $ACCESS_JWT" \
-H 'Content-Type: application/json' \
-d "$record_payload" \
-w '\n%{http_code}' \
"$PDS_URL/xrpc/com.atproto.repo.createRecord") || die "createRecord request failed"
status=${response##*$'\n'}
body=${response%$'\n'*}
[ "$status" = 200 ] || die "createRecord HTTP $status: $body"
CREATED_URI=$(jq -er '.uri' <<<"$body") || die "createRecord response missing uri"
jq -e --arg rkey "$RKEY" \
'(.uri | endswith("/" + $rkey)) and (.cid | type == "string")' <<<"$body" >/dev/null ||
die "unexpected createRecord response: $body"
printf 'uri: %s\n' "$CREATED_URI"
note "reading back via listRecords"
list_response=$(curl -sS --max-time 15 -G \
-H "Authorization: Bearer $ACCESS_JWT" \
--data-urlencode "repo=$DID" \
--data-urlencode "collection=$COLLECTION" \
-w '\n%{http_code}' \
"$PDS_URL/xrpc/com.atproto.repo.listRecords") || die "listRecords request failed"
status=${list_response##*$'\n'}
list_body=${list_response%$'\n'*}
[ "$status" = 200 ] || die "listRecords HTTP $status: $list_body"
jq -e --arg rkey "$RKEY" '
(.records | type == "array") and
any(.records[]; (.uri | endswith("/" + $rkey)) and .value.id == $rkey and .value.vulnStatus == "Analyzed")
' <<<"$list_body" >/dev/null || die "readback missing $RKEY: $list_body"
printf 'readback ok: %s record(s)\n' "$(jq '.records | length' <<<"$list_body")"
NOTIF_RESULT=SKIP
if [ ! -x "$VULN_NOTIF_BIN" ]; then
NOTIF_RESULT="SKIP (binary not found: $VULN_NOTIF_BIN)"
elif [ "${SKIP_NOTIF:-0}" = 1 ]; then
NOTIF_RESULT="SKIP (SKIP_NOTIF=1)"
elif ! curl -sS --max-time 8 -o /dev/null \
"https://services.nvd.nist.gov/rest/json/cves/2.0?resultsPerPage=1" 2>/dev/null; then
NOTIF_RESULT="SKIP (NVD unreachable)"
else
note "running vuln-notif --once (timeout ${NOTIF_TIMEOUT}s)"
NOTIF_LOG=$TMP_ROOT/notif.log
set +e
run_with_timeout "$NOTIF_TIMEOUT" "$NOTIF_LOG" "$VULN_NOTIF_BIN" \
--once --limit 5 --initial-lookback-days 1 --cache-db "$TMP_ROOT/cache.db"
notif_rc=$?
set -e
if [ "$notif_rc" -eq 124 ]; then
NOTIF_RESULT="FAIL (timed out after ${NOTIF_TIMEOUT}s)"
elif [ "$notif_rc" -ne 0 ]; then
NOTIF_RESULT="FAIL (exit $notif_rc)"
else
NOTIF_RESULT=PASS
fi
if [ "$NOTIF_RESULT" != PASS ]; then
log "vuln-notif last log lines:"
tail -n 20 "$NOTIF_LOG" >&2 || true
fi
fi
case "$NOTIF_RESULT" in
PASS | SKIP*) printf '\nRESULT: PASS\n' ;;
*)
printf '\nRESULT: FAIL (vuln-notif: %s)\n' "$NOTIF_RESULT" >&2
exit 1
;;
esac
printf ' PDS: %s\n' "$PDS_URL"
printf ' PLC: %s\n' "$PLC_URL"
printf ' Health: %s\n' "$health_body"
printf ' Account: %s (%s)\n' "$HANDLE" "$DID"
printf ' Record: %s\n' "$CREATED_URI"
printf ' vuln-notif: %s\n' "$NOTIF_RESULT"
printf '\nExports for a follow-up script:\n'
printf ' export ATP_PDS_URL=%q\n' "$ATP_PDS_URL"
printf ' export ATP_HANDLE=%q\n' "$ATP_HANDLE"
printf ' export ATP_APP_PASSWORD=%q\n' "$ATP_APP_PASSWORD"