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/PaymentBrowserPrivacyTest.php

95 lines
4.2 KiB
PHTML

<?php
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Controllers\Admin\PaytaroController as AdminPaytaroController;
use App\Controllers\Admin\YipayController as AdminYipayController;
function failPaymentBrowserPrivacyTest($message)
{
fwrite(STDERR, $message . PHP_EOL);
exit(1);
}
function sourceFile($path)
{
$source = file_get_contents($path);
if ($source === false) {
failPaymentBrowserPrivacyTest('Could not read ' . $path);
}
return $source;
}
$root = dirname(__DIR__);
$venixTemplates = [
$root . '/resources/views/venix/admin/yipay/index.tpl',
$root . '/resources/views/venix/admin/paytaro/index.tpl',
$root . '/resources/views/venix/admin/usdt/index.tpl',
$root . '/resources/views/venix/user/paytaro.tpl',
$root . '/resources/views/venix/auth/register.tpl',
];
foreach ($venixTemplates as $template) {
$source = sourceFile($template);
foreach (['order_no', 'gateway_trade_no', 'business_order_no', 'data.pid', "get('pid')", 'get("pid")', 'pid:'] as $forbidden) {
if (strpos($source, $forbidden) !== false) {
failPaymentBrowserPrivacyTest('Payment identifier is exposed by ' . $template . ': ' . $forbidden);
}
}
}
$yipayTemplate = sourceFile($root . '/resources/views/venix/admin/yipay/index.tpl');
foreach (['yipay_gateway_base_url|escape', 'yipay_callback_base_url|escape', 'yipay_pid|escape'] as $forbidden) {
if (strpos($yipayTemplate, $forbidden) !== false) {
failPaymentBrowserPrivacyTest('Yipay write-only field is rendered back to the browser: ' . $forbidden);
}
}
$paytaroTemplate = sourceFile($root . '/resources/views/venix/admin/paytaro/index.tpl');
foreach (['paytaro_gateway_url|escape', 'paytaro_callback_base_url|escape', 'paytaro_app_id|escape', 'paytaro_method_uuid|escape'] as $forbidden) {
if (strpos($paytaroTemplate, $forbidden) !== false) {
failPaymentBrowserPrivacyTest('Paytaro write-only field is rendered back to the browser: ' . $forbidden);
}
}
foreach ([
$root . '/app/Controllers/YipayController.php',
$root . '/app/Controllers/PaytaroController.php',
$root . '/app/Controllers/UsdtController.php',
] as $controller) {
$source = sourceFile($controller);
foreach (["'pid' =>", 'getParam(\'pid\'', '?payment=yipay&pid=', '?payment=paytaro&pid='] as $forbidden) {
if (strpos($source, $forbidden) !== false) {
failPaymentBrowserPrivacyTest('Payment controller exposes a browser order identifier: ' . $controller);
}
}
}
$yipayReflection = new ReflectionClass(AdminYipayController::class);
$yipayController = $yipayReflection->newInstanceWithoutConstructor();
$yipayValues = $yipayReflection->getMethod('validateConfig')->invoke($yipayController, [], [
'yipay_gateway_base_url' => 'https://private-gateway.example.com',
'yipay_callback_base_url' => 'https://private-callback.example.com',
'yipay_pid' => '123456',
]);
if ($yipayValues['yipay_gateway_base_url'] !== 'https://private-gateway.example.com'
|| $yipayValues['yipay_callback_base_url'] !== 'https://private-callback.example.com'
|| $yipayValues['yipay_pid'] !== '123456') {
failPaymentBrowserPrivacyTest('Blank Yipay write-only fields did not preserve stored values.');
}
$paytaroReflection = new ReflectionClass(AdminPaytaroController::class);
$paytaroController = $paytaroReflection->newInstanceWithoutConstructor();
$paytaroValues = $paytaroReflection->getMethod('validateConfig')->invoke($paytaroController, [], [
'paytaro_gateway_url' => 'https://private-paytaro.example.com/v1/pay',
'paytaro_callback_base_url' => 'https://private-panel.example.com',
'paytaro_app_id' => 'A1B2C3D4E5F',
'paytaro_method_uuid' => '12345678-1234-1234-1234-123456789abc',
]);
if ($paytaroValues['paytaro_gateway_url'] !== \App\Services\Payment\PaytaroConfig::MAPI_GATEWAY_URL
|| $paytaroValues['paytaro_callback_base_url'] !== 'https://private-panel.example.com'
|| $paytaroValues['paytaro_app_id'] !== 'A1B2C3D4E5F'
|| $paytaroValues['paytaro_method_uuid'] !== '12345678-1234-1234-1234-123456789abc') {
failPaymentBrowserPrivacyTest('Paytaro MAPI pinning or write-only fields failed.');
}
echo 'Payment browser privacy and write-only configuration checks passed.' . PHP_EOL;