You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/RegistrationIpRestrictionRe...

44 lines
1.8 KiB
PHP

<?php
$root = dirname(__DIR__, 2);
$read = static function (string $path) use ($root): string {
$content = file_get_contents($root . '/' . $path);
if ($content === false) {
throw new RuntimeException('Cannot read ' . $path);
}
return $content;
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$adminTemplate = $read('web/resources/views/venix/admin/config.tpl');
$adminController = $read('web/app/Controllers/Admin/ConfigController.php');
$authController = $read('web/app/Controllers/AuthController.php');
$assert(!str_contains($adminTemplate, 'name="cnreg"')
&& !str_contains($adminTemplate, 'id="cnreg"')
&& !str_contains($adminTemplate, '禁止中国大陆 IP 注册'),
'The retired registration IP restriction is still visible in administrator settings.');
$assert(!preg_match("/'cnreg'\\s*=>/", $adminController),
'The retired registration IP restriction is still writable through the configuration API.');
$assert(!str_contains($authController, 'RegistrationIpRestriction')
&& !str_contains($authController, 'cnreg'),
'Registration requests still execute the retired IP restriction.');
foreach ([
'web/app/Services/RegistrationIpRestriction.php',
'web/tests/RegistrationIpRestrictionTest.php',
'web/docs/china-ip-registration.md',
] as $path) {
$assert(!file_exists($root . '/' . $path), 'Retired registration IP restriction file remains: ' . $path);
}
$assert(file_exists($root . '/web/app/Utils/QQWry.php')
&& str_contains($read('web/app/Services/SiteAnalyticsService.php'), 'QQWry'),
'Shared IP geolocation support required by site analytics was removed accidentally.');
echo "Registration IP restriction removal contract passed.\n";