bug #30995 [Mailer] allow user/pass on dsn while using failover/roundrobin (scuben)
This PR was merged into the 4.3-dev branch.
Discussion
----------
[Mailer] allow user/pass on dsn while using failover/roundrobin
| Q | A
| ------------- | ---
| Branch? | master <!-- see below -->
| Bug fix? | yes
| New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
this PR provides two things:
1. It is possible now to user `username` and `password` in a failover or round robin transport when using smtp
2. Fixed a type problem with `username` and `password` for the smtp transport as `getUsername()` cannot return `null` because of its signature but if no `username` is provided then the property would have been `null`. Fixed with setting an empty string as default. Same for `password`. (This was discovered by adding a test - yeah!)
Commits
-------
4518ac56a1
allow user/pass on dns while using failover/roundrobin and type fix for username/password
This commit is contained in:
commit
35684187d5
@ -236,9 +236,11 @@ class TransportTest extends TestCase
|
|||||||
|
|
||||||
public function testFromDsnFailover()
|
public function testFromDsnFailover()
|
||||||
{
|
{
|
||||||
|
$user = 'user';
|
||||||
|
$pass = 'pass';
|
||||||
$dispatcher = $this->createMock(EventDispatcherInterface::class);
|
$dispatcher = $this->createMock(EventDispatcherInterface::class);
|
||||||
$logger = $this->createMock(LoggerInterface::class);
|
$logger = $this->createMock(LoggerInterface::class);
|
||||||
$transport = Transport::fromDsn('smtp://null || smtp://null || smtp://null', $dispatcher, null, $logger);
|
$transport = Transport::fromDsn('smtp://example.com || smtp://'.urlencode($user).'@example.com || smtp://'.urlencode($user).':'.urlencode($pass).'@example.com', $dispatcher, null, $logger);
|
||||||
$this->assertInstanceOf(Transport\FailoverTransport::class, $transport);
|
$this->assertInstanceOf(Transport\FailoverTransport::class, $transport);
|
||||||
$p = new \ReflectionProperty(Transport\RoundRobinTransport::class, 'transports');
|
$p = new \ReflectionProperty(Transport\RoundRobinTransport::class, 'transports');
|
||||||
$p->setAccessible(true);
|
$p->setAccessible(true);
|
||||||
@ -247,6 +249,12 @@ class TransportTest extends TestCase
|
|||||||
foreach ($transports as $transport) {
|
foreach ($transports as $transport) {
|
||||||
$this->assertProperties($transport, $dispatcher, $logger);
|
$this->assertProperties($transport, $dispatcher, $logger);
|
||||||
}
|
}
|
||||||
|
$this->assertSame('', $transports[0]->getUsername());
|
||||||
|
$this->assertSame('', $transports[0]->getPassword());
|
||||||
|
$this->assertSame($user, $transports[1]->getUsername());
|
||||||
|
$this->assertSame('', $transports[1]->getPassword());
|
||||||
|
$this->assertSame($user, $transports[2]->getUsername());
|
||||||
|
$this->assertSame($pass, $transports[2]->getPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFromDsnRoundRobin()
|
public function testFromDsnRoundRobin()
|
||||||
|
@ -171,7 +171,17 @@ class Transport
|
|||||||
throw new LogicException(sprintf('The "%s" scheme is not supported for mailer "%s".', $parsedDsn['scheme'], $parsedDsn['host']));
|
throw new LogicException(sprintf('The "%s" scheme is not supported for mailer "%s".', $parsedDsn['scheme'], $parsedDsn['host']));
|
||||||
default:
|
default:
|
||||||
if ('smtp' === $parsedDsn['scheme']) {
|
if ('smtp' === $parsedDsn['scheme']) {
|
||||||
return new Transport\Smtp\EsmtpTransport($parsedDsn['host'], $parsedDsn['port'] ?? 25, $query['encryption'] ?? null, $query['auth_mode'] ?? null, $dispatcher, $logger);
|
$transport = new Transport\Smtp\EsmtpTransport($parsedDsn['host'], $parsedDsn['port'] ?? 25, $query['encryption'] ?? null, $query['auth_mode'] ?? null, $dispatcher, $logger);
|
||||||
|
|
||||||
|
if ($user) {
|
||||||
|
$transport->setUsername($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($pass) {
|
||||||
|
$transport->setPassword($pass);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $transport;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new LogicException(sprintf('The "%s" mailer is not supported.', $parsedDsn['host']));
|
throw new LogicException(sprintf('The "%s" mailer is not supported.', $parsedDsn['host']));
|
||||||
|
@ -29,8 +29,8 @@ use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream;
|
|||||||
class EsmtpTransport extends SmtpTransport
|
class EsmtpTransport extends SmtpTransport
|
||||||
{
|
{
|
||||||
private $authenticators = [];
|
private $authenticators = [];
|
||||||
private $username;
|
private $username = '';
|
||||||
private $password;
|
private $password = '';
|
||||||
private $authMode;
|
private $authMode;
|
||||||
|
|
||||||
public function __construct(string $host = 'localhost', int $port = 25, string $encryption = null, string $authMode = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
|
public function __construct(string $host = 'localhost', int $port = 25, string $encryption = null, string $authMode = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
|
||||||
|
Reference in New Issue
Block a user