Skip to content

Commit

Permalink
Hide password in SymfonyMailer DSN
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhukV committed Jun 26, 2024
1 parent 303962e commit cc14406
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Check/Mailer/SymfonyMailerSmtpConnectionCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use FiveLab\Component\Diagnostic\Result\Failure;
use FiveLab\Component\Diagnostic\Result\Result;
use FiveLab\Component\Diagnostic\Result\Success;
use FiveLab\Component\Diagnostic\Util\HttpSecurityEncoder;
use Symfony\Component\Mailer\Exception\TransportException;
use Symfony\Component\Mailer\Transport;

Expand All @@ -28,11 +29,16 @@ class SymfonyMailerSmtpConnectionCheck implements CheckInterface
/**
* Constructor.
*
* @param string $dsn
* @param array<int> $codes
* @param string $dsn
* @param array<int> $codes
* @param HttpSecurityEncoder $securityEncoder
*/
public function __construct(private readonly string $dsn, private readonly array $codes = [220, 250])
{
public function __construct(
private readonly string $dsn,
private readonly array $codes = [220, 250],
private ?HttpSecurityEncoder $securityEncoder = null
) {
$this->securityEncoder = $this->securityEncoder ?: new HttpSecurityEncoder();
}

/**
Expand Down Expand Up @@ -84,7 +90,7 @@ public function check(): Result
public function getExtraParameters(): array
{
return [
'dsn' => $this->dsn,
'dsn' => $this->securityEncoder->encodeUri($this->dsn),

Check failure on line 93 in src/Check/Mailer/SymfonyMailerSmtpConnectionCheck.php

View workflow job for this annotation

GitHub Actions / Run PHP-Stan

Cannot call method encodeUri() on FiveLab\Component\Diagnostic\Util\HttpSecurityEncoder|null.
];
}
}
10 changes: 10 additions & 0 deletions tests/Check/Mailer/SymfonyMailerSmtpConnectionCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,14 @@ public function shouldSuccessGetExtra(): void
'dsn' => 'smtp://foo-bar:1025?username=some',
], $check->getExtraParameters());
}

#[Test]
public function shouldSuccessGetExtraWithHidePassword(): void
{
$check = new SymfonyMailerSmtpConnectionCheck('smtp://user:pass@foo-bar:1025?username=some');

self::assertEquals([
'dsn' => 'smtp://user:***@foo-bar:1025?username=some',
], $check->getExtraParameters());
}
}

0 comments on commit cc14406

Please sign in to comment.