N°9584 - Fix "Unable to connect with STARTTLS" error when sending emails (#901)

* N°9584 - Fix "Unable to connect with STARTTLS" error when sending emails

* N°9584 - Refactor EMailSymfony transport to add unit tests
This commit is contained in:
Molkobain
2026-05-05 09:51:09 +02:00
committed by GitHub
parent 7cac280b83
commit 7676115725
2 changed files with 92 additions and 12 deletions

View File

@@ -2,6 +2,7 @@
use Combodo\iTop\Core\Email\EMailSymfony;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Component\Mime\Part\Multipart\AlternativePart;
use Symfony\Component\Mime\Part\Multipart\RelatedPart;
@@ -298,4 +299,63 @@ HTML;
],
];
}
/**
* @dataProvider provideCreateSmtpTransportSslOptions
*/
public function testCreateSmtpTransportSslOptions(string $sDsn, bool $bVerifyPeer, array $aExpectedSslOptions): void
{
$oEmail = new EMailSymfony();
/** @var EsmtpTransport $oTransport */
$oTransport = $this->InvokeNonPublicMethod(EMailSymfony::class, 'CreateSmtpTransport', $oEmail, [$sDsn, $bVerifyPeer]);
$aActualSslOptions = $oTransport->getStream()->getStreamOptions()['ssl'] ?? [];
$this->assertSame($aExpectedSslOptions, $aActualSslOptions);
}
public function provideCreateSmtpTransportSslOptions(): array
{
$aDisabledVerification = [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
];
return [
// Regression scenario (N°9584): STARTTLS starts the connection unencrypted, so the 'ssl' key
// is absent from stream options at construction time. verify_peer=false must still be applied.
'STARTTLS, verify_peer=false' => [
'smtp://localhost:587?encryption=starttls',
false,
$aDisabledVerification,
],
'implicit TLS (smtps), verify_peer=false' => [
'smtps://localhost:465',
false,
$aDisabledVerification,
],
'plain SMTP, verify_peer=false' => [
'smtp://localhost:25',
false,
$aDisabledVerification,
],
// Default behavior: verify_peer=true must leave stream options untouched (empty).
'STARTTLS, verify_peer=true (default)' => [
'smtp://localhost:587?encryption=starttls',
true,
[],
],
'implicit TLS (smtps), verify_peer=true (default)' => [
'smtps://localhost:465',
true,
[],
],
'plain SMTP, verify_peer=true (default)' => [
'smtp://localhost:25',
true,
[],
],
];
}
}