|
|
<?php
|
|
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
|
|
use App\Services\Cloud\CloudIpChangeBillingService;
|
|
|
use App\Services\Cloud\CloudPaidIpChangeFeature;
|
|
|
use App\Services\Cloud\CloudPublicNetworkTransitionCommand;
|
|
|
|
|
|
$root = dirname(__DIR__);
|
|
|
$read = static function (string $path) use ($root): string {
|
|
|
$value = file_get_contents($root . '/' . $path);
|
|
|
if (!is_string($value)) {
|
|
|
throw new RuntimeException('Unable to read ' . $path);
|
|
|
}
|
|
|
return $value;
|
|
|
};
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
|
if (!$condition) {
|
|
|
throw new RuntimeException($message);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$routes = $read('config/routes_cloud.php');
|
|
|
$controller = $read('app/Controllers/CloudApiController.php');
|
|
|
$options = $read(
|
|
|
'app/Services/Cloud/CloudNetworkChangeOptionsService.php'
|
|
|
);
|
|
|
$jobs = $read('app/Services/Cloud/CloudJobService.php');
|
|
|
$transitionWorkflow = $read(
|
|
|
'app/Services/Cloud/CloudPublicNetworkTransitionWorkflow.php'
|
|
|
);
|
|
|
$config = $read('app/Controllers/Admin/ConfigController.php');
|
|
|
$configView = $read('resources/views/venix/admin/config.tpl');
|
|
|
$pageController = $read('app/Controllers/CloudPageController.php');
|
|
|
$feature = $read(
|
|
|
'app/Services/Cloud/CloudPaidIpChangeFeature.php'
|
|
|
);
|
|
|
$detailView = $read('resources/views/venix/cloud/pages/detail.tpl');
|
|
|
$detailScript = $read('public/cloud/detail.js');
|
|
|
$detailCopy = $read(
|
|
|
'resources/user-copy/entries/detail-reinstall.entries.php'
|
|
|
);
|
|
|
$billingCatalog = $read(
|
|
|
'app/Services/Cloud/CloudBillingPresentationCatalog.php'
|
|
|
);
|
|
|
$invoiceService = $read('app/Services/Cloud/CloudInvoiceService.php');
|
|
|
$adminBilling = $read('app/Services/Cloud/CloudAdminBillingService.php');
|
|
|
$documentation = $read('../docs/MULTI_PUBLIC_IPV4_POOLS.md');
|
|
|
|
|
|
$assert(str_contains($routes,
|
|
|
"'/vms/{id:[0-9]+}/network-options'")
|
|
|
&& str_contains($routes, "'/vms/{id:[0-9]+}/network'")
|
|
|
&& str_contains($routes, 'CloudApiController:networkOptions')
|
|
|
&& str_contains($routes, 'CloudApiController:network'),
|
|
|
'Tenant paid IP-change routes are missing.');
|
|
|
|
|
|
$optionsStart = strpos($controller, 'public function networkOptions(');
|
|
|
$networkStart = strpos($controller, 'public function network(',
|
|
|
$optionsStart === false ? 0 : $optionsStart);
|
|
|
$networkEnd = strpos($controller, 'public function rescue(',
|
|
|
$networkStart === false ? 0 : $networkStart);
|
|
|
$optionsMethod = $optionsStart !== false && $networkStart !== false
|
|
|
? substr($controller, $optionsStart, $networkStart - $optionsStart) : '';
|
|
|
$networkMethod = $networkStart !== false && $networkEnd !== false
|
|
|
? substr($controller, $networkStart, $networkEnd - $networkStart) : '';
|
|
|
$assert($optionsMethod !== ''
|
|
|
&& str_contains($optionsMethod,
|
|
|
'(int) $instance->user_id !== (int) $actor[\'user_id\']')
|
|
|
&& str_contains($optionsMethod,
|
|
|
'CloudNetworkChangeOptionsService::tenantQuote($instance)')
|
|
|
&& str_contains($optionsMethod,
|
|
|
"'address_family' => (int) (\$options['address_family'] ?? 0)")
|
|
|
&& str_contains($optionsMethod, 'CloudIpChangeBillingService::price()')
|
|
|
&& str_contains($optionsMethod,
|
|
|
'CloudPaidIpChangeFeature::assertVisible()')
|
|
|
&& !str_contains($optionsMethod, "'available_ip_options'")
|
|
|
&& !str_contains($optionsMethod, "'available_count'")
|
|
|
&& !str_contains($optionsMethod, "'current_ip_cidr'")
|
|
|
&& !str_contains($optionsMethod, "'balance' =>")
|
|
|
&& !str_contains($optionsMethod, "'host_id'")
|
|
|
&& !str_contains($optionsMethod, "'gateway'")
|
|
|
&& !str_contains($optionsMethod, "'dns_servers'"),
|
|
|
'Tenant quote exposed IP inventory or lost ownership and pricing boundaries.');
|
|
|
$assert($networkMethod !== ''
|
|
|
&& str_contains($networkMethod, "'request_idempotency_key'")
|
|
|
&& str_contains($networkMethod, "'expected_amount'")
|
|
|
&& str_contains($networkMethod,
|
|
|
"CloudInput::only(\$body, ['expected_amount', 'confirm_restart'])")
|
|
|
&& str_contains($networkMethod, 'CloudIpChangeBillingService::normalizePrice')
|
|
|
&& str_contains($networkMethod, '$expectedAmount')
|
|
|
&& !str_contains($networkMethod, "'public_ip_cidr'")
|
|
|
&& !str_contains($networkMethod, "'public_pool_key'")
|
|
|
&& str_contains($networkMethod,
|
|
|
'CloudPublicNetworkTransitionCommand::')
|
|
|
&& str_contains($networkMethod, 'userPaidAutomatic(')
|
|
|
&& str_contains($networkMethod,
|
|
|
'CloudPublicNetworkTransitionWorkflow::begin($command)')
|
|
|
&& str_contains($networkMethod,
|
|
|
"'task_id' => (string) \$dispatch->jobId()")
|
|
|
&& str_contains($networkMethod,
|
|
|
"'status_url' => '/api/v1/tasks/' . \$dispatch->jobId()")
|
|
|
&& !str_contains($networkMethod, "'invoice_id'")
|
|
|
&& !str_contains($networkMethod, "'balance' =>"),
|
|
|
'Paid IP submission lost its quote check, idempotency, or strict task receipt.');
|
|
|
$existingTransitionLookup = strpos(
|
|
|
$transitionWorkflow,
|
|
|
"'transition_key', \$command->transitionKey()"
|
|
|
);
|
|
|
$tenantAdmissionGate = strpos(
|
|
|
$transitionWorkflow,
|
|
|
'CloudPaidIpChangeFeature::assertVisible()'
|
|
|
);
|
|
|
$assert($existingTransitionLookup !== false
|
|
|
&& $tenantAdmissionGate !== false
|
|
|
&& $tenantAdmissionGate > $existingTransitionLookup
|
|
|
&& str_contains($transitionWorkflow,
|
|
|
"\$command->kind() === 'user_paid'")
|
|
|
&& str_contains($transitionWorkflow,
|
|
|
'!$existingHint instanceof CloudPublicNetworkTransition'),
|
|
|
'Hidden paid IP changes must block new purchases without blocking an exact idempotent replay.');
|
|
|
|
|
|
$assert(str_contains($options, "->where('state', 'available')")
|
|
|
&& str_contains($options, "'address_family' => 4")
|
|
|
&& str_contains($options, "->whereNull('reservation_id')")
|
|
|
&& str_contains($options, "->whereNull('instance_id')")
|
|
|
&& str_contains($options, "->whereNull('operation_id')")
|
|
|
&& str_contains($options, "->where('state', 'active')")
|
|
|
&& str_contains($options, "sync_state', 'applied'")
|
|
|
&& str_contains($options, "->where('line_id',")
|
|
|
&& str_contains($options, "->where('verification_state', 'verified')")
|
|
|
&& str_contains($options, "->where('verified_agent_revision',")
|
|
|
&& str_contains($options, "->where('last_verified_at', '>', 0)")
|
|
|
&& !str_contains($options, 'default_network'),
|
|
|
'Tenant choices can include cross-line, stale, assigned, or unapplied IPs.');
|
|
|
|
|
|
$enqueueStart = strpos($jobs, 'public static function enqueue(');
|
|
|
$enqueueEnd = strpos($jobs, 'public static function enqueueExpiryDelete(',
|
|
|
$enqueueStart === false ? 0 : $enqueueStart);
|
|
|
$enqueue = $enqueueStart !== false && $enqueueEnd !== false
|
|
|
? substr($jobs, $enqueueStart, $enqueueEnd - $enqueueStart) : '';
|
|
|
$assert($enqueue !== ''
|
|
|
&& str_contains($enqueue, "if (\$kind === 'network_change')")
|
|
|
&& str_contains($enqueue, '旧公网网络写入口已停用')
|
|
|
&& !str_contains($enqueue, 'paidNetworkChangeExpectedAmount'),
|
|
|
'The retired scalar paid network-change writer returned.');
|
|
|
|
|
|
$commandReflection = new ReflectionClass(
|
|
|
CloudPublicNetworkTransitionCommand::class
|
|
|
);
|
|
|
foreach (['userPaidAutomatic', 'adminExact', 'poolReplacement'] as $factory) {
|
|
|
$assert(
|
|
|
$commandReflection->hasMethod($factory)
|
|
|
&& $commandReflection->getMethod($factory)->isStatic(),
|
|
|
'Typed network-transition command factory is missing: ' . $factory
|
|
|
);
|
|
|
}
|
|
|
$billingReflection = new ReflectionClass(CloudIpChangeBillingService::class);
|
|
|
$billingMethods = array_values(array_map(
|
|
|
static fn (ReflectionMethod $method): string => $method->getName(),
|
|
|
array_filter(
|
|
|
$billingReflection->getMethods(ReflectionMethod::IS_PUBLIC),
|
|
|
static fn (ReflectionMethod $method): bool =>
|
|
|
$method->getDeclaringClass()->getName()
|
|
|
=== CloudIpChangeBillingService::class
|
|
|
)
|
|
|
));
|
|
|
$expectedBillingMethods = [
|
|
|
'price',
|
|
|
'priceCents',
|
|
|
'normalizePrice',
|
|
|
'chargeTransitionLocked',
|
|
|
'chargeLocked',
|
|
|
'refundNotAppliedLocked',
|
|
|
'refundTransitionNotAppliedLocked',
|
|
|
];
|
|
|
sort($billingMethods, SORT_STRING);
|
|
|
sort($expectedBillingMethods, SORT_STRING);
|
|
|
$assert(
|
|
|
CloudIpChangeBillingService::PRICE_CONFIG_KEY === 'cloud_ip_change_price'
|
|
|
&& CloudIpChangeBillingService::DEFAULT_PRICE === '0.00'
|
|
|
&& CloudIpChangeBillingService::PURPOSE === 'ip_change'
|
|
|
&& $billingMethods === $expectedBillingMethods,
|
|
|
'IP-change billing public contract drifted.'
|
|
|
);
|
|
|
|
|
|
$assert(str_contains($config,
|
|
|
'CloudIpChangeBillingService::PRICE_CONFIG_KEY')
|
|
|
&& str_contains($config,
|
|
|
'CloudPaidIpChangeFeature::CONFIG_KEY')
|
|
|
&& str_contains($config,
|
|
|
'CloudIpChangeBillingService::normalizePrice(')
|
|
|
&& str_contains($configView, 'name="cloud_ip_change_price"')
|
|
|
&& str_contains($configView,
|
|
|
'name="cloud_paid_ip_change_visible"')
|
|
|
&& str_contains($configView,
|
|
|
'用户报价和新提交会被拒绝')
|
|
|
&& str_contains($feature,
|
|
|
"public const CONFIG_KEY = 'cloud_paid_ip_change_visible'")
|
|
|
&& CloudPaidIpChangeFeature::DEFAULT_VALUE === 'true',
|
|
|
'Administrator price or tenant-visibility configuration is missing.');
|
|
|
|
|
|
$ipChangeUiStart = strpos($detailScript, 'function ipChangeStatus(');
|
|
|
$ipChangeUiEnd = strpos($detailScript, 'function settingError(',
|
|
|
$ipChangeUiStart === false ? 0 : $ipChangeUiStart);
|
|
|
$ipChangeUi = $ipChangeUiStart !== false && $ipChangeUiEnd !== false
|
|
|
? substr($detailScript, $ipChangeUiStart,
|
|
|
$ipChangeUiEnd - $ipChangeUiStart) : '';
|
|
|
$assert(str_contains($detailView, 'data-instance-setting-tab="ip_change"')
|
|
|
&& substr_count($detailView,
|
|
|
'$cloud_paid_ip_change_visible|default:false') === 2
|
|
|
&& str_contains($pageController,
|
|
|
"'cloud_paid_ip_change_visible' =>")
|
|
|
&& str_contains($pageController,
|
|
|
'CloudPaidIpChangeFeature::visible()')
|
|
|
&& str_contains($detailView, 'id="vm-ip-change-form"')
|
|
|
&& str_contains($detailView, 'id="vm-ip-change-price"')
|
|
|
&& str_contains($detailView,
|
|
|
"user_copy key='instance_detail.settings.ip_change.description'")
|
|
|
&& str_contains($detailView,
|
|
|
"user_copy key='instance_detail.settings.ip_change.notice_body'")
|
|
|
&& str_contains($detailCopy,
|
|
|
'系统会从当前宿主机同一网络线路的可用 IPv4 地址池中自动分配新地址')
|
|
|
&& str_contains($detailCopy, '公网 IPv6 保持不变')
|
|
|
&& str_contains($detailCopy,
|
|
|
'只有系统明确确认变更未生效时才会自动退回余额')
|
|
|
&& !str_contains($detailView, 'id="vm-ip-change-target"')
|
|
|
&& !str_contains($detailView, 'id="vm-ip-change-current"')
|
|
|
&& !str_contains($detailView, 'id="vm-ip-change-balance"')
|
|
|
&& $ipChangeUi !== ''
|
|
|
&& str_contains($ipChangeUi, "headers: { 'Idempotency-Key': idempotencyKey }")
|
|
|
&& str_contains($ipChangeUi, 'expected_amount: expectedAmount')
|
|
|
&& str_contains($ipChangeUi, 'sessionStorage.setItem')
|
|
|
&& str_contains($ipChangeUi, 'automatic|${expectedAmount}')
|
|
|
&& str_contains($ipChangeUi, 'payload.address_family !== 4')
|
|
|
&& str_contains($ipChangeUi,
|
|
|
"t('instance_detail.ip_change.confirm_body'")
|
|
|
&& str_contains($ipChangeUi,
|
|
|
"t('instance_detail.public_ip_change.notice.completed_ipv6_unchanged')")
|
|
|
&& str_contains($ipChangeUi,
|
|
|
"t('instance_detail.public_ip_change.error.uncertain_reconcile_same_request')")
|
|
|
&& !str_contains($ipChangeUi, 'available_ip_options')
|
|
|
&& !str_contains($ipChangeUi, 'available_count')
|
|
|
&& !str_contains($ipChangeUi, 'public_ip_cidr:')
|
|
|
&& !str_contains($ipChangeUi, 'public_pool_key:')
|
|
|
&& !str_contains($ipChangeUi, '可选择')
|
|
|
&& str_contains($ipChangeUi, "task.effect_resolution === 'not_applied'")
|
|
|
&& str_contains($ipChangeUi, "task.effect_resolution === 'applied'"),
|
|
|
'Tenant settings UI exposed targets or lost pricing, durable retry, or outcome guidance.');
|
|
|
|
|
|
$assert(str_contains($billingCatalog, "'ip_change' => '更换公网 IPv4'")
|
|
|
&& str_contains($configView, '更换公网 IPv4 价格(USD)')
|
|
|
&& str_contains($configView, 'IPv6 保持不变')
|
|
|
&& !str_contains($configView, '更换公网 IP 价格(USD)')
|
|
|
&& substr_count($invoiceService,
|
|
|
'CloudBillingPresentationCatalog::knownPurposeLabel($purpose)') >= 2
|
|
|
&& str_contains($adminBilling,
|
|
|
"'provision', 'renewal', 'upgrade', 'ip_change'")
|
|
|
&& str_contains($documentation, '## 用户付费更换公网 IPv4')
|
|
|
&& str_contains($documentation, '用户页面只显示单次更换费用')
|
|
|
&& str_contains($documentation, '也不接受用户指定目标地址')
|
|
|
&& str_contains($documentation, '钱包 → 实例 → 网络账本'),
|
|
|
'Billing presentation or operational documentation omitted paid IP changes.');
|
|
|
|
|
|
echo "Cloud paid IP-change contract tests passed.\n";
|