37 lines
4.1 KiB
PHP
37 lines
4.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
const MINIAPI_TOKEN_KEY = 'test';
|
|
function authcode($value, $operation = 'DECODE', $key = '', $expiry = 0) { return $value; }
|
|
|
|
require dirname(__DIR__) . '/app/miniapi/service/VisaApplication/VisaApplicationService.php';
|
|
|
|
use app\miniapi\service\VisaApplication\VisaApplicationService;
|
|
|
|
$service = new VisaApplicationService();
|
|
if ($service->endpoint('https://user.example.com/users/list', 'start') !== 'https://user.example.com/visa_service/start') throw new RuntimeException('endpoint construction failed');
|
|
if ($service->endpoint('https://user.example.com/users/list', 'dataSource') !== 'https://user.example.com/visa_service/dataSource') throw new RuntimeException('data source forwarding endpoint failed');
|
|
if ($service->endpoint('https://user.example.com/users/list', 'agree') !== 'https://user.example.com/visa_service/agree') throw new RuntimeException('legal document forwarding endpoint failed');
|
|
if ($service->endpoint('https://user.example.com/users/list', 'invalid') !== '') throw new RuntimeException('action allowlist failed');
|
|
$payload = $service->payload(9, ['order_source' => 'jnwxmini']);
|
|
if (isset($payload['user_id']) || (json_decode((string)($payload['user_token'] ?? ''), true) !== ['purpose' => 'visa_api', 'user_id' => 9, 'order_source' => 'jnwxmini'])) throw new RuntimeException('trusted token payload failed');
|
|
if (str_contains((new ReflectionMethod($service, 'start'))->getFileName() ? file_get_contents((new ReflectionMethod($service, 'start'))->getFileName()) : '', '$data + [\'order_source\'')) throw new RuntimeException('start source override failed');
|
|
if (!str_contains((string)file_get_contents(dirname(__DIR__) . '/app/miniapi/controller/VisaApplication.php'), "sourceForCode(string \$code)") || !str_contains((string)file_get_contents(dirname(__DIR__) . '/app/miniapi/controller/VisaApplication.php'), "\$code === 'evus_bj_mp'") || !str_contains((string)file_get_contents(dirname(__DIR__) . '/app/miniapi/controller/VisaApplication.php'), "\$filters['source_code'] = \$this->orderSource()")) throw new RuntimeException('visa source allowlist failed');
|
|
$neutral = VisaApplicationService::decorateSubmitForCheck(['code' => 1, 'data' => ['order_sn' => 'V1', 'requires_payment' => false]]);
|
|
$payable = VisaApplicationService::decorateSubmitForCheck(['code' => 1, 'data' => ['order_sn' => 'V 1', 'requires_payment' => true]]);
|
|
if (isset($neutral['data']['pay_url']) || ($payable['data']['pay_url'] ?? '') !== 'https://www.qlevisa.com/index/pay/h5pay.html?order_sn=V%201') throw new RuntimeException('miniapi payment decoration failed');
|
|
$native = VisaApplicationService::nativePaymentForCheck([
|
|
'requires_payment' => true,
|
|
'total_price' => 7900,
|
|
'target_orders' => [
|
|
['target_table' => 'singapore', 'target_order_sn' => '2026090412000012', 'applicant_index' => 0],
|
|
],
|
|
]);
|
|
if ($native !== ['target_table' => 'singapore', 'order_sn' => '2026090412000012', 'money' => '79.00']) throw new RuntimeException('native payment target failed');
|
|
if (VisaApplicationService::nativePaymentForCheck(['requires_payment' => true, 'total_price' => 7900, 'target_orders' => [['target_table' => 'bad-table', 'target_order_sn' => '1']]]) !== []) throw new RuntimeException('unsafe payment target accepted');
|
|
if (VisaApplicationService::dataSourceQueryForCheck('inac.city', ['model' => 'region', 'source_code' => 'jnwxmini', 'state_id' => '11', 'hotel_state' => '12', 'provinceCode' => '13', 'country' => 'CN', 'application_token' => 'secret', 'user_token' => 'secret']) !== ['type' => 'inac.city', 'model' => 'region', 'source_code' => 'jnwxmini', 'state_id' => '11', 'hotel_state' => '12', 'provinceCode' => '13', 'country' => 'CN']) throw new RuntimeException('miniapi data source filtering failed');
|
|
$controllerSource = (string)file_get_contents(dirname(__DIR__) . '/app/miniapi/controller/VisaApplication.php');
|
|
$routeSource = (string)file_get_contents(dirname(__DIR__) . '/app/miniapi/route/app.php');
|
|
if (!str_contains($controllerSource, 'public function agree()') || !str_contains($routeSource, "Route::get('visa/agree'")) throw new RuntimeException('miniapi legal document route missing');
|
|
echo "PASS visa_application_facade_self_check\n";
|