diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-06-04 14:03:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-04 14:03:54 +0200 |
commit | c1661b60238554fcac93160bffcb478e355b4c2c (patch) | |
tree | 7a5af2aa9508d06ccce42eeb5562bf2c99a291e6 /tests | |
parent | dbf0d9380985bfce318417495c709bf82d5418fa (diff) | |
parent | 1a273145304601d98383d18848331ab6335a63f2 (diff) | |
download | nextcloud-server-c1661b60238554fcac93160bffcb478e355b4c2c.tar.gz nextcloud-server-c1661b60238554fcac93160bffcb478e355b4c2c.zip |
Merge pull request #45570 from nextcloud/fix/strict-email-verification
fix(Mailer): Allow to enforce strict email format
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Mail/MailerTest.php | 26 | ||||
-rw-r--r-- | tests/lib/UtilTest.php | 16 |
2 files changed, 33 insertions, 9 deletions
diff --git a/tests/lib/Mail/MailerTest.php b/tests/lib/Mail/MailerTest.php index baa44975333..91006a8331a 100644 --- a/tests/lib/Mail/MailerTest.php +++ b/tests/lib/Mail/MailerTest.php @@ -38,7 +38,7 @@ class MailerTest extends TestCase { private $l10n; /** @var Mailer */ private $mailer; - /** @var IEventDispatcher */ + /** @var IEventDispatcher&MockObject */ private $dispatcher; @@ -193,6 +193,7 @@ class MailerTest extends TestCase { ]); $this->expectException(\Exception::class); + /** @var Message&MockObject */ $message = $this->getMockBuilder('\OC\Mail\Message') ->disableOriginalConstructor()->getMock(); $message->expects($this->once()) @@ -207,20 +208,27 @@ class MailerTest extends TestCase { */ public function mailAddressProvider() { return [ - ['lukas@owncloud.com', true], - ['lukas@localhost', true], - ['lukas@192.168.1.1', true], - ['lukas@éxämplè.com', true], - ['asdf', false], - ['', false], - ['lukas@owncloud.org@owncloud.com', false], + ['lukas@owncloud.com', true, false], + ['lukas@localhost', true, false], + ['lukas@192.168.1.1', true, false], + ['lukas@éxämplè.com', true, false], + ['asdf', false, false], + ['', false, false], + ['lukas@owncloud.org@owncloud.com', false, false], + ['test@localhost', true, false], + ['test@localhost', false, true], ]; } /** * @dataProvider mailAddressProvider */ - public function testValidateMailAddress($email, $expected) { + public function testValidateMailAddress($email, $expected, $strict) { + $this->config + ->expects($this->atMost(1)) + ->method('getAppValue') + ->with('core', 'enforce_strict_email_check') + ->willReturn($strict ? 'yes' : 'no'); $this->assertSame($expected, $this->mailer->validateMailAddress($email)); } diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php index 4c346b072f1..82897cbca29 100644 --- a/tests/lib/UtilTest.php +++ b/tests/lib/UtilTest.php @@ -90,9 +90,25 @@ class UtilTest extends \Test\TestCase { $this->assertEquals($expected, \OC_Util::fileInfoLoaded()); } + /** + * Host is "localhost" this is a valid for emails, + * but not for default strict email verification that requires a top level domain. + * So we check that with strict email verification we fallback to the default + */ + public function testGetDefaultEmailAddressStrict() { + $email = \OCP\Util::getDefaultEmailAddress("no-reply"); + $this->assertEquals('no-reply@localhost.localdomain', $email); + } + + /** + * If no strict email check is enabled "localhost" should validate as a valid email domain + */ public function testGetDefaultEmailAddress() { + $config = \OC::$server->getConfig(); + $config->setAppValue('core', 'enforce_strict_email_check', 'no'); $email = \OCP\Util::getDefaultEmailAddress("no-reply"); $this->assertEquals('no-reply@localhost', $email); + $config->deleteAppValue('core', 'enforce_strict_email_check'); } public function testGetDefaultEmailAddressFromConfig() { |