Files
jiapu/tests/security-upload-scope.test.js
T

53 lines
1.9 KiB
JavaScript

const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const test = require('node:test');
const SecurityPages = require('../public/js/security-pages.js');
const UploadPages = require('../public/js/upload-pages.js');
test('security forms use PC verification operation codes and submit only documented business fields', () => {
assert.equal(SecurityPages.getCaptchaOperation('phone'), 'phone-change');
assert.equal(SecurityPages.getCaptchaOperation('deactivate'), 'account-deactivate');
assert.deepEqual(
SecurityPages.buildPasswordChangeBody({
oldPassword: 'old',
newPassword: 'new',
validToken: 'captcha-ticket'
}, (value) => 'md5-' + value),
{
oldPassword: 'md5-old',
newPassword: 'md5-new'
}
);
assert.deepEqual(
SecurityPages.buildPhoneChangeBody({
phone: '13800000000',
smsCode: '123456',
validToken: 'captcha-ticket'
}),
{
phone: '13800000000',
smsCode: '123456'
}
);
assert.deepEqual(SecurityPages.buildDeactivateBody({ smsCode: '654321' }), { smsCode: '654321' });
});
test('upload helper keeps the avatar flow blocked until the current PC resumable response is defined', async () => {
assert.equal(UploadPages.getUploadMode(5 * 1024 * 1024), 'resumable');
await assert.rejects(
UploadPages.uploadFileForPage({ initResumableUpload() {} }, { name: 'avatar.png' }),
/当前 PC 文件上传响应未定义头像回填字段/
);
});
test('security page field names match phone-change and account-deactivation DTOs', () => {
const source = fs.readFileSync(path.join(__dirname, '..', 'profile-security.html'), 'utf8');
assert.match(source, /id="newPhone"\s+name="phone"/);
assert.match(source, /data-security-form="deactivate"/);
assert.match(source, /id="deactivateSmsCode"\s+name="smsCode"/);
assert.match(source, /data-security-send-deactivate-code/);
});