diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/DB/MigratorTest.php | 3 | ||||
-rw-r--r-- | tests/lib/InstallerTest.php | 6 | ||||
-rw-r--r-- | tests/lib/L10N/L10nTest.php | 3 | ||||
-rw-r--r-- | tests/lib/Mail/MailerTest.php | 26 | ||||
-rw-r--r-- | tests/lib/TestCase.php | 2 | ||||
-rw-r--r-- | tests/lib/UtilTest.php | 16 |
6 files changed, 41 insertions, 15 deletions
diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php index 4714b569d81..eaa6540b93b 100644 --- a/tests/lib/DB/MigratorTest.php +++ b/tests/lib/DB/MigratorTest.php @@ -19,6 +19,7 @@ use OC\DB\OracleMigrator; use OC\DB\SQLiteMigrator; use OCP\DB\Types; use OCP\IConfig; +use OCP\Security\ISecureRandom; /** * Class MigratorTest @@ -56,7 +57,7 @@ class MigratorTest extends \Test\TestCase { private function getMigrator(): Migrator { $platform = $this->connection->getDatabasePlatform(); - $random = \OC::$server->getSecureRandom(); + $random = \OC::$server->get(ISecureRandom::class); $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class); if ($platform instanceof SqlitePlatform) { return new SQLiteMigrator($this->connection, $this->config, $dispatcher); diff --git a/tests/lib/InstallerTest.php b/tests/lib/InstallerTest.php index 3a62a57fdab..1fd48ea4fc9 100644 --- a/tests/lib/InstallerTest.php +++ b/tests/lib/InstallerTest.php @@ -51,7 +51,7 @@ class InstallerTest extends TestCase { $config->setSystemValue('appstoreenabled', true); $installer = new Installer( \OC::$server->get(AppFetcher::class), - \OC::$server->getHTTPClientService(), + \OC::$server->get(IClientService::class), \OC::$server->getTempManager(), \OC::$server->get(LoggerInterface::class), $config, @@ -74,7 +74,7 @@ class InstallerTest extends TestCase { protected function tearDown(): void { $installer = new Installer( \OC::$server->get(AppFetcher::class), - \OC::$server->getHTTPClientService(), + \OC::$server->get(IClientService::class), \OC::$server->getTempManager(), \OC::$server->get(LoggerInterface::class), \OC::$server->getConfig(), @@ -98,7 +98,7 @@ class InstallerTest extends TestCase { // Install app $installer = new Installer( \OC::$server->get(AppFetcher::class), - \OC::$server->getHTTPClientService(), + \OC::$server->get(IClientService::class), \OC::$server->getTempManager(), \OC::$server->get(LoggerInterface::class), \OC::$server->getConfig(), diff --git a/tests/lib/L10N/L10nTest.php b/tests/lib/L10N/L10nTest.php index 9a6d119330b..38d0a5626b0 100644 --- a/tests/lib/L10N/L10nTest.php +++ b/tests/lib/L10N/L10nTest.php @@ -15,6 +15,7 @@ use OCP\ICacheFactory; use OCP\IConfig; use OCP\IRequest; use OCP\IUserSession; +use OCP\L10N\IFactory; use Test\TestCase; /** @@ -219,7 +220,7 @@ class L10nTest extends TestCase { public function testFindLanguageFromLocale($locale, $language) { $this->assertEquals( $language, - \OC::$server->getL10NFactory()->findLanguageFromLocale('lib', $locale) + \OC::$server->get(IFactory::class)->findLanguageFromLocale('lib', $locale) ); } 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/TestCase.php b/tests/lib/TestCase.php index 5732e981ec7..8c97c184c6f 100644 --- a/tests/lib/TestCase.php +++ b/tests/lib/TestCase.php @@ -264,7 +264,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase { * @return string */ protected static function getUniqueID($prefix = '', $length = 13) { - return $prefix . \OC::$server->getSecureRandom()->generate( + return $prefix . \OC::$server->get(ISecureRandom::class)->generate( $length, // Do not use dots and slashes as we use the value for file names ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER 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() { |