8000 [Mailer] bug - fix EsmtpTransport variable $code definition by kgnblg · Pull Request #51568 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Mailer] bug - fix EsmtpTransport variable $code definition #51568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
kgnblg committed Sep 5, 2023
commit 772050bbc58ad91f6357eb286f499d6a8069f870
Original file line number Diff line number Diff line change
Expand Up @@ -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->getMes 8000 sage());
$this->assertEquals(504, $e->getCode());
}
}
}

class CustomEsmtpTransport extends EsmtpTransport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ private function handleAuth(array $modes): void
return;
}

$code = null;
$authNames = [];
$errors = [];
$modes = array_map('strtolower', $modes);
Expand All @@ -192,7 +193,6 @@ private function handleAuth(array $modes): void
continue;
}

$code = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we still reset it on each iteration of the loop ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you are right. I added it in my forked branch should I create a new PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it is: #51581 :)

$authNames[] = $authenticator->getAuthKeyword();
try {
$authenticator->authenticate($this);
Expand Down
0