1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-24 07:42:07 +03:00

Mail: Removed custom symfony/mailer fork

Moved to standard symfony mailer now that my patches have been
upstreamed. This changes the config to work with the symfony option,
following the same overall logic.
Also updated testing to allow test runs via mulitple custom env options.

Closes #5636
This commit is contained in:
Dan Brown
2025-07-15 15:24:31 +01:00
parent 2442829ef2
commit d13abc7e1d
8 changed files with 155 additions and 158 deletions

View File

@ -16,7 +16,7 @@ class ConfigTest extends TestCase
{
public function test_filesystem_images_falls_back_to_storage_type_var()
{
$this->runWithEnv('STORAGE_TYPE', 'local_secure', function () {
$this->runWithEnv(['STORAGE_TYPE' => 'local_secure'], function () {
$this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', 's3', 'filesystems.images', 's3');
$this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', null, 'filesystems.images', 'local_secure');
});
@ -24,7 +24,7 @@ class ConfigTest extends TestCase
public function test_filesystem_attachments_falls_back_to_storage_type_var()
{
$this->runWithEnv('STORAGE_TYPE', 'local_secure', function () {
$this->runWithEnv(['STORAGE_TYPE' => 'local_secure'], function () {
$this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', 's3', 'filesystems.attachments', 's3');
$this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', null, 'filesystems.attachments', 'local_secure');
});
@ -114,7 +114,7 @@ class ConfigTest extends TestCase
$this->assertEmpty($getStreamOptions());
$this->runWithEnv('MAIL_VERIFY_SSL', 'false', function () use ($getStreamOptions) {
$this->runWithEnv(['MAIL_VERIFY_SSL' => 'false'], function () use ($getStreamOptions) {
$options = $getStreamOptions();
$this->assertArrayHasKey('ssl', $options);
$this->assertFalse($options['ssl']['verify_peer']);
@ -124,9 +124,9 @@ class ConfigTest extends TestCase
public function test_non_null_mail_encryption_options_enforce_smtp_scheme()
{
$this->checkEnvConfigResult('MAIL_ENCRYPTION', 'tls', 'mail.mailers.smtp.tls_required', true);
$this->checkEnvConfigResult('MAIL_ENCRYPTION', 'ssl', 'mail.mailers.smtp.tls_required', true);
$this->checkEnvConfigResult('MAIL_ENCRYPTION', 'null', 'mail.mailers.smtp.tls_required', false);
$this->checkEnvConfigResult('MAIL_ENCRYPTION', 'tls', 'mail.mailers.smtp.require_tls', true);
$this->checkEnvConfigResult('MAIL_ENCRYPTION', 'ssl', 'mail.mailers.smtp.require_tls', true);
$this->checkEnvConfigResult('MAIL_ENCRYPTION', 'null', 'mail.mailers.smtp.require_tls', false);
}
public function test_smtp_scheme_and_certain_port_forces_tls_usage()
@ -135,29 +135,18 @@ class ConfigTest extends TestCase
/** @var EsmtpTransport $transport */
$transport = Mail::mailer('smtp')->getSymfonyTransport();
Mail::purge('smtp');
return $transport->getTlsRequirement();
return $transport->isTlsRequired();
};
config()->set([
'mail.mailers.smtp.tls_required' => null,
'mail.mailers.smtp.port' => 587,
]);
$runTest = function (string $tlsOption, int $port, bool $expectedResult) use ($isMailTlsRequired) {
$this->runWithEnv(['MAIL_ENCRYPTION' => $tlsOption, 'MAIL_PORT' => $port], function () use ($isMailTlsRequired, $port, $expectedResult) {
$this->assertEquals($expectedResult, $isMailTlsRequired());
});
};
$this->assertFalse($isMailTlsRequired());
config()->set([
'mail.mailers.smtp.tls_required' => 'tls',
'mail.mailers.smtp.port' => 587,
]);
$this->assertTrue($isMailTlsRequired());
config()->set([
'mail.mailers.smtp.tls_required' => null,
'mail.mailers.smtp.port' => 465,
]);
$this->assertTrue($isMailTlsRequired());
$runTest('null', 587, false);
$runTest('tls', 587, true);
$runTest('null', 465, true);
}
public function test_mysql_host_parsed_as_expected()
@ -174,7 +163,7 @@ class ConfigTest extends TestCase
];
foreach ($cases as $host => [$expectedHost, $expectedPort]) {
$this->runWithEnv("DB_HOST", $host, function () use ($expectedHost, $expectedPort) {
$this->runWithEnv(["DB_HOST" => $host], function () use ($expectedHost, $expectedPort) {
$this->assertEquals($expectedHost, config("database.connections.mysql.host"));
$this->assertEquals($expectedPort, config("database.connections.mysql.port"));
}, false);
@ -185,12 +174,10 @@ class ConfigTest extends TestCase
* Set an environment variable of the given name and value
* then check the given config key to see if it matches the given result.
* Providing a null $envVal clears the variable.
*
* @param mixed $expectedResult
*/
protected function checkEnvConfigResult(string $envName, ?string $envVal, string $configKey, $expectedResult)
protected function checkEnvConfigResult(string $envName, ?string $envVal, string $configKey, mixed $expectedResult): void
{
$this->runWithEnv($envName, $envVal, function () use ($configKey, $expectedResult) {
$this->runWithEnv([$envName => $envVal], function () use ($configKey, $expectedResult) {
$this->assertEquals($expectedResult, config($configKey));
});
}