Add S/MIME signing test with auto-generated certificate

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-03-19 00:10:17 +01:00
parent 63c6ba5470
commit d34a684552

View File

@@ -137,4 +137,39 @@ class MailerServiceTest extends TestCase
$this->createService()->sendEmail('user@example.com', 'Test', '<p>Content</p>');
}
public function testSendSignsWithSmime(): void
{
if (!\extension_loaded('openssl')) {
self::markTestSkipped('OpenSSL extension required');
}
$privKey = openssl_pkey_new(['private_key_bits' => 2048, 'private_key_type' => OPENSSL_KEYTYPE_RSA]);
$csr = openssl_csr_new(['commonName' => 'test'], $privKey);
$cert = openssl_csr_sign($csr, null, $privKey, 1);
openssl_x509_export($cert, $certPem);
openssl_pkey_export($privKey, $keyPem, 'testpass');
file_put_contents($this->projectDir.'/config/cert/certificate.pem', $certPem);
file_put_contents($this->projectDir.'/config/cert/private-key.pem', $keyPem);
$service = new MailerService(
$this->bus,
$this->projectDir,
'testpass',
$this->urlGenerator,
$this->unsubscribeManager,
$this->em,
);
$this->unsubscribeManager->method('isUnsubscribed')->willReturn(false);
$this->unsubscribeManager->method('generateToken')->willReturn('token');
$this->urlGenerator->method('generate')->willReturn('https://example.com/url');
$this->em->expects(self::once())->method('persist');
$this->em->expects(self::once())->method('flush');
$this->bus->expects(self::once())->method('dispatch')->willReturn(new Envelope(new \stdClass()));
$service->sendEmail('user@example.com', 'Test', '<p>Signed</p>');
}
}