diff --git a/src/Check/Mailer/SymfonyMailerSmtpConnectionCheck.php b/src/Check/Mailer/SymfonyMailerSmtpConnectionCheck.php index a4221f1..374861b 100644 --- a/src/Check/Mailer/SymfonyMailerSmtpConnectionCheck.php +++ b/src/Check/Mailer/SymfonyMailerSmtpConnectionCheck.php @@ -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; @@ -28,11 +29,16 @@ class SymfonyMailerSmtpConnectionCheck implements CheckInterface /** * Constructor. * - * @param string $dsn - * @param array $codes + * @param string $dsn + * @param array $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(); } /** @@ -84,7 +90,7 @@ public function check(): Result public function getExtraParameters(): array { return [ - 'dsn' => $this->dsn, + 'dsn' => $this->securityEncoder->encodeUri($this->dsn), ]; } } diff --git a/tests/Check/Mailer/SymfonyMailerSmtpConnectionCheckTest.php b/tests/Check/Mailer/SymfonyMailerSmtpConnectionCheckTest.php index 14be629..bfae8a5 100644 --- a/tests/Check/Mailer/SymfonyMailerSmtpConnectionCheckTest.php +++ b/tests/Check/Mailer/SymfonyMailerSmtpConnectionCheckTest.php @@ -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()); + } }