cmvr-wms/mobile-app/tests/account.test.mjs
lixiaolong 149bde836f feat(assistant): 扩展业务助手功能支持更多文档类型和业务场景
- 新增 PDF 文档支持,包括格式校验和完整性检查
- 扩展 Word、TXT 和 ZIP 格式附件处理能力
- 添加 Excel 附件可选择仅作为业务文件不解析行数据
- 实现业务助手表格布局配置新增库存和预算字段
- 集成通知、反馈通知等新的业务助手动作类型
- 完善部门管理包含父级部门和排序字段支持
- 增强业务规则校验涵盖更多系统管理场景
- 优化附件上传限制提示信息更准确
- 添加生成文件下载的安全性校验机制
- 扩展测试覆盖确保各业务动作规则正确性
2026-10-18 08:49:30 +08:00

46 lines
4.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import test from 'node:test';
import assert from 'node:assert/strict';
import {profilePayload,profileError,passwordError,feedbackPayload,feedbackStatuses,imagePath} from '../src/core/account.ts';
import {ApiClient,base64} from '../src/core/network.ts';
test('profile update allowlist preserves all four fields, never submits identity or role changes',()=>{
const form=profilePayload({nickName:' 同事 ',email:' a@cmvr.cn ',phonenumber:'13812345678',sex:'1',userId:2,roles:['admin'],deptId:1});
assert.deepEqual(form,{nickName:'同事',email:'a@cmvr.cn',phonenumber:'13812345678',sex:'1'});
assert.equal(profileError(form),'');assert.match(profileError({...form,email:'abc'}),/邮箱/);assert.match(profileError({...form,phonenumber:'123'}),/手机/);
assert.equal(profileError({...form,email:'',phonenumber:''}),'');assert.equal(profilePayload({nickName:'甲'}).sex,'2');
});
test('password validation follows current server account policy and confirms without changing credentials',()=>{
assert.match(passwordError('','123456','123456','0'),/当前密码/);
assert.match(passwordError('oldpass','123','123','0'),/6–20/);
assert.match(passwordError('oldpass','123456','654321','0'),/不一致/);
assert.match(passwordError('123456','123456','123456','0'),/相同/);
assert.match(passwordError('oldpass','123456','123456','3'),/字母和数字/);
assert.equal(passwordError('oldpass','New123','New123','3'),'');
assert.equal(passwordError('oldpass','New123!','New123!','4'),'');
assert.match(passwordError('oldpass','bad<123','bad<123','0'),/请勿/);
});
test('feedback uses backend enums and image ownership identifiers, no client identity/admin fields',()=>{
const id='a'.repeat(32);assert.deepEqual(feedbackPayload('BUG',' 标题 ',' 详细情况 ',[id]),{type:'BUG',title:'标题',description:'详细情况',images:[id],pagePath:'/mobile/feedback',pageTitle:'移动端问题反馈'});
assert.throws(()=>feedbackPayload('REQUIREMENT','标题','描述',[]));
assert.throws(()=>feedbackPayload('BUG',' ','描述',[]));assert.throws(()=>feedbackPayload('BUG','标题','描述',[id,id]));
assert.throws(()=>feedbackPayload('FEATURE','标题','描述',['../../other.png']));
assert.equal(feedbackStatuses.RESOLVED,'已解决');
});
test('avatar never takes credentials off-origin through a user supplied URL',()=>{
assert.equal(imagePath('/profile/avatar/2026/a.jpg'),'/profile/avatar/2026/a.jpg');
for(const path of ['https://evil.test/a.png','//evil.test/profile/a','/profile/../secret','/profile/%2e%2e/file','/profile/a?token=123'])assert.equal(imagePath(path),null);
});
test('binary image content is authenticated, validated and encoded without leaking a bearer in URLs',async()=>{
let request;const api=new ApiClient('http://192.168.1.1',()=>{},async(url,options)=>{request={url,options};return new Response(new Uint8Array([1,2,3,4]),{headers:{'Content-Type':'image/png'}});});api.authenticate('test-only');
const uri=await api.request('/system/feedback/images/abc/content',{responseType:'image'});
assert.equal(uri,'data:image/png;base64,AQIDBA==');assert.equal(request.options.headers.Authorization,'Bearer test-only');assert.doesNotMatch(request.url,/test-only/);assert.equal(request.options.redirect,'error');
for(let size=0;size<100;size++){const bytes=Uint8Array.from({length:size},(_,i)=>i*7%256);assert.equal(base64(bytes),Buffer.from(bytes).toString('base64'));}
});
test('stale images and forbidden image reads are not displayed as successful content',async()=>{
let finish;const api=new ApiClient('http://192.168.1.1',()=>{},()=>new Promise(r=>finish=r));api.authenticate('a');const old=api.request('/profile/a.png',{responseType:'image'});api.authenticate('b');finish(new Response(new Uint8Array([1]),{headers:{'Content-Type':'image/png'}}));await assert.rejects(old,e=>e.code===409);
const denied=new ApiClient('http://192.168.1.1',()=>{},async()=>new Response(JSON.stringify({code:403}),{headers:{'Content-Type':'application/json'}}));await assert.rejects(denied.request('/system/feedback/images/a/content',{responseType:'image'}),e=>e.code===403);
});
test('oversized protected image is rejected before decoding',async()=>{
const api=new ApiClient('http://192.168.1.1',()=>{},async()=>new Response(new Uint8Array([1]),{headers:{'Content-Type':'image/png','Content-Length':String(7*1024*1024)}}));await assert.rejects(api.request('/profile/a.png',{responseType:'image'}),e=>e.code===413);
});