@crombolo/remote-conformance 0.65.1 → 0.67.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/package.json +1 -1
- package/src/index.ts +381 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/remote-conformance",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.67.0",
|
|
4
4
|
"description": "Checks a server against the Crombolo remote protocol: discovery, sign-in, environments, pulls, pushes and media by reference.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
package/src/index.ts
CHANGED
|
@@ -22,6 +22,12 @@ export interface ConformanceOptions {
|
|
|
22
22
|
push?: boolean
|
|
23
23
|
/** How long to wait for a job, in milliseconds. */
|
|
24
24
|
timeoutMs?: number
|
|
25
|
+
/**
|
|
26
|
+
* Mints a token one of the providers `auth.people` names issued for the
|
|
27
|
+
* remote, for a person signed in to it once (story 364): the exchange is
|
|
28
|
+
* then checked end to end. Without it, only its refusals are.
|
|
29
|
+
*/
|
|
30
|
+
personToken?: (provider: { id: string; issuer: string; audience: string }) => Promise<string>
|
|
25
31
|
fetch?: typeof fetch
|
|
26
32
|
}
|
|
27
33
|
|
|
@@ -169,6 +175,67 @@ export async function runConformance(options: ConformanceOptions): Promise<Confo
|
|
|
169
175
|
})
|
|
170
176
|
}
|
|
171
177
|
|
|
178
|
+
// Optional: a person signed in through a provider (story 364). Offered by
|
|
179
|
+
// discovery alone, with the same endpoint and grant as CI's.
|
|
180
|
+
const people = (state.discovery?.auth as Json | undefined)?.people as Json | undefined
|
|
181
|
+
if (people) {
|
|
182
|
+
const providers = (people.providers as Json[] | undefined) ?? []
|
|
183
|
+
const exchange = (token: string) =>
|
|
184
|
+
http(String(people.tokenExchange), {
|
|
185
|
+
method: 'POST',
|
|
186
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
187
|
+
body: new URLSearchParams({
|
|
188
|
+
grant_type: String(people.grantType),
|
|
189
|
+
subject_token: token,
|
|
190
|
+
subject_token_type: String(people.subjectTokenType),
|
|
191
|
+
}).toString(),
|
|
192
|
+
})
|
|
193
|
+
const refusal = async (response: Response, token: string) => {
|
|
194
|
+
assert(response.status === 400, `answered ${response.status}`)
|
|
195
|
+
const text = await response.text()
|
|
196
|
+
assert(text.includes('invalid_grant'), 'the refusal is not invalid_grant')
|
|
197
|
+
assert(!text.includes(token), 'the refusal repeats the token')
|
|
198
|
+
}
|
|
199
|
+
await check(
|
|
200
|
+
'people: discovery names the exchange and each provider, issuer and audience',
|
|
201
|
+
async () => {
|
|
202
|
+
for (const field of ['tokenExchange', 'grantType', 'subjectTokenType', 'audience'])
|
|
203
|
+
assert(typeof people[field] === 'string', `auth.people.${field} is missing`)
|
|
204
|
+
assert(providers.length > 0, 'auth.people.providers is empty')
|
|
205
|
+
for (const provider of providers)
|
|
206
|
+
for (const field of ['id', 'issuer', 'audience'])
|
|
207
|
+
assert(typeof provider[field] === 'string', `a provider's ${field} is missing`)
|
|
208
|
+
},
|
|
209
|
+
)
|
|
210
|
+
await check("people: an unsigned token naming a provider's issuer is refused", async () => {
|
|
211
|
+
const claims = Buffer.from(JSON.stringify({ iss: providers[0]?.issuer })).toString(
|
|
212
|
+
'base64url',
|
|
213
|
+
)
|
|
214
|
+
const forged = `eyJhbGciOiJub25lIn0.${claims}.`
|
|
215
|
+
await refusal(await exchange(forged), forged)
|
|
216
|
+
})
|
|
217
|
+
await check('people: a minted token signs the person in, once', async () => {
|
|
218
|
+
const provider = providers[0]
|
|
219
|
+
if (!options.personToken || !provider) return 'skip'
|
|
220
|
+
const token = await options.personToken({
|
|
221
|
+
id: String(provider.id),
|
|
222
|
+
issuer: String(provider.issuer),
|
|
223
|
+
audience: String(provider.audience),
|
|
224
|
+
})
|
|
225
|
+
const answer = await exchange(token)
|
|
226
|
+
assert(answer.status === 200, `answered ${answer.status}`)
|
|
227
|
+
const body = (await answer.json()) as Json
|
|
228
|
+
assert(typeof body.access_token === 'string', 'no access_token')
|
|
229
|
+
assert(body.token_type === 'Bearer', 'token_type is not Bearer')
|
|
230
|
+
const me = await http(`${state.api}/me`, {
|
|
231
|
+
headers: { authorization: `Bearer ${String(body.access_token)}` },
|
|
232
|
+
})
|
|
233
|
+
assert(me.status === 200, `me answered ${me.status}`)
|
|
234
|
+
assert(((await me.json()) as Json).kind === 'person', 'me is not a person')
|
|
235
|
+
await refusal(await exchange(token), token)
|
|
236
|
+
})
|
|
237
|
+
}
|
|
238
|
+
|
|
172
239
|
await check('the API refuses a request without a token, as a problem', async () => {
|
|
173
240
|
const response = await http(`${state.api}/environments`)
|
|
174
241
|
assert(response.status === 401, `answered ${response.status}`)
|
|
@@ -269,6 +336,320 @@ export async function runConformance(options: ConformanceOptions): Promise<Confo
|
|
|
269
336
|
assert(isProblem(refused), 'not application/problem+json')
|
|
270
337
|
})
|
|
271
338
|
|
|
339
|
+
await check('content-history: an unknown page and an unknown version are not found', async () => {
|
|
340
|
+
const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
|
|
341
|
+
if (!capabilities.includes('content-history')) return 'skip'
|
|
342
|
+
const env = `environments/${state.environment}`
|
|
343
|
+
const page = await api(`${env}/content/${crypto.randomUUID()}/history`)
|
|
344
|
+
assert(page.status === 404, `an unknown page's history answered ${page.status}`)
|
|
345
|
+
assert(isProblem(page), 'not application/problem+json')
|
|
346
|
+
const version = await api(`${env}/content/versions/999999999`)
|
|
347
|
+
assert(version.status === 404, `an unknown version answered ${version.status}`)
|
|
348
|
+
const rollback = await api(`${env}/content/versions/999999999/rollback`, {
|
|
349
|
+
method: 'POST',
|
|
350
|
+
headers: { 'content-type': 'application/json' },
|
|
351
|
+
body: '{}',
|
|
352
|
+
})
|
|
353
|
+
assert(
|
|
354
|
+
rollback.status === 404,
|
|
355
|
+
`rolling back to an unknown version answered ${rollback.status}`,
|
|
356
|
+
)
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
await check(
|
|
360
|
+
'recycle-bin: lists its items, and refuses to restore what is not in it',
|
|
361
|
+
async () => {
|
|
362
|
+
const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
|
|
363
|
+
if (!capabilities.includes('recycle-bin')) return 'skip'
|
|
364
|
+
const env = `environments/${state.environment}`
|
|
365
|
+
const response = await api(`${env}/recycle-bin`)
|
|
366
|
+
assert(response.status === 200, `answered ${response.status}`)
|
|
367
|
+
const body = (await response.json()) as { items?: Json[] }
|
|
368
|
+
assert(Array.isArray(body.items), 'items is missing')
|
|
369
|
+
for (const item of body.items ?? []) {
|
|
370
|
+
assert(
|
|
371
|
+
typeof item.key === 'string' && typeof item.name === 'string',
|
|
372
|
+
'an item has no key or name',
|
|
373
|
+
)
|
|
374
|
+
assert(item.kind === 'content' || item.kind === 'media', `an item's kind is ${item.kind}`)
|
|
375
|
+
assert(typeof item.from === 'object' && item.from !== null, 'an item has no from')
|
|
376
|
+
}
|
|
377
|
+
const restore = await api(`${env}/recycle-bin/${crypto.randomUUID()}/restore`, {
|
|
378
|
+
method: 'POST',
|
|
379
|
+
headers: { 'content-type': 'application/json' },
|
|
380
|
+
body: '{}',
|
|
381
|
+
})
|
|
382
|
+
assert(restore.status === 404, `restoring what is not in the bin answered ${restore.status}`)
|
|
383
|
+
assert(isProblem(restore), 'not application/problem+json')
|
|
384
|
+
},
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
await check('members: lists members, and a member who is not there is not found', async () => {
|
|
388
|
+
const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
|
|
389
|
+
if (!capabilities.includes('members')) return 'skip'
|
|
390
|
+
const env = `environments/${state.environment}`
|
|
391
|
+
const listed = await api(`${env}/members?take=5`)
|
|
392
|
+
assert(listed.status === 200, `the list answered ${listed.status}`)
|
|
393
|
+
const body = (await listed.json()) as { items?: Json[]; total?: unknown }
|
|
394
|
+
assert(Array.isArray(body.items), 'items is missing')
|
|
395
|
+
assert(typeof body.total === 'number', 'total is missing')
|
|
396
|
+
for (const member of body.items ?? [])
|
|
397
|
+
assert(
|
|
398
|
+
typeof member.key === 'string' && typeof member.login === 'string',
|
|
399
|
+
'a member has no key or login',
|
|
400
|
+
)
|
|
401
|
+
const missing = await api(`${env}/members/${crypto.randomUUID()}`)
|
|
402
|
+
assert(missing.status === 404, `an unknown member answered ${missing.status}`)
|
|
403
|
+
assert(isProblem(missing), 'not application/problem+json')
|
|
404
|
+
const groups = await api(`${env}/member-groups`)
|
|
405
|
+
assert(groups.status === 200, `the groups answered ${groups.status}`)
|
|
406
|
+
assert(Array.isArray(((await groups.json()) as Json).groups), 'groups is missing')
|
|
407
|
+
})
|
|
408
|
+
|
|
409
|
+
await check(
|
|
410
|
+
"users: the caller's own sign-ins are listed, they are found, and a change of nothing changes nothing",
|
|
411
|
+
async () => {
|
|
412
|
+
const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
|
|
413
|
+
if (!capabilities.includes('users')) return 'skip'
|
|
414
|
+
const env = `environments/${state.environment}`
|
|
415
|
+
const listed = await api(`${env}/sign-ins`)
|
|
416
|
+
assert(listed.status === 200, `the sign-ins answered ${listed.status}`)
|
|
417
|
+
const items = ((await listed.json()) as { items?: Json[] }).items
|
|
418
|
+
assert(Array.isArray(items), 'items is missing')
|
|
419
|
+
const keys = new Set((items ?? []).map((item) => (item.user as Json | undefined)?.key))
|
|
420
|
+
for (const item of items ?? [])
|
|
421
|
+
assert(
|
|
422
|
+
typeof item.id === 'string' && (item.kind === 'browser' || item.kind === 'terminal'),
|
|
423
|
+
'a sign-in has no id, or is neither a browser nor a terminal',
|
|
424
|
+
)
|
|
425
|
+
assert(keys.size <= 1, "the sign-ins are not all the caller's own")
|
|
426
|
+
const me = [...keys][0]
|
|
427
|
+
if (typeof me !== 'string') return
|
|
428
|
+
const found = await api(`${env}/users?find=${encodeURIComponent(me)}`)
|
|
429
|
+
// Finding and changing users needs the Users section, which the caller may not have.
|
|
430
|
+
if (found.status === 403) return
|
|
431
|
+
assert(found.status === 200, `finding the caller answered ${found.status}`)
|
|
432
|
+
assert(((await found.json()) as Json).key === me, 'the user found is not the caller')
|
|
433
|
+
const missing = await api(`${env}/users?find=${crypto.randomUUID()}`)
|
|
434
|
+
assert(missing.status === 404, `an unknown user answered ${missing.status}`)
|
|
435
|
+
assert(isProblem(missing), 'not application/problem+json')
|
|
436
|
+
const unchanged = await api(`${env}/users/${me}`, {
|
|
437
|
+
method: 'PATCH',
|
|
438
|
+
headers: { 'content-type': 'application/json' },
|
|
439
|
+
body: '{}',
|
|
440
|
+
})
|
|
441
|
+
if (unchanged.status === 403) return
|
|
442
|
+
assert(unchanged.status === 200, `a change of nothing answered ${unchanged.status}`)
|
|
443
|
+
const done = (await unchanged.json()) as Json
|
|
444
|
+
assert(
|
|
445
|
+
Array.isArray(done.changed) && done.changed.length === 0,
|
|
446
|
+
'a change of nothing changed something',
|
|
447
|
+
)
|
|
448
|
+
},
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
await check(
|
|
452
|
+
'background-jobs: lists a page of jobs, and refuses to run again one that has not failed',
|
|
453
|
+
async () => {
|
|
454
|
+
const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
|
|
455
|
+
if (!capabilities.includes('background-jobs') || !state.may?.backgroundJobs) return 'skip'
|
|
456
|
+
const env = `environments/${state.environment}`
|
|
457
|
+
const listed = await api(`${env}/background-jobs?take=20`)
|
|
458
|
+
assert(listed.status === 200, `the list answered ${listed.status}`)
|
|
459
|
+
const body = (await listed.json()) as { items?: Json[]; total?: unknown }
|
|
460
|
+
assert(Array.isArray(body.items), 'items is missing')
|
|
461
|
+
assert(typeof body.total === 'number', 'total is missing')
|
|
462
|
+
assert('waitingSince' in body, 'waitingSince is missing')
|
|
463
|
+
for (const job of body.items ?? [])
|
|
464
|
+
assert(
|
|
465
|
+
typeof job.id === 'string' &&
|
|
466
|
+
typeof job.name === 'string' &&
|
|
467
|
+
typeof job.state === 'string',
|
|
468
|
+
'a job has no id, name or state',
|
|
469
|
+
)
|
|
470
|
+
const missing = await api(`${env}/background-jobs/${crypto.randomUUID()}/retry`, {
|
|
471
|
+
method: 'POST',
|
|
472
|
+
})
|
|
473
|
+
// A site that takes no changes refuses any retry first.
|
|
474
|
+
if (missing.status === 403 && ((await missing.json()) as Json).code === 'access-level') return
|
|
475
|
+
assert(missing.status === 404, `retrying an unknown job answered ${missing.status}`)
|
|
476
|
+
assert(isProblem(missing), 'not application/problem+json')
|
|
477
|
+
const notFailed = (body.items ?? []).find((job) => job.state !== 'failed')
|
|
478
|
+
if (!notFailed) return
|
|
479
|
+
const refused = await api(`${env}/background-jobs/${notFailed.id}/retry`, { method: 'POST' })
|
|
480
|
+
assert(
|
|
481
|
+
refused.status === 409,
|
|
482
|
+
`retrying a job that has not failed answered ${refused.status}`,
|
|
483
|
+
)
|
|
484
|
+
assert(isProblem(refused), 'not application/problem+json')
|
|
485
|
+
},
|
|
486
|
+
)
|
|
487
|
+
|
|
488
|
+
await check(
|
|
489
|
+
'extension-activity: a page, the counts and the CSV file of what an extension did',
|
|
490
|
+
async () => {
|
|
491
|
+
const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
|
|
492
|
+
if (!capabilities.includes('extension-activity') || !state.may?.extensionActivity)
|
|
493
|
+
return 'skip'
|
|
494
|
+
const base = `environments/${state.environment}/installed/conformance-check/activity`
|
|
495
|
+
const page = await api(`${base}?limit=5`)
|
|
496
|
+
assert(page.status === 200, `a page answered ${page.status}`)
|
|
497
|
+
const body = (await page.json()) as { items?: unknown; next?: unknown }
|
|
498
|
+
assert(Array.isArray(body.items), 'items is missing')
|
|
499
|
+
assert('next' in body, 'next is missing')
|
|
500
|
+
const summary = await api(`${base}/summary`)
|
|
501
|
+
assert(summary.status === 200, `the summary answered ${summary.status}`)
|
|
502
|
+
const counts = (await summary.json()) as {
|
|
503
|
+
counts?: unknown
|
|
504
|
+
people?: unknown
|
|
505
|
+
days?: unknown
|
|
506
|
+
}
|
|
507
|
+
assert(typeof counts.counts === 'object' && counts.counts !== null, 'counts is missing')
|
|
508
|
+
assert(Array.isArray(counts.people), 'people is missing')
|
|
509
|
+
assert(typeof counts.days === 'number', 'days is missing')
|
|
510
|
+
const csv = await api(`${base}.csv`)
|
|
511
|
+
assert(csv.status === 200, `the CSV file answered ${csv.status}`)
|
|
512
|
+
assert(
|
|
513
|
+
(csv.headers.get('content-type') ?? '').startsWith('text/csv'),
|
|
514
|
+
'the CSV file is not text/csv',
|
|
515
|
+
)
|
|
516
|
+
assert((await csv.text()).startsWith('when,person,kind,'), 'the CSV file has no header')
|
|
517
|
+
const wrong = await api(`${base}?limit=0`)
|
|
518
|
+
assert(wrong.status === 400, `a limit of 0 answered ${wrong.status}`)
|
|
519
|
+
assert(isProblem(wrong), 'not application/problem+json')
|
|
520
|
+
},
|
|
521
|
+
)
|
|
522
|
+
|
|
523
|
+
await check(
|
|
524
|
+
'media-library: a page of media, one item shown, and a change to its name undone',
|
|
525
|
+
async () => {
|
|
526
|
+
const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
|
|
527
|
+
if (!capabilities.includes('media-library') || !state.may?.mediaLibrary) return 'skip'
|
|
528
|
+
const base = `environments/${state.environment}/media-items`
|
|
529
|
+
const listed = await api(`${base}?take=5`)
|
|
530
|
+
assert(listed.status === 200, `the list answered ${listed.status}`)
|
|
531
|
+
const page = (await listed.json()) as { items?: Json[]; total?: unknown }
|
|
532
|
+
assert(Array.isArray(page.items), 'items is missing')
|
|
533
|
+
assert(typeof page.total === 'number', 'total is missing')
|
|
534
|
+
const missing = await api(`${base}/${crypto.randomUUID()}`)
|
|
535
|
+
assert(missing.status === 404, `an unknown item answered ${missing.status}`)
|
|
536
|
+
assert(isProblem(missing), 'not application/problem+json')
|
|
537
|
+
const first = page.items?.[0]
|
|
538
|
+
if (!first) return
|
|
539
|
+
assert(
|
|
540
|
+
typeof first.key === 'string' && typeof first.path === 'string',
|
|
541
|
+
'an item has no key or path',
|
|
542
|
+
)
|
|
543
|
+
const shown = await api(`${base}/${first.key}?references=true`)
|
|
544
|
+
assert(shown.status === 200, `showing an item answered ${shown.status}`)
|
|
545
|
+
const item = (await shown.json()) as Json
|
|
546
|
+
assert(typeof item.access === 'string', 'access is missing')
|
|
547
|
+
assert(
|
|
548
|
+
typeof (item.references as Json | undefined)?.total === 'number',
|
|
549
|
+
'references is missing',
|
|
550
|
+
)
|
|
551
|
+
const rename = (name: unknown) =>
|
|
552
|
+
api(`${base}/${first.key}`, {
|
|
553
|
+
method: 'PATCH',
|
|
554
|
+
headers: { 'content-type': 'application/json' },
|
|
555
|
+
body: JSON.stringify({ name }),
|
|
556
|
+
})
|
|
557
|
+
const renamed = await rename(`${first.name} (conformance)`)
|
|
558
|
+
// A site that takes no changes refuses the change first.
|
|
559
|
+
if (renamed.status === 403 && ((await renamed.json()) as Json).code === 'access-level') return
|
|
560
|
+
assert(renamed.status === 200, `renaming answered ${renamed.status}`)
|
|
561
|
+
const undone = await rename(first.name)
|
|
562
|
+
assert(undone.status === 200, `renaming it back answered ${undone.status}`)
|
|
563
|
+
assert(((await undone.json()) as Json).name === first.name, 'the name was not put back')
|
|
564
|
+
},
|
|
565
|
+
)
|
|
566
|
+
|
|
567
|
+
await check('media-access: who may see an item reads back, with its summary', async () => {
|
|
568
|
+
const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
|
|
569
|
+
if (!capabilities.includes('media-access') || !state.may?.mediaLibrary) return 'skip'
|
|
570
|
+
const base = `environments/${state.environment}/media-items`
|
|
571
|
+
const missing = await api(`${base}/${crypto.randomUUID()}/access`)
|
|
572
|
+
assert(missing.status === 404, `an unknown item's access answered ${missing.status}`)
|
|
573
|
+
const first = (((await (await api(`${base}?take=1`)).json()) as { items?: Json[] }).items ??
|
|
574
|
+
[])[0]
|
|
575
|
+
if (!first) return
|
|
576
|
+
const read = await api(`${base}/${first.key}/access`)
|
|
577
|
+
assert(read.status === 200, `reading access answered ${read.status}`)
|
|
578
|
+
const view = (await read.json()) as Json
|
|
579
|
+
assert(typeof view.summary === 'string', 'summary is missing')
|
|
580
|
+
assert(typeof (view.form as Json | undefined)?.inherit === 'boolean', 'form is missing')
|
|
581
|
+
const wrong = await api(`${base}/${first.key}/access`, {
|
|
582
|
+
method: 'PUT',
|
|
583
|
+
headers: { 'content-type': 'application/json' },
|
|
584
|
+
body: JSON.stringify({ level: 'everything' }),
|
|
585
|
+
})
|
|
586
|
+
if (wrong.status === 403 && ((await wrong.json()) as Json).code === 'access-level') return
|
|
587
|
+
assert(wrong.status === 400, `a change it cannot read answered ${wrong.status}`)
|
|
588
|
+
assert(isProblem(wrong), 'not application/problem+json')
|
|
589
|
+
})
|
|
590
|
+
|
|
591
|
+
await check(
|
|
592
|
+
'content-show: a page as content show gives it, and an unknown one is not found',
|
|
593
|
+
async () => {
|
|
594
|
+
const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
|
|
595
|
+
if (!capabilities.includes('content-show') || !state.may?.contentShow) return 'skip'
|
|
596
|
+
const env = `environments/${state.environment}`
|
|
597
|
+
const missing = await api(`${env}/content-items/${crypto.randomUUID()}`)
|
|
598
|
+
assert(missing.status === 404, `an unknown page answered ${missing.status}`)
|
|
599
|
+
assert(isProblem(missing), 'not application/problem+json')
|
|
600
|
+
if (!capabilities.includes('content-query')) return
|
|
601
|
+
const found = await api(`${env}/content/query`, {
|
|
602
|
+
method: 'POST',
|
|
603
|
+
headers: { 'content-type': 'application/json' },
|
|
604
|
+
body: JSON.stringify({ entity: 'document', take: 1 }),
|
|
605
|
+
})
|
|
606
|
+
const first = (((await found.json().catch(() => ({}))) as { items?: Json[] }).items ?? [])[0]
|
|
607
|
+
if (!first) return
|
|
608
|
+
const shown = await api(`${env}/content-items/${first.id}?references=true`)
|
|
609
|
+
assert(shown.status === 200, `showing a page answered ${shown.status}`)
|
|
610
|
+
const page = (await shown.json()) as Json
|
|
611
|
+
assert(
|
|
612
|
+
typeof page.path === 'string' && Array.isArray(page.values),
|
|
613
|
+
'path or values is missing',
|
|
614
|
+
)
|
|
615
|
+
assert(
|
|
616
|
+
typeof (page.references as Json | undefined)?.total === 'number',
|
|
617
|
+
'references is missing',
|
|
618
|
+
)
|
|
619
|
+
},
|
|
620
|
+
)
|
|
621
|
+
|
|
622
|
+
await check(
|
|
623
|
+
"public-access: a page's access reads back, and an unknown page's is not found",
|
|
624
|
+
async () => {
|
|
625
|
+
const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
|
|
626
|
+
if (!capabilities.includes('public-access')) return 'skip'
|
|
627
|
+
const env = `environments/${state.environment}`
|
|
628
|
+
const missing = await api(`${env}/content/${crypto.randomUUID()}/access`)
|
|
629
|
+
assert(missing.status === 404, `an unknown page's access answered ${missing.status}`)
|
|
630
|
+
assert(isProblem(missing), 'not application/problem+json')
|
|
631
|
+
if (!capabilities.includes('content-query')) return
|
|
632
|
+
const found = await api(`${env}/content/query`, {
|
|
633
|
+
method: 'POST',
|
|
634
|
+
headers: { 'content-type': 'application/json' },
|
|
635
|
+
body: JSON.stringify({ take: 1 }),
|
|
636
|
+
})
|
|
637
|
+
const page = ((await found.json()) as { items?: Json[] }).items?.[0]
|
|
638
|
+
if (!page) return
|
|
639
|
+
const access = await api(`${env}/content/${page.id}/access`)
|
|
640
|
+
assert(access.status === 200, `a page's access answered ${access.status}`)
|
|
641
|
+
const read = (await access.json()) as Json
|
|
642
|
+
assert(
|
|
643
|
+
read.rule === 'own' || read.rule === 'ancestor' || read.rule === 'none',
|
|
644
|
+
`a page's rule is ${read.rule}`,
|
|
645
|
+
)
|
|
646
|
+
assert(
|
|
647
|
+
(read.page as Json | undefined)?.key === page.id,
|
|
648
|
+
'the access is not the page asked for',
|
|
649
|
+
)
|
|
650
|
+
},
|
|
651
|
+
)
|
|
652
|
+
|
|
272
653
|
await check('a push check answers what would be recycled and removed', async () => {
|
|
273
654
|
const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
|
|
274
655
|
if (!capabilities.includes('push-check') || !state.may?.push) return 'skip'
|