From 772050bbc58ad91f6357eb286f499d6a8069f870 Mon Sep 17 00:00:00 2001 From: kgnblg Date: Tue, 5 Sep 2023 16:43:46 +0200 Subject: [PATCH] bug [mailer] fix EsmtpTransport variable $code definition the variable $code defined in the foreach loop, if there is no authenticators, then the $code will not be defined and therefore the following TransportException gives a PHP error. the use-case defined as a unit test in EsmtpTransportTest class. --- .../Transport/Smtp/EsmtpTransportTest.php | 22 +++++++++++++++++++ .../Mailer/Transport/Smtp/EsmtpTransport.php | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Mailer/Tests/Transport/Smtp/EsmtpTransportTest.php b/src/Symfony/Component/Mailer/Tests/Transport/Smtp/EsmtpTransportTest.php index 39dea5d3f3e62..8e7832258bd47 100644 --- a/src/Symfony/Component/Mailer/Tests/Transport/Smtp/EsmtpTransportTest.php +++ b/src/Symfony/Component/Mailer/Tests/Transport/Smtp/EsmtpTransportTest.php @@ -192,6 +192,28 @@ public function testSetAuthenticators() $stream->getCommands() ); } + + public function testConstructorWithEmptyAuthenticator() + { + $stream = new DummyStream(); + $transport = new EsmtpTransport(stream: $stream); + $transport->setUsername('testuser'); + $transport->setPassword('p4ssw0rd'); + $transport->setAuthenticators([]); // if no authenticators defined, then there needs to be a TransportException + + $message = new Email(); + $message->from('sender@example.org'); + $message->addTo('recipient@example.org'); + $message->text('.'); + + try { + $transport->send($message); + $this->fail('Symfony\Component\Mailer\Exception\TransportException to be thrown'); + } catch (TransportException $e) { + $this->assertStringStartsWith('Failed to find an authenticator supported by the SMTP server, which currently supports: "plain", "login", "cram-md5", "xoauth2".', $e->getMessage()); + $this->assertEquals(504, $e->getCode()); + } + } } class CustomEsmtpTransport extends EsmtpTransport diff --git a/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php b/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php index 83aef862155bf..b903d61ab3218 100644 --- a/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php +++ b/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php @@ -184,6 +184,7 @@ private function handleAuth(array $modes): void return; } + $code = null; $authNames = []; $errors = []; $modes = array_map('strtolower', $modes); @@ -192,7 +193,6 @@ private function handleAuth(array $modes): void continue; } - $code = null; $authNames[] = $authenticator->getAuthKeyword(); try { $authenticator->authenticate($this); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy