forked from wangziqi/gongxue-base
fix: require configured production SMS provider in DB
This commit is contained in:
@@ -171,6 +171,32 @@ function providerIn(provider, aliases) {
|
||||
return aliases.has(normalizeProvider(provider));
|
||||
}
|
||||
|
||||
function currentSmsProviderAliases() {
|
||||
const provider = normalizeProvider(env('AUTH_SMS_PROVIDER', 'mock')).replace(/_/g, '-');
|
||||
if (AUTH_PROVIDER_ALIASES.aliyunPnvs.has(provider)) return { provider: 'aliyun-pnvs', aliases: AUTH_PROVIDER_ALIASES.aliyunPnvs };
|
||||
if (AUTH_PROVIDER_ALIASES.aliyun.has(provider)) return { provider: 'aliyun', aliases: AUTH_PROVIDER_ALIASES.aliyun };
|
||||
if (AUTH_PROVIDER_ALIASES.tencent.has(provider)) return { provider: 'tencent', aliases: AUTH_PROVIDER_ALIASES.tencent };
|
||||
return { provider, aliases: new Set([provider]) };
|
||||
}
|
||||
|
||||
function validateActiveSmsProviderRows(rows, sourceLabel = 'database') {
|
||||
const expected = currentSmsProviderAliases();
|
||||
if (!PRODUCTION_SMS_PROVIDERS.has(normalizeProvider(env('AUTH_SMS_PROVIDER', 'mock')))) return;
|
||||
const activeRows = rows.filter(row => row.source === 'auth' && providerIn(row.provider, expected.aliases));
|
||||
if (activeRows.length === 0) {
|
||||
block('db.auth_sms_provider_configured', 'AUTH_SMS_PROVIDER must have a matching active/testing tenant_auth_providers row', {
|
||||
provider: expected.provider,
|
||||
source: sourceLabel,
|
||||
});
|
||||
return;
|
||||
}
|
||||
pass('db.auth_sms_provider_configured', 'AUTH_SMS_PROVIDER has matching active/testing tenant auth provider rows', {
|
||||
provider: expected.provider,
|
||||
count: activeRows.length,
|
||||
source: sourceLabel,
|
||||
});
|
||||
}
|
||||
|
||||
function validateProviderUrl({
|
||||
id,
|
||||
value,
|
||||
@@ -457,6 +483,7 @@ function validateProviderConfigRows(inputRows) {
|
||||
warn('db.provider_fixture.empty', 'Provider config fixture did not contain any rows');
|
||||
return;
|
||||
}
|
||||
validateActiveSmsProviderRows(rows, 'fixture');
|
||||
for (const row of rows) {
|
||||
const secretPaths = findSecretLikePaths(row.config_public || {});
|
||||
if (secretPaths.length > 0) {
|
||||
@@ -793,6 +820,7 @@ async function validateDatabase() {
|
||||
if (publicSecretRows.rows.every(row => findSecretLikePaths(row.config_public || {}).length === 0)) {
|
||||
pass('db.provider_public_config', 'Active provider public configs do not contain secret-like keys');
|
||||
}
|
||||
validateActiveSmsProviderRows(publicSecretRows.rows, 'database');
|
||||
|
||||
const activePlatformAdminRows = await pool.query(`
|
||||
select id, username, phone, auth_user_id
|
||||
|
||||
Reference in New Issue
Block a user