From 6b95da3e65baba83b1c5b145e45487a6caa3fd53 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 24 Jun 2021 19:07:24 +0200 Subject: [PATCH] Tests/reorganize: move denial of service tests to own file --- test/PHPMailer/PHPMailerTest.php | 30 ----------- test/Security/DenialOfServiceVectorsTest.php | 53 ++++++++++++++++++++ 2 files changed, 53 insertions(+), 30 deletions(-) create mode 100644 test/Security/DenialOfServiceVectorsTest.php diff --git a/test/PHPMailer/PHPMailerTest.php b/test/PHPMailer/PHPMailerTest.php index 462786cd..a7390910 100644 --- a/test/PHPMailer/PHPMailerTest.php +++ b/test/PHPMailer/PHPMailerTest.php @@ -865,36 +865,6 @@ EOT; $this->Mail->smtpClose(); } - /** - * Test this denial of service attack. - * - * @see http://www.cybsec.com/vuln/PHPMailer-DOS.pdf - */ - public function testDenialOfServiceAttack() - { - $this->Mail->Body = 'This should no longer cause a denial of service.'; - $this->buildBody(); - - $this->Mail->Subject = substr(str_repeat('0123456789', 100), 0, 998); - self::assertTrue($this->Mail->send(), $this->Mail->ErrorInfo); - } - - /** - * Tests this denial of service attack. - * - * According to the ticket, this should get stuck in a loop, though I can't make it happen. - * @see https://sourceforge.net/p/phpmailer/bugs/383/ - * - * @doesNotPerformAssertions - */ - public function testDenialOfServiceAttack2() - { - //Encoding name longer than 68 chars - $this->Mail->Encoding = '1234567890123456789012345678901234567890123456789012345678901234567890'; - //Call wrapText with a zero length value - $this->Mail->wrapText(str_repeat('This should no longer cause a denial of service. ', 30), 0); - } - /** * Test error handling. */ diff --git a/test/Security/DenialOfServiceVectorsTest.php b/test/Security/DenialOfServiceVectorsTest.php new file mode 100644 index 00000000..32f83781 --- /dev/null +++ b/test/Security/DenialOfServiceVectorsTest.php @@ -0,0 +1,53 @@ + + * @author Andy Prevost + * @copyright 2012 - 2020 Marcus Bointon + * @copyright 2004 - 2009 Andy Prevost + * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License + */ + +namespace PHPMailer\Test\Security; + +use PHPMailer\Test\SendTestCase; + +/** + * Test denial of service attack vectors, which have been mitigated. + */ +final class DenialOfServiceVectorsTest extends SendTestCase +{ + + /** + * Test this denial of service attack. + * + * @see http://www.cybsec.com/vuln/PHPMailer-DOS.pdf + */ + public function testDenialOfServiceAttack() + { + $this->Mail->Body = 'This should no longer cause a denial of service.'; + $this->buildBody(); + + $this->Mail->Subject = substr(str_repeat('0123456789', 100), 0, 998); + self::assertTrue($this->Mail->send(), $this->Mail->ErrorInfo); + } + + /** + * Tests this denial of service attack. + * + * According to the ticket, this should get stuck in a loop, though I can't make it happen. + * @see https://sourceforge.net/p/phpmailer/bugs/383/ + * + * @doesNotPerformAssertions + */ + public function testDenialOfServiceAttack2() + { + //Encoding name longer than 68 chars + $this->Mail->Encoding = '1234567890123456789012345678901234567890123456789012345678901234567890'; + //Call wrapText with a zero length value + $this->Mail->wrapText(str_repeat('This should no longer cause a denial of service. ', 30), 0); + } +}