aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-05-29 19:07:28 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2024-06-11 18:38:00 +0200
commit95cd3d59bdd28cb2084f316937349037362c3586 (patch)
treee6261ae4ca7f37e44a2a325f4c0023aa41b13a26 /tests
parent9db32d1ef60196f1c6008a408792be0a45633c3a (diff)
downloadnextcloud-server-95cd3d59bdd28cb2084f316937349037362c3586.tar.gz
nextcloud-server-95cd3d59bdd28cb2084f316937349037362c3586.zip
fix(Mailer): Allow to enforce strict email format
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Mail/MailerTest.php26
-rw-r--r--tests/lib/UtilTest.php16
2 files changed, 33 insertions, 9 deletions
diff --git a/tests/lib/Mail/MailerTest.php b/tests/lib/Mail/MailerTest.php
index 0eee7db126a..5626abb085a 100644
--- a/tests/lib/Mail/MailerTest.php
+++ b/tests/lib/Mail/MailerTest.php
@@ -42,7 +42,7 @@ class MailerTest extends TestCase {
private $l10n;
/** @var Mailer */
private $mailer;
- /** @var IEventDispatcher */
+ /** @var IEventDispatcher&MockObject */
private $dispatcher;
@@ -197,6 +197,7 @@ class MailerTest extends TestCase {
]);
$this->expectException(\Exception::class);
+ /** @var Message&MockObject */
$message = $this->getMockBuilder('\OC\Mail\Message')
->disableOriginalConstructor()->getMock();
$message->expects($this->once())
@@ -211,20 +212,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 568f535e557..1fdebfd5c4a 100644
--- a/tests/lib/UtilTest.php
+++ b/tests/lib/UtilTest.php
@@ -91,11 +91,27 @@ 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 testGetDefaultEmailAddress() {
$email = \OCP\Util::getDefaultEmailAddress("no-reply");
$this->assertEquals('no-reply@localhost', $email);
}
+ /**
+ * If strict email check is enabled "localhost.localdomain" should validate as a valid email domain
+ */
+ public function testGetDefaultEmailAddressStrict() {
+ $config = \OC::$server->getConfig();
+ $config->setAppValue('core', 'enforce_strict_email_check', 'yes');
+ $email = \OCP\Util::getDefaultEmailAddress("no-reply");
+ $this->assertEquals('no-reply@localhost.localdomain', $email);
+ $config->deleteAppValue('core', 'enforce_strict_email_check');
+ }
+
public function testGetDefaultEmailAddressFromConfig() {
$config = \OC::$server->getConfig();
$config->setSystemValue('mail_domain', 'example.com');