forked from wangziqi/gongxue-base
chore: require PNVS SMS smoke launch evidence
This commit is contained in:
@@ -13,6 +13,13 @@ function envNumber(env, key, fallback) {
|
||||
return Number.isFinite(value) && value > 0 ? Math.trunc(value) : fallback;
|
||||
}
|
||||
|
||||
function parseArgs(argv) {
|
||||
return {
|
||||
json: argv.includes('--json'),
|
||||
quiet: argv.includes('--quiet'),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeBaseUrl(value) {
|
||||
return value.replace(/\/+$/, '');
|
||||
}
|
||||
@@ -137,6 +144,7 @@ async function runRemoteSmsLoginSmoke(inputConfig, options = {}) {
|
||||
if (!options.quiet) {
|
||||
console.log(`PASS sms.send provider=${send.payload?.item?.provider || 'unknown'} expireIn=${send.payload?.expireIn || '-'} cooldown=${send.payload?.cooldown || '-'}`);
|
||||
}
|
||||
config.sendProvider = send.payload?.item?.provider || '';
|
||||
}
|
||||
|
||||
const code = await promptCode(config);
|
||||
@@ -160,6 +168,7 @@ async function runRemoteSmsLoginSmoke(inputConfig, options = {}) {
|
||||
}
|
||||
|
||||
let boundPhone = null;
|
||||
let bindProvider = '';
|
||||
if (config.bindPhone) {
|
||||
const sendBind = await requestJson(config, '/api/auth/sms/send', {
|
||||
method: 'POST',
|
||||
@@ -167,8 +176,9 @@ async function runRemoteSmsLoginSmoke(inputConfig, options = {}) {
|
||||
body: { phone: config.bindPhone, purpose: 'bind_phone' },
|
||||
});
|
||||
assertOk('sms.bind.send', sendBind);
|
||||
bindProvider = sendBind.payload?.item?.provider || '';
|
||||
if (!options.quiet) {
|
||||
console.log(`PASS sms.bind.send provider=${sendBind.payload?.item?.provider || 'unknown'} phone=${maskPhone(config.bindPhone)}`);
|
||||
console.log(`PASS sms.bind.send provider=${bindProvider || 'unknown'} phone=${maskPhone(config.bindPhone)}`);
|
||||
}
|
||||
|
||||
const bindCode = await promptBindCode(config);
|
||||
@@ -190,13 +200,30 @@ async function runRemoteSmsLoginSmoke(inputConfig, options = {}) {
|
||||
sessionToken: token,
|
||||
user: verify.payload?.user || verify.payload?.item || null,
|
||||
boundPhone,
|
||||
summary: {
|
||||
failed: 0,
|
||||
provider: config.sendProvider || 'unknown',
|
||||
loginVerified: true,
|
||||
authMe: !config.skipMe,
|
||||
bindProvider: bindProvider || undefined,
|
||||
bindVerified: Boolean(boundPhone),
|
||||
phoneMasked: maskPhone(config.phone),
|
||||
bindPhoneMasked: config.bindPhone ? maskPhone(config.bindPhone) : undefined,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const options = parseArgs(process.argv.slice(2));
|
||||
try {
|
||||
await runRemoteSmsLoginSmoke();
|
||||
const result = await runRemoteSmsLoginSmoke(null, { quiet: options.quiet || options.json });
|
||||
if (options.json) console.log(JSON.stringify(result.summary, null, 2));
|
||||
} catch (error) {
|
||||
if (options.json) {
|
||||
console.log(JSON.stringify({ failed: 1, error: error.message }, null, 2));
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
console.error(error.message);
|
||||
if (error.response?.payload) console.error(JSON.stringify(error.response.payload, null, 2));
|
||||
if (/Missing required remote SMS smoke env/.test(error.message)) {
|
||||
@@ -212,6 +239,7 @@ Optional:
|
||||
SMS_SMOKE_BIND_PHONE=<another-phone-to-bind>
|
||||
SMS_SMOKE_BIND_CODE=<bind-code-you-received>
|
||||
SMS_SMOKE_SKIP_SEND=true
|
||||
--json
|
||||
`);
|
||||
}
|
||||
process.exitCode = 1;
|
||||
|
||||
Reference in New Issue
Block a user