'login-session-revocation-test-key']; $fail = function ($message) { fwrite(STDERR, $message . PHP_EOL); exit(1); }; $user = new User(); $user->id = 17; $user->pass = 'stored-password-hash'; $user->login_session_version = 0; $legacyKey = Hash::cookieHash($user->pass); if (!LoginSessionRevocationService::cookieKeyMatches($user, $legacyKey, '')) { $fail('Legacy cookie should remain valid before the first revocation.'); } $versionZeroKey = LoginSessionRevocationService::cookieKey($user->pass, 0); if (!LoginSessionRevocationService::cookieKeyMatches($user, $versionZeroKey, '0')) { $fail('Versioned cookie was rejected before revocation.'); } $user->login_session_version = 1; if (LoginSessionRevocationService::cookieKeyMatches($user, $legacyKey, '') || LoginSessionRevocationService::cookieKeyMatches($user, $legacyKey, '1') || LoginSessionRevocationService::cookieKeyMatches($user, $versionZeroKey, '0')) { $fail('Revoked or forged cookie was accepted.'); } $versionOneKey = LoginSessionRevocationService::cookieKey($user->pass, 1); if (!LoginSessionRevocationService::cookieKeyMatches($user, $versionOneKey, '1')) { $fail('Current login cookie was rejected after revocation.'); } $legacyRedis = LoginSessionRevocationService::decodeRedisSession('17'); $versionedRedis = LoginSessionRevocationService::decodeRedisSession( LoginSessionRevocationService::encodeRedisSession(17, 1) ); if ($legacyRedis !== ['uid' => 17, 'version' => null] || $versionedRedis !== ['uid' => 17, 'version' => 1] || LoginSessionRevocationService::decodeRedisSession('not-a-session') !== null || LoginSessionRevocationService::snapshotMatches($legacyRedis['version'], 1) || !LoginSessionRevocationService::snapshotMatches($versionedRedis['version'], 1)) { $fail('Redis session compatibility or revocation checks failed.'); } $root = dirname(__DIR__); $cookieSource = file_get_contents($root . '/app/Services/Auth/Cookie.php'); $redisSource = file_get_contents($root . '/app/Services/Auth/Redis.php'); $jwtSource = file_get_contents($root . '/app/Services/Auth/JwtToken.php'); $configControllerSource = file_get_contents($root . '/app/Controllers/Admin/ConfigController.php'); $userControllerSource = file_get_contents($root . '/app/Controllers/Admin/UserController.php'); $routesSource = file_get_contents($root . '/config/routes.php'); $configSource = file_get_contents($root . '/resources/views/venix/admin/config.tpl'); $userSource = file_get_contents($root . '/resources/views/venix/admin/user/index.tpl'); $migrationSource = file_get_contents($root . '/sql/login_session_revocation.sql'); $baselineSqlSource = file_get_contents($root . '/sql/ss.sql'); if ($cookieSource === false || strpos($cookieSource, 'LoginSessionRevocationService::cookieKeyMatches') === false || $redisSource === false || strpos($redisSource, 'LoginSessionRevocationService::decodeRedisSession') === false || $jwtSource === false || strpos($jwtSource, 'session_version') === false || $configControllerSource === false || strpos($configControllerSource, 'LoginSessionRevocationService::revokeAll') === false || $userControllerSource === false || strpos($userControllerSource, 'LoginSessionRevocationService::revokeUser') === false || $routesSource === false || strpos($routesSource, '/config/login-sessions/clear') === false || $configSource === false || strpos($configSource, '/admin/config/login-sessions/clear') === false || $userSource === false || strpos($userSource, '/login-sessions/clear') === false || $migrationSource === false || strpos($migrationSource, 'login_session_version') === false || $baselineSqlSource === false || strpos($baselineSqlSource, '`login_session_version` bigint(20)') === false) { $fail('Login session revocation is not fully wired into the project.'); } echo 'Login session revocation and legacy credential checks passed.' . PHP_EOL;