diff --git a/web/app/Controllers/AccountSecurityController.php b/web/app/Controllers/AccountSecurityController.php index 5d1899a8..78f0eef5 100644 --- a/web/app/Controllers/AccountSecurityController.php +++ b/web/app/Controllers/AccountSecurityController.php @@ -79,6 +79,7 @@ class AccountSecurityController extends BaseController $result = AccountEmailChangeService::change( Auth::getUser(), $request->getParam('email', ''), + $request->getParam('oldpwd', ''), $request->getParam('emailcode', '') ); } catch (\Throwable $exception) { diff --git a/web/app/Services/AccountEmailChangeService.php b/web/app/Services/AccountEmailChangeService.php index 52528e2d..b8654b01 100644 --- a/web/app/Services/AccountEmailChangeService.php +++ b/web/app/Services/AccountEmailChangeService.php @@ -4,6 +4,7 @@ namespace App\Services; use App\Models\EmailVerify; use App\Models\User; +use App\Utils\Hash; use Illuminate\Database\QueryException; /** Securely replace an account email after verifying the new address. */ @@ -105,9 +106,16 @@ final class AccountEmailChangeService /** * @return array{ok:bool,msg:string,status:int,email?:string} */ - public static function change(User $user, $newEmail, $emailCode, ?RedisClient $redis = null): array + public static function change( + User $user, + $newEmail, + $currentPassword, + $emailCode, + ?RedisClient $redis = null + ): array { $newEmail = self::normalizeEmail($newEmail); + $currentPassword = is_string($currentPassword) ? $currentPassword : ''; $emailCode = is_scalar($emailCode) ? trim((string) $emailCode) : ''; $userId = (int) $user->id; if ($userId < 1 || $newEmail === null) { @@ -129,11 +137,24 @@ final class AccountEmailChangeService $connection = (new User())->getConnection(); try { $result = $connection->transaction( - static function () use ($userId, $newEmail, $emailCode): array { + static function () use ( + $userId, + $newEmail, + $currentPassword, + $emailCode + ): array { $locked = User::where('id', '=', $userId)->lockForUpdate()->first(); if ($locked === null) { return ['ok' => false, 'msg' => '账户不存在', 'status' => 404]; } + if (!Hash::checkPassword($locked->pass, $currentPassword)) { + return [ + 'ok' => false, + 'msg' => '当前密码错误', + 'status' => 422, + 'factor_failure' => true, + ]; + } $currentEmail = self::normalizeEmail($locked->email); if ($currentEmail === null) { diff --git a/web/app/Services/Cloud/CloudAdminInstanceService.php b/web/app/Services/Cloud/CloudAdminInstanceService.php index 9aecf8eb..0a9e1aef 100644 --- a/web/app/Services/Cloud/CloudAdminInstanceService.php +++ b/web/app/Services/Cloud/CloudAdminInstanceService.php @@ -327,8 +327,7 @@ final class CloudAdminInstanceService . "AND attention_job.outcome = 'failed' " . "AND (attention_job.updated_at >= ? OR " . "attention_job.effect_resolution = 'unknown')) OR " - . self::recoveryIncidentSql('attention_job') . ' OR ' - . self::terminalStateConflictSql('attention_job') . '))'; + . CloudJobRecoverySql::pendingSql('attention_job') . '))'; } /** A terminal failure may keep a safety fence, but it is never active work. */ @@ -341,77 +340,7 @@ final class CloudAdminInstanceService . $alias . ".effect_resolution = 'unknown' AND (" . $alias . '.effect_may_have_applied = 1 OR ' . $alias . '.safe_to_resubmit = 0)))) OR ' - . self::recoveryIncidentSql($alias) . ' OR ' - . self::terminalStateConflictSql($alias) . ')'; - } - - private static function recoveryIncidentSql(string $alias): string - { - $supported = self::sqlList(CloudOperationRecoveryPolicy::kinds()); - $repair = self::sqlList(CloudDispatchLedger::repairIncidentCodes()); - $aggregateKinds = self::sqlList(CloudJobService::aggregateKinds()); - $agent = '(' . $alias . ".execution_mode = 'agent' AND (" - . '(' . $alias . '.dispatch_attempts IS NULL OR ' - . $alias . '.dispatch_attempts NOT IN (0, 1)) OR (' - . $alias . ".phase = 'terminal' AND " - . $alias . '.finalization_incident = 1 AND (' - . $alias . '.finalization_error_code IN (' . $repair . ') OR (' - . $alias . ".outcome = 'failed' AND " - . $alias . ".status = 'failed' AND " - . $alias . '.dispatch_attempts = 0 AND ' - . $alias . '.kind IN (' . $supported . ')) OR (' - . $alias . '.dispatch_attempts IN (0, 1) AND ' - . $alias . '.effect_resolution IN (\'applied\', \'not_applied\') ' - . 'AND ' . $alias . '.kind IN (' . $supported . '))))))'; - $aggregateIncident = '(' . $alias . ".phase = 'terminal' AND " - . $alias . '.parent_job_id IS NULL AND ' - . $alias . '.finalization_incident = 1 AND ' - . '(' . $alias . ".execution_mode = 'aggregate' OR " - . $alias . '.kind IN (' . $aggregateKinds . ') OR ' - . $alias . '.finalization_error_code = ' - . "'recovery_aggregate_state_conflict'))"; - return '(' . $agent . ' OR ' - . CloudJobService::aggregateLocalStateConflictSql($alias) - . ' OR ' . $aggregateIncident . ')'; - } - - private static function terminalStateConflictSql(string $alias): string - { - return CloudJobService::terminalRecoveryStateConflictSql($alias); - } - - /** Keep raw attention/filter SQL aligned with the task DTO check. */ - private static function invalidResolvedTerminalTupleSql( - string $alias - ): string { - return '(' . $alias - . ".effect_resolution IN ('applied', 'not_applied') AND NOT ((" - . "COALESCE(" . $alias . ".outcome, '') = 'succeeded' AND " - . "COALESCE(" . $alias . ".status, '') = 'succeeded' AND " - . $alias . ".effect_resolution = 'applied' AND " - . 'COALESCE(' . $alias . '.effect_may_have_applied, -1) = 0 AND ' - . 'COALESCE(' . $alias . '.safe_to_resubmit, -1) = 0 AND ' - . 'COALESCE(' . $alias . '.terminal_at, 0) > 0 AND ' - . $alias . '.error_code IS NULL) OR (' - . "COALESCE(" . $alias . ".outcome, '') = 'failed' AND " - . "COALESCE(" . $alias . ".status, '') = 'failed' AND " - . 'COALESCE(' . $alias . '.terminal_at, 0) > 0 AND ' - . 'COALESCE(' . $alias . '.effect_may_have_applied, -1) IN (0, 1) AND ' - . 'COALESCE(' . $alias . '.safe_to_resubmit, -1) IN (0, 1) AND ((' - . $alias . '.effect_may_have_applied = 1 AND ' - . $alias . '.safe_to_resubmit = 0) OR (' - . $alias . '.effect_may_have_applied = 0 AND ' - . $alias . ".effect_resolution = 'not_applied')))))"; - } - - /** @param list $values */ - private static function sqlList(array $values): string - { - return implode(', ', array_map( - static fn (string $value): string => "'" - . str_replace("'", "''", $value) . "'", - $values - )); + . CloudJobRecoverySql::pendingSql($alias) . ')'; } private static function activeJobs($records): array diff --git a/web/app/Services/Cloud/CloudAdminOperationsService.php b/web/app/Services/Cloud/CloudAdminOperationsService.php index 09a94eee..53e6445a 100644 --- a/web/app/Services/Cloud/CloudAdminOperationsService.php +++ b/web/app/Services/Cloud/CloudAdminOperationsService.php @@ -373,7 +373,7 @@ final class CloudAdminOperationsService $failed->where('cloud_jobs.phase', 'terminal') ->where('cloud_jobs.outcome', 'failed'); })->orWhereRaw( - self::recoveryPendingSql('cloud_jobs') + CloudJobRecoverySql::pendingSql('cloud_jobs') ); }); } elseif ($filters['status'] === 'active') { @@ -686,89 +686,10 @@ final class CloudAdminOperationsService return $value !== null && (int) $value > 0 ? (int) $value : null; } - private static function recoveryIncidentSql(string $alias): string - { - $supported = self::sqlList(CloudOperationRecoveryPolicy::kinds()); - $repair = self::sqlList(CloudDispatchLedger::repairIncidentCodes()); - $aggregateKinds = self::sqlList(CloudJobService::aggregateKinds()); - $agent = '(' . $alias . ".execution_mode = 'agent' AND (" - . '(' . $alias . '.dispatch_attempts IS NULL OR ' - . $alias . '.dispatch_attempts NOT IN (0, 1)) OR (' - . $alias . ".phase = 'terminal' AND " - . $alias . '.finalization_incident = 1 AND (' - . $alias . '.finalization_error_code IN (' . $repair . ') OR (' - . $alias . ".outcome = 'failed' AND " - . $alias . ".status = 'failed' AND " - . $alias . '.dispatch_attempts = 0 AND ' - . $alias . '.kind IN (' . $supported . ')) OR (' - . $alias . '.dispatch_attempts IN (0, 1) AND ' - . $alias . '.effect_resolution IN (\'applied\', \'not_applied\') ' - . 'AND ' . $alias . '.kind IN (' . $supported . '))))))'; - $aggregateIncident = '(' . $alias . ".phase = 'terminal' AND " - . $alias . '.parent_job_id IS NULL AND ' - . $alias . '.finalization_incident = 1 AND ' - . '(' . $alias . ".execution_mode = 'aggregate' OR " - . $alias . '.kind IN (' . $aggregateKinds . ') OR ' - . $alias . '.finalization_error_code = ' - . "'recovery_aggregate_state_conflict'))"; - return '(' . $agent . ' OR ' - . CloudJobService::aggregateLocalStateConflictSql($alias) - . ' OR ' . $aggregateIncident . ')'; - } - - private static function recoveryPendingSql(string $alias): string - { - return '(' . self::recoveryIncidentSql($alias) . ' OR ' - . self::terminalStateConflictSql($alias) . ')'; - } - /** Shared source of truth for every resource-fence counter and filter. */ public static function resourceLockedSql(string $alias): string { - return '((' . $alias . ".phase = 'terminal' AND " - . $alias . ".outcome = 'failed' AND " - . $alias . ".effect_resolution = 'unknown' AND " - . $alias . ".kind <> 'host_storage_configure') OR " - . self::recoveryPendingSql($alias) . ')'; - } - - private static function terminalStateConflictSql(string $alias): string - { - return CloudJobService::terminalRecoveryStateConflictSql($alias); - } - - /** Keep raw inventory counts aligned with CloudJobService's DTO check. */ - private static function invalidResolvedTerminalTupleSql( - string $alias - ): string { - return '(' . $alias - . ".effect_resolution IN ('applied', 'not_applied') AND NOT ((" - . "COALESCE(" . $alias . ".outcome, '') = 'succeeded' AND " - . "COALESCE(" . $alias . ".status, '') = 'succeeded' AND " - . $alias . ".effect_resolution = 'applied' AND " - . 'COALESCE(' . $alias . '.effect_may_have_applied, -1) = 0 AND ' - . 'COALESCE(' . $alias . '.safe_to_resubmit, -1) = 0 AND ' - . 'COALESCE(' . $alias . '.terminal_at, 0) > 0 AND ' - . $alias . '.error_code IS NULL) OR (' - . "COALESCE(" . $alias . ".outcome, '') = 'failed' AND " - . "COALESCE(" . $alias . ".status, '') = 'failed' AND " - . 'COALESCE(' . $alias . '.terminal_at, 0) > 0 AND ' - . 'COALESCE(' . $alias . '.effect_may_have_applied, -1) IN (0, 1) AND ' - . 'COALESCE(' . $alias . '.safe_to_resubmit, -1) IN (0, 1) AND ((' - . $alias . '.effect_may_have_applied = 1 AND ' - . $alias . '.safe_to_resubmit = 0) OR (' - . $alias . '.effect_may_have_applied = 0 AND ' - . $alias . ".effect_resolution = 'not_applied')))))"; - } - - /** @param list $values */ - private static function sqlList(array $values): string - { - return implode(', ', array_map( - static fn (string $value): string => "'" - . str_replace("'", "''", $value) . "'", - $values - )); + return CloudJobRecoverySql::resourceLockedSql($alias); } private static function isLocalFinalizerRecovery(object $job): bool diff --git a/web/app/Services/Cloud/CloudJobRecoverySql.php b/web/app/Services/Cloud/CloudJobRecoverySql.php new file mode 100644 index 00000000..3de42f32 --- /dev/null +++ b/web/app/Services/Cloud/CloudJobRecoverySql.php @@ -0,0 +1,62 @@ + 'host_storage_configure') OR " + . self::pendingSql($alias) . ')'; + } + + private static function incidentSql(string $alias): string + { + $supported = self::sqlList(CloudOperationRecoveryPolicy::kinds()); + $repair = self::sqlList(CloudDispatchLedger::repairIncidentCodes()); + $aggregateKinds = self::sqlList(CloudJobService::aggregateKinds()); + $agent = '(' . $alias . ".execution_mode = 'agent' AND (" + . '(' . $alias . '.dispatch_attempts IS NULL OR ' + . $alias . '.dispatch_attempts NOT IN (0, 1)) OR (' + . $alias . ".phase = 'terminal' AND " + . $alias . '.finalization_incident = 1 AND (' + . $alias . '.finalization_error_code IN (' . $repair . ') OR (' + . $alias . ".outcome = 'failed' AND " + . $alias . ".status = 'failed' AND " + . $alias . '.dispatch_attempts = 0 AND ' + . $alias . '.kind IN (' . $supported . ')) OR (' + . $alias . '.dispatch_attempts IN (0, 1) AND ' + . $alias . '.effect_resolution IN (\'applied\', \'not_applied\') ' + . 'AND ' . $alias . '.kind IN (' . $supported . '))))))'; + $aggregateIncident = '(' . $alias . ".phase = 'terminal' AND " + . $alias . '.parent_job_id IS NULL AND ' + . $alias . '.finalization_incident = 1 AND ' + . '(' . $alias . ".execution_mode = 'aggregate' OR " + . $alias . '.kind IN (' . $aggregateKinds . ') OR ' + . $alias . '.finalization_error_code = ' + . "'recovery_aggregate_state_conflict'))"; + return '(' . $agent . ' OR ' + . CloudJobService::aggregateLocalStateConflictSql($alias) + . ' OR ' . $aggregateIncident . ')'; + } + + /** @param list $values */ + private static function sqlList(array $values): string + { + return implode(', ', array_map( + static fn (string $value): string => "'" + . str_replace("'", "''", $value) . "'", + $values + )); + } +} diff --git a/web/public/theme/venix/js/user-home.js b/web/public/theme/venix/js/user-home.js index 99a35d34..48ed7cdd 100644 --- a/web/public/theme/venix/js/user-home.js +++ b/web/public/theme/venix/js/user-home.js @@ -413,13 +413,19 @@ emailForm.addEventListener("submit", function (event) { event.preventDefault(); + var currentPasswordInput = qs("#account-email-current-password"); var emailInput = qs("#account-new-email"); var codeInput = qs("#account-email-code"); var button = qs("#account-email-update"); + var currentPassword = currentPasswordInput ? currentPasswordInput.value : ""; var email = emailInput ? emailInput.value.trim().toLowerCase() : ""; var currentEmail = (emailForm.getAttribute("data-current-email") || "").trim().toLowerCase(); var code = codeInput ? codeInput.value.trim() : ""; + if (!currentPasswordInput || !currentPasswordInput.checkValidity() || !currentPassword) { + alertModal("请输入当前密码。", "error"); + return; + } if (!emailInput || !emailInput.checkValidity() || !email) { alertModal("请输入有效的新邮箱地址。", "error"); return; @@ -434,7 +440,7 @@ } var done = setBusy(button, "保存中..."); - post("/user/email", { email: email, emailcode: code }).then(function (data) { + post("/user/email", { email: email, oldpwd: currentPassword, emailcode: code }).then(function (data) { alertModal(data.msg || "邮箱已更新", data.ret ? "success" : "error").then(function () { if (data.ret) { emailForm.reset(); diff --git a/web/resources/views/venix/layout_assets.tpl b/web/resources/views/venix/layout_assets.tpl index deeb72ac..654bcdb6 100644 --- a/web/resources/views/venix/layout_assets.tpl +++ b/web/resources/views/venix/layout_assets.tpl @@ -1,2 +1,2 @@ {* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *} -{assign var=venix_asset_version value='2026102410' scope='global'} +{assign var=venix_asset_version value='2026102411' scope='global'} diff --git a/web/resources/views/venix/user/edit.tpl b/web/resources/views/venix/user/edit.tpl index 4e029120..5644f8f4 100644 --- a/web/resources/views/venix/user/edit.tpl +++ b/web/resources/views/venix/user/edit.tpl @@ -83,9 +83,10 @@
+
新邮箱验证码
-

验证码会发送到上方填写的新邮箱。修改成功会退出所有已登录设备,请使用新邮箱重新登录。

+

更新时会校验当前密码和发送到新邮箱的验证码。修改成功会退出所有已登录设备,请使用新邮箱重新登录。

diff --git a/web/tests/AccountEmailChangeTest.php b/web/tests/AccountEmailChangeTest.php index 88aef2bb..e6d06655 100644 --- a/web/tests/AccountEmailChangeTest.php +++ b/web/tests/AccountEmailChangeTest.php @@ -126,6 +126,7 @@ $schema->create('configurations', static function (Blueprint $table): void { $schema->create('user', static function (Blueprint $table): void { $table->increments('id'); $table->string('email', 254)->unique(); + $table->string('pass'); $table->unsignedBigInteger('login_session_version')->default(0); }); $schema->create('email_verify', static function (Blueprint $table): void { @@ -137,9 +138,13 @@ $schema->create('email_verify', static function (Blueprint $table): void { }); Capsule::table('configurations')->insert(['name' => 'email_blacklist', 'value' => '']); +$currentPassword = 'Current#Pass123'; +$passwordHash = password_hash($currentPassword, PASSWORD_BCRYPT, ['cost' => 4]); Capsule::table('user')->insert([ - ['id' => 1, 'email' => 'old@example.com', 'login_session_version' => 0], - ['id' => 2, 'email' => 'used@example.com', 'login_session_version' => 0], + ['id' => 1, 'email' => 'old@example.com', 'pass' => $passwordHash, + 'login_session_version' => 0], + ['id' => 2, 'email' => 'used@example.com', 'pass' => $passwordHash, + 'login_session_version' => 0], ]); Capsule::table('email_verify')->insert([ ['email' => 'new@example.com', 'ip' => '127.0.0.1', @@ -158,28 +163,47 @@ $sharedClient->setValue(null, $backend); $redis = new AccountEmailChangeFakeRedis($backend); $user = User::findOrFail(1); -$invalid = AccountEmailChangeService::change($user, 'not-an-email', '123456', $redis); +$invalid = AccountEmailChangeService::change( + $user, 'not-an-email', $currentPassword, '123456', $redis +); $assert(!$invalid['ok'] && $invalid['status'] === 422, 'An invalid target email was accepted.'); $assert(Capsule::table('email_verify')->where('email', 'new@example.com')->count() === 3, 'Validation consumed a new-email code before the transaction.'); -$same = AccountEmailChangeService::change($user, 'OLD@example.com', '123456', $redis); +$same = AccountEmailChangeService::change( + $user, 'OLD@example.com', $currentPassword, '123456', $redis +); $assert(!$same['ok'] && $same['status'] === 422, 'The current email was accepted as a replacement.'); -$duplicate = AccountEmailChangeService::change($user, 'used@example.com', '123456', $redis); +$duplicate = AccountEmailChangeService::change( + $user, 'used@example.com', $currentPassword, '123456', $redis +); $assert(!$duplicate['ok'] && $duplicate['status'] === 409, 'An email owned by another account was accepted.'); $assert(Capsule::table('email_verify')->where('code', 'email_change:1:123456')->exists(), 'A rejected duplicate target consumed the new-email code.'); -$wrong = AccountEmailChangeService::change($user, 'new@example.com', '000000', $redis); +$wrongPassword = AccountEmailChangeService::change( + $user, 'new@example.com', 'Wrong#Pass123', '123456', $redis +); +$assert(!$wrongPassword['ok'] && $wrongPassword['status'] === 422 + && User::findOrFail(1)->email === 'old@example.com', + 'An invalid current password changed the account email.'); +$assert(Capsule::table('email_verify')->where('code', 'email_change:1:123456')->exists(), + 'An invalid current password consumed the new-email verification code.'); + +$wrong = AccountEmailChangeService::change( + $user, 'new@example.com', $currentPassword, '000000', $redis +); $assert(!$wrong['ok'] && $wrong['status'] === 422 && User::findOrFail(1)->email === 'old@example.com', 'An invalid new-email code changed the account email.'); -$changed = AccountEmailChangeService::change($user, ' New@Example.com ', '123456', $redis); +$changed = AccountEmailChangeService::change( + $user, ' New@Example.com ', $currentPassword, '123456', $redis +); $updated = User::findOrFail(1); $assert($changed['ok'] && $changed['email'] === 'new@example.com' && $updated->email === 'new@example.com' @@ -193,7 +217,9 @@ $assert(Capsule::table('email_verify')->where('code', 'email_change:2:999999')-> $assert(Capsule::table('email_verify')->where('code', 'password_change:777777')->exists(), 'Changing an email deleted an unrelated password verification code.'); -$replay = AccountEmailChangeService::change($user, 'second@example.com', '123456', $redis); +$replay = AccountEmailChangeService::change( + $user, 'second@example.com', $currentPassword, '123456', $redis +); $assert(!$replay['ok'] && User::findOrFail(1)->email === 'new@example.com', 'A consumed new-email code was replayed.'); @@ -210,8 +236,9 @@ foreach (compact('routes', 'controller', 'service', 'template', 'runtime', 'mail $assert(str_contains($routes, "'/email/verify/send'") && str_contains($routes, "'/email'") && str_contains($controller, 'AdminCsrf::verify') + && str_contains($controller, "getParam('oldpwd', '')") && str_contains($controller, 'Auth::logout()'), - 'The email-change API lost its authenticated CSRF or logout boundary.'); + 'The email-change API lost its password, CSRF or logout boundary.'); $assert(str_contains($service, "private const CODE_PREFIX = 'email_change:'") && str_contains($service, 'sendNewEmailCode') && str_contains($service, '$verification->email = $newEmail') @@ -222,13 +249,16 @@ $assert(str_contains($service, "private const CODE_PREFIX = 'email_change:'") && str_contains($service, "EmailVerify::where('email', '=', \$newEmail)"), 'The email-change service lost code isolation, locking, cleanup or session revocation.'); $assert(str_contains($template, 'id="vuEmailForm"') + && str_contains($template, 'id="account-email-current-password"') + && str_contains($template, 'autocomplete="current-password"') && str_contains($template, '新邮箱验证码') && str_contains($runtime, 'post("/user/email/verify/send"') && str_contains($runtime, '{ email: email }') && str_contains($runtime, 'post("/user/email"') + && str_contains($runtime, 'oldpwd: currentPassword') && str_contains($runtime, 'window.top.location.href = loginUrl') && str_contains($mail, "\$scene == 'email_change'"), - 'The account drawer, browser behavior or email scene is not fully wired.'); + 'The account drawer, current-password submission, browser behavior or email scene is not fully wired.'); RedisClient::resetSharedClient(); echo "Account email change new-address verification checks passed.\n"; diff --git a/web/tests/CloudAdminInstanceServiceTest.php b/web/tests/CloudAdminInstanceServiceTest.php index 91a614d8..5f640eb7 100644 --- a/web/tests/CloudAdminInstanceServiceTest.php +++ b/web/tests/CloudAdminInstanceServiceTest.php @@ -62,8 +62,10 @@ namespace { use App\Services\AdminPermission; use App\Services\Auth; use App\Services\Cloud\CloudAdminInstanceService; + use App\Services\Cloud\CloudAdminOperationsService; use App\Services\Cloud\CloudAgentSettingsService; use App\Services\Cloud\CloudError; + use App\Services\Cloud\CloudJobRecoverySql; use App\Services\Cloud\CloudSessionService; use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Database\Schema\Blueprint; @@ -617,6 +619,29 @@ namespace { 'Administrator job-attention filter omitted recovery-fenced instance ' . $expectedAttentionId . '.'); } + $sharedResourceLockedSql = CloudJobRecoverySql::resourceLockedSql('cloud_jobs'); + $compatibilityResourceLockedSql = CloudAdminOperationsService::resourceLockedSql( + 'cloud_jobs' + ); + $assert($compatibilityResourceLockedSql === $sharedResourceLockedSql, + 'The administrator operations compatibility seam changed the shared recovery predicate.'); + $sharedLockedJobIds = Capsule::table('cloud_jobs') + ->whereRaw($sharedResourceLockedSql) + ->orderBy('id')->pluck('id') + ->map(static fn ($id): int => (int) $id)->all(); + $compatibilityLockedJobIds = Capsule::table('cloud_jobs') + ->whereRaw($compatibilityResourceLockedSql) + ->orderBy('id')->pluck('id') + ->map(static fn ($id): int => (int) $id)->all(); + $assert($compatibilityLockedJobIds === $sharedLockedJobIds, + 'The administrator operations compatibility seam diverged from the shared recovery predicate.'); + foreach ([31 => 213, 34 => 204, 35 => 203, 36 => 202, + 37 => 201, 38 => 200, 39 => 199] as $jobId => $instanceId) { + $assert(in_array($jobId, $sharedLockedJobIds, true) + && in_array($instanceId, $jobAttentionIds, true), + 'Recovery-fenced task and instance inventories diverged for job ' + . $jobId . '.'); + } $unsupported = CloudAdminInstanceService::detail($admin, '214'); $assert($unsupported['instance']['network_change_supported'] === false && $unsupported['instance']['instance_settings_supported'] === false, diff --git a/web/tests/CloudFirewallUiContractTest.php b/web/tests/CloudFirewallUiContractTest.php index b19ad8d0..6b41018c 100644 --- a/web/tests/CloudFirewallUiContractTest.php +++ b/web/tests/CloudFirewallUiContractTest.php @@ -43,9 +43,22 @@ $assert(str_contains($template, 'id="vm-firewall-state"') && str_contains($template, 'id="vm-firewall-last-failure"'), 'Firewall UI must expose desired/applied evidence and last success/failure timestamps.'); -$assert(str_contains($script, - "const INSTANCE_SETTING_TABS = Object.freeze(['hostname', 'password', 'ssh_key', 'ip_change', 'firewall', 'snapshots'])") - && str_contains($script, "if (tab === 'firewall')") +$settingTabs = []; +if (preg_match( + '/const INSTANCE_SETTING_TABS = Object\.freeze\(\[([^\]]*)\]\);/', + $script, + $settingTabList + ) === 1 + && preg_match_all('/[\'\"]([a-z_]+)[\'\"]/', $settingTabList[1], $settingTabNames) !== false) { + $settingTabs = $settingTabNames[1]; +} +$assert(in_array('firewall', $settingTabs, true) + && str_contains($script, 'const selected = INSTANCE_SETTING_TABS.includes(tab)') + && str_contains($script, '.filter(tab => INSTANCE_SETTING_TABS.includes(tab))') + && preg_match( + "/if \(tab === 'firewall'\) \\{[\\s\\S]*?void loadVmFirewall\\(vmId\\);/", + $script + ) === 1 && str_contains($script, 'function loadVmFirewall(') && str_contains($script, 'function saveVmFirewall('), 'Firewall must participate in accessible settings navigation and lazy loading.');