mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Mail Config: Updated how TLS is configured
After full review of current MAIL_ENCRYPTION usage in laravel and smyfony mailer, this updates the options in BookStack to be simplified and specific in usage: - Removed mail.mailers.smtp.encryption option since it did not actually affect anything in the current state of dependancies. - Updated MAIL_ENCRYPTION so values of tls OR ssl will force-enable tls via 'scheme' option with laravel passes to the SMTP transfport, which Smyfony uses as an indicator to force TLS. When MAIL_ENCRYPTION is not used, STARTTLS will still be attempted by symfony mailer. Updated .env files to refer to BookStack docs (which was updated for this) and to reflect correct default port. Related to #4342
This commit is contained in:
@ -5,6 +5,7 @@ namespace Tests\Unit;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
|
||||
use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@ -122,6 +123,45 @@ class ConfigTest extends TestCase
|
||||
});
|
||||
}
|
||||
|
||||
public function test_non_null_mail_encryption_options_enforce_smtp_scheme()
|
||||
{
|
||||
$this->checkEnvConfigResult('MAIL_ENCRYPTION', 'tls', 'mail.mailers.smtp.scheme', 'smtps');
|
||||
$this->checkEnvConfigResult('MAIL_ENCRYPTION', 'ssl', 'mail.mailers.smtp.scheme', 'smtps');
|
||||
$this->checkEnvConfigResult('MAIL_ENCRYPTION', 'null', 'mail.mailers.smtp.scheme', null);
|
||||
}
|
||||
|
||||
public function test_smtp_scheme_and_certain_port_forces_tls_usage()
|
||||
{
|
||||
$isMailTlsForcedEnabled = function () {
|
||||
$transport = Mail::mailer('smtp')->getSymfonyTransport();
|
||||
/** @var SocketStream $stream */
|
||||
$stream = $transport->getStream();
|
||||
Mail::purge('smtp');
|
||||
return $stream->isTLS();
|
||||
};
|
||||
|
||||
config()->set([
|
||||
'mail.mailers.smtp.scheme' => null,
|
||||
'mail.mailers.smtp.port' => 587,
|
||||
]);
|
||||
|
||||
$this->assertFalse($isMailTlsForcedEnabled());
|
||||
|
||||
config()->set([
|
||||
'mail.mailers.smtp.scheme' => 'smtps',
|
||||
'mail.mailers.smtp.port' => 587,
|
||||
]);
|
||||
|
||||
$this->assertTrue($isMailTlsForcedEnabled());
|
||||
|
||||
config()->set([
|
||||
'mail.mailers.smtp.scheme' => '',
|
||||
'mail.mailers.smtp.port' => 465,
|
||||
]);
|
||||
|
||||
$this->assertTrue($isMailTlsForcedEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an environment variable of the given name and value
|
||||
* then check the given config key to see if it matches the given result.
|
||||
|
Reference in New Issue
Block a user