Files
postfixadmin/tests/SmtpTest.php
Rodrigo Cortés Cano 4a23d84ac4 4.x: enforce SMTP protocol state (#1138)
Improve SMTP (see smtp_mail()) - treat unexpected SMTP replies, incomplete writes, and failed TLS
negotiation as delivery failures. 

Refs #1128

thanks @TrapoSAMA
2026-09-02 20:15:54 +01:00

37 lines
932 B
PHP

<?php
use PHPUnit\Framework\TestCase;
class SmtpTest extends TestCase
{
public function testRequireResponseAcceptsExpectedCode(): void
{
$stream = fopen('php://memory', 'r+');
fwrite($stream, "220 ready\r\n");
rewind($stream);
smtp_require_response($stream, 220);
$this->assertTrue(true);
fclose($stream);
}
public function testRequireResponseRejectsUnexpectedCode(): void
{
$stream = fopen('php://memory', 'r+');
fwrite($stream, "550 rejected\r\n");
rewind($stream);
$this->expectException(RuntimeException::class);
smtp_require_response($stream, 250);
}
public function testSmtpWriteRejectsClosedStream(): void
{
$stream = fopen('php://memory', 'r+');
fclose($stream);
$this->expectException(RuntimeException::class);
smtp_write($stream, "EHLO example.com\r\n");
}
}