Persist user GUI preferences and resize the shared media modal
DC CMS qualification / qualify (push) Successful in 2m22s

This commit is contained in:
DCCONSTRUCTIONS
2026-11-13 17:56:23 +03:00
parent ff90b633d9
commit 5d56f5fe21
19 changed files with 321 additions and 110 deletions
+10 -1
View File
@@ -187,13 +187,22 @@ test('independent sites, rendering, secrets and publication ownership', async t
await t.test('cross-origin registry mutations are refused',async()=>{
const response=await fetch(base+'/api/sites',{method:'POST',headers:{origin:'https://untrusted.invalid','content-type':'application/json'},body:JSON.stringify({id:'attack',copyFrom:'nodedc'})});assert.equal(response.status,403);
});
await t.test('GUI preferences persist outside sites and reject cross-origin writes', async () => {
assert.equal((await api('/api/user/preferences')).exists, false);
await api('/api/user/preferences','PATCH',{gui:{modals:{'media-library':{width:1200,height:800}}}});
await api('/api/user/preferences','PATCH',{appearance:{theme:'light'}});
const response = await fetch(base+'/api/user/preferences',{method:'PATCH',headers:{origin:'https://untrusted.invalid','content-type':'application/json'},body:'{}'});
assert.equal(response.status,403);
assert.equal((await api('/api/sites')).sites.length,2);
});
await stop(); await start();
await t.test('registry and edits survive server restart',async()=>{
assert.equal((await api('/api/user/preferences')).preferences.gui.modals['media-library'].width,1200);
assert.equal((await api('/api/sites')).sites.length,2);assert.equal((await api('/s/mission-core/api/page/home')).title,'Mission edited');assert.equal((await api('/s/nodedc/api/page/home')).title,'Agent edited');
});
await stop();await start(true);
await t.test('registry, scoped content and preview retain authentication',async()=>{
for(const path of ['/api/sites','/s/mission-core/api/page/home','/s/mission-core/api/project/backup','/s/mission-core/api/media/download?path=assets/proof.txt']){const response=await fetch(base+path,{redirect:'manual'});assert.equal(response.status,401,path);assert.match(response.headers.get('content-type'),/json/);}
for(const path of ['/api/user/preferences','/api/sites','/s/mission-core/api/page/home','/s/mission-core/api/project/backup','/s/mission-core/api/media/download?path=assets/proof.txt']){const response=await fetch(base+path,{redirect:'manual'});assert.equal(response.status,401,path);assert.match(response.headers.get('content-type'),/json/);}
assert.equal((await fetch(base+'/s/mission-core/api/project/backup',{method:'POST',redirect:'manual'})).status,401);
assert.equal((await fetch(base+'/s/mission-core/index.html',{redirect:'manual'})).status,302);
assert.equal((await fetch(base+'/healthz')).status,200);
+33
View File
@@ -0,0 +1,33 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { mkdtemp, readdir, readFile, rm, stat } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { UserPreferencesStore } from '../server/user-preferences.mjs';
test('user GUI metadata is isolated, durable, private and merges independent writes', async t => {
const root = await mkdtemp(join(tmpdir(), 'cms-user-meta-')); t.after(() => rm(root, { recursive: true, force: true }));
const store = new UserPreferencesStore(root);
assert.equal((await store.read('alice')).exists, false);
await Promise.all([
store.patch('alice', { appearance: { theme: 'light', accent: '#AABBCC' } }),
store.patch('alice', { gui: { modals: { 'media-library': { width: 1250, height: 800 } } } }),
store.patch('bob', { gui: { modals: { 'media-library': { width: 640, height: 480 } } } }),
]);
const restarted = new UserPreferencesStore(root);
const alice = (await restarted.read('alice')).preferences;
assert.equal(alice.appearance.theme, 'light'); assert.equal(alice.appearance.accent, '#aabbcc');
assert.deepEqual(alice.gui.modals['media-library'], {width:1250,height:800});
assert.equal((await restarted.read('bob')).preferences.gui.modals['media-library'].width, 640);
assert.deepEqual((await restarted.patch('alice', { appearance: { theme: 'dark' } }, { ifAbsent: true })).preferences, alice);
const files = await readdir(join(root,'.user-meta')); assert.equal(files.length, 2);
for (const file of files) {
assert.match(file, /^[a-f\d]{64}\.json$/);
assert.equal((await stat(join(root,'.user-meta',file))).mode & 0o777, 0o600);
assert.ok(JSON.parse(await readFile(join(root,'.user-meta',file))).gui);
}
for (const patch of [{ user: 'bob' }, { gui: { modals: { '../evil': {width:900,height:600} } } }, { gui: {modals: {'media-library': {width:1e7,height:800}}} }, {appearance:{accent:'red'}}, JSON.parse('{"gui":{"modals":{"__proto__":null}}}')]) {
await assert.rejects(store.patch('alice', patch), {status:400});
}
await assert.rejects(store.read(''), { status: 401 });
assert.deepEqual((await store.read('alice')).preferences, alice);
});