feat(cms): download portable backups from site settings
DC CMS qualification / qualify (push) Successful in 1m57s

This commit is contained in:
DCCONSTRUCTIONS
2026-11-05 22:37:55 +03:00
parent d86be605a8
commit 5ea737318b
10 changed files with 320 additions and 29 deletions
+27 -1
View File
@@ -110,6 +110,31 @@ test('independent sites, rendering, secrets and publication ownership', async t
assert.equal((await fetch(base+'/s/mission-core/api/project/upload-site',{method:'POST',body:invalid})).status,500);
assert.equal((await api('/s/mission-core/api/page/home')).title,'Mission edited');
});
await t.test('downloaded backup is current, isolated and can be imported unchanged',async()=>{
const beforePage=await api('/s/mission-core/api/page/home');
const prepared=await api('/s/mission-core/api/project/backup','POST');
await api('/s/mission-core/api/project/backup','POST',undefined,409);
const response=await fetch(base+'/s/mission-core'+prepared.downloadUrl);
assert.equal(response.status,200);assert.equal(response.headers.get('content-type'),'application/zip');
assert.match(response.headers.get('content-disposition'),/MISSION_CORE_TECH\.zip/);
assert.equal(response.headers.get('cache-control'),'no-store');
const bytes=Buffer.from(await response.arrayBuffer());const zip=new AdmZip(bytes);
assert.equal(bytes.length,Number(response.headers.get('content-length')));assert.equal(zip.test(),true);
assert.equal((await fetch(base+'/s/mission-core'+prepared.downloadUrl)).status,404);
assert.deepEqual(JSON.parse(zip.readAsText('content/pages/home.json')),beforePage);
assert.ok(zip.getEntry('tools/render-home.mjs'));assert.ok(zip.getEntry('templates/pages/home/shell.html'));
assert.ok(!zip.getEntries().some(e=>/\.cms-backups|\.git\/|secrets|publish-state/.test(e.entryName)));
const preparedAgent=await api('/s/nodedc/api/project/backup','POST');
assert.equal((await fetch(base+'/s/mission-core'+preparedAgent.downloadUrl)).status,404);
const agentResponse=await fetch(base+'/s/nodedc'+preparedAgent.downloadUrl);assert.equal(agentResponse.status,200);
const agentZip=new AdmZip(Buffer.from(await agentResponse.arrayBuffer()));
assert.equal(JSON.parse(agentZip.readAsText('content/pages/home.json')).title,'Agent edited');
const form=new FormData();form.append('file',new Blob([bytes],{type:'application/zip'}),'restored.zip');
const restored=await fetch(base+'/s/mission-core/api/project/upload-site',{method:'POST',body:form});
assert.equal(restored.status,200);assert.equal((await restored.json()).site.ready,true);
assert.deepEqual(await api('/s/mission-core/api/page/home'),beforePage);
assert.equal((await api('/s/nodedc/api/page/home')).title,'Agent edited');
});
await t.test('encrypted credentials transfer with source disabled',async()=>{
const config=await api('/s/nodedc/api/project/config');
await api('/s/nodedc/api/project/config','PUT',{...config,deploy:{...config.deploy,enabled:true}});
@@ -139,7 +164,8 @@ test('independent sites, rendering, secrets and publication ownership', async t
});
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']){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/sites','/s/mission-core/api/page/home','/s/mission-core/api/project/backup']){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);
});