|
|
|
|
<?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');
|
|
|
|
|
|
|
|
|
|
$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 ([$verify, $reset, $renewal, $provisioned] as $template) {
|
|
|
|
|
$assert(str_contains($template, "{extends file='layout.tpl'}"),
|
|
|
|
|
'A customer-facing system email does not use the shared panel theme.');
|
|
|
|
|
}
|
|
|
|
|
foreach (['#f4f7fb', '#101d2c', '#159da9', '#15243a', '#e7ecf2'] 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($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"}'),
|
|
|
|
|
'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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$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 "Panel-themed registration, reset, invoice and provisioning email contracts passed.\n";
|