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.
62 lines
1.9 KiB
PHTML
62 lines
1.9 KiB
PHTML
|
1 week ago
|
<?php
|
||
|
|
|
||
|
|
namespace App\Services {
|
||
|
|
class SiteName
|
||
|
|
{
|
||
|
|
public static string $name = 'Default Site';
|
||
|
|
|
||
|
|
public static function defaultName(): string
|
||
|
|
{
|
||
|
|
return self::$name;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
namespace {
|
||
|
|
use App\Services\MailSenderIdentity;
|
||
|
|
use App\Services\SiteName;
|
||
|
|
|
||
|
|
require dirname(__DIR__) . '/app/Services/MailSenderIdentity.php';
|
||
|
|
|
||
|
|
function expectMailSenderIdentity($condition, string $message): void
|
||
|
|
{
|
||
|
|
if (!$condition) {
|
||
|
|
fwrite(STDERR, $message . PHP_EOL);
|
||
|
|
exit(1);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
expectMailSenderIdentity(
|
||
|
|
MailSenderIdentity::displayName() === 'Default Site',
|
||
|
|
'The sender display name must use the site default title.'
|
||
|
|
);
|
||
|
|
|
||
|
|
SiteName::$name = " Default\r\nSite\tTitle ";
|
||
|
|
expectMailSenderIdentity(
|
||
|
|
MailSenderIdentity::displayName() === 'Default Site Title',
|
||
|
|
'Control characters were not removed from the sender display name.'
|
||
|
|
);
|
||
|
|
|
||
|
|
SiteName::$name = 'Default "Cloud"';
|
||
|
|
expectMailSenderIdentity(
|
||
|
|
MailSenderIdentity::header('Legacy Name <sender@example.com>') === '"Default \\"Cloud\\"" <sender@example.com>',
|
||
|
|
'The Mailgun sender header was not rebuilt from the default title and configured mailbox.'
|
||
|
|
);
|
||
|
|
|
||
|
|
$invalidWasRejected = false;
|
||
|
|
try {
|
||
|
|
MailSenderIdentity::mailbox("sender@example.com\r\nBcc: victim@example.com");
|
||
|
|
} catch (\InvalidArgumentException $exception) {
|
||
|
|
$invalidWasRejected = true;
|
||
|
|
}
|
||
|
|
expectMailSenderIdentity($invalidWasRejected, 'A header-injection sender value was not rejected.');
|
||
|
|
|
||
|
|
$mailgunSource = file_get_contents(dirname(__DIR__) . '/app/Services/Mail/Mailgun.php');
|
||
|
|
expectMailSenderIdentity(
|
||
|
|
is_string($mailgunSource) && str_contains($mailgunSource, 'MailSenderIdentity::header'),
|
||
|
|
'Mailgun does not use the shared sender identity.'
|
||
|
|
);
|
||
|
|
|
||
|
|
echo 'Mail sender identity checks passed.' . PHP_EOL;
|
||
|
|
}
|