@getcirrus/space-conformance 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base-D8a-ZK57.d.ts +249 -0
- package/dist/base-D8a-ZK57.d.ts.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +373 -0
- package/dist/cli.js.map +1 -0
- package/dist/coverage-DhJZu8P8.js +1914 -0
- package/dist/coverage-DhJZu8P8.js.map +1 -0
- package/dist/full-D4ufJLcw.js +409 -0
- package/dist/full-D4ufJLcw.js.map +1 -0
- package/dist/full.d.ts +59 -0
- package/dist/full.d.ts.map +1 -0
- package/dist/full.js +4 -0
- package/dist/index.d.ts +178 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +114 -0
- package/dist/index.js.map +1 -0
- package/dist/operator-BErXCDow.js +923 -0
- package/dist/operator-BErXCDow.js.map +1 -0
- package/lexicons/MANIFEST.json +7 -0
- package/lexicons/simplespace/addMember.json +37 -0
- package/lexicons/simplespace/checkUserAccess.json +43 -0
- package/lexicons/simplespace/createSpace.json +74 -0
- package/lexicons/simplespace/defs.json +47 -0
- package/lexicons/simplespace/deleteSpace.json +32 -0
- package/lexicons/simplespace/getSpace.json +53 -0
- package/lexicons/simplespace/listMembers.json +65 -0
- package/lexicons/simplespace/removeMember.json +37 -0
- package/lexicons/simplespace/updateSpace.json +57 -0
- package/lexicons/space/applyWrites.json +163 -0
- package/lexicons/space/createRecord.json +79 -0
- package/lexicons/space/defs.json +38 -0
- package/lexicons/space/deleteRecord.json +51 -0
- package/lexicons/space/getBlob.json +54 -0
- package/lexicons/space/getDelegationToken.json +34 -0
- package/lexicons/space/getLatestCommit.json +57 -0
- package/lexicons/space/getRecord.json +76 -0
- package/lexicons/space/getRepo.json +41 -0
- package/lexicons/space/getSpaceCredential.json +67 -0
- package/lexicons/space/listBlobs.json +59 -0
- package/lexicons/space/listRecords.json +108 -0
- package/lexicons/space/listRepoOps.json +111 -0
- package/lexicons/space/listRepos.json +75 -0
- package/lexicons/space/listSpaces.json +65 -0
- package/lexicons/space/notifySpaceDeleted.json +24 -0
- package/lexicons/space/notifyWrite.json +38 -0
- package/lexicons/space/putRecord.json +75 -0
- package/lexicons/space/registerNotify.json +49 -0
- package/lexicons/space/unregisterNotify.json +29 -0
- package/package.json +53 -0
|
@@ -0,0 +1,923 @@
|
|
|
1
|
+
import { decode } from "@atproto/lex-cbor";
|
|
2
|
+
|
|
3
|
+
//#region src/model.ts
|
|
4
|
+
const pass = (detail, evidence) => ({
|
|
5
|
+
status: "pass",
|
|
6
|
+
detail,
|
|
7
|
+
...evidence !== void 0 ? { evidence } : {}
|
|
8
|
+
});
|
|
9
|
+
const fail = (detail, evidence) => ({
|
|
10
|
+
status: "fail",
|
|
11
|
+
detail,
|
|
12
|
+
...evidence !== void 0 ? { evidence } : {}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/registry.ts
|
|
17
|
+
/**
|
|
18
|
+
* Define a check, enforcing the catalog's structural rules at
|
|
19
|
+
* registration time rather than in review:
|
|
20
|
+
*
|
|
21
|
+
* - ids are `area.slug`, unique within a catalog;
|
|
22
|
+
* - a `must` check carries at least one citation to specified behavior —
|
|
23
|
+
* without one it is someone's opinion and belongs in `should` or `info`.
|
|
24
|
+
*/
|
|
25
|
+
function defineCheck(check) {
|
|
26
|
+
if (!/^[a-z0-9-]+\.[a-z0-9-]+$/.test(check.id)) throw new Error(`Check id must be "area.slug" (kebab-case): ${check.id}`);
|
|
27
|
+
if (check.tier === "must" && check.citations.length === 0) throw new Error(`Check ${check.id} is tier "must" but cites nothing. Cite the lexicon, proposal or design spec — or demote it.`);
|
|
28
|
+
return check;
|
|
29
|
+
}
|
|
30
|
+
function buildCatalog(checks) {
|
|
31
|
+
const seen = /* @__PURE__ */ new Set();
|
|
32
|
+
for (const check of checks) {
|
|
33
|
+
if (seen.has(check.id)) throw new Error(`Duplicate check id: ${check.id}`);
|
|
34
|
+
seen.add(check.id);
|
|
35
|
+
}
|
|
36
|
+
return checks;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Partition a catalog into runnable and skipped for a given harness. A
|
|
40
|
+
* skipped check is part of the report — "not testable here" must never
|
|
41
|
+
* silently read as "conformant".
|
|
42
|
+
*/
|
|
43
|
+
function filterCatalog(catalog, filter) {
|
|
44
|
+
const capabilities = new Set(filter.capabilities ?? []);
|
|
45
|
+
const runnable = [];
|
|
46
|
+
const skipped = [];
|
|
47
|
+
const ids = filter.ids?.length ? filter.ids : void 0;
|
|
48
|
+
const areas = filter.areas?.length ? filter.areas : void 0;
|
|
49
|
+
const tiers = filter.tiers?.length ? filter.tiers : void 0;
|
|
50
|
+
for (const check of catalog) {
|
|
51
|
+
if (ids && !ids.includes(check.id)) continue;
|
|
52
|
+
const area = check.id.split(".")[0];
|
|
53
|
+
if (areas && !areas.includes(area)) continue;
|
|
54
|
+
if (tiers && !tiers.includes(check.tier)) {
|
|
55
|
+
skipped.push({
|
|
56
|
+
check,
|
|
57
|
+
reason: `tier ${check.tier} excluded`
|
|
58
|
+
});
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (check.destructive && !filter.destructive) {
|
|
62
|
+
skipped.push({
|
|
63
|
+
check,
|
|
64
|
+
reason: "destructive checks not enabled"
|
|
65
|
+
});
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (check.slow && !filter.slow) {
|
|
69
|
+
skipped.push({
|
|
70
|
+
check,
|
|
71
|
+
reason: "slow checks not enabled"
|
|
72
|
+
});
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const missing = check.needs.filter((need) => !capabilities.has(need));
|
|
76
|
+
if (missing.length > 0) {
|
|
77
|
+
skipped.push({
|
|
78
|
+
check,
|
|
79
|
+
reason: `missing capabilities: ${missing.join(", ")}`
|
|
80
|
+
});
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
runnable.push(check);
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
runnable,
|
|
87
|
+
skipped
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/http.ts
|
|
93
|
+
function xrpcUrl(origin, nsid, params) {
|
|
94
|
+
const url = new URL(`${origin}/xrpc/${nsid}`);
|
|
95
|
+
for (const [key, value] of Object.entries(params ?? {})) if (value !== void 0) url.searchParams.set(key, value);
|
|
96
|
+
return url.toString();
|
|
97
|
+
}
|
|
98
|
+
async function toResult(response) {
|
|
99
|
+
const contentType = response.headers.get("Content-Type") ?? "";
|
|
100
|
+
let json;
|
|
101
|
+
let error;
|
|
102
|
+
if (contentType.includes("application/json")) {
|
|
103
|
+
json = await response.clone().json().catch(() => void 0);
|
|
104
|
+
if (json && typeof json === "object" && "error" in json) error = String(json.error);
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
status: response.status,
|
|
108
|
+
json,
|
|
109
|
+
error,
|
|
110
|
+
headers: response.headers,
|
|
111
|
+
response
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** GET an XRPC query. `headers` may carry auth. */
|
|
115
|
+
async function xrpcGet(ctx, nsid, params, headers) {
|
|
116
|
+
return toResult(await ctx.fetch(xrpcUrl(ctx.target.origin, nsid, params), {
|
|
117
|
+
method: "GET",
|
|
118
|
+
headers
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
/** POST an XRPC procedure with a JSON body. */
|
|
122
|
+
async function xrpcPost(ctx, nsid, body, headers) {
|
|
123
|
+
const merged = new Headers(headers);
|
|
124
|
+
merged.set("Content-Type", "application/json");
|
|
125
|
+
return toResult(await ctx.fetch(xrpcUrl(ctx.target.origin, nsid), {
|
|
126
|
+
method: "POST",
|
|
127
|
+
headers: merged,
|
|
128
|
+
body: JSON.stringify(body)
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
/** Add the operator's auth to a headers object, if a session is present. */
|
|
132
|
+
async function operatorHeaders(ctx, extra) {
|
|
133
|
+
const headers = new Headers(extra);
|
|
134
|
+
if (ctx.operator?.authorize) await ctx.operator.authorize({ headers });
|
|
135
|
+
return headers;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* A fetch that carries the operator's credentials: the operator's own
|
|
139
|
+
* signing fetch when it has one (a DPoP-bound OAuth session must sign each
|
|
140
|
+
* request individually), otherwise the transport fetch with
|
|
141
|
+
* `authorize`-injected headers. With no operator at all it falls back to
|
|
142
|
+
* the plain transport — the runner skips operator-needing checks then, so
|
|
143
|
+
* that path is only reached by checks that can also run anonymously.
|
|
144
|
+
*/
|
|
145
|
+
function operatorFetch(ctx) {
|
|
146
|
+
const operator = ctx.operator;
|
|
147
|
+
if (!operator) return ctx.fetch;
|
|
148
|
+
if (operator.fetch) return operator.fetch;
|
|
149
|
+
const baseFetch = ctx.fetch;
|
|
150
|
+
return async (input, init) => {
|
|
151
|
+
const headers = new Headers(init?.headers);
|
|
152
|
+
await operator.authorize?.({
|
|
153
|
+
...init,
|
|
154
|
+
headers
|
|
155
|
+
});
|
|
156
|
+
return baseFetch(input, {
|
|
157
|
+
...init,
|
|
158
|
+
headers
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* The same context with the operator's credentials on `fetch`, so a check
|
|
164
|
+
* can write `xrpcGet(asOperator(ctx), …)` for authenticated calls while
|
|
165
|
+
* keeping the bare `ctx` for requests that must stay anonymous.
|
|
166
|
+
*/
|
|
167
|
+
function asOperator(ctx) {
|
|
168
|
+
return {
|
|
169
|
+
...ctx,
|
|
170
|
+
fetch: operatorFetch(ctx)
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/checks/base.ts
|
|
176
|
+
/**
|
|
177
|
+
* Browser-safe checks: discovery and unauthenticated request shapes.
|
|
178
|
+
*
|
|
179
|
+
* These need only `fetch` — no token minting, no @atproto/space — so they
|
|
180
|
+
* run in any transport including a browser bundle. Everything crypto-bound
|
|
181
|
+
* lives in `../checks/full-checks.ts` behind the `./full` entry.
|
|
182
|
+
*/
|
|
183
|
+
const SPACE_HOST_FRAGMENT = "#atproto_space_host";
|
|
184
|
+
const discoveryServiceEntry = defineCheck({
|
|
185
|
+
id: "discovery.space-host-service",
|
|
186
|
+
title: "DID document advertises the space host service endpoint",
|
|
187
|
+
tier: "must",
|
|
188
|
+
citations: [{
|
|
189
|
+
source: "proposal",
|
|
190
|
+
ref: "0016#space-authority"
|
|
191
|
+
}],
|
|
192
|
+
needs: [],
|
|
193
|
+
async run(ctx) {
|
|
194
|
+
const res = await ctx.fetch(`${ctx.target.origin}/.well-known/did.json`);
|
|
195
|
+
if (!res.ok) return fail(`did.json returned ${res.status}`);
|
|
196
|
+
const doc = await res.json();
|
|
197
|
+
const entry = (doc.service ?? []).find((s) => s.id.endsWith(SPACE_HOST_FRAGMENT));
|
|
198
|
+
if (!entry) return fail("no #atproto_space_host service entry", doc.service);
|
|
199
|
+
return pass(`serviceEndpoint ${String(entry.serviceEndpoint)}`, entry);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
const discoveryVerificationKey = defineCheck({
|
|
203
|
+
id: "discovery.verification-key",
|
|
204
|
+
title: "DID document exposes an atproto verification key",
|
|
205
|
+
tier: "must",
|
|
206
|
+
citations: [{
|
|
207
|
+
source: "proposal",
|
|
208
|
+
ref: "0016#space-authority"
|
|
209
|
+
}],
|
|
210
|
+
needs: [],
|
|
211
|
+
async run(ctx) {
|
|
212
|
+
const res = await ctx.fetch(`${ctx.target.origin}/.well-known/did.json`);
|
|
213
|
+
if (!res.ok) return fail(`did.json returned ${res.status}`);
|
|
214
|
+
const doc = await res.json();
|
|
215
|
+
return (doc.verificationMethod ?? []).some((m) => m.id.endsWith("#atproto")) ? pass("#atproto verification method present") : fail("no #atproto verification method", doc.verificationMethod);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
const authGetRecordRequiresAuth = defineCheck({
|
|
219
|
+
id: "auth.getrecord-unauthenticated-refused",
|
|
220
|
+
title: "space.getRecord refuses an unauthenticated request",
|
|
221
|
+
tier: "must",
|
|
222
|
+
citations: [{
|
|
223
|
+
source: "lexicon",
|
|
224
|
+
ref: "com.atproto.space.getRecord"
|
|
225
|
+
}],
|
|
226
|
+
needs: [],
|
|
227
|
+
async run(ctx) {
|
|
228
|
+
const res = await xrpcGet(ctx, "com.atproto.space.getRecord", {
|
|
229
|
+
space: `at://${ctx.target.did}/space/app.bsky.group/probe`,
|
|
230
|
+
repo: ctx.target.did,
|
|
231
|
+
collection: "app.bsky.feed.post",
|
|
232
|
+
rkey: "whatever"
|
|
233
|
+
});
|
|
234
|
+
if (res.status === 401 || res.status === 403) return pass(`refused with ${res.status}`);
|
|
235
|
+
return fail(`unauthenticated read was not refused with 401/403 (got ${res.status} ${res.error ?? ""})`, res.json);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
const authCredentialRequiresToken = defineCheck({
|
|
239
|
+
id: "auth.getspacecredential-untoken-refused",
|
|
240
|
+
title: "space.getSpaceCredential refuses a request with no delegation token",
|
|
241
|
+
tier: "must",
|
|
242
|
+
citations: [{
|
|
243
|
+
source: "lexicon",
|
|
244
|
+
ref: "com.atproto.space.getSpaceCredential"
|
|
245
|
+
}],
|
|
246
|
+
needs: [],
|
|
247
|
+
async run(ctx) {
|
|
248
|
+
const res = await xrpcPost(ctx, "com.atproto.space.getSpaceCredential", { space: `at://${ctx.target.did}/space/app.bsky.group/probe` });
|
|
249
|
+
if (res.status === 401 || res.status === 403 || res.status === 400) return pass(`refused with ${res.status} ${res.error ?? ""}`);
|
|
250
|
+
return fail(`unexpected ${res.status} for a tokenless credential request`, res.json);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
const requestInvalidSpaceUri = defineCheck({
|
|
254
|
+
id: "request.invalid-space-uri-rejected",
|
|
255
|
+
title: "A malformed space reference is rejected, not misread",
|
|
256
|
+
tier: "must",
|
|
257
|
+
citations: [{
|
|
258
|
+
source: "lexicon",
|
|
259
|
+
ref: "com.atproto.space.getLatestCommit"
|
|
260
|
+
}],
|
|
261
|
+
needs: [],
|
|
262
|
+
async run(ctx) {
|
|
263
|
+
const res = await xrpcGet(ctx, "com.atproto.space.getLatestCommit", {
|
|
264
|
+
space: "not-a-space-uri",
|
|
265
|
+
repo: ctx.target.did
|
|
266
|
+
});
|
|
267
|
+
if (res.status >= 400 && res.status < 500) return pass(`rejected with ${res.status} ${res.error ?? ""}`);
|
|
268
|
+
return fail(`did not reject a malformed space uri (${res.status})`, res.json);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
/** Checks that need no crypto and no session — safe in any transport. */
|
|
272
|
+
const baseChecks = [
|
|
273
|
+
discoveryServiceEntry,
|
|
274
|
+
discoveryVerificationKey,
|
|
275
|
+
authGetRecordRequiresAuth,
|
|
276
|
+
authCredentialRequiresToken,
|
|
277
|
+
requestInvalidSpaceUri
|
|
278
|
+
];
|
|
279
|
+
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/dpop.ts
|
|
282
|
+
function b64url(bytes) {
|
|
283
|
+
let bin = "";
|
|
284
|
+
for (const b of bytes) bin += String.fromCharCode(b);
|
|
285
|
+
return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* WebCrypto ES256 DPoP key implementing the minimal surface a DPoP proof
|
|
289
|
+
* needs (`bareJwk`, `algorithms`, `createJwt`) plus the RFC 7638
|
|
290
|
+
* thumbprint. Hand-rolled to avoid `@atproto/jwk-jose`, whose bundled jose
|
|
291
|
+
* resolves to its Node build under the workers test pool and cannot sign.
|
|
292
|
+
*/
|
|
293
|
+
async function createDpopKey() {
|
|
294
|
+
const pair = await crypto.subtle.generateKey({
|
|
295
|
+
name: "ECDSA",
|
|
296
|
+
namedCurve: "P-256"
|
|
297
|
+
}, true, ["sign"]);
|
|
298
|
+
const jwk = await crypto.subtle.exportKey("jwk", pair.publicKey);
|
|
299
|
+
const bareJwk = {
|
|
300
|
+
crv: jwk.crv,
|
|
301
|
+
kty: jwk.kty,
|
|
302
|
+
x: jwk.x,
|
|
303
|
+
y: jwk.y
|
|
304
|
+
};
|
|
305
|
+
const thumbInput = new TextEncoder().encode(JSON.stringify(bareJwk));
|
|
306
|
+
const jkt = b64url(new Uint8Array(await crypto.subtle.digest("SHA-256", thumbInput)));
|
|
307
|
+
const encode = (obj) => b64url(new TextEncoder().encode(JSON.stringify(obj)));
|
|
308
|
+
return {
|
|
309
|
+
bareJwk,
|
|
310
|
+
algorithms: ["ES256"],
|
|
311
|
+
jkt,
|
|
312
|
+
async createJwt(header, payload) {
|
|
313
|
+
const input = `${encode(header)}.${encode(payload)}`;
|
|
314
|
+
return `${input}.${b64url(new Uint8Array(await crypto.subtle.sign({
|
|
315
|
+
name: "ECDSA",
|
|
316
|
+
hash: "SHA-256"
|
|
317
|
+
}, pair.privateKey, new TextEncoder().encode(input))))}`;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* An RFC 9449 DPoP proof over `key`, matching the reference verifier:
|
|
323
|
+
* header `{alg, typ: "dpop+jwt", jwk}`; claims `jti` (random), `htm`,
|
|
324
|
+
* `htu` (query and fragment stripped, RFC 9449 §4.2), `iat`, and — only
|
|
325
|
+
* when presenting a credential — `ath`, the base64url SHA-256 of it.
|
|
326
|
+
*/
|
|
327
|
+
async function createDpopProofJwt(key, opts) {
|
|
328
|
+
const htuUrl = new URL(opts.htu);
|
|
329
|
+
const jti = b64url(crypto.getRandomValues(new Uint8Array(16)));
|
|
330
|
+
const ath = opts.credential !== void 0 ? b64url(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(opts.credential)))) : void 0;
|
|
331
|
+
return key.createJwt({
|
|
332
|
+
alg: "ES256",
|
|
333
|
+
typ: "dpop+jwt",
|
|
334
|
+
jwk: key.bareJwk
|
|
335
|
+
}, {
|
|
336
|
+
jti,
|
|
337
|
+
htm: opts.htm,
|
|
338
|
+
htu: htuUrl.origin + htuUrl.pathname,
|
|
339
|
+
...ath !== void 0 ? { ath } : {},
|
|
340
|
+
iat: Math.floor(Date.now() / 1e3)
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region src/car.ts
|
|
346
|
+
/**
|
|
347
|
+
* Just enough CARv1 reading to assert getRepo's declared shape: the
|
|
348
|
+
* lexicon requires exactly two roots (the signed commit, then the index).
|
|
349
|
+
* Reading the header needs only a varint and a dag-cbor decode — no CAR
|
|
350
|
+
* library, no node streams — so it stays runnable anywhere the full entry
|
|
351
|
+
* runs.
|
|
352
|
+
*/
|
|
353
|
+
function readVarint(bytes, offset) {
|
|
354
|
+
let result = 0;
|
|
355
|
+
let shift = 0;
|
|
356
|
+
let pos = offset;
|
|
357
|
+
for (;;) {
|
|
358
|
+
const byte = bytes[pos];
|
|
359
|
+
if (byte === void 0) throw new Error("truncated varint");
|
|
360
|
+
result |= (byte & 127) << shift;
|
|
361
|
+
pos += 1;
|
|
362
|
+
if ((byte & 128) === 0) break;
|
|
363
|
+
shift += 7;
|
|
364
|
+
}
|
|
365
|
+
return [result, pos];
|
|
366
|
+
}
|
|
367
|
+
/** Parse just the CARv1 header block and report its version and root count. */
|
|
368
|
+
function readCarHeader(bytes) {
|
|
369
|
+
const [headerLen, afterVarint] = readVarint(bytes, 0);
|
|
370
|
+
const header = decode(bytes.subarray(afterVarint, afterVarint + headerLen));
|
|
371
|
+
return {
|
|
372
|
+
version: header.version ?? 0,
|
|
373
|
+
rootCount: Array.isArray(header.roots) ? header.roots.length : 0
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/checks/operator.ts
|
|
379
|
+
/**
|
|
380
|
+
* Operator checks: everything an authenticated session can prove with the
|
|
381
|
+
* platform's own `fetch` and WebCrypto — no alpha crypto libs, no foreign
|
|
382
|
+
* identities. They run wherever the base checks run, browsers included, as
|
|
383
|
+
* long as the harness supplies an `operator` capability (and, for the
|
|
384
|
+
* blob and credential checks, `pds-blobs` / `pds-delegation`).
|
|
385
|
+
*
|
|
386
|
+
* The split matters: checks live here or in `../full/checks.js` by what
|
|
387
|
+
* they *actually import*, not by topic. A check that only makes authed
|
|
388
|
+
* XRPC calls belongs here even if its subject is credentials — the
|
|
389
|
+
* operator's own delegation → credential → read flow needs nothing but an
|
|
390
|
+
* ES256 JWT the browser can mint.
|
|
391
|
+
*/
|
|
392
|
+
const POST = "test.conformance.note";
|
|
393
|
+
const note = (text) => ({
|
|
394
|
+
$type: POST,
|
|
395
|
+
text
|
|
396
|
+
});
|
|
397
|
+
const PROBE_TYPE = "app.bsky.group";
|
|
398
|
+
/** A run-unique skey so probe spaces never collide with real ones. */
|
|
399
|
+
function probeSkey() {
|
|
400
|
+
const rand = crypto.getRandomValues(new Uint8Array(8));
|
|
401
|
+
return `probe${Array.from(rand, (b) => b.toString(36)).join("").slice(0, 10)}`;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Create a probe space owned by the target and cache it for the run.
|
|
405
|
+
* Requires an operator session with space management authority.
|
|
406
|
+
*/
|
|
407
|
+
async function createProbeSpace(ctx, policy = { $type: "com.atproto.simplespace.defs#memberListPolicy" }, appAccess = { $type: "com.atproto.simplespace.defs#open" }) {
|
|
408
|
+
const skey = probeSkey();
|
|
409
|
+
const res = await xrpcPost(asOperator(ctx), "com.atproto.simplespace.createSpace", {
|
|
410
|
+
type: PROBE_TYPE,
|
|
411
|
+
skey,
|
|
412
|
+
policy,
|
|
413
|
+
appAccess
|
|
414
|
+
});
|
|
415
|
+
if (res.status !== 200) throw new Error(`createSpace failed: ${res.status} ${res.error ?? ""} ${JSON.stringify(res.json)}`);
|
|
416
|
+
return {
|
|
417
|
+
uri: res.json.uri,
|
|
418
|
+
type: PROBE_TYPE,
|
|
419
|
+
skey
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
/** Delete a probe space, best-effort (cleanup). */
|
|
423
|
+
async function deleteProbeSpace(ctx, space) {
|
|
424
|
+
await xrpcPost(asOperator(ctx), "com.atproto.simplespace.deleteSpace", { space }).catch(() => {});
|
|
425
|
+
}
|
|
426
|
+
/** Operator creates a record in a space; returns the response. */
|
|
427
|
+
async function operatorCreateRecord(ctx, space, collection, rkey, record) {
|
|
428
|
+
return xrpcPost(asOperator(ctx), "com.atproto.space.createRecord", {
|
|
429
|
+
space,
|
|
430
|
+
repo: ctx.target.did,
|
|
431
|
+
collection,
|
|
432
|
+
rkey,
|
|
433
|
+
record
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Obtain a credential the way a real app does: ask the target's own
|
|
438
|
+
* `getDelegationToken` (with the operator session) for a delegation token,
|
|
439
|
+
* then exchange it at `getSpaceCredential`. This is the bulletin self-flow
|
|
440
|
+
* — it needs no harness-held reader key, so it runs against any real PDS
|
|
441
|
+
* (Cirrus, the reference) and exercises the target's own token minting.
|
|
442
|
+
*/
|
|
443
|
+
async function obtainCredentialViaDelegation(ctx, space) {
|
|
444
|
+
const delegation = await xrpcGet(asOperator(ctx), "com.atproto.space.getDelegationToken", { space });
|
|
445
|
+
if (delegation.status !== 200) return {
|
|
446
|
+
result: delegation,
|
|
447
|
+
delegation
|
|
448
|
+
};
|
|
449
|
+
const token = delegation.json.token;
|
|
450
|
+
const dpopKey = await createDpopKey();
|
|
451
|
+
const proof = await createDpopProofJwt(dpopKey, {
|
|
452
|
+
htm: "POST",
|
|
453
|
+
htu: `${ctx.target.origin}/xrpc/com.atproto.space.getSpaceCredential`
|
|
454
|
+
});
|
|
455
|
+
const result = await xrpcPost(ctx, "com.atproto.space.getSpaceCredential", { space }, {
|
|
456
|
+
Authorization: `Bearer ${token}`,
|
|
457
|
+
DPoP: proof
|
|
458
|
+
});
|
|
459
|
+
if (result.status === 200) return {
|
|
460
|
+
result,
|
|
461
|
+
credential: {
|
|
462
|
+
credential: result.json.credential,
|
|
463
|
+
dpopKey
|
|
464
|
+
},
|
|
465
|
+
delegation
|
|
466
|
+
};
|
|
467
|
+
return {
|
|
468
|
+
result,
|
|
469
|
+
delegation
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
/** A credential-authenticated GET, with a fresh proof bound to the request. */
|
|
473
|
+
async function credentialGet(ctx, credential, nsid, params) {
|
|
474
|
+
const url = new URL(`${ctx.target.origin}/xrpc/${nsid}`);
|
|
475
|
+
for (const [key, value] of Object.entries(params)) if (value !== void 0) url.searchParams.set(key, value);
|
|
476
|
+
const proof = await createDpopProofJwt(credential.dpopKey, {
|
|
477
|
+
htm: "GET",
|
|
478
|
+
htu: `${ctx.target.origin}/xrpc/${nsid}`,
|
|
479
|
+
credential: credential.credential
|
|
480
|
+
});
|
|
481
|
+
const response = await ctx.fetch(url.toString(), {
|
|
482
|
+
method: "GET",
|
|
483
|
+
headers: {
|
|
484
|
+
Authorization: `DPoP ${credential.credential}`,
|
|
485
|
+
DPoP: proof
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
const contentType = response.headers.get("Content-Type") ?? "";
|
|
489
|
+
let json;
|
|
490
|
+
let error;
|
|
491
|
+
if (contentType.includes("application/json")) {
|
|
492
|
+
json = await response.clone().json().catch(() => void 0);
|
|
493
|
+
if (json && typeof json === "object" && "error" in json) error = String(json.error);
|
|
494
|
+
}
|
|
495
|
+
return {
|
|
496
|
+
status: response.status,
|
|
497
|
+
json,
|
|
498
|
+
error,
|
|
499
|
+
headers: response.headers,
|
|
500
|
+
response
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
const writesCreateRead = defineCheck({
|
|
504
|
+
id: "writes.create-and-read",
|
|
505
|
+
title: "Operator creates a record and reads it back",
|
|
506
|
+
tier: "must",
|
|
507
|
+
citations: [{
|
|
508
|
+
source: "lexicon",
|
|
509
|
+
ref: "com.atproto.space.createRecord"
|
|
510
|
+
}, {
|
|
511
|
+
source: "lexicon",
|
|
512
|
+
ref: "com.atproto.space.getRecord"
|
|
513
|
+
}],
|
|
514
|
+
needs: ["operator"],
|
|
515
|
+
destructive: true,
|
|
516
|
+
async run(ctx) {
|
|
517
|
+
const space = await createProbeSpace(ctx);
|
|
518
|
+
try {
|
|
519
|
+
const created = await operatorCreateRecord(ctx, space.uri, POST, "rec1", note("hello"));
|
|
520
|
+
if (created.status !== 200) return fail(`createRecord ${created.status} ${created.error ?? ""}`, created.json);
|
|
521
|
+
const read = await xrpcGet(asOperator(ctx), "com.atproto.space.getRecord", {
|
|
522
|
+
space: space.uri,
|
|
523
|
+
repo: ctx.target.did,
|
|
524
|
+
collection: POST,
|
|
525
|
+
rkey: "rec1"
|
|
526
|
+
});
|
|
527
|
+
if (read.status !== 200) return fail(`getRecord ${read.status} ${read.error ?? ""}`, read.json);
|
|
528
|
+
return read.json.value?.text === "hello" ? pass("round-tripped the record value") : fail("record value did not round-trip", read.json);
|
|
529
|
+
} finally {
|
|
530
|
+
await deleteProbeSpace(ctx, space.uri);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
const writesUnauthReadRefused = defineCheck({
|
|
535
|
+
id: "auth.existing-record-unauth-refused",
|
|
536
|
+
title: "An existing space record is not readable without auth",
|
|
537
|
+
tier: "must",
|
|
538
|
+
citations: [{
|
|
539
|
+
source: "lexicon",
|
|
540
|
+
ref: "com.atproto.space.getRecord"
|
|
541
|
+
}],
|
|
542
|
+
needs: ["operator"],
|
|
543
|
+
destructive: true,
|
|
544
|
+
async run(ctx) {
|
|
545
|
+
const space = await createProbeSpace(ctx);
|
|
546
|
+
try {
|
|
547
|
+
const created = await operatorCreateRecord(ctx, space.uri, POST, "private", note("not for you"));
|
|
548
|
+
if (created.status !== 200) return fail(`createRecord ${created.status} ${created.error ?? ""}; cannot probe the unauth read`, created.json);
|
|
549
|
+
const res = await xrpcGet(ctx, "com.atproto.space.getRecord", {
|
|
550
|
+
space: space.uri,
|
|
551
|
+
repo: ctx.target.did,
|
|
552
|
+
collection: POST,
|
|
553
|
+
rkey: "private"
|
|
554
|
+
});
|
|
555
|
+
if (res.status === 200) return fail("an existing space record was served with no auth", res.json);
|
|
556
|
+
return res.status === 401 || res.status === 403 ? pass(`unauthenticated read of a real record refused (${res.status})`) : fail(`refused, but with ${res.status} ${res.error ?? ""} rather than 401/403`, res.json);
|
|
557
|
+
} finally {
|
|
558
|
+
await deleteProbeSpace(ctx, space.uri);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
const writesDuplicate = defineCheck({
|
|
563
|
+
id: "writes.duplicate-rejected",
|
|
564
|
+
title: "A second create at the same key is refused with RecordAlreadyExists",
|
|
565
|
+
tier: "must",
|
|
566
|
+
citations: [{
|
|
567
|
+
source: "lexicon",
|
|
568
|
+
ref: "com.atproto.space.createRecord@error:RecordAlreadyExists"
|
|
569
|
+
}],
|
|
570
|
+
needs: ["operator"],
|
|
571
|
+
destructive: true,
|
|
572
|
+
async run(ctx) {
|
|
573
|
+
const space = await createProbeSpace(ctx);
|
|
574
|
+
try {
|
|
575
|
+
const first = await operatorCreateRecord(ctx, space.uri, POST, "dup", note("one"));
|
|
576
|
+
if (first.status !== 200) return fail(`first create failed (${first.status}); cannot test duplicates`, first.json);
|
|
577
|
+
const second = await operatorCreateRecord(ctx, space.uri, POST, "dup", note("two"));
|
|
578
|
+
if (second.status === 200) return fail("duplicate create returned 200");
|
|
579
|
+
return second.error === "RecordAlreadyExists" ? pass("refused with RecordAlreadyExists") : fail(`refused but error was ${second.error} (${second.status})`, second.json);
|
|
580
|
+
} finally {
|
|
581
|
+
await deleteProbeSpace(ctx, space.uri);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
const writesDeleteIdempotent = defineCheck({
|
|
586
|
+
id: "writes.delete-idempotent",
|
|
587
|
+
title: "deleteRecord removes the record and is idempotent",
|
|
588
|
+
tier: "must",
|
|
589
|
+
citations: [{
|
|
590
|
+
source: "lexicon",
|
|
591
|
+
ref: "com.atproto.space.deleteRecord"
|
|
592
|
+
}, {
|
|
593
|
+
source: "lexicon",
|
|
594
|
+
ref: "com.atproto.space.getRecord"
|
|
595
|
+
}],
|
|
596
|
+
needs: ["operator"],
|
|
597
|
+
destructive: true,
|
|
598
|
+
async run(ctx) {
|
|
599
|
+
const space = await createProbeSpace(ctx);
|
|
600
|
+
try {
|
|
601
|
+
const del = (rkey) => xrpcPost(asOperator(ctx), "com.atproto.space.deleteRecord", {
|
|
602
|
+
space: space.uri,
|
|
603
|
+
repo: ctx.target.did,
|
|
604
|
+
collection: POST,
|
|
605
|
+
rkey
|
|
606
|
+
});
|
|
607
|
+
const created = await operatorCreateRecord(ctx, space.uri, POST, "doomed", note("bye"));
|
|
608
|
+
if (created.status !== 200) return fail(`createRecord ${created.status} ${created.error ?? ""}; cannot test deletion`, created.json);
|
|
609
|
+
const removed = await del("doomed");
|
|
610
|
+
if (removed.status !== 200) return fail(`delete of an existing record returned ${removed.status} ${removed.error ?? ""}`, removed.json);
|
|
611
|
+
const after = await xrpcGet(asOperator(ctx), "com.atproto.space.getRecord", {
|
|
612
|
+
space: space.uri,
|
|
613
|
+
repo: ctx.target.did,
|
|
614
|
+
collection: POST,
|
|
615
|
+
rkey: "doomed"
|
|
616
|
+
});
|
|
617
|
+
if (after.status === 200) return fail("a deleted record was still readable", after.json);
|
|
618
|
+
const again = await del("doomed");
|
|
619
|
+
const ghost = await del("ghost");
|
|
620
|
+
if (again.status !== 200 || ghost.status !== 200) return fail(`repeat delete returned ${again.status}, absent-key delete returned ${ghost.status}`, {
|
|
621
|
+
again: again.json,
|
|
622
|
+
ghost: ghost.json
|
|
623
|
+
});
|
|
624
|
+
return pass("delete removed the record; repeat and absent deletes 200");
|
|
625
|
+
} finally {
|
|
626
|
+
await deleteProbeSpace(ctx, space.uri);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
const writesApplyWritesAtomic = defineCheck({
|
|
631
|
+
id: "writes.applywrites-atomic",
|
|
632
|
+
title: "A failing applyWrites batch commits nothing",
|
|
633
|
+
tier: "must",
|
|
634
|
+
citations: [{
|
|
635
|
+
source: "lexicon",
|
|
636
|
+
ref: "com.atproto.space.applyWrites"
|
|
637
|
+
}, {
|
|
638
|
+
source: "lexicon",
|
|
639
|
+
ref: "com.atproto.space.applyWrites@error:RecordAlreadyExists"
|
|
640
|
+
}],
|
|
641
|
+
needs: ["operator"],
|
|
642
|
+
destructive: true,
|
|
643
|
+
async run(ctx) {
|
|
644
|
+
const space = await createProbeSpace(ctx);
|
|
645
|
+
const op = asOperator(ctx);
|
|
646
|
+
try {
|
|
647
|
+
await operatorCreateRecord(ctx, space.uri, POST, "exists", note("here"));
|
|
648
|
+
const ok = await xrpcPost(op, "com.atproto.space.applyWrites", {
|
|
649
|
+
space: space.uri,
|
|
650
|
+
repo: ctx.target.did,
|
|
651
|
+
writes: [{
|
|
652
|
+
$type: "com.atproto.space.applyWrites#create",
|
|
653
|
+
collection: POST,
|
|
654
|
+
rkey: "ok1",
|
|
655
|
+
value: note("1")
|
|
656
|
+
}, {
|
|
657
|
+
$type: "com.atproto.space.applyWrites#create",
|
|
658
|
+
collection: POST,
|
|
659
|
+
rkey: "ok2",
|
|
660
|
+
value: note("2")
|
|
661
|
+
}]
|
|
662
|
+
});
|
|
663
|
+
if (ok.status !== 200) return fail(`applyWrites did not accept a valid batch (${ok.status} ${ok.error ?? ""})`, ok.json);
|
|
664
|
+
const batch = await xrpcPost(op, "com.atproto.space.applyWrites", {
|
|
665
|
+
space: space.uri,
|
|
666
|
+
repo: ctx.target.did,
|
|
667
|
+
writes: [{
|
|
668
|
+
$type: "com.atproto.space.applyWrites#create",
|
|
669
|
+
collection: POST,
|
|
670
|
+
rkey: "fresh",
|
|
671
|
+
value: note("new")
|
|
672
|
+
}, {
|
|
673
|
+
$type: "com.atproto.space.applyWrites#create",
|
|
674
|
+
collection: POST,
|
|
675
|
+
rkey: "exists",
|
|
676
|
+
value: note("collide")
|
|
677
|
+
}]
|
|
678
|
+
});
|
|
679
|
+
if (batch.status === 200) return fail("colliding batch returned 200");
|
|
680
|
+
if (batch.error !== "RecordAlreadyExists") return fail(`colliding batch refused with ${batch.error} (${batch.status}), expected RecordAlreadyExists`, batch.json);
|
|
681
|
+
const check = await xrpcGet(op, "com.atproto.space.getRecord", {
|
|
682
|
+
space: space.uri,
|
|
683
|
+
repo: ctx.target.did,
|
|
684
|
+
collection: POST,
|
|
685
|
+
rkey: "fresh"
|
|
686
|
+
});
|
|
687
|
+
return check.status !== 200 ? pass("a failed batch committed nothing") : fail("a failed batch left its first op committed", check.json);
|
|
688
|
+
} finally {
|
|
689
|
+
await deleteProbeSpace(ctx, space.uri);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
const credentialSelfRoundTrip = defineCheck({
|
|
694
|
+
id: "credential.self-round-trip",
|
|
695
|
+
title: "Operator obtains a credential for its own space via getDelegationToken and reads",
|
|
696
|
+
tier: "must",
|
|
697
|
+
citations: [
|
|
698
|
+
{
|
|
699
|
+
source: "lexicon",
|
|
700
|
+
ref: "com.atproto.space.getDelegationToken"
|
|
701
|
+
},
|
|
702
|
+
{
|
|
703
|
+
source: "lexicon",
|
|
704
|
+
ref: "com.atproto.space.getSpaceCredential"
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
source: "lexicon",
|
|
708
|
+
ref: "com.atproto.space.getRecord"
|
|
709
|
+
}
|
|
710
|
+
],
|
|
711
|
+
needs: ["operator", "pds-delegation"],
|
|
712
|
+
destructive: true,
|
|
713
|
+
async run(ctx) {
|
|
714
|
+
const space = await createProbeSpace(ctx, { $type: "com.atproto.simplespace.defs#publicPolicy" });
|
|
715
|
+
try {
|
|
716
|
+
await operatorCreateRecord(ctx, space.uri, POST, "self", note("mine"));
|
|
717
|
+
const { result, credential, delegation } = await obtainCredentialViaDelegation(ctx, space.uri);
|
|
718
|
+
if (delegation.status !== 200) return fail(`getDelegationToken ${delegation.status} ${delegation.error ?? ""}`, delegation.json);
|
|
719
|
+
if (!credential) return fail(`getSpaceCredential ${result.status} ${result.error ?? ""}`, result.json);
|
|
720
|
+
const read = await credentialGet(ctx, credential, "com.atproto.space.getRecord", {
|
|
721
|
+
space: space.uri,
|
|
722
|
+
repo: ctx.target.did,
|
|
723
|
+
collection: POST,
|
|
724
|
+
rkey: "self"
|
|
725
|
+
});
|
|
726
|
+
return read.status === 200 ? pass("delegation → credential → read round-trip works") : fail(`credential read failed: ${read.status} ${read.error ?? ""}`, read.json);
|
|
727
|
+
} finally {
|
|
728
|
+
await deleteProbeSpace(ctx, space.uri);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
const syncGetRepoTwoRoots = defineCheck({
|
|
733
|
+
id: "sync.getrepo-two-roots",
|
|
734
|
+
title: "getRepo returns a CAR declaring exactly two roots",
|
|
735
|
+
tier: "must",
|
|
736
|
+
citations: [{
|
|
737
|
+
source: "lexicon",
|
|
738
|
+
ref: "com.atproto.space.getRepo"
|
|
739
|
+
}],
|
|
740
|
+
needs: ["operator"],
|
|
741
|
+
destructive: true,
|
|
742
|
+
async run(ctx) {
|
|
743
|
+
const space = await createProbeSpace(ctx);
|
|
744
|
+
try {
|
|
745
|
+
await operatorCreateRecord(ctx, space.uri, POST, "x", note("car"));
|
|
746
|
+
const res = await operatorFetch(ctx)(`${ctx.target.origin}/xrpc/com.atproto.space.getRepo?space=${encodeURIComponent(space.uri)}&repo=${encodeURIComponent(ctx.target.did)}`);
|
|
747
|
+
if (res.status !== 200) return fail(`getRepo ${res.status}`);
|
|
748
|
+
const contentType = res.headers.get("Content-Type") ?? "";
|
|
749
|
+
if (!contentType.includes("application/vnd.ipld.car")) return fail(`getRepo content-type was ${contentType}`);
|
|
750
|
+
const header = readCarHeader(new Uint8Array(await res.arrayBuffer()));
|
|
751
|
+
return header.rootCount === 2 ? pass(`CAR v${header.version} with 2 roots`) : fail(`CAR declared ${header.rootCount} roots, expected 2`);
|
|
752
|
+
} finally {
|
|
753
|
+
await deleteProbeSpace(ctx, space.uri);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
});
|
|
757
|
+
const syncListRecordsDescending = defineCheck({
|
|
758
|
+
id: "sync.listrecords-descending-default",
|
|
759
|
+
title: "listRecords defaults to descending record order",
|
|
760
|
+
tier: "should",
|
|
761
|
+
citations: [{
|
|
762
|
+
source: "reference",
|
|
763
|
+
ref: "listRecords default order (descending)"
|
|
764
|
+
}, {
|
|
765
|
+
source: "lexicon",
|
|
766
|
+
ref: "com.atproto.space.listRecords"
|
|
767
|
+
}],
|
|
768
|
+
needs: ["operator"],
|
|
769
|
+
destructive: true,
|
|
770
|
+
async run(ctx) {
|
|
771
|
+
const space = await createProbeSpace(ctx);
|
|
772
|
+
try {
|
|
773
|
+
for (const rkey of [
|
|
774
|
+
"aaa",
|
|
775
|
+
"bbb",
|
|
776
|
+
"ccc"
|
|
777
|
+
]) await operatorCreateRecord(ctx, space.uri, POST, rkey, note(rkey));
|
|
778
|
+
const res = await xrpcGet(asOperator(ctx), "com.atproto.space.listRecords", {
|
|
779
|
+
space: space.uri,
|
|
780
|
+
repo: ctx.target.did,
|
|
781
|
+
collection: POST
|
|
782
|
+
});
|
|
783
|
+
if (res.status !== 200) return fail(`listRecords ${res.status}`);
|
|
784
|
+
const rkeys = res.json.records.map((r) => r.rkey);
|
|
785
|
+
return rkeys.join(",") === "ccc,bbb,aaa" ? pass("records returned descending by default") : fail(`order was ${rkeys.join(",")}, reference is descending`);
|
|
786
|
+
} finally {
|
|
787
|
+
await deleteProbeSpace(ctx, space.uri);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
const hostListReposNeedsCredential = defineCheck({
|
|
792
|
+
id: "host.listrepos-requires-credential",
|
|
793
|
+
title: "listRepos requires a space credential",
|
|
794
|
+
tier: "must",
|
|
795
|
+
citations: [{
|
|
796
|
+
source: "lexicon",
|
|
797
|
+
ref: "com.atproto.space.listRepos"
|
|
798
|
+
}],
|
|
799
|
+
needs: ["operator"],
|
|
800
|
+
destructive: true,
|
|
801
|
+
async run(ctx) {
|
|
802
|
+
const space = await createProbeSpace(ctx);
|
|
803
|
+
try {
|
|
804
|
+
const res = await xrpcGet(ctx, "com.atproto.space.listRepos", { space: space.uri });
|
|
805
|
+
return res.status === 401 || res.status === 403 ? pass(`unauthenticated listRepos refused with ${res.status}`) : fail(`unauthenticated listRepos returned ${res.status}`, res.json);
|
|
806
|
+
} finally {
|
|
807
|
+
await deleteProbeSpace(ctx, space.uri);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
const simplespaceUnsupportedPolicy = defineCheck({
|
|
812
|
+
id: "simplespace.unsupported-policy-rejected",
|
|
813
|
+
title: "createSpace rejects an unknown policy variant",
|
|
814
|
+
tier: "must",
|
|
815
|
+
citations: [{
|
|
816
|
+
source: "lexicon",
|
|
817
|
+
ref: "com.atproto.simplespace.createSpace@error:UnsupportedPolicy"
|
|
818
|
+
}],
|
|
819
|
+
needs: ["operator"],
|
|
820
|
+
async run(ctx) {
|
|
821
|
+
const res = await xrpcPost(asOperator(ctx), "com.atproto.simplespace.createSpace", {
|
|
822
|
+
type: "app.bsky.group",
|
|
823
|
+
policy: { $type: "com.example.mysteryPolicy" },
|
|
824
|
+
appAccess: { $type: "com.atproto.simplespace.defs#open" }
|
|
825
|
+
});
|
|
826
|
+
if (res.status === 200) {
|
|
827
|
+
await deleteProbeSpace(ctx, res.json.uri);
|
|
828
|
+
return fail("an unknown policy variant was accepted");
|
|
829
|
+
}
|
|
830
|
+
return res.error === "UnsupportedPolicy" ? pass("rejected with UnsupportedPolicy") : fail(`rejected with ${res.error} (${res.status}), expected UnsupportedPolicy`, res.json);
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
const simplespaceGetSpace = defineCheck({
|
|
834
|
+
id: "simplespace.getspace-reflects-config",
|
|
835
|
+
title: "getSpace reflects the created policy and appAccess",
|
|
836
|
+
tier: "must",
|
|
837
|
+
citations: [{
|
|
838
|
+
source: "lexicon",
|
|
839
|
+
ref: "com.atproto.simplespace.createSpace"
|
|
840
|
+
}, {
|
|
841
|
+
source: "lexicon",
|
|
842
|
+
ref: "com.atproto.simplespace.getSpace"
|
|
843
|
+
}],
|
|
844
|
+
needs: ["operator"],
|
|
845
|
+
destructive: true,
|
|
846
|
+
async run(ctx) {
|
|
847
|
+
const space = await createProbeSpace(ctx, { $type: "com.atproto.simplespace.defs#publicPolicy" });
|
|
848
|
+
try {
|
|
849
|
+
const res = await xrpcGet(asOperator(ctx), "com.atproto.simplespace.getSpace", { space: space.uri });
|
|
850
|
+
if (res.status !== 200) return fail(`getSpace ${res.status} ${res.error ?? ""}`, res.json);
|
|
851
|
+
const body = res.json;
|
|
852
|
+
const policyType = body.policy?.$type;
|
|
853
|
+
if (policyType !== "com.atproto.simplespace.defs#publicPolicy") return fail(`getSpace policy was ${policyType}`, res.json);
|
|
854
|
+
const appAccessType = body.appAccess?.$type;
|
|
855
|
+
return appAccessType === "com.atproto.simplespace.defs#open" ? pass("getSpace reported the public policy and open appAccess") : fail(`getSpace appAccess was ${appAccessType}`, res.json);
|
|
856
|
+
} finally {
|
|
857
|
+
await deleteProbeSpace(ctx, space.uri);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
/** Blob isolation (S6): a space blob is never public. */
|
|
862
|
+
const blobsSpaceNotPublic = defineCheck({
|
|
863
|
+
id: "blobs.space-blob-not-public",
|
|
864
|
+
title: "A blob is not publicly served unless a public record references it",
|
|
865
|
+
tier: "must",
|
|
866
|
+
citations: [{
|
|
867
|
+
source: "lexicon",
|
|
868
|
+
ref: "com.atproto.space.getBlob"
|
|
869
|
+
}, {
|
|
870
|
+
source: "proposal",
|
|
871
|
+
ref: "0016#blob-sync"
|
|
872
|
+
}],
|
|
873
|
+
needs: ["operator", "pds-blobs"],
|
|
874
|
+
destructive: true,
|
|
875
|
+
async run(ctx) {
|
|
876
|
+
const space = await createProbeSpace(ctx);
|
|
877
|
+
try {
|
|
878
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
879
|
+
const upload = await operatorFetch(ctx)(`${ctx.target.origin}/xrpc/com.atproto.repo.uploadBlob`, {
|
|
880
|
+
method: "POST",
|
|
881
|
+
headers: { "Content-Type": "application/octet-stream" },
|
|
882
|
+
body: bytes
|
|
883
|
+
});
|
|
884
|
+
if (upload.status !== 200) return fail(`uploadBlob ${upload.status}`);
|
|
885
|
+
const blob = (await upload.json()).blob;
|
|
886
|
+
const cid = blob.ref.$link;
|
|
887
|
+
const publicUrl = `${ctx.target.origin}/xrpc/com.atproto.sync.getBlob?did=${encodeURIComponent(ctx.target.did)}&cid=${cid}`;
|
|
888
|
+
const stagedGet = await ctx.fetch(publicUrl);
|
|
889
|
+
if (stagedGet.status === 200) return fail("an uploaded, unreferenced blob was served by the public sync.getBlob");
|
|
890
|
+
const write = await operatorCreateRecord(ctx, space.uri, "test.conformance.withblob", "self", {
|
|
891
|
+
$type: "test.conformance.withblob",
|
|
892
|
+
file: blob
|
|
893
|
+
});
|
|
894
|
+
if (write.status !== 200) return fail(`referencing write ${write.status} ${write.error ?? ""}`, write.json);
|
|
895
|
+
const publicGet = await ctx.fetch(publicUrl);
|
|
896
|
+
return publicGet.status === 200 ? fail("a space blob was served by the public sync.getBlob") : pass(`public sync.getBlob refused the blob unreferenced (${stagedGet.status}) and space-referenced (${publicGet.status})`);
|
|
897
|
+
} finally {
|
|
898
|
+
await deleteProbeSpace(ctx, space.uri);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
});
|
|
902
|
+
/**
|
|
903
|
+
* The operator catalog: runnable anywhere the harness has an operator
|
|
904
|
+
* session — browser included.
|
|
905
|
+
*/
|
|
906
|
+
const operatorChecks = [
|
|
907
|
+
writesCreateRead,
|
|
908
|
+
writesUnauthReadRefused,
|
|
909
|
+
writesDuplicate,
|
|
910
|
+
writesDeleteIdempotent,
|
|
911
|
+
writesApplyWritesAtomic,
|
|
912
|
+
credentialSelfRoundTrip,
|
|
913
|
+
syncGetRepoTwoRoots,
|
|
914
|
+
syncListRecordsDescending,
|
|
915
|
+
hostListReposNeedsCredential,
|
|
916
|
+
simplespaceUnsupportedPolicy,
|
|
917
|
+
simplespaceGetSpace,
|
|
918
|
+
blobsSpaceNotPublic
|
|
919
|
+
];
|
|
920
|
+
|
|
921
|
+
//#endregion
|
|
922
|
+
export { pass as S, xrpcUrl as _, note as a, filterCatalog as b, operatorCreateRecord as c, createDpopProofJwt as d, baseChecks as f, xrpcPost as g, xrpcGet as h, deleteProbeSpace as i, readCarHeader as l, operatorHeaders as m, createProbeSpace as n, obtainCredentialViaDelegation as o, asOperator as p, credentialGet as r, operatorChecks as s, POST as t, createDpopKey as u, buildCatalog as v, fail as x, defineCheck as y };
|
|
923
|
+
//# sourceMappingURL=operator-BErXCDow.js.map
|