#!/usr/bin/env sh set -eu root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) work=$(mktemp -d "${TMPDIR:-/tmp}/zds-smoke.XXXXXX") port="${ZDS_SMOKE_PORT:-2585}" db="${work}/zds-smoke.sqlite3" blob_root="${work}/zds-smoke-blobs" log="${work}/zds-smoke.log" base="http://127.0.0.1:${port}" jwt_secret="smoke-jwt-secret" cleanup() { status=$? if [ -n "${server_pid:-}" ]; then kill "$server_pid" 2>/dev/null || true wait "$server_pid" 2>/dev/null || true fi if [ -n "${plc_stub_pid:-}" ]; then kill "$plc_stub_pid" 2>/dev/null || true wait "$plc_stub_pid" 2>/dev/null || true fi if [ "$status" -eq 0 ]; then rm -rf "$work" else echo "Smoke failed; diagnostic files: $work" >&2 fi } trap cleanup EXIT trap 'exit 130' INT trap 'exit 143' TERM cd "$root" rm -f "$db" "$db-wal" "$db-shm" "$log" rm -rf "$blob_root" mkdir -p "$blob_root" if [ "${ZDS_SMOKE_PREBUILT:-0}" != 1 ]; then zig build smoke-build fi # stand-in PLC directory so createAccount genesis never reaches plc.directory; # it also hosts a public OAuth client's metadata so PAR can be exercised, and # stands in for the default appview so proxying never reaches api.bsky.app. plc_port="${ZDS_SMOKE_PLC_PORT:-2586}" client_id="http://127.0.0.1:${plc_port}/oauth-client-metadata.json" uv run --no-project python -c " import json from urllib.parse import unquote from http.server import BaseHTTPRequestHandler, HTTPServer # operations posted per DID, so log/last can serve them back plc_ops = {} # DIDs whose tombstone the directory refuses, to show a failed tombstone keeps the account refuse_tombstone = set() metadata = json.dumps({ 'client_id': '$client_id', 'client_name': 'smoke', 'redirect_uris': ['http://127.0.0.1/callback'], 'scope': 'atproto repo:*', 'grant_types': ['authorization_code', 'refresh_token'], 'response_types': ['code'], 'token_endpoint_auth_method': 'none', 'application_type': 'native', 'dpop_bound_access_tokens': True, }).encode() feed = json.dumps({'feed': [], 'cursor': 'smoke-appview'}).encode() # a DID hosted elsewhere, so service auth from it resolves through this directory remote_did = 'did:plc:smokeremoteissuer' remote_doc = json.dumps({ '@context': ['https://www.w3.org/ns/did/v1'], 'id': remote_did, 'alsoKnownAs': ['at://remote-issuer.test'], 'verificationMethod': [{'id': remote_did + '#atproto', 'type': 'Multikey', 'controller': remote_did, 'publicKeyMultibase': 'zQ3shXjHeiBuRCKmM36cuYnm7YEMzhGnCmCyW92sRJ9pribSF'}], 'service': [{'id': '#atproto_pds', 'type': 'AtprotoPersonalDataServer', 'serviceEndpoint': 'https://pds.remote.example'}], }).encode() class Stub(BaseHTTPRequestHandler): def do_GET(self): if self.path.startswith('/xrpc/app.bsky.feed.getTimeline') and self.headers.get('authorization', '').startswith('Bearer '): if self.headers.get('if-none-match') == '\"smoke-etag\"': self.send_response(304) self.send_header('etag', '\"smoke-etag\"') self.end_headers() return body = b'timeline as text' self.send_response(200) for name, value in (('content-type', 'text/plain; charset=utf-8'), ('content-language', 'en'), ('atproto-repo-rev', '3smokerev'), ('atproto-content-labelers', 'did:plc:labeler'), ('retry-after', '7'), ('vary', 'accept-language'), ('etag', '\"smoke-etag\"'), ('x-upstream-only', 'dropped')): self.send_header(name, value) self.send_header('content-length', str(len(body))) self.end_headers() self.wfile.write(body) return if self.path.startswith('/xrpc/app.bsky.feed.getAuthorFeed') and self.headers.get('authorization', '').startswith('Bearer '): seen = {k.lower(): v for k, v in self.headers.items() if k.lower().startswith('x-atproto-') or k.lower() in ('dpop', 'accept-language', 'atproto-accept-labelers', 'x-bsky-topics')} body = json.dumps({'feed': [], 'cursor': 'smoke-appview', 'forwarded': seen}).encode() elif self.path == '/oauth-client-metadata.json': body = metadata elif unquote(self.path[1:]) == remote_did: body = remote_doc elif self.path.endswith('/log/last') and unquote(self.path[1:-len('/log/last')]) in plc_ops: body = json.dumps(plc_ops[unquote(self.path[1:-len('/log/last')])][-1]).encode() elif self.path.startswith('/_refuse/'): refuse_tombstone.add(unquote(self.path[len('/_refuse/'):])) body = b'{}' elif self.path.startswith('/_ops/'): body = json.dumps(plc_ops.get(unquote(self.path[len('/_ops/'):]), [])).encode() else: self.send_response(404) self.end_headers() return self.send_response(200) self.send_header('content-type', 'application/json') self.send_header('content-length', str(len(body))) self.end_headers() self.wfile.write(body) def do_POST(self): payload = self.rfile.read(int(self.headers.get('content-length', 0))) did = unquote(self.path[1:]) if did.startswith('did:plc:'): op = json.loads(payload) expected = ['*'] if op.get('prev') is not None else None if self.headers.get_all('If-Match') != expected or (expected and did not in plc_ops): self.send_error(412) return if op.get('type') == 'plc_tombstone' and did in refuse_tombstone: refuse_tombstone.discard(did) self.send_response(500) self.end_headers() return plc_ops.setdefault(did, []).append(op) self.send_response(200) self.end_headers() def log_message(self, *args): pass HTTPServer(('127.0.0.1', $plc_port), Stub).serve_forever() " & plc_stub_pid=$! # run the installed binary directly so $! is the server itself; killing the # `zig build run` wrapper orphans zds and leaves the port taken for the next run ZDS_PLC_ROTATION_KEY=1111111111111111111111111111111111111111111111111111111111111111 \ ZDS_MAIL_PROVIDER=outbox \ ZDS_PLC_TOMBSTONE_ON_DELETE=true \ ZDS_PROXY_SERVICE_URL="http://127.0.0.1:${plc_port}" \ ZDS_ALLOW_PRIVATE_FETCH=true ./zig-out/bin/zds \ --host 127.0.0.1 \ --jwt-secret "$jwt_secret" \ --port "$port" \ --db "$db" \ --blobstore-path "$blob_root" \ --public-url "$base" \ --server-did did:web:localhost \ --handle-domains .test \ --invite-required \ --admin-token smoke-admin-token \ --operator-handle smoke-operator.test \ --plc-directory "http://127.0.0.1:${plc_port}" \ >"$log" 2>&1 & server_pid=$! i=0 while [ "$i" -lt 80 ]; do if curl -fsS "$base/xrpc/_health" >/dev/null 2>&1; then break fi i=$((i + 1)) sleep 0.1 done curl -fsS "$base/xrpc/_health" >/dev/null # A normal build must never pick up cached operator drawings implicitly. account_page=$(curl -fsS "$base/account/manage") if printf '%s' "$account_page" | grep -q '/ui/icon?cid='; then echo 'unconfigured build unexpectedly includes custom drawings' >&2 exit 1 fi test "$(curl -sS -o /dev/null -w '%{http_code}' "$base/ui/icon?cid=bafkreidhkabyea5vkonzvfdjvgbinqt76kovuli7hrwqqffx5cx2nf4chi")" = 404 stats_page=$(curl -fsS "$base/stats") printf '%s' "$stats_page" | grep -q '

stats

' printf '%s' "$stats_page" | grep -q 'slowest routes' for range in 1h 24h 7d 30d; do for tab in overview repos accounts; do curl -fsS "$base/stats?tab=$tab&range=$range" | grep -q "href=\"/stats?tab=$tab&range=$range\" aria-current=\"page\"" done done curl -fsS "$base/xrpc/com.atproto.server.describeServer" >/dev/null uv run tools/smoke-firehose-resets.py 127.0.0.1 "$port" uv run tools/smoke-large-bodies.py 127.0.0.1 "$port" # An empty body must reach the socket as a valid pointer: copying zero bytes # gave Zig's placeholder address, which Linux writev rejects, and one request # for an unknown icon took the server down. test "$(curl -sS -o /dev/null -w '%{http_code}' "$base/oauth/client-icon?request_uri=urn:ietf:params:oauth:request_uri:missing")" = "404" curl -fsS "$base/xrpc/_health" >/dev/null # A long OAuth authorize URL plus browser headers must fit (zds#26): the header # block may reach 16 KiB, and past that the answer is 431. header_pad=$(head -c 12000 /dev/zero | tr '\0' a) test "$(curl -sS -o /dev/null -w '%{http_code}' -H "x-pad: $header_pad" "$base/xrpc/_health?q=$(head -c 3000 /dev/zero | tr '\0' b)")" = "200" test "$(curl -sS -o /dev/null -w '%{http_code}' -H "x-pad: ${header_pad}${header_pad}" "$base/xrpc/_health")" = "431" sqlite3 "$db" "insert into accounts (did, handle, email, password_hash, activated_at, email_confirmed_at) values ('did:plc:smoketest', 'smoke.test', 'smoke@test.com', 'password', unixepoch(), unixepoch())" sqlite3 "$db" "insert into oauth_requests (request_id, client_id, redirect_uri, scope, state, code_challenge, code_challenge_method, login_hint, expires_at) values ('smoke-oauth', 'https://client.example/oauth-client.json', 'https://client.example/callback', 'repo:*?action=create blob:*/*', 'state', 'challenge', 'S256', 'smoke.test', unixepoch() + 600)" resolved=$(curl -fsS "$base/xrpc/com.atproto.identity.resolveHandle?handle=smoke.test") printf '%s' "$resolved" | grep -q '"did":"did:plc:smoketest"' well_known=$(curl -fsS -H 'host: smoke.test' "$base/.well-known/atproto-did") test "$well_known" = "did:plc:smoketest" unsupported_well_known_status=$(curl -sS -o "$work/zds-unsupported-handle.txt" -w '%{http_code}' \ -H 'host: smoke.example.com' "$base/.well-known/atproto-did") test "$unsupported_well_known_status" = "404" session=$(curl -fsS -X POST "$base/xrpc/com.atproto.server.createSession" \ -H 'content-type: application/json' \ --data '{"identifier":"smoke.test","password":"password"}') token=$(printf '%s' "$session" | sed -n 's/.*"accessJwt":"\([^"]*\)".*/\1/p') test -n "$token" printf '%s' "$session" | grep -q '"didDoc":' ! printf '%s' "$session" | grep -q '"status":' printf '%s' "$session" | grep -q '"serviceEndpoint":"http://127.0.0.1:' session_did=$(printf '%s' "$session" | jq -r .did) ZDS_SMOKE_TOKEN="$token" uv run tools/smoke-record-size.py "$base" "$db" "$session_did" # Grouped account access uses the same password-session boundary and validates paging. access_page=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/dev.zat.account.listAccess?kind=password&limit=1") printf '%s' "$access_page" | jq -e '.authorized >= 1 and (.groups | length) == 1 and (.connections | length) == 0' >/dev/null access_group=$(printf '%s' "$access_page" | jq -r '.groups[0].key') curl -fsS -G -H "authorization: Bearer $token" --data-urlencode "kind=password" --data-urlencode "group=$access_group" "$base/xrpc/dev.zat.account.listAccess" | jq -e --arg did "$session_did" '.connections | length > 0 and all(.[]; .did == $did)' >/dev/null for query in 'kind=unknown' 'state=unknown' 'cursor=-1' 'cursor=nope' 'limit=0' 'limit=101'; do test "$(curl -sS -o /dev/null -w '%{http_code}' -H "authorization: Bearer $token" "$base/xrpc/dev.zat.account.listAccess?$query")" = 400 done test "$(curl -sS -o /dev/null -w '%{http_code}' "$base/xrpc/dev.zat.account.listAccess")" = 401 # an access token this server signed whose exp has passed must answer 400 # ExpiredToken (the reference PDS's answer, which clients key on to refresh), # while a token that never verified stays 401 InvalidToken. expired_token=$(uv run --no-project python -c " import base64, hashlib, hmac, json, time def b64(b): return base64.urlsafe_b64encode(b).rstrip(b'=').decode() header = b64(json.dumps({'alg': 'HS256', 'typ': 'JWT'}).encode()) now = int(time.time()) payload = b64(json.dumps({'sub': '$session_did', 'scope': 'com.atproto.access', 'iat': now - 7200, 'exp': now - 3600, 'jti': 'zds-smoke-expired'}).encode()) sig = hmac.new(b'$jwt_secret', f'{header}.{payload}'.encode(), hashlib.sha256).digest() print(f'{header}.{payload}.{b64(sig)}') ") expired_body="${work}/zds-smoke-expired.json" expired_status=$(curl -sS -o "$expired_body" -w '%{http_code}' \ -H "authorization: Bearer $expired_token" "$base/xrpc/com.atproto.server.getSession") test "$expired_status" = "400" grep -q '"error":"ExpiredToken"' "$expired_body" garbage_status=$(curl -sS -o "$expired_body" -w '%{http_code}' \ -H "authorization: Bearer ${expired_token}x" "$base/xrpc/com.atproto.server.getSession") test "$garbage_status" = "401" grep -q '"error":"InvalidToken"' "$expired_body" invalid_auth_headers="${work}/zds-smoke-invalid-auth.headers" invalid_auth_body="${work}/zds-smoke-invalid-auth.json" invalid_auth_status=$(curl -sS -D "$invalid_auth_headers" -o "$invalid_auth_body" -w '%{http_code}' \ -H 'authorization: Bearer invalid-token' \ "$base/xrpc/com.atproto.server.getSession") test "$invalid_auth_status" = "401" grep -qi '^www-authenticate: Bearer error="invalid_token", error_description="Token is invalid"' "$invalid_auth_headers" invalid_dpop_status=$(curl -sS -D "$invalid_auth_headers" -o "$invalid_auth_body" -w '%{http_code}' \ -H 'authorization: DPoP invalid-token' \ "$base/xrpc/com.atproto.server.getSession") test "$invalid_dpop_status" = "401" grep -qi '^www-authenticate: DPoP error="invalid_token", error_description="Token is invalid"' "$invalid_auth_headers" grep -qi '^dpop-nonce:' "$invalid_auth_headers" # PAR scope validation must terminate the request: an unregistered scope is a # 400 invalid_scope, never a 201 (a helper once wrote the error and returned # success, and the handler overwrote it with a request_uri). par_body="${work}/zds-smoke-par.json" # the client is native and registers a port-less loopback redirect, so PAR # sending the port it actually bound is the RFC 8252 exception at work; the # path still has to match exactly. par() { par_redirect="${par_redirect:-http://127.0.0.1:${plc_port}/callback}" curl -sS -o "$par_body" -w '%{http_code}' -X POST "$base/oauth/par" \ --data-urlencode "client_id=${par_client:-$client_id}" \ --data-urlencode "redirect_uri=$par_redirect" \ --data-urlencode 'response_type=code' \ --data-urlencode 'code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM' \ --data-urlencode 'code_challenge_method=S256' \ --data-urlencode 'state=x' \ --data-urlencode "scope=$1" } test "$(par_redirect="http://127.0.0.1:${plc_port}/elsewhere" par 'atproto repo:*')" = "400" grep -q 'redirect_uri not registered' "$par_body" test "$(par 'atproto garbage:thing')" = "400" grep -q '"error":"invalid_scope"' "$par_body" test "$(par 'atproto include:com.example.nope')" = "400" grep -q '"error":"invalid_scope"' "$par_body" test "$(par 'atproto transition:generic repo:*')" = "400" grep -q '"error":"invalid_scope"' "$par_body" # a valid scope gets past validation to the DPoP check (no proof was sent) test "$(par 'atproto repo:*')" = "400" grep -q '"error":"use_dpop_nonce"' "$par_body" # the spec's localhost client development exception: an `http://localhost` # client_id (no port) is virtual, so nothing is fetched and its metadata comes # from the query string. Reaching the DPoP check proves metadata, redirect, and # scope all resolved. test "$(par_client='http://localhost?redirect_uri=http%3A%2F%2F127.0.0.1%3A4444%2Fcb&scope=atproto%20repo%3A*' par_redirect='http://127.0.0.1:4444/cb' par 'atproto repo:*')" = "400" grep -q '"error":"use_dpop_nonce"' "$par_body" test "$(par_client='http://localhost' par_redirect='http://127.0.0.1:5199/' par 'atproto')" = "400" grep -q '"error":"use_dpop_nonce"' "$par_body" test "$(par_client='http://localhost?scope=atproto' par_redirect='http://[::1]:5199/' par 'atproto repo:*')" = "400" grep -q '"error":"invalid_scope"' "$par_body" test "$(par_client='http://localhost?redirect_uri=https%3A%2F%2Fevil.example%2F' par_redirect='https://evil.example/' par 'atproto')" = "400" grep -q 'Invalid loopback client_id' "$par_body" test "$(par_client='http://localhost?redirect_uri=http%3A%2F%2Flocalhost%3A4444%2Fcb' par_redirect='http://localhost:4444/cb' par 'atproto')" = "400" grep -q 'Invalid loopback client_id' "$par_body" # a port makes it an ordinary URL client, which has to be fetched test "$(par_client='http://localhost:1' par_redirect='http://127.0.0.1:5199/' par 'atproto')" = "400" grep -q 'Could not fetch client metadata' "$par_body" describe=$(curl -fsS "$base/xrpc/com.atproto.server.describeServer") printf '%s' "$describe" | grep -q '"inviteCodeRequired":true' ! printf '%s' "$describe" | grep -q 'spacesAlpha' missing_invite_status=$(curl -sS -o "$work/zds-missing-invite.json" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.server.createAccount" \ -H 'content-type: application/json' \ --data '{"handle":"missing-invite.test","email":"missing-invite@test.com","password":"password"}') test "$missing_invite_status" = "400" grep -q '"error":"InvalidInviteCode"' "$work/zds-missing-invite.json" invite=$(curl -fsS -X POST "$base/xrpc/com.atproto.server.createInviteCode" \ -H "authorization: Bearer smoke-admin-token" \ -H 'content-type: application/json' \ --data '{"useCount":1,"forAccount":"did:plc:smoketest"}') printf '%s' "$invite" | grep -q '"code":"127-0-0-1-' invites=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.server.getAccountInviteCodes") printf '%s' "$invites" | grep -q '"available":1' signup_page=$(curl -fsS "$base/signup") for page in / /account /signup /api /stats /admin/sessions; do page_headers=$(curl -fsS -D - -o /dev/null "$base$page" | tr -d '\r') printf '%s' "$page_headers" | grep -qi "^content-security-policy: default-src 'self';.*connect-src 'self';.*frame-ancestors 'none'" printf '%s' "$page_headers" | grep -qi '^x-frame-options: DENY' printf '%s' "$page_headers" | grep -qi '^x-content-type-options: nosniff' printf '%s' "$page_headers" | grep -qi '^referrer-policy: no-referrer' done uv run tools/smoke-csp.py "$base" / /account /signup /api /stats /admin/sessions printf '%s' "$signup_page" | grep -q 'join zds' printf '%s' "$signup_page" | grep -q 'com.atproto.server.describeServer' printf '%s' "$signup_page" | grep -q 'com.atproto.server.createAccount' printf '%s' "$signup_page" | grep -q 'DM /dev/null test "$(refresh_session "$app_refresh" "$refresh_body")" = "400" grep -q '"error":"ExpiredToken"' "$refresh_body" # deleteSession signs out: it takes the refresh token, not the access token, # and afterwards neither token of that session works logout_session=$(curl -fsS -X POST "$base/xrpc/com.atproto.server.createSession" \ -H 'content-type: application/json' \ --data '{"identifier":"signup-smoke.test","password":"signup-password"}') logout_access=$(printf '%s' "$logout_session" | jq -r .accessJwt) logout_refresh=$(printf '%s' "$logout_session" | jq -r .refreshJwt) logout_body="${work}/zds-smoke-logout.json" test "$(curl -sS -o "$logout_body" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.server.deleteSession" -H "authorization: Bearer $logout_access")" = "400" grep -q '"error":"InvalidToken"' "$logout_body" test "$(curl -sS -o "$logout_body" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.server.deleteSession" -H "authorization: Bearer $logout_refresh")" = "200" test "$(refresh_session "$logout_refresh" "$refresh_body")" = "400" grep -q '"error":"ExpiredToken"' "$refresh_body" test "$(curl -sS -o /dev/null -w '%{http_code}' -H "authorization: Bearer $logout_access" "$base/xrpc/com.atproto.server.getSession")" != "200" curl -fsS -H "authorization: Bearer $signup_access" "$base/xrpc/com.atproto.server.getSession" >/dev/null # The outbox provider keeps mail for dev.zat.admin.listMail, and an emailed code # authorizes only the purpose it was sent for. outbox_code() { curl -fsS -G -H 'authorization: Bearer smoke-admin-token' --data-urlencode "to=$1" "$base/xrpc/dev.zat.admin.listMail" \ | jq -er --arg subject "$2" '[.messages[] | select(.subject == $subject)][0].code' } test "$(curl -sS -o /dev/null -w '%{http_code}' "$base/xrpc/dev.zat.admin.listMail")" = "401" curl -fsS -X POST -H "authorization: Bearer $signup_access" "$base/xrpc/com.atproto.server.requestEmailConfirmation" >/dev/null confirm_code=$(outbox_code signup-smoke@test.com 'Confirm email') code_body="${work}/zds-smoke-code.json" test "$(curl -sS -o "$code_body" -w '%{http_code}' -X POST -H "authorization: Bearer $signup_access" -H 'content-type: application/json' \ --data "$(jq -nc --arg token "$confirm_code" '{token:$token}')" "$base/xrpc/com.atproto.identity.signPlcOperation")" = "400" grep -q '"error":"InvalidToken"' "$code_body" curl -fsS -X POST -H "authorization: Bearer $signup_access" -H 'content-type: application/json' \ --data "$(jq -nc --arg token "$confirm_code" '{email:"signup-smoke@test.com",token:$token}')" "$base/xrpc/com.atproto.server.confirmEmail" >/dev/null curl -fsS -H "authorization: Bearer $signup_access" "$base/xrpc/com.atproto.server.getSession" | jq -e '.emailConfirmed == true' >/dev/null curl -fsS -X POST -H "authorization: Bearer $signup_access" "$base/xrpc/com.atproto.identity.requestPlcOperationSignature" >/dev/null plc_code=$(outbox_code signup-smoke@test.com 'PLC operation') test "$plc_code" != "$confirm_code" signed_plc_update=$(curl -fsS -X POST -H "authorization: Bearer $signup_access" -H 'content-type: application/json' \ --data "$(jq -nc --arg token "$plc_code" '{token:$token}')" "$base/xrpc/com.atproto.identity.signPlcOperation") printf '%s' "$signed_plc_update" | jq -e '.operation.type == "plc_operation" and (.operation.sig | length) > 0' >/dev/null curl -fsS -X POST -H "authorization: Bearer $signup_access" -H 'content-type: application/json' \ --data "$signed_plc_update" "$base/xrpc/com.atproto.identity.submitPlcOperation" >/dev/null # Self-delete, as the reference PDS does: requestAccountDelete emails a # delete_account code, and deleteAccount takes the DID, password, and code. delete_invite=$(curl -fsS -X POST "$base/xrpc/com.atproto.server.createInviteCode" \ -H "authorization: Bearer smoke-admin-token" -H 'content-type: application/json' --data '{"useCount":1}' | jq -r .code) doomed=$(curl -fsS -X POST "$base/xrpc/com.atproto.server.createAccount" -H 'content-type: application/json' \ --data "$(jq -nc --arg invite "$delete_invite" '{handle:"delete-smoke.test",email:"delete-smoke@test.com",password:"delete-password",inviteCode:$invite}')") doomed_did=$(printf '%s' "$doomed" | jq -r .did) doomed_access=$(printf '%s' "$doomed" | jq -r .accessJwt) delete_body="${work}/zds-smoke-delete.json" delete_account() { curl -sS -o "$delete_body" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.server.deleteAccount" -H 'content-type: application/json' \ --data "$(jq -nc --arg did "$doomed_did" --arg password "$1" --arg token "$2" '{did:$did,password:$password,token:$token}')" } test "$(curl -sS -o /dev/null -w '%{http_code}' -X POST "$base/xrpc/com.atproto.server.requestAccountDelete")" = "401" curl -fsS -X POST -H "authorization: Bearer $doomed_access" "$base/xrpc/com.atproto.identity.requestPlcOperationSignature" >/dev/null wrong_purpose=$(outbox_code delete-smoke@test.com 'PLC operation') curl -fsS -X POST -H "authorization: Bearer $doomed_access" "$base/xrpc/com.atproto.server.requestAccountDelete" >/dev/null delete_code=$(outbox_code delete-smoke@test.com 'Delete account') test "$(delete_account wrong-password "$delete_code")" = "401" grep -q '"error":"AuthenticationRequired"' "$delete_body" test "$(delete_account delete-password "$wrong_purpose")" = "400" grep -q '"error":"InvalidToken"' "$delete_body" test "$(delete_account delete-password "$delete_code")" = "200" test "$(curl -sS -o /dev/null -w '%{http_code}' "$base/xrpc/com.atproto.sync.getRepoStatus?did=$doomed_did")" != "200" test "$(curl -sS -o /dev/null -w '%{http_code}' -X POST "$base/xrpc/com.atproto.server.createSession" -H 'content-type: application/json' \ --data '{"identifier":"delete-smoke.test","password":"delete-password"}')" = "401" test "$(delete_account delete-password "$delete_code")" = "400" grep -q 'account not found' "$delete_body" test "$(sqlite3 "$db" "select count(*) from seq_events where did = '$doomed_did'")" = "1" # With ZDS_PLC_TOMBSTONE_ON_DELETE the DID is tombstoned, after its genesis. curl -fsS "http://127.0.0.1:${plc_port}/_ops/${doomed_did}" \ | jq -e 'length == 2 and .[0].type == "plc_operation" and .[1].type == "plc_tombstone" and (.[1].prev | startswith("bafyrei")) and (.[1].sig | length) > 0 and (.[1] | keys) == ["prev", "sig", "type"]' >/dev/null # A tombstone the directory refuses leaves the account in place to delete again. kept_invite=$(curl -fsS -X POST "$base/xrpc/com.atproto.server.createInviteCode" \ -H "authorization: Bearer smoke-admin-token" -H 'content-type: application/json' --data '{"useCount":1}' | jq -r .code) kept_did=$(curl -fsS -X POST "$base/xrpc/com.atproto.server.createAccount" -H 'content-type: application/json' \ --data "$(jq -nc --arg invite "$kept_invite" '{handle:"keep-smoke.test",email:"keep-smoke@test.com",password:"keep-password",inviteCode:$invite}')" | jq -r .did) curl -fsS "http://127.0.0.1:${plc_port}/_refuse/${kept_did}" >/dev/null admin_delete_body="${work}/zds-smoke-admin-delete.json" test "$(curl -sS -o "$admin_delete_body" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.admin.deleteAccount" \ -H 'authorization: Bearer smoke-admin-token' -H 'content-type: application/json' --data "$(jq -nc --arg did "$kept_did" '{did:$did}')")" = "502" grep -q '"error":"UpstreamFailure"' "$admin_delete_body" curl -fsS "$base/xrpc/com.atproto.sync.getRepoStatus?did=$kept_did" | jq -e '.active == true' >/dev/null curl -fsS -X POST "$base/xrpc/com.atproto.admin.deleteAccount" \ -H 'authorization: Bearer smoke-admin-token' -H 'content-type: application/json' --data "$(jq -nc --arg did "$kept_did" '{did:$did}')" >/dev/null curl -fsS "http://127.0.0.1:${plc_port}/_ops/${kept_did}" | jq -e '.[-1].type == "plc_tombstone"' >/dev/null # Migrating in an existing DID resolves its service auth issuer through the # configured PLC directory: the stub serves this DID's document, so a bad # signature is refused as InvalidToken rather than as a resolution failure. remote_invite=$(curl -fsS -X POST "$base/xrpc/com.atproto.server.createInviteCode" \ -H "authorization: Bearer smoke-admin-token" -H 'content-type: application/json' --data '{"useCount":1}' | jq -r .code) remote_auth=$(uv run --no-project python -c " import base64, json, time b64 = lambda raw: base64.urlsafe_b64encode(raw).rstrip(b'=').decode() header = b64(json.dumps({'typ': 'JWT', 'alg': 'ES256K'}).encode()) payload = b64(json.dumps({'iss': 'did:plc:smokeremoteissuer', 'aud': 'did:web:localhost', 'lxm': 'com.atproto.server.createAccount', 'exp': int(time.time()) + 60}).encode()) print(header + '.' + payload + '.' + b64(bytes(64))) ") remote_body="${work}/zds-smoke-remote-issuer.json" test "$(curl -sS -o "$remote_body" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.server.createAccount" \ -H "authorization: Bearer $remote_auth" -H 'content-type: application/json' \ --data "$(jq -nc --arg invite "$remote_invite" '{handle:"remote-issuer.test",email:"remote-issuer@test.com",password:"remote-password",did:"did:plc:smokeremoteissuer",inviteCode:$invite}')")" = "401" jq -e '.error == "InvalidToken"' "$remote_body" >/dev/null # a new account must be announced on the firehose immediately: identity, # account, genesis commit, and sync events plus a servable empty repo genesis=$(curl -fsS "$base/xrpc/com.atproto.sync.getLatestCommit?did=$signup_did") printf '%s' "$genesis" | grep -q '"cid":' printf '%s' "$genesis" | grep -q '"rev":' curl -fsS "$base/xrpc/com.atproto.sync.getRepo?did=$signup_did" -o "$work/zds-signup-genesis.car" # getBlocks returns the requested blocks as a rootless CAR, and names the CIDs # it doesn't hold the way the reference PDS does genesis_cid=$(printf '%s' "$genesis" | jq -r .cid) curl -fsS "$base/xrpc/com.atproto.sync.getBlocks?did=$signup_did&cids=$genesis_cid" -o "$work/zds-blocks.car" uv run --no-project python - "$work/zds-blocks.car" "$genesis_cid" <<'PY' import base64, sys data = open(sys.argv[1], 'rb').read() def varint(b, i): n = s = 0 while True: n |= (b[i] & 0x7f) << s; i += 1 if b[i - 1] < 0x80: return n, i s += 7 hlen, i = varint(data, 0) assert data[i:i + hlen] == bytes.fromhex('a265726f6f7473806776657273696f6e01'), data[i:i + hlen] i += hlen blen, i = varint(data, i) cid = base64.b32decode(sys.argv[2][1:].upper() + '=' * (-len(sys.argv[2][1:]) % 8)) assert data[i:i + len(cid)] == cid assert i + blen == len(data) PY missing_cid=bafyreih6ce5bdeftdgnbl5owctbxyokmo6t3lsxwrhgpklu4mtjhzt6zlm blocks_body="$work/zds-blocks.json" test "$(curl -sS -o "$blocks_body" -w '%{http_code}' "$base/xrpc/com.atproto.sync.getBlocks?did=$signup_did&cids=$genesis_cid&cids=$missing_cid")" = "400" grep -q "Could not find cids: $missing_cid" "$blocks_body" test "$(curl -sS -o /dev/null -w '%{http_code}' "$base/xrpc/com.atproto.sync.getBlocks?did=$signup_did&cids=nope")" = "400" test "$(curl -sS -o /dev/null -w '%{http_code}' "$base/xrpc/com.atproto.sync.getBlocks?did=$signup_did")" = "400" # A cursor past the head gets one FutureCursor error frame and a close, as the # reference PDS does, instead of a silent open stream (issue 25). # Fifty in a row: the stream thread must leave the socket to its reader, which # a debug build turns into a crash when it doesn't. node -e ' const once = () => new Promise((resolve, reject) => { const ws = new WebSocket(process.argv[1]); ws.binaryType = "arraybuffer"; const frames = []; const timer = setTimeout(() => reject(new Error("FutureCursor: stream stayed open")), 5000); ws.onmessage = (event) => frames.push(Buffer.from(event.data)); ws.onclose = (event) => { clearTimeout(timer); const text = Buffer.concat(frames).toString("latin1"); if (frames.length !== 1 || !text.includes("FutureCursor") || event.code !== 1008) reject(new Error(`FutureCursor frames=${frames.length} code=${event.code} ${text}`)); else resolve(); }; }); (async () => { for (let i = 0; i < 50; i++) await once(); })().catch((err) => { console.error(err.message); process.exit(1); }); ' "ws://127.0.0.1:${port}/xrpc/com.atproto.sync.subscribeRepos?cursor=999999999" curl -fsS "$base/xrpc/_health" >/dev/null # Subscribers that hang up mid-backfill, four at a time (the backfill limit): # close waits for each stream thread, so a stalled teardown times out here. node -e ' const once = () => new Promise((resolve, reject) => { const ws = new WebSocket(process.argv[1]); const timer = setTimeout(() => reject(new Error("subscribeRepos: no frame or close")), 5000); ws.onmessage = () => ws.close(); ws.onclose = () => { clearTimeout(timer); resolve(); }; ws.onerror = () => {}; }); (async () => { for (let round = 0; round < 25; round++) await Promise.all(Array.from({ length: 4 }, once)); })().catch((err) => { console.error(err.message); process.exit(1); }); ' "ws://127.0.0.1:${port}/xrpc/com.atproto.sync.subscribeRepos?cursor=0" curl -fsS --max-time 5 "$base/xrpc/_health" >/dev/null test -s "$work/zds-signup-genesis.car" signup_events=$(sqlite3 "$db" "select count(*) from seq_events where did = '$signup_did'") test "$signup_events" = "4" signup_taken_invite=$(curl -fsS -X POST "$base/xrpc/com.atproto.server.createInviteCode" \ -H "authorization: Bearer smoke-admin-token" \ -H 'content-type: application/json' \ --data '{"useCount":1}' | jq -r .code) signup_taken_status=$(curl -sS -o "$work/zds-signup-taken.json" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.server.createAccount" \ -H 'content-type: application/json' \ --data "$(printf '{"handle":"signup-smoke.test","email":"signup-smoke-2@test.com","password":"signup-password","inviteCode":"%s"}' "$signup_taken_invite")") test "$signup_taken_status" = "400" ! grep -q '"error":"InvalidInviteCode"' "$work/zds-signup-taken.json" grep -q '"error":' "$work/zds-signup-taken.json" curl -fsS -X POST "$base/xrpc/app.bsky.actor.putPreferences" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data '{"preferences":[{"$type":"app.bsky.actor.defs#contentLabelPref","label":"dogs","visibility":"show"},{"$type":"app.bsky.actor.defs#contentLabelPref","label":"cats","visibility":"warn"},{"$type":"app.bsky.actor.defs#personalDetailsPref","birthDate":"1970-01-01"},{"$type":"app.bsky.actor.defs#declaredAgePref","isOverAge13":false,"isOverAge16":false,"isOverAge18":false}]}' >/dev/null prefs=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/app.bsky.actor.getPreferences") printf '%s' "$prefs" | grep -q '"label":"dogs"' printf '%s' "$prefs" | grep -q '"label":"cats"' printf '%s' "$prefs" | grep -q '"birthDate":"1970-01-01"' printf '%s' "$prefs" | grep -q '"isOverAge13":true' printf '%s' "$prefs" | grep -q '"isOverAge16":true' printf '%s' "$prefs" | grep -q '"isOverAge18":true' test "$(printf '%s' "$prefs" | grep -o 'declaredAgePref' | wc -l | tr -d ' ')" = "1" create=$(curl -fsS -X POST "$base/xrpc/com.atproto.repo.createRecord" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data '{"repo":"did:plc:smoketest","collection":"app.bsky.feed.post","record":{"$type":"app.bsky.feed.post","text":"smoke","createdAt":"2026-05-22T00:00:00.000Z"}}') printf '%s' "$create" | grep -q '"uri":"at://did:plc:smoketest/app.bsky.feed.post/' printf '%s' "$create" | grep -q '"validationStatus":"valid"' post_uri=$(printf '%s' "$create" | jq -r .uri) post_cid=$(printf '%s' "$create" | jq -r .cid) test -n "$post_cid" post_rkey=$(printf '%s' "$create" | jq -r '.uri | split("/")[-1]') uv run tools/smoke-repo-memory.py "$base" "$server_pid" did:plc:smoketest app.bsky.feed.post "$post_rkey" "$post_cid" # sync.getRecord serves a proof CAR (commit + mst path + record); strict OAuth # lexicon resolvers depend on it and previously got 404 UnknownMethod proof_car="$work/zds-record-proof.car" proof_status=$(curl -sS -o "$proof_car" -w '%{http_code}' "$base/xrpc/com.atproto.sync.getRecord?did=did:plc:smoketest&collection=app.bsky.feed.post&rkey=$post_rkey") test "$proof_status" = "200" test -s "$proof_car" proof_type=$(curl -sS -o /dev/null -w '%{content_type}' "$base/xrpc/com.atproto.sync.getRecord?did=did:plc:smoketest&collection=app.bsky.feed.post&rkey=$post_rkey") test "$proof_type" = "application/vnd.ipld.car" proof_head=$(curl -sSI -o /dev/null -w '%{http_code}' "$base/xrpc/com.atproto.sync.getRecord?did=did:plc:smoketest&collection=app.bsky.feed.post&rkey=$post_rkey") test "$proof_head" = "200" # exclusion proof for an absent rkey is still a 200 CAR exclusion_status=$(curl -sS -o "$proof_car" -w '%{http_code}' "$base/xrpc/com.atproto.sync.getRecord?did=did:plc:smoketest&collection=app.bsky.feed.post&rkey=3zdsnosuchrkey") test "$exclusion_status" = "200" test -s "$proof_car" proof_missing_repo=$(curl -sS -o /dev/null -w '%{http_code}' "$base/xrpc/com.atproto.sync.getRecord?did=did:plc:nobody&collection=app.bsky.feed.post&rkey=$post_rkey") test "$proof_missing_repo" = "404" like=$(curl -fsS -X POST "$base/xrpc/com.atproto.repo.createRecord" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data "$(printf '{"repo":"did:plc:smoketest","collection":"app.bsky.feed.like","record":{"$type":"app.bsky.feed.like","subject":{"uri":"%s","cid":"%s"},"createdAt":"2026-05-22T00:00:01.000Z"}}' "$post_uri" "$post_cid")") printf '%s' "$like" | grep -q '"uri":"at://did:plc:smoketest/app.bsky.feed.like/' printf '%s' "$like" | grep -q '"validationStatus":"valid"' like_rkey=$(printf '%s' "$like" | jq -r '.uri | split("/")[-1]') test "$(printf '%s' "$like_rkey" | wc -c | tr -d ' ')" = "13" case "$like_rkey" in 3zds*) echo "generated app.bsky.feed.like rkey is not a TID: $like_rkey" >&2 exit 1 ;; esac invalid_like_status=$(curl -sS -o "$work/zds-invalid-like.json" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.repo.createRecord" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data "$(printf '{"repo":"did:plc:smoketest","collection":"app.bsky.feed.like","rkey":"3zdsbad","record":{"$type":"app.bsky.feed.like","subject":{"uri":"%s","cid":"%s"},"createdAt":"2026-05-22T00:00:02.000Z"}}' "$post_uri" "$post_cid")") test "$invalid_like_status" = "400" grep -q '"error":"InvalidRequest"' "$work/zds-invalid-like.json" # a record without $type is stored as its collection, as the reference PDS # does (Grain's iOS app writes favorites this way); a $type naming another # collection is still refused untyped=$(curl -fsS -X POST "$base/xrpc/com.atproto.repo.createRecord" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data '{"repo":"did:plc:smoketest","collection":"social.grain.favorite","record":{"subject":"at://did:plc:smoketest/social.grain.gallery/3zdsgallery","createdAt":"2026-05-22T00:00:02.500Z"}}') untyped_rkey=$(printf '%s' "$untyped" | jq -r '.uri | split("/")[-1]') curl -fsS "$base/xrpc/com.atproto.repo.getRecord?repo=did:plc:smoketest&collection=social.grain.favorite&rkey=$untyped_rkey" \ | jq -e '.value."$type" == "social.grain.favorite"' >/dev/null mismatched_status=$(curl -sS -o "$work/zds-mismatched-type.json" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.repo.createRecord" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data '{"repo":"did:plc:smoketest","collection":"social.grain.favorite","record":{"$type":"app.bsky.feed.like","createdAt":"2026-05-22T00:00:02.600Z"}}') test "$mismatched_status" = "400" # a guard that writes an xrpc error must end the request. requireRepoMatches # once wrote 400 and returned success, and createRecord went on to write the # record and answer 200 over it. wrong_repo_body="${work}/zds-smoke-wrong-repo.json" wrong_repo_status=$(curl -sS -o "$wrong_repo_body" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.repo.createRecord" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data '{"repo":"did:plc:someoneelse","collection":"app.bsky.feed.post","record":{"$type":"app.bsky.feed.post","text":"must not land","createdAt":"2026-05-22T00:00:03.000Z"}}') test "$wrong_repo_status" = "400" grep -q '"error":"InvalidRepo"' "$wrong_repo_body" ! curl -fsS "$base/xrpc/com.atproto.repo.listRecords?repo=did:plc:smoketest&collection=app.bsky.feed.post&limit=10" | grep -q 'must not land' # getRecord not-found answers match the reference PDS: 400 for a repo this PDS # does not host, and 400 RecordNotFound for a missing record, which clients # such as Germ's sign-in treat as "no record yet" missing_repo_status=$(curl -sS -o "$wrong_repo_body" -w '%{http_code}' "$base/xrpc/com.atproto.repo.getRecord?repo=did:plc:nobody&collection=app.bsky.feed.post&rkey=3zds") test "$missing_repo_status" = "400" grep -q '"error":"InvalidRequest"' "$wrong_repo_body" missing_record_status=$(curl -sS -o "$wrong_repo_body" -w '%{http_code}' "$base/xrpc/com.atproto.repo.getRecord?repo=did:plc:smoketest&collection=com.germnetwork.declaration&rkey=self") test "$missing_record_status" = "400" jq -e '.error == "RecordNotFound" and .message == "Could not locate record: at://did:plc:smoketest/com.germnetwork.declaration/self"' "$wrong_repo_body" >/dev/null # the xrpc proxy path bypasses dispatch, so its HandledResponse must be caught # there too: a bad token on a proxied method is a 401 InvalidToken json body, # never a plain-text 500 (the top-level handler once overwrote it). proxy_body="${work}/zds-smoke-proxy.json" proxy_status=$(curl -sS -o "$proxy_body" -w '%{http_code}' -X POST "$base/xrpc/app.bsky.notification.updateSeen" \ -H "authorization: Bearer not-a-real-token" \ -H 'atproto-proxy: did:web:api.bsky.app#bsky_appview' \ -H 'content-type: application/json' \ --data '{"seenAt":"2026-05-22T00:00:03.000Z"}') test "$proxy_status" = "401" grep -q '"error":"InvalidToken"' "$proxy_body" # clients such as Bridgy call app.bsky.* on the PDS without an atproto-proxy # header; like the reference PDS, those go to the configured appview instead # of 404 UnknownMethod, and still require the caller's own session. default_proxy_status=$(curl -sS -o "$proxy_body" -w '%{http_code}' "$base/xrpc/app.bsky.feed.getAuthorFeed?actor=did:plc:smoketest&limit=30" \ -H "authorization: Bearer $token") test "$default_proxy_status" = "200" test "$(jq -r .cursor "$proxy_body")" = "smoke-appview" default_proxy_status=$(curl -sS -o "$proxy_body" -w '%{http_code}' "$base/xrpc/app.bsky.feed.getAuthorFeed?actor=did:plc:smoketest&limit=30" \ -H "authorization: Bearer $token" -H 'X-Atproto-Bsky-Topics: smoke' -H 'atproto-accept-labelers: did:plc:labeler' \ -H 'accept-language: en' -H 'dpop: not-for-the-appview' -H 'x-other: dropped') test "$default_proxy_status" = "200" test "$(jq -cS .forwarded "$proxy_body")" = '{"accept-language":"en","atproto-accept-labelers":"did:plc:labeler","x-atproto-bsky-topics":"smoke"}' # the Bluesky app's feed requests carry more headers than the proxy client once # had room for; every one reaches the appview, as with the reference PDS. default_proxy_status=$(curl -sS -o "$proxy_body" -w '%{http_code}' "$base/xrpc/app.bsky.feed.getAuthorFeed?actor=did:plc:smoketest&limit=30" \ -H "authorization: Bearer $token" -H 'accept-language: en' -H 'atproto-accept-labelers: did:plc:labeler' \ -H 'x-bsky-topics: smoke' -H 'x-atproto-bsky-topics: smoke' -H 'x-atproto-bsky-platform: ios' \ -H 'x-atproto-device-id: device' -H 'x-atproto-session-id: session' -H 'x-atproto-bsky-geo-ip: 192.0.2.1' \ -H 'x-atproto-bsky-geo-country: US' -H 'x-atproto-bsky-geo-region: IL' -H 'x-atproto-bsky-geo-city: Chicago') test "$default_proxy_status" = "200" test "$(jq -c '.forwarded | length' "$proxy_body")" = "11" # the service's content type and the reference's forwarded response headers # come back, and a conditional request passes through to a bodyless 304 proxy_headers="${work}/zds-smoke-proxy-headers.txt" default_proxy_status=$(curl -sS -D "$proxy_headers" -o "$proxy_body" -w '%{http_code}' "$base/xrpc/app.bsky.feed.getTimeline" \ -H "authorization: Bearer $token") test "$default_proxy_status" = "200" test "$(cat "$proxy_body")" = "timeline as text" for header in 'content-type: text/plain; charset=utf-8' 'content-language: en' 'atproto-repo-rev: 3smokerev' \ 'atproto-content-labelers: did:plc:labeler' 'retry-after: 7' 'vary: accept-language' 'etag: "smoke-etag"'; do tr -d '\r' < "$proxy_headers" | grep -qix "$header" done test -z "$(grep -i '^x-upstream-only' "$proxy_headers")" rm -f "$proxy_body" default_proxy_status=$(curl -sS -D "$proxy_headers" -o "$proxy_body" -w '%{http_code}' "$base/xrpc/app.bsky.feed.getTimeline" \ -H "authorization: Bearer $token" -H 'if-none-match: "smoke-etag"') test "$default_proxy_status" = "304" test ! -s "$proxy_body" tr -d '\r' < "$proxy_headers" | grep -qix 'etag: "smoke-etag"' default_proxy_status=$(curl -sS -o "$proxy_body" -w '%{http_code}' "$base/xrpc/app.bsky.feed.getAuthorFeed?actor=did:plc:smoketest&limit=30") test "$default_proxy_status" = "401" grep -q '"error":"AuthenticationRequired"' "$proxy_body" default_proxy_status=$(curl -sS -o "$proxy_body" -w '%{http_code}' "$base/xrpc/com.example.noSuchMethod" \ -H "authorization: Bearer $token") test "$default_proxy_status" = "404" grep -q '"error":"UnknownMethod"' "$proxy_body" records=$(curl -fsS "$base/xrpc/com.atproto.repo.listRecords?repo=did:plc:smoketest&collection=app.bsky.feed.post&limit=10") printf '%s' "$records" | grep -q '"text":"smoke"' latest=$(curl -fsS "$base/xrpc/com.atproto.sync.getLatestCommit?did=did:plc:smoketest") printf '%s' "$latest" | grep -q '"cid":"' printf '%s' "$latest" | grep -q '"rev":"' repo_car="${work}/zds-smoke.car" code=$(curl -sS -o "$repo_car" -w '%{http_code}' "$base/xrpc/com.atproto.sync.getRepo?did=did:plc:smoketest") test "$code" = "200" test "$(wc -c < "$repo_car")" -gt 100 repo_head=$(curl -sSI -o /dev/null -w '%{http_code}' "$base/xrpc/com.atproto.sync.getRepo?did=did:plc:smoketest") test "$repo_head" = "200" # Sync reads carry the head commit as a weak ETag and answer 304 to it. latest_cid=$(printf '%s' "$latest" | jq -r .cid) repo_etag=$(curl -sS -D - -o /dev/null "$base/xrpc/com.atproto.sync.getRepo?did=did:plc:smoketest" | tr -d '\r' | sed -n 's/^etag: //Ip') test "$repo_etag" = "W/\"$latest_cid\"" for sync_url in \ "$base/xrpc/com.atproto.sync.getRepo?did=did:plc:smoketest" \ "$base/xrpc/com.atproto.sync.getRepo?did=did:plc:smoketest&since=$(printf '%s' "$latest" | jq -r .rev)" \ "$base/xrpc/com.atproto.sync.getLatestCommit?did=did:plc:smoketest" \ "$base/xrpc/com.atproto.sync.getRecord?did=did:plc:smoketest&collection=app.bsky.feed.post&rkey=nope"; do test "$(curl -sS -o /dev/null -w '%{http_code}' -H "if-none-match: $repo_etag" "$sync_url")" = "304" test "$(curl -sS -o /dev/null -w '%{http_code}' -H 'if-none-match: W/"bafystale"' "$sync_url")" = "200" done blob_payload="${work}/zds-smoke-blob.jpg" printf '\377\330\377\340zds-smoke' > "$blob_payload" blob=$(curl -fsS -X POST "$base/xrpc/com.atproto.repo.uploadBlob" \ -H "authorization: Bearer $token" \ -H 'content-type: image/jpeg' \ --data-binary "@$blob_payload") printf '%s' "$blob" | grep -q '"blob":' printf '%s' "$blob" | grep -q '"mimeType":"image/jpeg"' blob_cid=$(printf '%s' "$blob" | sed -n 's/.*"\$link":"\([^"]*\)".*/\1/p') test -n "$blob_cid" blob_head=$(curl -sSI -o /dev/null -w '%{http_code}' "$base/xrpc/com.atproto.sync.getBlob?did=did:plc:smoketest&cid=$blob_cid") test "$blob_head" = "404" blob_ref=$(curl -fsS -X POST "$base/xrpc/com.atproto.repo.createRecord" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg cid "$blob_cid" '{repo:"did:plc:smoketest",collection:"dev.zds.smoke.blob",record:{"$type":"dev.zds.smoke.blob",blob:{"$type":"blob",ref:{"$link":$cid},mimeType:"image/jpeg",size:13}}}')") printf '%s' "$blob_ref" | grep -q '"uri":"at://did:plc:smoketest/dev.zds.smoke.blob/' # A write moves the repo on: the cached full export is not served for it. moved_car="${work}/zds-smoke-moved.car" moved_etag=$(curl -sS -D - -o "$moved_car" "$base/xrpc/com.atproto.sync.getRepo?did=did:plc:smoketest" | tr -d '\r' | sed -n 's/^etag: //Ip') test "$moved_etag" = "W/\"$(curl -fsS "$base/xrpc/com.atproto.sync.getLatestCommit?did=did:plc:smoketest" | jq -r .cid)\"" test "$moved_etag" != "$repo_etag" # cksum, not cmp: the CI image has coreutils but not diffutils. test "$(cksum < "$repo_car")" != "$(cksum < "$moved_car")" test "$(curl -fsS "$base/xrpc/com.atproto.sync.getRepo?did=did:plc:smoketest" | cksum)" = "$(cksum < "$moved_car")" blob_head=$(curl -sSI -o /dev/null -w '%{http_code}' "$base/xrpc/com.atproto.sync.getBlob?did=did:plc:smoketest&cid=$blob_cid") test "$blob_head" = "200" test "$(curl -sS -o /dev/null -w '%{http_code}' -H "if-none-match: \"$blob_cid\"" "$base/xrpc/com.atproto.sync.getBlob?did=did:plc:smoketest&cid=$blob_cid")" = "304" # Record and blob takedowns: the subject stops being served until lifted, and a # taken down blob can't be uploaded again. admin_status() { curl -sS -o "$2" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.admin.updateSubjectStatus" \ -H 'authorization: Bearer smoke-admin-token' -H 'content-type: application/json' --data "$1" } takedown_body="${work}/zds-smoke-takedown.json" blob_ref_uri=$(printf '%s' "$blob_ref" | jq -r .uri) blob_ref_cid=$(printf '%s' "$blob_ref" | jq -r .cid) blob_ref_rkey=${blob_ref_uri##*/} record_subject=$(jq -nc --arg uri "$blob_ref_uri" --arg cid "$blob_ref_cid" '{"$type":"com.atproto.repo.strongRef",uri:$uri,cid:$cid}') test "$(admin_status "$(jq -nc --argjson s "$record_subject" '{subject:$s,takedown:{applied:true,ref:"smoke-mod-1"}}')" "$takedown_body")" = "200" jq -e '.takedown.applied == true and .takedown.ref == "smoke-mod-1" and .subject.uri != null' "$takedown_body" >/dev/null test "$(curl -sS -o "$takedown_body" -w '%{http_code}' "$base/xrpc/com.atproto.repo.getRecord?repo=did:plc:smoketest&collection=dev.zds.smoke.blob&rkey=$blob_ref_rkey")" = "400" grep -q '"error":"RecordNotFound"' "$takedown_body" curl -fsS "$base/xrpc/com.atproto.repo.listRecords?repo=did:plc:smoketest&collection=dev.zds.smoke.blob" | jq -e --arg uri "$blob_ref_uri" 'all(.records[]; .uri != $uri)' >/dev/null curl -fsS -G -H 'authorization: Bearer smoke-admin-token' --data-urlencode "uri=$blob_ref_uri" "$base/xrpc/com.atproto.admin.getSubjectStatus" \ | jq -e --arg cid "$blob_ref_cid" '.subject["$type"] == "com.atproto.repo.strongRef" and .subject.cid == $cid and .takedown.ref == "smoke-mod-1"' >/dev/null test "$(admin_status "$(jq -nc --argjson s "$record_subject" '{subject:$s,takedown:{applied:false}}')" "$takedown_body")" = "200" curl -fsS "$base/xrpc/com.atproto.repo.getRecord?repo=did:plc:smoketest&collection=dev.zds.smoke.blob&rkey=$blob_ref_rkey" >/dev/null test "$(curl -sS -o /dev/null -w '%{http_code}' -G -H 'authorization: Bearer smoke-admin-token' --data-urlencode "uri=$blob_ref_uri" "$base/xrpc/com.atproto.admin.getSubjectStatus")" = "400" blob_subject=$(jq -nc --arg cid "$blob_cid" '{"$type":"com.atproto.admin.defs#repoBlobRef",did:"did:plc:smoketest",cid:$cid}') test "$(admin_status "$(jq -nc --argjson s "$blob_subject" '{subject:$s,takedown:{applied:true}}')" "$takedown_body")" = "200" jq -e '.takedown.applied == true and (.takedown.ref | test("^20"))' "$takedown_body" >/dev/null test "$(curl -sS -o /dev/null -w '%{http_code}' "$base/xrpc/com.atproto.sync.getBlob?did=did:plc:smoketest&cid=$blob_cid")" = "404" curl -fsS -H 'authorization: Bearer smoke-admin-token' "$base/xrpc/com.atproto.admin.getSubjectStatus?did=did:plc:smoketest&blob=$blob_cid" \ | jq -e '.subject["$type"] == "com.atproto.admin.defs#repoBlobRef" and .takedown.applied' >/dev/null test "$(curl -sS -o "$takedown_body" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.repo.uploadBlob" \ -H "authorization: Bearer $token" -H 'content-type: image/jpeg' --data-binary "@$blob_payload")" = "400" grep -q 'Blob has been takendown, cannot re-upload' "$takedown_body" # a record may only name blobs this account uploaded and that are not taken # down; the reference answers BlobNotFound with the CID blob_record() { curl -sS -o "$2" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.repo.createRecord" \ -H "authorization: Bearer $token" -H 'content-type: application/json' \ --data "$(jq -nc --arg cid "$1" '{repo:"did:plc:smoketest",collection:"dev.zds.smoke.blob",record:{"$type":"dev.zds.smoke.blob",blob:{"$type":"blob",ref:{"$link":$cid},mimeType:"image/jpeg",size:13}}}')" } test "$(blob_record "$blob_cid" "$takedown_body")" = "400" jq -e --arg cid "$blob_cid" '.error == "BlobNotFound" and .message == "Could not find blob: \($cid)"' "$takedown_body" >/dev/null unknown_blob_cid=bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku test "$(blob_record "$unknown_blob_cid" "$takedown_body")" = "400" jq -e --arg cid "$unknown_blob_cid" '.error == "BlobNotFound" and .message == "Could not find blob: \($cid)"' "$takedown_body" >/dev/null test "$(admin_status "$(jq -nc --argjson s "$blob_subject" '{subject:$s,takedown:{applied:false}}')" "$takedown_body")" = "200" test "$(curl -sS -o /dev/null -w '%{http_code}' "$base/xrpc/com.atproto.sync.getBlob?did=did:plc:smoketest&cid=$blob_cid")" = "200" curl -fsS -H 'authorization: Bearer smoke-admin-token' "$base/xrpc/com.atproto.admin.getSubjectStatus?did=did:plc:smoketest" \ | jq -e '.subject["$type"] == "com.atproto.admin.defs#repoRef" and .takedown.applied == false and .deactivated.applied == false' >/dev/null test "$(curl -sS -o /dev/null -w '%{http_code}' "$base/xrpc/com.atproto.admin.getSubjectStatus?did=did:plc:smoketest")" = "401" large_blob_payload="${work}/zds-smoke-large-blob.jpg" dd if=/dev/zero bs=1048576 count=17 of="$large_blob_payload" 2>/dev/null large_blob=$(curl -fsS -X POST "$base/xrpc/com.atproto.repo.uploadBlob" \ -H "authorization: Bearer $token" \ -H 'content-type: image/jpeg' \ --data-binary "@$large_blob_payload") printf '%s' "$large_blob" | grep -q '"blob":' printf '%s' "$large_blob" | grep -q '"size":17825792' oauth_info=$(curl -fsS -H 'accept: application/json' "$base/oauth/authorize?request_uri=urn%3Aietf%3Aparams%3Aoauth%3Arequest_uri%3Asmoke-oauth") printf '%s' "$oauth_info" | grep -q '"login_hint":"smoke.test"' oauth_page="${work}/zds-smoke-oauth.html" curl -fsS "$base/oauth/authorize?request_uri=urn%3Aietf%3Aparams%3Aoauth%3Arequest_uri%3Asmoke-oauth" > "$oauth_page" # login_hint names a local account: the page starts from that account. grep -q 'name="username" value="smoke.test"' "$oauth_page" grep -q '@smoke.test' "$oauth_page" grep -q 'to continue to client.example' "$oauth_page" sqlite3 "$db" "insert into oauth_requests (request_id, client_id, redirect_uri, scope, state, code_challenge, code_challenge_method, login_hint, expires_at) values ('smoke-loopback', 'http://localhost?scope=atproto', 'http://127.0.0.1:5199/', 'atproto', 'state', 'challenge', 'S256', 'smoke.test', unixepoch() + 600)" curl -fsS "$base/oauth/authorize?request_uri=urn%3Aietf%3Aparams%3Aoauth%3Arequest_uri%3Asmoke-loopback" | grep -q 'An app on your device' uv run tools/smoke-browser-login.py "$base" "$db" uv run tools/smoke-passwords.py "$base" "$db" ZDS_SMOKE_TOKEN="$token" uv run tools/smoke-blob-mime.py "$base" "$db" ZDS_SMOKE_TOKEN="$token" ZDS_SMOKE_OTHER_TOKEN="$signup_access" uv run tools/smoke-migration.py "$base" "$db" "$session_did" "$blob_cid" uv run tools/smoke-preview.py "$base" echo "zds smoke ok"