@crombolo/remote-conformance 0.64.0 → 0.66.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +314 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/remote-conformance",
3
- "version": "0.64.0",
3
+ "version": "0.66.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
@@ -269,6 +269,320 @@ export async function runConformance(options: ConformanceOptions): Promise<Confo
269
269
  assert(isProblem(refused), 'not application/problem+json')
270
270
  })
271
271
 
272
+ await check('content-history: an unknown page and an unknown version are not found', async () => {
273
+ const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
274
+ if (!capabilities.includes('content-history')) return 'skip'
275
+ const env = `environments/${state.environment}`
276
+ const page = await api(`${env}/content/${crypto.randomUUID()}/history`)
277
+ assert(page.status === 404, `an unknown page's history answered ${page.status}`)
278
+ assert(isProblem(page), 'not application/problem+json')
279
+ const version = await api(`${env}/content/versions/999999999`)
280
+ assert(version.status === 404, `an unknown version answered ${version.status}`)
281
+ const rollback = await api(`${env}/content/versions/999999999/rollback`, {
282
+ method: 'POST',
283
+ headers: { 'content-type': 'application/json' },
284
+ body: '{}',
285
+ })
286
+ assert(
287
+ rollback.status === 404,
288
+ `rolling back to an unknown version answered ${rollback.status}`,
289
+ )
290
+ })
291
+
292
+ await check(
293
+ 'recycle-bin: lists its items, and refuses to restore what is not in it',
294
+ async () => {
295
+ const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
296
+ if (!capabilities.includes('recycle-bin')) return 'skip'
297
+ const env = `environments/${state.environment}`
298
+ const response = await api(`${env}/recycle-bin`)
299
+ assert(response.status === 200, `answered ${response.status}`)
300
+ const body = (await response.json()) as { items?: Json[] }
301
+ assert(Array.isArray(body.items), 'items is missing')
302
+ for (const item of body.items ?? []) {
303
+ assert(
304
+ typeof item.key === 'string' && typeof item.name === 'string',
305
+ 'an item has no key or name',
306
+ )
307
+ assert(item.kind === 'content' || item.kind === 'media', `an item's kind is ${item.kind}`)
308
+ assert(typeof item.from === 'object' && item.from !== null, 'an item has no from')
309
+ }
310
+ const restore = await api(`${env}/recycle-bin/${crypto.randomUUID()}/restore`, {
311
+ method: 'POST',
312
+ headers: { 'content-type': 'application/json' },
313
+ body: '{}',
314
+ })
315
+ assert(restore.status === 404, `restoring what is not in the bin answered ${restore.status}`)
316
+ assert(isProblem(restore), 'not application/problem+json')
317
+ },
318
+ )
319
+
320
+ await check('members: lists members, and a member who is not there is not found', async () => {
321
+ const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
322
+ if (!capabilities.includes('members')) return 'skip'
323
+ const env = `environments/${state.environment}`
324
+ const listed = await api(`${env}/members?take=5`)
325
+ assert(listed.status === 200, `the list answered ${listed.status}`)
326
+ const body = (await listed.json()) as { items?: Json[]; total?: unknown }
327
+ assert(Array.isArray(body.items), 'items is missing')
328
+ assert(typeof body.total === 'number', 'total is missing')
329
+ for (const member of body.items ?? [])
330
+ assert(
331
+ typeof member.key === 'string' && typeof member.login === 'string',
332
+ 'a member has no key or login',
333
+ )
334
+ const missing = await api(`${env}/members/${crypto.randomUUID()}`)
335
+ assert(missing.status === 404, `an unknown member answered ${missing.status}`)
336
+ assert(isProblem(missing), 'not application/problem+json')
337
+ const groups = await api(`${env}/member-groups`)
338
+ assert(groups.status === 200, `the groups answered ${groups.status}`)
339
+ assert(Array.isArray(((await groups.json()) as Json).groups), 'groups is missing')
340
+ })
341
+
342
+ await check(
343
+ "users: the caller's own sign-ins are listed, they are found, and a change of nothing changes nothing",
344
+ async () => {
345
+ const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
346
+ if (!capabilities.includes('users')) return 'skip'
347
+ const env = `environments/${state.environment}`
348
+ const listed = await api(`${env}/sign-ins`)
349
+ assert(listed.status === 200, `the sign-ins answered ${listed.status}`)
350
+ const items = ((await listed.json()) as { items?: Json[] }).items
351
+ assert(Array.isArray(items), 'items is missing')
352
+ const keys = new Set((items ?? []).map((item) => (item.user as Json | undefined)?.key))
353
+ for (const item of items ?? [])
354
+ assert(
355
+ typeof item.id === 'string' && (item.kind === 'browser' || item.kind === 'terminal'),
356
+ 'a sign-in has no id, or is neither a browser nor a terminal',
357
+ )
358
+ assert(keys.size <= 1, "the sign-ins are not all the caller's own")
359
+ const me = [...keys][0]
360
+ if (typeof me !== 'string') return
361
+ const found = await api(`${env}/users?find=${encodeURIComponent(me)}`)
362
+ // Finding and changing users needs the Users section, which the caller may not have.
363
+ if (found.status === 403) return
364
+ assert(found.status === 200, `finding the caller answered ${found.status}`)
365
+ assert(((await found.json()) as Json).key === me, 'the user found is not the caller')
366
+ const missing = await api(`${env}/users?find=${crypto.randomUUID()}`)
367
+ assert(missing.status === 404, `an unknown user answered ${missing.status}`)
368
+ assert(isProblem(missing), 'not application/problem+json')
369
+ const unchanged = await api(`${env}/users/${me}`, {
370
+ method: 'PATCH',
371
+ headers: { 'content-type': 'application/json' },
372
+ body: '{}',
373
+ })
374
+ if (unchanged.status === 403) return
375
+ assert(unchanged.status === 200, `a change of nothing answered ${unchanged.status}`)
376
+ const done = (await unchanged.json()) as Json
377
+ assert(
378
+ Array.isArray(done.changed) && done.changed.length === 0,
379
+ 'a change of nothing changed something',
380
+ )
381
+ },
382
+ )
383
+
384
+ await check(
385
+ 'background-jobs: lists a page of jobs, and refuses to run again one that has not failed',
386
+ async () => {
387
+ const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
388
+ if (!capabilities.includes('background-jobs') || !state.may?.backgroundJobs) return 'skip'
389
+ const env = `environments/${state.environment}`
390
+ const listed = await api(`${env}/background-jobs?take=20`)
391
+ assert(listed.status === 200, `the list answered ${listed.status}`)
392
+ const body = (await listed.json()) as { items?: Json[]; total?: unknown }
393
+ assert(Array.isArray(body.items), 'items is missing')
394
+ assert(typeof body.total === 'number', 'total is missing')
395
+ assert('waitingSince' in body, 'waitingSince is missing')
396
+ for (const job of body.items ?? [])
397
+ assert(
398
+ typeof job.id === 'string' &&
399
+ typeof job.name === 'string' &&
400
+ typeof job.state === 'string',
401
+ 'a job has no id, name or state',
402
+ )
403
+ const missing = await api(`${env}/background-jobs/${crypto.randomUUID()}/retry`, {
404
+ method: 'POST',
405
+ })
406
+ // A site that takes no changes refuses any retry first.
407
+ if (missing.status === 403 && ((await missing.json()) as Json).code === 'access-level') return
408
+ assert(missing.status === 404, `retrying an unknown job answered ${missing.status}`)
409
+ assert(isProblem(missing), 'not application/problem+json')
410
+ const notFailed = (body.items ?? []).find((job) => job.state !== 'failed')
411
+ if (!notFailed) return
412
+ const refused = await api(`${env}/background-jobs/${notFailed.id}/retry`, { method: 'POST' })
413
+ assert(
414
+ refused.status === 409,
415
+ `retrying a job that has not failed answered ${refused.status}`,
416
+ )
417
+ assert(isProblem(refused), 'not application/problem+json')
418
+ },
419
+ )
420
+
421
+ await check(
422
+ 'extension-activity: a page, the counts and the CSV file of what an extension did',
423
+ async () => {
424
+ const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
425
+ if (!capabilities.includes('extension-activity') || !state.may?.extensionActivity)
426
+ return 'skip'
427
+ const base = `environments/${state.environment}/installed/conformance-check/activity`
428
+ const page = await api(`${base}?limit=5`)
429
+ assert(page.status === 200, `a page answered ${page.status}`)
430
+ const body = (await page.json()) as { items?: unknown; next?: unknown }
431
+ assert(Array.isArray(body.items), 'items is missing')
432
+ assert('next' in body, 'next is missing')
433
+ const summary = await api(`${base}/summary`)
434
+ assert(summary.status === 200, `the summary answered ${summary.status}`)
435
+ const counts = (await summary.json()) as {
436
+ counts?: unknown
437
+ people?: unknown
438
+ days?: unknown
439
+ }
440
+ assert(typeof counts.counts === 'object' && counts.counts !== null, 'counts is missing')
441
+ assert(Array.isArray(counts.people), 'people is missing')
442
+ assert(typeof counts.days === 'number', 'days is missing')
443
+ const csv = await api(`${base}.csv`)
444
+ assert(csv.status === 200, `the CSV file answered ${csv.status}`)
445
+ assert(
446
+ (csv.headers.get('content-type') ?? '').startsWith('text/csv'),
447
+ 'the CSV file is not text/csv',
448
+ )
449
+ assert((await csv.text()).startsWith('when,person,kind,'), 'the CSV file has no header')
450
+ const wrong = await api(`${base}?limit=0`)
451
+ assert(wrong.status === 400, `a limit of 0 answered ${wrong.status}`)
452
+ assert(isProblem(wrong), 'not application/problem+json')
453
+ },
454
+ )
455
+
456
+ await check(
457
+ 'media-library: a page of media, one item shown, and a change to its name undone',
458
+ async () => {
459
+ const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
460
+ if (!capabilities.includes('media-library') || !state.may?.mediaLibrary) return 'skip'
461
+ const base = `environments/${state.environment}/media-items`
462
+ const listed = await api(`${base}?take=5`)
463
+ assert(listed.status === 200, `the list answered ${listed.status}`)
464
+ const page = (await listed.json()) as { items?: Json[]; total?: unknown }
465
+ assert(Array.isArray(page.items), 'items is missing')
466
+ assert(typeof page.total === 'number', 'total is missing')
467
+ const missing = await api(`${base}/${crypto.randomUUID()}`)
468
+ assert(missing.status === 404, `an unknown item answered ${missing.status}`)
469
+ assert(isProblem(missing), 'not application/problem+json')
470
+ const first = page.items?.[0]
471
+ if (!first) return
472
+ assert(
473
+ typeof first.key === 'string' && typeof first.path === 'string',
474
+ 'an item has no key or path',
475
+ )
476
+ const shown = await api(`${base}/${first.key}?references=true`)
477
+ assert(shown.status === 200, `showing an item answered ${shown.status}`)
478
+ const item = (await shown.json()) as Json
479
+ assert(typeof item.access === 'string', 'access is missing')
480
+ assert(
481
+ typeof (item.references as Json | undefined)?.total === 'number',
482
+ 'references is missing',
483
+ )
484
+ const rename = (name: unknown) =>
485
+ api(`${base}/${first.key}`, {
486
+ method: 'PATCH',
487
+ headers: { 'content-type': 'application/json' },
488
+ body: JSON.stringify({ name }),
489
+ })
490
+ const renamed = await rename(`${first.name} (conformance)`)
491
+ // A site that takes no changes refuses the change first.
492
+ if (renamed.status === 403 && ((await renamed.json()) as Json).code === 'access-level') return
493
+ assert(renamed.status === 200, `renaming answered ${renamed.status}`)
494
+ const undone = await rename(first.name)
495
+ assert(undone.status === 200, `renaming it back answered ${undone.status}`)
496
+ assert(((await undone.json()) as Json).name === first.name, 'the name was not put back')
497
+ },
498
+ )
499
+
500
+ await check('media-access: who may see an item reads back, with its summary', async () => {
501
+ const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
502
+ if (!capabilities.includes('media-access') || !state.may?.mediaLibrary) return 'skip'
503
+ const base = `environments/${state.environment}/media-items`
504
+ const missing = await api(`${base}/${crypto.randomUUID()}/access`)
505
+ assert(missing.status === 404, `an unknown item's access answered ${missing.status}`)
506
+ const first = (((await (await api(`${base}?take=1`)).json()) as { items?: Json[] }).items ??
507
+ [])[0]
508
+ if (!first) return
509
+ const read = await api(`${base}/${first.key}/access`)
510
+ assert(read.status === 200, `reading access answered ${read.status}`)
511
+ const view = (await read.json()) as Json
512
+ assert(typeof view.summary === 'string', 'summary is missing')
513
+ assert(typeof (view.form as Json | undefined)?.inherit === 'boolean', 'form is missing')
514
+ const wrong = await api(`${base}/${first.key}/access`, {
515
+ method: 'PUT',
516
+ headers: { 'content-type': 'application/json' },
517
+ body: JSON.stringify({ level: 'everything' }),
518
+ })
519
+ if (wrong.status === 403 && ((await wrong.json()) as Json).code === 'access-level') return
520
+ assert(wrong.status === 400, `a change it cannot read answered ${wrong.status}`)
521
+ assert(isProblem(wrong), 'not application/problem+json')
522
+ })
523
+
524
+ await check(
525
+ 'content-show: a page as content show gives it, and an unknown one is not found',
526
+ async () => {
527
+ const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
528
+ if (!capabilities.includes('content-show') || !state.may?.contentShow) return 'skip'
529
+ const env = `environments/${state.environment}`
530
+ const missing = await api(`${env}/content-items/${crypto.randomUUID()}`)
531
+ assert(missing.status === 404, `an unknown page answered ${missing.status}`)
532
+ assert(isProblem(missing), 'not application/problem+json')
533
+ if (!capabilities.includes('content-query')) return
534
+ const found = await api(`${env}/content/query`, {
535
+ method: 'POST',
536
+ headers: { 'content-type': 'application/json' },
537
+ body: JSON.stringify({ entity: 'document', take: 1 }),
538
+ })
539
+ const first = (((await found.json().catch(() => ({}))) as { items?: Json[] }).items ?? [])[0]
540
+ if (!first) return
541
+ const shown = await api(`${env}/content-items/${first.id}?references=true`)
542
+ assert(shown.status === 200, `showing a page answered ${shown.status}`)
543
+ const page = (await shown.json()) as Json
544
+ assert(
545
+ typeof page.path === 'string' && Array.isArray(page.values),
546
+ 'path or values is missing',
547
+ )
548
+ assert(
549
+ typeof (page.references as Json | undefined)?.total === 'number',
550
+ 'references is missing',
551
+ )
552
+ },
553
+ )
554
+
555
+ await check(
556
+ "public-access: a page's access reads back, and an unknown page's is not found",
557
+ async () => {
558
+ const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
559
+ if (!capabilities.includes('public-access')) return 'skip'
560
+ const env = `environments/${state.environment}`
561
+ const missing = await api(`${env}/content/${crypto.randomUUID()}/access`)
562
+ assert(missing.status === 404, `an unknown page's access answered ${missing.status}`)
563
+ assert(isProblem(missing), 'not application/problem+json')
564
+ if (!capabilities.includes('content-query')) return
565
+ const found = await api(`${env}/content/query`, {
566
+ method: 'POST',
567
+ headers: { 'content-type': 'application/json' },
568
+ body: JSON.stringify({ take: 1 }),
569
+ })
570
+ const page = ((await found.json()) as { items?: Json[] }).items?.[0]
571
+ if (!page) return
572
+ const access = await api(`${env}/content/${page.id}/access`)
573
+ assert(access.status === 200, `a page's access answered ${access.status}`)
574
+ const read = (await access.json()) as Json
575
+ assert(
576
+ read.rule === 'own' || read.rule === 'ancestor' || read.rule === 'none',
577
+ `a page's rule is ${read.rule}`,
578
+ )
579
+ assert(
580
+ (read.page as Json | undefined)?.key === page.id,
581
+ 'the access is not the page asked for',
582
+ )
583
+ },
584
+ )
585
+
272
586
  await check('a push check answers what would be recycled and removed', async () => {
273
587
  const capabilities = (state.discovery?.capabilities as string[] | undefined) ?? []
274
588
  if (!capabilities.includes('push-check') || !state.may?.push) return 'skip'