#!/usr/bin/env sh set -eu root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) work=$(mktemp -d "${TMPDIR:-/tmp}/zds-smoke.XXXXXX") port="${ZDS_PERMISSIONED_SMOKE_PORT:-2586}" db="${work}/zds-permissioned-smoke.sqlite3" blob_root="${work}/zds-permissioned-smoke-blobs" log="${work}/zds-permissioned-smoke.log" # stand-in PLC directory and managing app, served by tools/smoke-space-access.py stub_port="${ZDS_PERMISSIONED_SMOKE_STUB_PORT:-$((port + 1))}" base="http://127.0.0.1:${port}" jwt_secret="smoke-jwt-secret" space_uri="at:space/did:plc:permissionsmoke/fm.plyr.privateMedia/self" encoded_space=$(printf '%s' "$space_uri" | jq -sRr @uri) other_space_uri="at:space/did:plc:permissionsmoke/fm.plyr.privateMedia/other" encoded_other_space=$(printf '%s' "$other_space_uri" | jq -sRr @uri) external_space_uri="at:space/did:plc:externalspace/fm.plyr.privateMedia/shared" encoded_external_space=$(printf '%s' "$external_space_uri" | jq -sRr @uri) cleanup() { status=$? if [ -n "${server_pid:-}" ]; then kill "$server_pid" 2>/dev/null || true wait "$server_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 space_signature() { ./zig-out/bin/zds-space-signature "$@" 2>&1 } # 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_PERMISSIONED_DATA=true 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 \ --admin-token permissioned-smoke-admin-token \ --plc-directory "http://127.0.0.1:${stub_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 sqlite3 "$db" "insert into accounts (did, handle, email, password_hash, activated_at, email_confirmed_at, kem_key) values ('did:plc:permissionsmoke', 'permissioned-smoke.test', 'permissioned-smoke@test.com', 'password', unixepoch(), unixepoch(), x'3131313131313131313131313131313131313131313131313131313131313131')" policy_status=$(curl -sS -o "$work/zds-space-policy.json" -w '%{http_code}' \ "$base/xrpc/com.atproto.managedspace.checkAccess?space=$encoded_space&repo=did:plc:permissionsmoke") test "$policy_status" = "401" grep -q '"error":"AuthenticationRequired"' "$work/zds-space-policy.json" session=$(curl -fsS -X POST "$base/xrpc/com.atproto.server.createSession" \ -H 'content-type: application/json' \ --data '{"identifier":"permissioned-smoke.test","password":"password"}') token=$(printf '%s' "$session" | sed -n 's/.*"accessJwt":"\([^"]*\)".*/\1/p') test -n "$token" session_did=$(printf '%s' "$session" | jq -r .did) # 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-permissioned-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-permissioned-expired.json" expired_status=$(curl -sS -o "$expired_body" -w '%{http_code}' \ -H "authorization: Bearer $expired_token" "$base/xrpc/com.atproto.space.getSpace?space=$encoded_space") 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.space.getSpace?space=$encoded_space") test "$garbage_status" = "401" grep -q '"error":"InvalidToken"' "$expired_body" # A resident OAuth credential may read the resident's own repo in a space # hosted by another authority. The repo need not be materialized yet. sqlite3 "$db" "insert into permissioned_spaces (uri, authority_did, space_type, skey, is_authority) values ('$external_space_uri', 'did:plc:externalspace', 'fm.plyr.privateMedia', 'shared', 0)" external_records=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.listRecords?space=$encoded_external_space&repo=did:plc:permissionsmoke&collection=fm.plyr.track") test "$external_records" = '{"records":[]}' blob_payload="${work}/zds-permissioned-smoke-blob.jpg" printf '\377\330\377\340zds-permissioned-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") blob_cid=$(printf '%s' "$blob" | sed -n 's/.*"\$link":"\([^"]*\)".*/\1/p') test -n "$blob_cid" public_blob_status=$(curl -sS -o "$work/zds-space-public-blob.bin" -w '%{http_code}' \ "$base/xrpc/com.atproto.sync.getBlob?did=did:plc:permissionsmoke&cid=$blob_cid") test "$public_blob_status" = "404" space_create=$(curl -fsS -X POST "$base/xrpc/com.atproto.space.createSpace" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data '{"spaceType":"fm.plyr.privateMedia","skey":"self","policy":{"$type":"com.atproto.managedspace.policy","managingApp":"did:web:plyr.fm#plyr"}}') test "$space_create" = '{"space":"at:space/did:plc:permissionsmoke/fm.plyr.privateMedia/self"}' old_ref_status=$(curl -sS -G -o "$work/zds-space-old-ref.json" -w '%{http_code}' \ -H "authorization: Bearer $token" \ --data-urlencode 'space=at://did:plc:permissionsmoke/space/fm.plyr.privateMedia/self' \ "$base/xrpc/com.atproto.space.getSpace") test "$old_ref_status" = "400" grep -q '"error":"InvalidRequest"' "$work/zds-space-old-ref.json" # the pre-alpha body shape (did + config wrapper) is rejected, not silently accepted legacy_create_status=$(curl -sS -o "$work/zds-space-legacy-create.json" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.space.createSpace" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data '{"did":"did:plc:permissionsmoke","spaceType":"fm.plyr.privateMedia","skey":"legacy","config":{"policy":"member-list"}}') test "$legacy_create_status" = "400" grep -q '"error":"InvalidRequest"' "$work/zds-space-legacy-create.json" unsupported_policy_status=$(curl -sS -o "$work/zds-space-unsupported-policy.json" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.space.createSpace" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data '{"spaceType":"fm.plyr.privateMedia","skey":"unsupported","policy":{"$type":"com.atproto.simplespace.defs#publicPolicy"}}') test "$unsupported_policy_status" = "400" grep -q '"error":"UnsupportedPolicy"' "$work/zds-space-unsupported-policy.json" # a managing app must be a DID with an optional service fragment invalid_managing_app_status=$(curl -sS -o "$work/zds-space-invalid-managing-app.json" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.space.createSpace" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data '{"spaceType":"fm.plyr.privateMedia","skey":"unsupported","policy":{"$type":"com.atproto.managedspace.policy","managingApp":"https://plyr.fm"}}') test "$invalid_managing_app_status" = "400" grep -q '"error":"InvalidRequest"' "$work/zds-space-invalid-managing-app.json" curl -fsS -X POST "$base/xrpc/com.atproto.space.createSpace" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data '{"spaceType":"fm.plyr.privateMedia","skey":"other","policy":{"$type":"com.atproto.memberspace.policy"}}' \ | grep -q '"space":"at:space/did:plc:permissionsmoke/fm.plyr.privateMedia/other"' space_duplicate_status=$(curl -sS -o "$work/zds-space-duplicate.json" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.space.createSpace" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data '{"spaceType":"fm.plyr.privateMedia","skey":"self","policy":{"$type":"com.atproto.memberspace.policy"}}') test "$space_duplicate_status" = "400" grep -q '"error":"SpaceAlreadyExists"' "$work/zds-space-duplicate.json" # recreate-after-delete: a deleted space may be created again (per the lexicon), # and the fresh config replaces the old one with the tombstone cleared. recreate_space_uri="at:space/did:plc:permissionsmoke/fm.plyr.privateMedia/recreate" encoded_recreate_space=$(printf '%s' "$recreate_space_uri" | jq -sRr @uri) curl -fsS -X POST "$base/xrpc/com.atproto.space.createSpace" \ -H "authorization: Bearer $token" -H 'content-type: application/json' \ --data '{"spaceType":"fm.plyr.privateMedia","skey":"recreate","policy":{"$type":"com.atproto.memberspace.policy","publicRead":true,"publicWrite":true}}' \ | grep -q '"space":"'"$recreate_space_uri"'"' curl -fsS -X POST "$base/xrpc/com.atproto.space.deleteSpace" \ -H "authorization: Bearer $token" -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$recreate_space_uri" '{space:$space}')" | grep -q '{}' recreate_after_delete=$(curl -fsS -X POST "$base/xrpc/com.atproto.space.createSpace" \ -H "authorization: Bearer $token" -H 'content-type: application/json' \ --data '{"spaceType":"fm.plyr.privateMedia","skey":"recreate","policy":{"$type":"com.atproto.managedspace.policy","managingApp":"did:web:plyr.fm#plyr"}}') test "$recreate_after_delete" = '{"space":"'"$recreate_space_uri"'"}' recreate_get=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.getSpace?space=$encoded_recreate_space") test "$recreate_get" = '{"space":"'"$recreate_space_uri"'","policy":{"$type":"com.atproto.managedspace.policy","managingApp":"did:web:plyr.fm#plyr","publishPolicy":false}}' # ---- deletion purges the authority-hosted state, and a non-member on this # PDS cannot write into a locally hosted member-list space ---- purge_space_uri="at:space/did:plc:permissionsmoke/fm.plyr.privateMedia/purge" encoded_purge_space=$(printf '%s' "$purge_space_uri" | jq -sRr @uri) sqlite3 "$db" "insert into accounts (did, handle, email, password_hash, activated_at, email_confirmed_at, kem_key) values ('did:plc:spacesmokebob', 'space-smoke-bob.test', 'space-smoke-bob@test.com', 'password', unixepoch(), unixepoch(), x'3232323232323232323232323232323232323232323232323232323232323232')" bob_session=$(curl -fsS -X POST "$base/xrpc/com.atproto.server.createSession" \ -H 'content-type: application/json' \ --data '{"identifier":"space-smoke-bob.test","password":"password"}') bob_token=$(printf '%s' "$bob_session" | sed -n 's/.*"accessJwt":"\([^"]*\)".*/\1/p') test -n "$bob_token" curl -fsS -X POST "$base/xrpc/com.atproto.space.createSpace" \ -H "authorization: Bearer $token" -H 'content-type: application/json' \ --data '{"spaceType":"fm.plyr.privateMedia","skey":"purge","policy":{"$type":"com.atproto.memberspace.policy"}}' \ | grep -q '"space":"'"$purge_space_uri"'"' # An unlisted writer can store records but is not registered by the authority. bob_write_status=$(curl -sS -o "$work/zds-space-bob-write.json" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.space.createRecord" \ -H "authorization: Bearer $bob_token" -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$purge_space_uri" '{space:$space,repo:"did:plc:spacesmokebob",collection:"fm.plyr.track",rkey:"bob-one",record:{"$type":"fm.plyr.track",title:"not allowed"}}')") test "$bob_write_status" = "200" test "$(sqlite3 "$db" "select count(*) from permissioned_space_writers where space = '$purge_space_uri'")" = "0" test "$(sqlite3 "$db" "select count(*) from permissioned_space_records where space = '$purge_space_uri'")" = "1" # added to the list: the same write lands curl -fsS -X POST "$base/xrpc/com.atproto.memberspace.putMembers" \ -H "authorization: Bearer $token" -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$purge_space_uri" '{space:$space,members:[{did:"did:plc:spacesmokebob",read:true,write:true}]}')" | grep -q '{}' curl -fsS -X POST "$base/xrpc/com.atproto.space.putRecord" \ -H "authorization: Bearer $bob_token" -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$purge_space_uri" '{space:$space,repo:"did:plc:spacesmokebob",collection:"fm.plyr.track",rkey:"bob-one",record:{"$type":"fm.plyr.track",title:"allowed now"}}')" \ | grep -q '"uri":"' curl -fsS -X POST "$base/xrpc/com.atproto.space.createRecord" \ -H "authorization: Bearer $token" -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$purge_space_uri" '{space:$space,repo:"did:plc:permissionsmoke",collection:"fm.plyr.track",rkey:"own-one",record:{"$type":"fm.plyr.track",title:"authority record"}}')" \ | grep -q '"uri":"' # delete: the authority's own records, the member list, and the writer registry # are purged; bob's record survives in his own writer repo (it is his data) curl -fsS -X POST "$base/xrpc/com.atproto.space.deleteSpace" \ -H "authorization: Bearer $token" -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$purge_space_uri" '{space:$space}')" | grep -q '{}' test "$(sqlite3 "$db" "select count(*) from permissioned_space_records where space = '$purge_space_uri' and repo_did = 'did:plc:permissionsmoke'")" = "0" test "$(sqlite3 "$db" "select count(*) from memberspace_members where space = '$purge_space_uri'")" = "0" test "$(sqlite3 "$db" "select count(*) from permissioned_space_writers where space = '$purge_space_uri'")" = "0" test "$(sqlite3 "$db" "select count(*) from permissioned_space_records where space = '$purge_space_uri' and repo_did = 'did:plc:spacesmokebob'")" = "1" # recreated, the space starts with an empty member list — nothing resurrects curl -fsS -X POST "$base/xrpc/com.atproto.space.createSpace" \ -H "authorization: Bearer $token" -H 'content-type: application/json' \ --data '{"spaceType":"fm.plyr.privateMedia","skey":"purge","policy":{"$type":"com.atproto.memberspace.policy"}}' \ | grep -q '"space":"'"$purge_space_uri"'"' bob_write_again_status=$(curl -sS -o "$work/zds-space-bob-write-again.json" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.space.createRecord" \ -H "authorization: Bearer $bob_token" -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$purge_space_uri" '{space:$space,repo:"did:plc:spacesmokebob",collection:"fm.plyr.track",rkey:"bob-two",record:{"$type":"fm.plyr.track",title:"still not a member"}}')") test "$bob_write_again_status" = "200" test "$(sqlite3 "$db" "select count(*) from permissioned_space_writers where space = '$purge_space_uri'")" = "0" space_get=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.getSpace?space=$encoded_space") test "$space_get" = '{"space":"at:space/did:plc:permissionsmoke/fm.plyr.privateMedia/self","policy":{"$type":"com.atproto.managedspace.policy","managingApp":"did:web:plyr.fm#plyr","publishPolicy":false}}' # a new policy $type replaces the managing app wholesale curl -fsS -X POST "$base/xrpc/com.atproto.space.updateSpace" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$space_uri" '{space:$space,policy:{"$type":"com.atproto.memberspace.policy"}}')" \ | grep -q '{}' space_get_updated=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.getSpace?space=$encoded_space") test "$space_get_updated" = '{"space":"at:space/did:plc:permissionsmoke/fm.plyr.privateMedia/self","policy":{"$type":"com.atproto.memberspace.policy","publicRead":false,"publicWrite":false,"publishPolicy":false,"publishMembers":false}}' delegation=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.getDelegationToken?space=$encoded_space" | jq -r '.token') test -n "$delegation" curl -fsS "$base/xrpc/com.atproto.server.describeServer" | grep -q '"spacesAlpha":true' credential_kid=$(space_signature kid) # A malformed request must not consume the one-use delegation grant. space_credential_missing_kid=$(curl -sS -o "$work/zds-space-credential-missing-kid.json" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.space.authorizeSpaceSync" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$space_uri" --arg delegation "$delegation" '{space:$space,delegationToken:$delegation}')") test "$space_credential_missing_kid" = "400" grep -q '"error":"InvalidRequest"' "$work/zds-space-credential-missing-kid.json" space_credential_bad_kid=$(curl -sS -o "$work/zds-space-credential-bad-kid.json" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.space.authorizeSpaceSync" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$space_uri" --arg delegation "$delegation" '{space:$space,delegationToken:$delegation,credentialKey:"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"}')") test "$space_credential_bad_kid" = "400" grep -q '"error":"InvalidRequest"' "$work/zds-space-credential-bad-kid.json" # Without a delegation token a member-list space answers as though it does not exist. space_credential_anonymous=$(curl -sS -o "$work/zds-space-credential-anonymous.json" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.space.authorizeSpaceSync" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$space_uri" --arg kid "$credential_kid" '{space:$space,credentialKey:$kid}')") test "$space_credential_anonymous" = "400" grep -q '"error":"SpaceNotFound"' "$work/zds-space-credential-anonymous.json" credential_exchange_url="$base/xrpc/com.atproto.space.authorizeSpaceSync" space_credential_status=$(curl -sS -o "$work/zds-space-credential.json" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.space.authorizeSpaceSync" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$space_uri" --arg delegation "$delegation" --arg kid "$credential_kid" '{space:$space,delegationToken:$delegation,credentialKey:$kid}')") test "$space_credential_status" = "200" space_credential=$(jq -r '.credential' "$work/zds-space-credential.json") test -n "$space_credential" credential_bearer_status=$(curl -sS -o "$work/zds-space-credential-bearer.json" -w '%{http_code}' \ -H "authorization: Bearer $space_credential" \ "$base/xrpc/com.atproto.space.getSpace?space=$encoded_space") test "$credential_bearer_status" = "401" space_signature "Atproto-Space-Credential $space_credential" did:plc:permissionsmoke > "$work/credential-headers" # getSpace is the owner's; a member or syncer reads a published policy instead credential_space_get_status=$(curl -sS -o "$work/zds-space-credential-get.json" -w '%{http_code}' \ -H "authorization: Atproto-Space-Credential $space_credential" -H @"$work/credential-headers" \ "$base/xrpc/com.atproto.space.getSpace?space=$encoded_space") test "$credential_space_get_status" = "401" for _ in 1 2; do curl -fsS -H "authorization: Atproto-Space-Credential $space_credential" -H @"$work/credential-headers" \ "$base/xrpc/com.atproto.space.listWriters?space=$encoded_space" | grep -q '"repos":' done space_list=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.listSpaces?spaceDid=did:plc:permissionsmoke&spaceType=fm.plyr.privateMedia") printf '%s' "$space_list" | grep -q '"space":"at:space/did:plc:permissionsmoke/fm.plyr.privateMedia/self"' printf '%s' "$space_list" | jq -e 'all(.spaces[]; (.repoRev == null) == (.data == null))' >/dev/null curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.listSpaces?spaceDid=did:plc:otherauthority" | jq -e '.spaces == []' >/dev/null printf '%s' "$space_list" | grep -q '"cursor":"at:space/did:plc:permissionsmoke/fm.plyr.privateMedia/self"' ! printf '%s' "$space_list" | grep -q '"isMember":' space_members=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.memberspace.listMembers?space=$encoded_space") test "$space_members" = '{"members":[]}' space_record=$(curl -fsS -X POST "$base/xrpc/com.atproto.space.createRecord" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$space_uri" --arg cid "$blob_cid" '{space:$space,repo:"did:plc:permissionsmoke",collection:"fm.plyr.track",rkey:"track-one",record:{"$type":"fm.plyr.track",title:"private smoke",audioBlob:{"$type":"blob",ref:{"$link":$cid},mimeType:"image/jpeg",size:12}}}')") printf '%s' "$space_record" | grep -q '"uri":"at:space/did:plc:permissionsmoke/fm.plyr.privateMedia/self/did:plc:permissionsmoke/fm.plyr.track/track-one"' printf '%s' "$space_record" | grep -q '"cid":"' ! printf '%s' "$space_record" | grep -q '"validationStatus":' space_record_get=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.getRecord?space=$encoded_space&repo=did:plc:permissionsmoke&collection=fm.plyr.track&rkey=track-one") printf '%s' "$space_record_get" | grep -q '"title":"private smoke"' public_blob_status=$(curl -sS -o "$work/zds-space-public-blob.bin" -w '%{http_code}' \ "$base/xrpc/com.atproto.sync.getBlob?did=did:plc:permissionsmoke&cid=$blob_cid") test "$public_blob_status" = "404" space_blobs=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.listBlobs?space=$encoded_space&repo=did:plc:permissionsmoke") printf '%s' "$space_blobs" | grep -q "\"$blob_cid\"" space_blobs_bad_limit=$(curl -sS -o "$work/zds-space-blobs-bad-limit.json" -w '%{http_code}' \ -H "authorization: Bearer $token" \ "$base/xrpc/com.atproto.space.listBlobs?space=$encoded_space&repo=did:plc:permissionsmoke&limit=0") test "$space_blobs_bad_limit" = "400" grep -q '"error":"InvalidRequest"' "$work/zds-space-blobs-bad-limit.json" space_records=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.listRecords?space=$encoded_space&repo=did:plc:permissionsmoke&collection=fm.plyr.track&limit=1") printf '%s' "$space_records" | grep -q '"collection":"fm.plyr.track"' printf '%s' "$space_records" | grep -q '"value":' printf '%s' "$space_records" | grep -q '"title":"private smoke"' printf '%s' "$space_records" | grep -q '"cursor":"fm.plyr.track/track-one"' space_record_refs=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.listRecords?space=$encoded_space&repo=did:plc:permissionsmoke&collection=fm.plyr.track&limit=1&excludeValues=true") printf '%s' "$space_record_refs" | grep -q '"collection":"fm.plyr.track"' ! printf '%s' "$space_record_refs" | grep -q '"value":' space_ops=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.listRepoOps?space=$encoded_space&repo=did:plc:permissionsmoke") printf '%s' "$space_ops" | grep -q '"collection":"fm.plyr.track"' printf '%s' "$space_ops" | grep -q '"value":' printf '%s' "$space_ops" | grep -q '"commit":' ! printf '%s' "$space_ops" | grep -q '"cursor":' ! printf '%s' "$space_ops" | grep -q '"action":' # a full page carries a rev/idx cursor beside the current commit; the next page has no cursor space_ops_page=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.listRepoOps?space=$encoded_space&repo=did:plc:permissionsmoke&limit=1") test "$(printf '%s' "$space_ops_page" | jq -c '.commit')" = "$(printf '%s' "$space_ops" | jq -c '.commit')" space_ops_cursor=$(printf '%s' "$space_ops_page" | jq -r '.cursor') printf '%s' "$space_ops_cursor" | grep -Eq '^[0-9a-z]+/[0-9]+$' space_ops_rest=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.listRepoOps?space=$encoded_space&repo=did:plc:permissionsmoke&limit=1&cursor=$(printf '%s' "$space_ops_cursor" | jq -sRr @uri)") test "$(printf '%s' "$space_ops_rest" | jq -r '.ops | length')" = "0" printf '%s' "$space_ops_rest" | grep -q '"commit":' ! printf '%s' "$space_ops_rest" | grep -q '"cursor":' space_op_refs=$(curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.listRepoOps?space=$encoded_space&repo=did:plc:permissionsmoke&excludeValues=true") printf '%s' "$space_op_refs" | grep -q '"collection":"fm.plyr.track"' ! printf '%s' "$space_op_refs" | grep -q '"value":' # writing into a space whose authority lives elsewhere needs no local setup: # the first write materializes the writer's repo here remote_space_uri="at:space/did:plc:remoteauthority/my.bulletin.board/self" remote_write=$(curl -fsS -X POST "$base/xrpc/com.atproto.space.createRecord" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$remote_space_uri" '{space:$space,repo:"did:plc:permissionsmoke",collection:"my.bulletin.post",rkey:"note-one",record:{"$type":"my.bulletin.post",text:"hi"}}')") printf '%s' "$remote_write" | grep -q '"uri":"at:space/did:plc:remoteauthority/my.bulletin.board/self/did:plc:permissionsmoke/my.bulletin.post/note-one"' curl -fsS -H "authorization: Bearer $token" "$base/xrpc/com.atproto.space.listSpaces?spaceDid=did:plc:remoteauthority" \ | grep -q '"space":"at:space/did:plc:remoteauthority/my.bulletin.board/self"' duplicate_write_status=$(curl -sS -o "$work/zds-space-duplicate-record.json" -w '%{http_code}' -X POST "$base/xrpc/com.atproto.space.createRecord" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$remote_space_uri" '{space:$space,repo:"did:plc:permissionsmoke",collection:"my.bulletin.post",rkey:"note-one",record:{"$type":"my.bulletin.post",text:"again"}}')") test "$duplicate_write_status" = "400" grep -q '"error":"RecordAlreadyExists"' "$work/zds-space-duplicate-record.json" curl -fsS -X POST "$base/xrpc/com.atproto.space.deleteRecord" \ -H "authorization: Bearer $token" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg space "$space_uri" '{space:$space,repo:"did:plc:permissionsmoke",collection:"fm.plyr.track",rkey:"never-existed"}')" \ | grep -q '{}' space_repo_headers="${work}/zds-space-repo.headers" space_repo_star="${work}/zds-space-repo.star" curl -fsS -D "$space_repo_headers" -o "$space_repo_star" \ -H "authorization: Bearer $token" \ "$base/xrpc/com.atproto.space.getRepo?space=$encoded_space&repo=did:plc:permissionsmoke" grep -qi '^content-type: application/vnd.dasl.star' "$space_repo_headers" test "$(head -c 4 "$space_repo_star" | od -An -tx1 | tr -d ' \n')" = "2a6c0100" test "$(wc -c < "$space_repo_star" | tr -d ' ')" -gt 100 space_blob_status=$(curl -sS -o "$work/zds-space-blob-range.bin" -w '%{http_code}' \ -H "authorization: Bearer $token" \ -H 'range: bytes=0-2' \ "$base/xrpc/com.atproto.space.getBlob?space=$encoded_space&repo=did:plc:permissionsmoke&cid=$blob_cid") test "$space_blob_status" = "206" test "$(wc -c < "$work/zds-space-blob-range.bin" | tr -d ' ')" = "3" other_space_blob_status=$(curl -sS -o "$work/zds-space-other-blob.json" -w '%{http_code}' \ -H "authorization: Bearer $token" \ "$base/xrpc/com.atproto.space.getBlob?space=$encoded_other_space&repo=did:plc:permissionsmoke&cid=$blob_cid") test "$other_space_blob_status" = "404" grep -q '"error":"BlobNotFound"' "$work/zds-space-other-blob.json" # A blob takedown covers the space copy too, as proposal 0016 asks of a repo host. space_blob_takedown() { curl -fsS -X POST "$base/xrpc/com.atproto.admin.updateSubjectStatus" \ -H 'authorization: Bearer permissioned-smoke-admin-token' -H 'content-type: application/json' \ --data "$(jq -nc --arg cid "$blob_cid" --argjson applied "$1" '{subject:{"$type":"com.atproto.admin.defs#repoBlobRef",did:"did:plc:permissionsmoke",cid:$cid},takedown:{applied:$applied}}')" >/dev/null } space_blob_takedown true test "$(curl -sS -o "$work/zds-space-blob-takedown.json" -w '%{http_code}' -H "authorization: Bearer $token" \ "$base/xrpc/com.atproto.space.getBlob?space=$encoded_space&repo=did:plc:permissionsmoke&cid=$blob_cid")" = "404" grep -q '"error":"BlobNotFound"' "$work/zds-space-blob-takedown.json" space_blob_takedown false test "$(curl -sS -o /dev/null -w '%{http_code}' -H "authorization: Bearer $token" \ "$base/xrpc/com.atproto.space.getBlob?space=$encoded_space&repo=did:plc:permissionsmoke&cid=$blob_cid")" = "200" if [ -n "${ZDS_SPACE_SDK_DIR:-}" ]; then SMOKE_BASE="$base" SMOKE_TOKEN="$token" SMOKE_BOB_TOKEN="$bob_token" "${ZDS_SPACE_SDK_RUNNER:-node}" tools/smoke-space-interop.mjs fi # Last: it takes both smoke accounts down, which revokes their sessions. SMOKE_BASE="$base" SMOKE_TOKEN="$token" SMOKE_BOB_TOKEN="$bob_token" SMOKE_STUB_PORT="$stub_port" SMOKE_DB="$db" uv run tools/smoke-space-access.py echo "zds permissioned smoke ok"