10000 allow user/pass on dns while using failover/roundrobin and type fix f… · symfony/symfony@4518ac5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4518ac5

Browse files
committed
allow user/pass on dns while using failover/roundrobin and type fix for username/password
1 parent 2efd7b2 commit 4518ac5

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/Symfony/Component/Mailer/Tests/TransportTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,11 @@ public function testFromDsnMailchimp()
236236

237237
public function testFromDsnFailover()
238238
{
239+
$user = 'user';
240+
$pass = 'pass';
239241
$dispatcher = $this->createMock(EventDispatcherInterface::class);
240242
$logger = $this->createMock(LoggerInterface::class);
241-
$transport = Transport::fromDsn('smtp://null || smtp://null || smtp://null', $dispatcher, null, $logger);
243+
$transport = Transport::fromDsn('smtp://example.com || smtp://'.urlencode($user).'@example.com || smtp://'.urlencode($user).':'.urlencode($pass).'@example.com', $dispatcher, null, $logger);
242244
$this->assertInstanceOf(Transport\FailoverTransport::class, $transport);
243245
$p = new \ReflectionProperty(Transport\RoundRobinTransport::class, 'transports');
244246
$p->setAccessible(true);
@@ -247,6 +249,12 @@ public function testFromDsnFailover()
247249
foreach ($transports as $transport) {
248250
$this->assertProperties($transport, $dispatcher, $logger);
249251
}
252+
$this->assertSame('', $transports[0]->getUsername());
253+
$this->assertSame('', $transports[0]->getPassword());
254+
$this->assertSame($user, $transports[1]->getUsername());
255+
$this->assertSame('', $transports[1]->getPassword());
256+
$this->assertSame($user, $transports[2]->getUsername());
257+
$this->assertSame($pass, $transports[2]->getPassword());
250258
}
251259

252260
public function testFromDsnRoundRobin()

src/Symfony/Component/Mailer/Transport.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,17 @@ private static function createTransport(string $dsn, EventDispatcherInterface $d
171171
throw new LogicException(sprintf('The "%s" scheme is not supported for mailer "%s".', $parsedDsn['scheme'], $parsedDsn['host']));
172172
default:
173173
if ('smtp' === $parsedDsn['scheme']) {
174-
return new Transport\Smtp\EsmtpTransport($parsedDsn['host'], $parsedDsn['port'] ?? 25, $query['encryption'] ?? null, $query['auth_mode'] ?? null, $dispatcher, $logger);
174+
$transport = new Transport\Smtp\EsmtpTransport($parsedDsn['host'], $parsedDsn['port'] ?? 25, $query['encryption'] ?? null, $query['auth_mode'] ?? null, $dispatcher, $logger);
175+
176+
if ($user) {
177+
$transport->setUsername($user);
178+
}
179+
180+
if ($pass) {
181+
$transport->setPassword($pass);
182+
}
183+
184+
return $transport;
175185
}
176186

177187
throw new LogicException(sprintf('The "%s" mailer is not supported.', $parsedDsn['host']));

src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
class EsmtpTransport extends SmtpTransport
3030
{
3131
private $authenticators = [];
32-
private $username;
33-
private $password;
32+
private $username = '';
33+
private $password = '';
3434
private $authMode;
3535

3636
public function __construct(string $host = 'localhost', int $port = 25, string $encryption = null, string $authMode = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)

0 commit comments

Comments
 (0)
0