forked from wangziqi/gongxue-base
test: extend remote SMS smoke to phone binding
This commit is contained in:
@@ -4,6 +4,7 @@ import { runRemoteSmsLoginSmoke } from './remote-sms-login-smoke.js';
|
||||
|
||||
const tenantId = '00000000-0000-0000-0000-000000000001';
|
||||
const phone = '13800138000';
|
||||
const bindPhone = '13900139000';
|
||||
|
||||
function json(res, status, payload) {
|
||||
res.writeHead(status, { 'content-type': 'application/json' });
|
||||
@@ -31,10 +32,11 @@ const server = http.createServer(async (req, res) => {
|
||||
|
||||
if (url.pathname === '/api/auth/sms/send' && req.method === 'POST') {
|
||||
const body = await bodyJson(req);
|
||||
assert.equal(body.phone, phone);
|
||||
assert.equal(body.purpose, 'login');
|
||||
assert.ok([phone, bindPhone].includes(body.phone));
|
||||
assert.equal(body.purpose, body.phone === bindPhone ? 'bind_phone' : 'login');
|
||||
if (body.phone === bindPhone) assert.equal(req.headers.authorization, 'Bearer session-token');
|
||||
json(res, 200, {
|
||||
item: { id: 'sms-id', phone, purpose: 'login', provider: 'aliyun-pnvs', status: 'sent' },
|
||||
item: { id: 'sms-id', phone: body.phone, purpose: body.purpose, provider: 'aliyun-pnvs', status: 'sent' },
|
||||
expireIn: 300,
|
||||
cooldown: 60,
|
||||
});
|
||||
@@ -58,6 +60,16 @@ const server = http.createServer(async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (url.pathname === '/api/auth/phone/bind' && req.method === 'POST') {
|
||||
assert.equal(req.headers.authorization, 'Bearer session-token');
|
||||
const body = await bodyJson(req);
|
||||
assert.equal(body.phone, bindPhone);
|
||||
assert.equal(body.code, '654321');
|
||||
assert.equal(body.purpose, 'bind_phone');
|
||||
json(res, 200, { ok: true, user: { id: 'user-id', phone: bindPhone }, phoneChanged: true, revokedOtherSessions: 0 });
|
||||
return;
|
||||
}
|
||||
|
||||
json(res, 404, { code: 'NOT_FOUND', path: url.pathname });
|
||||
});
|
||||
|
||||
@@ -73,6 +85,8 @@ try {
|
||||
origin: 'https://admin.tjszsb.com',
|
||||
purpose: 'login',
|
||||
code: '123456',
|
||||
bindPhone,
|
||||
bindCode: '654321',
|
||||
timeoutMs: 5000,
|
||||
skipSend: false,
|
||||
skipMe: false,
|
||||
@@ -81,9 +95,11 @@ try {
|
||||
);
|
||||
|
||||
assert.equal(result.sessionToken, 'session-token');
|
||||
assert.equal(result.boundPhone, bindPhone);
|
||||
assert.equal(seen.some(item => item.path === '/api/auth/sms/send' && item.tenantId === tenantId), true);
|
||||
assert.equal(seen.some(item => item.path === '/api/auth/sms/verify' && item.origin === 'https://admin.tjszsb.com'), true);
|
||||
assert.equal(seen.some(item => item.path === '/api/auth/me'), true);
|
||||
assert.equal(seen.some(item => item.path === '/api/auth/phone/bind'), true);
|
||||
console.log('[PASS] remote SMS login smoke script');
|
||||
} finally {
|
||||
await new Promise(resolve => server.close(resolve));
|
||||
|
||||
Reference in New Issue
Block a user