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.
65 lines
2.2 KiB
PHP
65 lines
2.2 KiB
PHP
<?php
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
$System_Config = [];
|
|
|
|
use App\Models\User;
|
|
use App\Services\AccountSecurityService;
|
|
use App\Services\Payment\RechargeMethodsService;
|
|
use App\Utils\Totp;
|
|
|
|
$assert = static function ($condition, $message) {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$user = new User();
|
|
$user->ga_enable = 1;
|
|
$user->ga_token = Totp::generateSecret();
|
|
$assert(AccountSecurityService::hasTotp($user), 'Enabled TOTP was not detected.');
|
|
$user->ga_enable = 0;
|
|
$assert(!AccountSecurityService::hasTotp($user), 'Disabled TOTP was reported as enabled.');
|
|
$assert(AccountSecurityService::consumePasswordFactor($user, '', '') === null,
|
|
'An empty password factor was accepted.');
|
|
|
|
$routes = file_get_contents(dirname(__DIR__) . '/config/routes.php');
|
|
foreach ([
|
|
"'/email/verify/send'",
|
|
"'/email'",
|
|
"'/password/verify/send'",
|
|
"'/password'",
|
|
"'/recharge/options'",
|
|
'AccountSecurityController:emailVerifySend',
|
|
'AccountSecurityController:updateEmail',
|
|
'AccountSecurityController:passwordVerifySend',
|
|
'AccountSecurityController:updatePassword',
|
|
'AccountSecurityController:rechargeOptions',
|
|
] as $needle) {
|
|
$assert(strpos($routes, $needle) !== false, 'Missing account API route: ' . $needle);
|
|
}
|
|
|
|
$controller = file_get_contents(dirname(__DIR__) . '/app/Controllers/AccountSecurityController.php');
|
|
foreach (['oldpwd', 'emailcode', 'gacode', 'need_security_verify', 'AdminCsrf::verify'] as $needle) {
|
|
$assert(strpos($controller, $needle) !== false, 'Password API dropped security field: ' . $needle);
|
|
}
|
|
|
|
$security = file_get_contents(dirname(__DIR__) . '/app/Services/AccountSecurityService.php');
|
|
foreach ([
|
|
"'password_change:' . \$plainCode",
|
|
"'password_change:' . \$emailCode",
|
|
"->where('code', 'like', 'password_change:%')",
|
|
'is_scalar($emailCode)',
|
|
'is_scalar($totpCode)',
|
|
'->incr($key)',
|
|
'->getClient()->set(',
|
|
] as $needle) {
|
|
$assert(strpos($security, $needle) !== false, 'Password factor hardening is missing: ' . $needle);
|
|
}
|
|
|
|
$methods = RechargeMethodsService::class;
|
|
$assert(method_exists($methods, 'forUser'), 'Recharge method discovery service is missing.');
|
|
|
|
echo "Account security and recharge API contract checks passed.\n";
|