|
|
<?php
|
|
|
|
|
|
$root = dirname(__DIR__);
|
|
|
$assert = static function ($condition, string $message): void {
|
|
|
if (!$condition) {
|
|
|
throw new RuntimeException($message);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$auth = file_get_contents($root . '/app/Controllers/AuthController.php');
|
|
|
$password = file_get_contents($root . '/app/Services/Password.php');
|
|
|
$invoices = file_get_contents($root . '/app/Services/Cloud/CloudInvoiceService.php');
|
|
|
$worker = file_get_contents($root . '/app/Services/Cloud/CloudWorkerService.php');
|
|
|
$layout = file_get_contents($root . '/resources/email/layout.tpl');
|
|
|
$verify = file_get_contents($root . '/resources/email/auth/verify.tpl');
|
|
|
$reset = file_get_contents($root . '/resources/email/password/reset.tpl');
|
|
|
$renewal = file_get_contents($root . '/resources/email/cloud/invoice.tpl');
|
|
|
$provisioned = file_get_contents($root . '/resources/email/cloud/provision-success.tpl');
|
|
|
$maintenance = file_get_contents($root . '/resources/email/cloud/maintenance-notice.tpl');
|
|
|
$compensation = file_get_contents(
|
|
|
$root . '/resources/email/cloud/service-compensation.tpl'
|
|
|
);
|
|
|
$contentTemplates = [];
|
|
|
$templateFiles = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(
|
|
|
$root . '/resources/email', FilesystemIterator::SKIP_DOTS
|
|
|
));
|
|
|
foreach ($templateFiles as $templateFile) {
|
|
|
if (!$templateFile->isFile()
|
|
|
|| $templateFile->getExtension() !== 'tpl'
|
|
|
|| $templateFile->getFilename() === 'layout.tpl') {
|
|
|
continue;
|
|
|
}
|
|
|
$contentTemplates[$templateFile->getPathname()] = file_get_contents(
|
|
|
$templateFile->getPathname()
|
|
|
);
|
|
|
}
|
|
|
|
|
|
$assert(str_contains($auth, '"scene" => "registration"')
|
|
|
&& str_contains($auth, '"scene" => "login"'),
|
|
|
'Registration and login verification emails do not identify their scene.');
|
|
|
$assert(str_contains($password, '"expire" => date(')
|
|
|
&& str_contains($password, '$expiresAt = $now + 3600 * 24;'),
|
|
|
'Password reset email does not receive its real expiry timestamp.');
|
|
|
|
|
|
foreach ($contentTemplates as $path => $template) {
|
|
|
$assert(str_contains($template, "{extends file='layout.tpl'}"),
|
|
|
'An email template does not use the shared panel theme: ' . $path);
|
|
|
}
|
|
|
$assert(count($contentTemplates) === 15,
|
|
|
'Expected every one of the 15 content email templates to be covered.');
|
|
|
foreach (['#edf3f8', '#102235', '#159da9', '#15243a', '#f5f8fb'] as $color) {
|
|
|
$assert(str_contains(strtolower($layout), $color),
|
|
|
'Shared email layout is missing a user-panel theme color: ' . $color);
|
|
|
}
|
|
|
$assert(str_contains($layout, 'role="presentation"')
|
|
|
&& str_contains($layout, 'CONTROL PANEL')
|
|
|
&& str_contains($layout, '{$config["appName"]|escape:"html"}'),
|
|
|
'Shared email layout lacks its compatible branded table shell.');
|
|
|
$assert(str_contains($layout, '@media only screen and (max-width: 620px)')
|
|
|
&& str_contains($layout,
|
|
|
'.email-outer { padding: 12px 10px 28px !important; }')
|
|
|
&& str_contains($layout, '.email-fact-cell')
|
|
|
&& str_contains($layout, '.email-button-table'),
|
|
|
'Shared email layout lost its mobile responsive rules.');
|
|
|
$assert(str_contains($layout,
|
|
|
'© 2026 {$config["appName"]|escape:"html"}. All rights reserved.')
|
|
|
&& strrpos($layout, '© 2026') > strrpos($layout, '云资源控制台'),
|
|
|
'Shared email footer is missing the final dynamic copyright line.');
|
|
|
$assert(preg_match('/border(?:-(?:top|right|bottom|left))?\s*:\s*[1-9]/i',
|
|
|
$layout . implode("\n", $contentTemplates)) !== 1,
|
|
|
'Email UI contains a visible divider or panel border.');
|
|
|
|
|
|
$assert(str_contains($verify, '{$code|escape:"html"}')
|
|
|
&& str_contains($verify, '{$expire|escape:"html"}')
|
|
|
&& str_contains($verify, '$scene == \'login\'')
|
|
|
&& str_contains($verify, '$scene == \'registration\''),
|
|
|
'Verification email lost escaped code, expiry or scene-specific content.');
|
|
|
$assert(str_contains($reset, '{$resetUrl|escape:"html"}')
|
|
|
&& str_contains($reset, '{$expire|escape:"html"}'),
|
|
|
'Password reset email lost its escaped link or expiry.');
|
|
|
$assert(str_contains($renewal, '#{$invoice_id|escape:"html"}')
|
|
|
&& str_contains($renewal, '${$amount|escape:"html"}')
|
|
|
&& str_contains($renewal, '{$invoice_url|escape:"html"}')
|
|
|
&& str_contains($renewal, '{$due_at|escape:"html"}')
|
|
|
&& str_contains($renewal, '{$payment_deadline_at|escape:"html"}'),
|
|
|
'Automatic renewal invoice email is missing public billing details.');
|
|
|
foreach (['instance_name', 'instance_id', 'region', 'public_ip', 'os_name',
|
|
|
'login_name', 'created_at', 'expires_at', 'instance_url'] as $field) {
|
|
|
$assert(preg_match('/\{\$' . preg_quote($field, '/')
|
|
|
. '(?:\|[^}]*)?\|escape:"html"\}/', $provisioned) === 1,
|
|
|
'Provision success email is missing escaped field: ' . $field);
|
|
|
}
|
|
|
foreach (['root_password', 'private_key', 'sealed_credential', 'generated_password'] as $secret) {
|
|
|
$assert(!str_contains($provisioned, $secret),
|
|
|
'Provision success email references a forbidden secret: ' . $secret);
|
|
|
}
|
|
|
foreach (['notice_subject', 'message_text', 'scope_label', 'impact_label',
|
|
|
'maintenance_starts_utc', 'maintenance_ends_utc'] as $field) {
|
|
|
$assert(str_contains($maintenance, '{$' . $field . '|escape:"html"'),
|
|
|
'Maintenance email is missing escaped field: ' . $field);
|
|
|
}
|
|
|
$assert(str_contains($maintenance, '{foreach $instances as $instance}')
|
|
|
&& str_contains($maintenance, '{$instance.name|escape:"html"}')
|
|
|
&& str_contains($maintenance, '{$instance.ipv4|default:\'—\'|escape:"html"}')
|
|
|
&& str_contains($maintenance, '{$instance.ipv6|default:\'—\'|escape:"html"}')
|
|
|
&& str_contains($maintenance, '开始时间(UTC)')
|
|
|
&& str_contains($maintenance, '结束时间(UTC)'),
|
|
|
'Maintenance email lost its escaped instance list or UTC window.');
|
|
|
foreach (['reason_text', 'compensation_duration',
|
|
|
'incident_window_utc'] as $field) {
|
|
|
$assert(str_contains($compensation, '{$' . $field . '|escape:"html"'),
|
|
|
'Compensation email is missing escaped field: ' . $field);
|
|
|
}
|
|
|
$assert(str_contains(
|
|
|
$compensation,
|
|
|
'{$scope_label|default:\'实例服务\'|escape:"html"}'
|
|
|
)
|
|
|
&& str_contains($compensation, '{foreach $instances as $instance}')
|
|
|
&& str_contains(
|
|
|
$compensation,
|
|
|
'{$instance.instance_name|escape:"html"}'
|
|
|
)
|
|
|
&& str_contains(
|
|
|
$compensation,
|
|
|
'{$instance.previous_expires_utc|escape:"html"}'
|
|
|
)
|
|
|
&& str_contains(
|
|
|
$compensation,
|
|
|
'{$instance.new_expires_utc|escape:"html"}'
|
|
|
)
|
|
|
&& str_contains($compensation, '时间统一使用 UTC'),
|
|
|
'Compensation email lost its escaped instance list or UTC contract.');
|
|
|
foreach (['root_password', 'private_key', 'sealed_credential',
|
|
|
'generated_password'] as $secret) {
|
|
|
$assert(!str_contains($compensation, $secret),
|
|
|
'Compensation email references a forbidden secret: ' . $secret);
|
|
|
}
|
|
|
|
|
|
$assert(str_contains($worker,
|
|
|
'CloudInvoiceService::queueProvisionSucceeded(')
|
|
|
&& str_contains($invoices, "'provision_succeeded'")
|
|
|
&& str_contains($invoices, "'renewal_due'")
|
|
|
&& str_contains($invoices,
|
|
|
"'cloud/provision-success.tpl'")
|
|
|
&& str_contains($invoices, "'cloud/invoice.tpl'"),
|
|
|
'Reliable outbox dispatch is missing a required cloud notification.');
|
|
|
$assert(str_contains($invoices, "CloudMailOutbox::where('invoice_id', \$invoice->id)")
|
|
|
&& str_contains($invoices, "->where('kind', \$kind)->exists()")
|
|
|
&& str_contains($invoices, '$mail = new CloudMailOutbox();')
|
|
|
&& str_contains($invoices, '$mail->invoice_id = $invoice->id;')
|
|
|
&& str_contains($invoices, '$mail->kind = $kind;')
|
|
|
&& str_contains($invoices, "['renewal_due', 'provision_succeeded']"),
|
|
|
'Cloud notification queue is not idempotent per invoice and kind.');
|
|
|
|
|
|
echo "All panel-themed email template and notification contracts passed.\n";
|