- 新增 PDF 文档支持,包括格式校验和完整性检查 - 扩展 Word、TXT 和 ZIP 格式附件处理能力 - 添加 Excel 附件可选择仅作为业务文件不解析行数据 - 实现业务助手表格布局配置新增库存和预算字段 - 集成通知、反馈通知等新的业务助手动作类型 - 完善部门管理包含父级部门和排序字段支持 - 增强业务规则校验涵盖更多系统管理场景 - 优化附件上传限制提示信息更准确 - 添加生成文件下载的安全性校验机制 - 扩展测试覆盖确保各业务动作规则正确性
65 lines
4.4 KiB
JavaScript
65 lines
4.4 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
import { createHash, verify, X509Certificate } from 'node:crypto';
|
|
const origin = 'http://192.168.28.10';
|
|
const runtime = 'ac523f4137469f9f4b0faaca30982e68445686df';
|
|
const headers = { 'expo-platform': 'android', 'expo-runtime-version': runtime,
|
|
'expo-protocol-version': '1', 'expo-expect-signature': 'sig, keyid="prod", alg="rsa-v1_5-sha256"',
|
|
accept: 'application/expo+json, application/json, multipart/mixed' };
|
|
const request = (route, options = {}) => fetch(origin + route, { ...options, redirect: 'error', signal: AbortSignal.timeout(15000) });
|
|
const response = await request('/updates/prod', { headers });
|
|
assert.equal(response.status, 200);
|
|
assert.match(response.headers.get('content-type'), /application\/expo\+json/);
|
|
assert.equal(response.headers.get('expo-protocol-version'), '1');
|
|
assert.equal(response.headers.get('cache-control'), 'no-store');
|
|
assert.equal(response.headers.get('expo-server-defined-headers'), '');
|
|
const body = Buffer.from(await response.arrayBuffer());
|
|
const manifest = JSON.parse(body);
|
|
const signatureHeader = response.headers.get('expo-signature');
|
|
assert.match(signatureHeader, /keyid="prod"/);
|
|
const signature = Buffer.from(/sig="([^"]+)"/.exec(signatureHeader)[1], 'base64');
|
|
const cert = new X509Certificate(await readFile(new URL('../certs/prod.pem', import.meta.url)));
|
|
assert.ok(Date.now() >= Date.parse(cert.validFrom) && Date.now() < Date.parse(cert.validTo));
|
|
assert.equal(verify('RSA-SHA256', body, cert.publicKey, signature), true);
|
|
assert.equal(verify('RSA-SHA256', Buffer.concat([body, Buffer.from('tampered')]), cert.publicKey, signature), false);
|
|
const developerCert = new X509Certificate(await readFile(new URL('../certs/dev.pem', import.meta.url)));
|
|
assert.equal(verify('RSA-SHA256', body, developerCert.publicKey, signature), false);
|
|
assert.equal(manifest.runtimeVersion, runtime);
|
|
assert.equal(manifest.metadata.environment, 'prod');
|
|
assert.equal(manifest.extra.expoClient.extra.apiUrl, origin + '/prod-api');
|
|
const verifiedAssets = [];
|
|
for (const asset of [manifest.launchAsset, ...manifest.assets]) {
|
|
const url = new URL(asset.url);
|
|
assert.equal(url.origin, origin);
|
|
assert.match(url.pathname, /^\/assets\/[a-f0-9]{64}$/);
|
|
const result = await request(url.pathname);
|
|
assert.equal(result.status, 200);
|
|
assert.match(result.headers.get('cache-control'), /immutable/);
|
|
assert.ok(result.headers.get('content-type').startsWith(asset.contentType));
|
|
const bytes = Buffer.from(await result.arrayBuffer());
|
|
assert.equal(createHash('sha256').update(bytes).digest('base64url'), asset.hash);
|
|
assert.equal(createHash('sha256').update(bytes).digest('hex'), url.pathname.split('/').pop());
|
|
verifiedAssets.push({ url: asset.url, bytes: bytes.length, hash: asset.hash });
|
|
}
|
|
assert.equal((await request('/updates/dev', { headers })).status, 404);
|
|
assert.equal((await request('/updates/prod')).status, 400);
|
|
assert.equal((await request('/updates/prod', { method: 'POST', headers })).status, 405);
|
|
assert.equal((await request('/updates/prod', { headers: { ...headers, 'expo-protocol-version': '2' } })).status, 406);
|
|
const incompatible = await request('/updates/prod', { headers: { ...headers, 'expo-runtime-version': 'incompatible-test-runtime' } });
|
|
assert.equal(incompatible.status, 200);
|
|
assert.match(incompatible.headers.get('content-type'), /multipart\/mixed/);
|
|
assert.equal(await incompatible.text(), '--empty--\r\n');
|
|
const missing = await request('/assets/' + '0'.repeat(64));
|
|
assert.equal(missing.status, 404);
|
|
const home = await request('/'); assert.equal(home.status, 200);
|
|
assert.match(home.headers.get('content-type'), /text\/html/);
|
|
const api = await request('/prod-api/captchaImage');
|
|
assert.equal(api.status, 200); assert.equal((await api.json()).code, 200);
|
|
const result = { checkedAt: new Date().toISOString(), url: origin + '/updates/prod', updateId: manifest.id,
|
|
runtime, certificateSha256: cert.fingerprint256, productionManifestSignature: 'verified',
|
|
tamperedManifestRejected: true, developerKeyRejected: true, verifiedAssets,
|
|
developerChannelBlocked: true, incompatibleRuntimeIsolated: true, missingAsset404: true,
|
|
invalidRequestsBlocked: true, webAndPublicApiAvailable: true, deviceAcceptance: 'pending, no physical Android device connected' };
|
|
if (process.argv[2]) await writeFile(process.argv[2], JSON.stringify(result, null, 2));
|
|
console.log(JSON.stringify(result, null, 2));
|