拆分免加载业务脚本的手机登录页

This commit is contained in:
summer committed 2026-12-04 21:45:41 +08:00
1 parent 36ddf35da0
commit 67b145c4b8
10 files changed
+166 -59

No files matched your search

+12 -1
View File
@@ -18,10 +18,21 @@ test('店内账号均可登录;离店后重新检查账号,包括已有会
const login = (zone, member) => call('/api/login', zone, null, {member,password});
assert.equal((await call('/api/session')).status,403);
assert.deepEqual((await (await call('/api/session','owner')).json()).loginOptions.map(x=>x.member),['owner']);
const page=await call('/','store');
const html=await page.text();
assert.equal(page.status,200);
assert.match(html,/<select name="member"/);
assert.match(html,/<option value="assistant">/);
assert.doesNotMatch(html,/<script[^>]+src=|<link[^>]+stylesheet|src="\/app.js"/);
const script=html.match(/<script>([\s\S]+?)<\/script>/)[1];
const hash=require('node:crypto').createHash('sha256').update(script).digest('base64');
assert.ok(page.headers.get('content-security-policy').includes("script-src 'sha256-"+hash+"'"));
assert.doesNotMatch(await (await call('/','owner')).text(),/<option value="assistant">/);
const staff = await login('store','assistant');
assert.equal(staff.status,200);
const cookie = staff.headers.get('set-cookie').split(';')[0];
for (const route of ['/api/session','/api/state','/print/missing']) assert.equal((await call(route,'owner',cookie)).status,403);
assert.match(await (await call('/','store',cookie)).text(),/src="\/app.js"/);
for (const route of ['/','/api/session','/api/state','/print/missing']) assert.equal((await call(route,'owner',cookie)).status,403);
assert.equal((await call('/api/stock','owner',cookie,{})).status,403);
assert.equal((await login('owner','assistant')).status,403);
const boss = await login('owner','owner');