aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/Accounts/AccountManagerTest.php6
-rw-r--r--tests/lib/AppFramework/Middleware/Security/Mock/PasswordConfirmationMiddlewareController.php4
-rw-r--r--tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php60
-rw-r--r--tests/lib/Authentication/Token/PublicKeyTokenTest.php5
-rw-r--r--tests/lib/BackgroundJob/DummyJobList.php22
-rw-r--r--tests/lib/DB/ConnectionTest.php101
-rw-r--r--tests/lib/DB/Exception/DbalExceptionTest.php2
-rw-r--r--tests/lib/DB/MigratorTest.php3
-rw-r--r--tests/lib/FileChunkingTest.php58
-rw-r--r--tests/lib/InstallerTest.php6
-rw-r--r--tests/lib/L10N/L10nTest.php3
-rw-r--r--tests/lib/Lockdown/Filesystem/NoFSTest.php5
-rw-r--r--tests/lib/Lockdown/LockdownManagerTest.php5
-rw-r--r--tests/lib/Mail/MailerTest.php26
-rw-r--r--tests/lib/Repair/RepairMimeTypesTest.php6
-rw-r--r--tests/lib/Route/RouterTest.php19
-rw-r--r--tests/lib/Share20/DefaultShareProviderTest.php30
-rw-r--r--tests/lib/TestCase.php2
-rw-r--r--tests/lib/UtilTest.php16
19 files changed, 277 insertions, 102 deletions
diff --git a/tests/lib/Accounts/AccountManagerTest.php b/tests/lib/Accounts/AccountManagerTest.php
index 0a29ff02d30..da31c77abc6 100644
--- a/tests/lib/Accounts/AccountManagerTest.php
+++ b/tests/lib/Accounts/AccountManagerTest.php
@@ -617,6 +617,12 @@ class AccountManagerTest extends TestCase {
],
[
+ 'name' => IAccountManager::PROPERTY_BIRTHDATE,
+ 'value' => '',
+ 'scope' => IAccountManager::SCOPE_LOCAL,
+ ],
+
+ [
'name' => IAccountManager::PROPERTY_PROFILE_ENABLED,
'value' => '1',
],
diff --git a/tests/lib/AppFramework/Middleware/Security/Mock/PasswordConfirmationMiddlewareController.php b/tests/lib/AppFramework/Middleware/Security/Mock/PasswordConfirmationMiddlewareController.php
index 82d6cf8f251..02159661ff6 100644
--- a/tests/lib/AppFramework/Middleware/Security/Mock/PasswordConfirmationMiddlewareController.php
+++ b/tests/lib/AppFramework/Middleware/Security/Mock/PasswordConfirmationMiddlewareController.php
@@ -30,4 +30,8 @@ class PasswordConfirmationMiddlewareController extends \OCP\AppFramework\Control
#[PasswordConfirmationRequired]
public function testAttribute() {
}
+
+ #[PasswordConfirmationRequired]
+ public function testSSO() {
+ }
}
diff --git a/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php
index 3613ca624a3..beee7151264 100644
--- a/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php
@@ -9,7 +9,9 @@ namespace Test\AppFramework\Middleware\Security;
use OC\AppFramework\Middleware\Security\Exceptions\NotConfirmedException;
use OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware;
use OC\AppFramework\Utility\ControllerMethodReflector;
+use OC\Authentication\Token\IProvider;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Authentication\Token\IToken;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUser;
@@ -32,6 +34,7 @@ class PasswordConfirmationMiddlewareTest extends TestCase {
private $controller;
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
private $timeFactory;
+ private IProvider|\PHPUnit\Framework\MockObject\MockObject $tokenProvider;
protected function setUp(): void {
$this->reflector = new ControllerMethodReflector();
@@ -39,6 +42,7 @@ class PasswordConfirmationMiddlewareTest extends TestCase {
$this->userSession = $this->createMock(IUserSession::class);
$this->user = $this->createMock(IUser::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
+ $this->tokenProvider = $this->createMock(IProvider::class);
$this->controller = new PasswordConfirmationMiddlewareController(
'test',
$this->createMock(IRequest::class)
@@ -48,7 +52,8 @@ class PasswordConfirmationMiddlewareTest extends TestCase {
$this->reflector,
$this->session,
$this->userSession,
- $this->timeFactory
+ $this->timeFactory,
+ $this->tokenProvider,
);
}
@@ -90,6 +95,13 @@ class PasswordConfirmationMiddlewareTest extends TestCase {
$this->timeFactory->method('getTime')
->willReturn($currentTime);
+ $token = $this->createMock(IToken::class);
+ $token->method('getScopeAsArray')
+ ->willReturn([]);
+ $this->tokenProvider->expects($this->once())
+ ->method('getToken')
+ ->willReturn($token);
+
$thrown = false;
try {
$this->middleware->beforeController($this->controller, __FUNCTION__);
@@ -118,6 +130,13 @@ class PasswordConfirmationMiddlewareTest extends TestCase {
$this->timeFactory->method('getTime')
->willReturn($currentTime);
+ $token = $this->createMock(IToken::class);
+ $token->method('getScopeAsArray')
+ ->willReturn([]);
+ $this->tokenProvider->expects($this->once())
+ ->method('getToken')
+ ->willReturn($token);
+
$thrown = false;
try {
$this->middleware->beforeController($this->controller, __FUNCTION__);
@@ -128,6 +147,8 @@ class PasswordConfirmationMiddlewareTest extends TestCase {
$this->assertSame($exception, $thrown);
}
+
+
public function dataProvider() {
return [
['foo', 2000, 4000, true],
@@ -138,4 +159,41 @@ class PasswordConfirmationMiddlewareTest extends TestCase {
['foo', 2000, 3816, true],
];
}
+
+ public function testSSO() {
+ static $sessionId = 'mySession1d';
+
+ $this->reflector->reflect($this->controller, __FUNCTION__);
+
+ $this->user->method('getBackendClassName')
+ ->willReturn('fictional_backend');
+ $this->userSession->method('getUser')
+ ->willReturn($this->user);
+
+ $this->session->method('get')
+ ->with('last-password-confirm')
+ ->willReturn(0);
+ $this->session->method('getId')
+ ->willReturn($sessionId);
+
+ $this->timeFactory->method('getTime')
+ ->willReturn(9876);
+
+ $token = $this->createMock(IToken::class);
+ $token->method('getScopeAsArray')
+ ->willReturn([IToken::SCOPE_SKIP_PASSWORD_VALIDATION => true]);
+ $this->tokenProvider->expects($this->once())
+ ->method('getToken')
+ ->with($sessionId)
+ ->willReturn($token);
+
+ $thrown = false;
+ try {
+ $this->middleware->beforeController($this->controller, __FUNCTION__);
+ } catch (NotConfirmedException) {
+ $thrown = true;
+ }
+
+ $this->assertSame(false, $thrown);
+ }
}
diff --git a/tests/lib/Authentication/Token/PublicKeyTokenTest.php b/tests/lib/Authentication/Token/PublicKeyTokenTest.php
index acbddebea35..cc8890002e9 100644
--- a/tests/lib/Authentication/Token/PublicKeyTokenTest.php
+++ b/tests/lib/Authentication/Token/PublicKeyTokenTest.php
@@ -9,11 +9,12 @@ declare(strict_types=1);
namespace Test\Authentication\Token;
use OC\Authentication\Token\PublicKeyToken;
+use OCP\Authentication\Token\IToken;
use Test\TestCase;
class PublicKeyTokenTest extends TestCase {
public function testSetScopeAsArray() {
- $scope = ['filesystem' => false];
+ $scope = [IToken::SCOPE_FILESYSTEM => false];
$token = new PublicKeyToken();
$token->setScope($scope);
$this->assertEquals(json_encode($scope), $token->getScope());
@@ -21,7 +22,7 @@ class PublicKeyTokenTest extends TestCase {
}
public function testDefaultScope() {
- $scope = ['filesystem' => true];
+ $scope = [IToken::SCOPE_FILESYSTEM => true];
$token = new PublicKeyToken();
$this->assertEquals($scope, $token->getScopeAsArray());
}
diff --git a/tests/lib/BackgroundJob/DummyJobList.php b/tests/lib/BackgroundJob/DummyJobList.php
index fc80786d28b..7b7fce7e9e8 100644
--- a/tests/lib/BackgroundJob/DummyJobList.php
+++ b/tests/lib/BackgroundJob/DummyJobList.php
@@ -26,6 +26,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
private array $reserved = [];
private int $last = 0;
+ private int $lastId = 0;
public function __construct() {
}
@@ -40,6 +41,8 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
$job = \OCP\Server::get($job);
}
$job->setArgument($argument);
+ $job->setId($this->lastId);
+ $this->lastId++;
if (!$this->has($job, null)) {
$this->jobs[] = $job;
}
@@ -54,9 +57,20 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
* @param mixed $argument
*/
public function remove($job, $argument = null): void {
- $index = array_search($job, $this->jobs);
- if ($index !== false) {
- unset($this->jobs[$index]);
+ foreach ($this->jobs as $index => $listJob) {
+ if (get_class($job) === get_class($listJob) && $job->getArgument() == $listJob->getArgument()) {
+ unset($this->jobs[$index]);
+ return;
+ }
+ }
+ }
+
+ public function removeById(int $id): void {
+ foreach ($this->jobs as $index => $listJob) {
+ if ($listJob->getId() === $id) {
+ unset($this->jobs[$index]);
+ return;
+ }
}
}
@@ -126,7 +140,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
}
}
- public function getById(int $id): IJob {
+ public function getById(int $id): ?IJob {
foreach ($this->jobs as $job) {
if ($job->getId() === $id) {
return $job;
diff --git a/tests/lib/DB/ConnectionTest.php b/tests/lib/DB/ConnectionTest.php
new file mode 100644
index 00000000000..3f06082ff0c
--- /dev/null
+++ b/tests/lib/DB/ConnectionTest.php
@@ -0,0 +1,101 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace Test\DB;
+
+use Doctrine\DBAL\Configuration;
+use Doctrine\DBAL\Driver;
+use Doctrine\DBAL\Driver\Connection as DriverConnection;
+use Doctrine\DBAL\Platforms\MySQLPlatform;
+use OC\DB\Adapter;
+use OC\DB\Connection;
+use Test\TestCase;
+
+/**
+ * @group DB
+ */
+class ConnectionTest extends TestCase {
+
+ public function testSingleNodeConnectsToPrimaryOnly(): void {
+ $connectionParams = [
+ 'user' => 'test',
+ 'password' => 'topsecret',
+ 'host' => 'test',
+ ];
+ $adapter = $this->createMock(Adapter::class);
+ $driver = $this->createMock(Driver::class);
+ $configuration = $this->createMock(Configuration::class);
+ $connection = $this->getMockBuilder(Connection::class)
+ ->onlyMethods(['connectTo'])
+ ->setConstructorArgs([
+ [
+ 'adapter' => $adapter,
+ 'platform' => new MySQLPlatform(),
+ 'tablePrefix' => 'nctest',
+ 'primary' => $connectionParams,
+ 'replica' => [
+ $connectionParams,
+ ],
+ ],
+ $driver,
+ $configuration,
+ ])
+ ->getMock();
+ $driverConnection = $this->createMock(DriverConnection::class);
+ $connection->expects(self::once())
+ ->method('connectTo')
+ ->with('primary')
+ ->willReturn($driverConnection);
+
+ $connection->ensureConnectedToReplica();
+ $connection->ensureConnectedToPrimary();
+ $connection->ensureConnectedToReplica();
+ }
+
+ public function testClusterConnectsToPrimaryAndReplica(): void {
+ $connectionParamsPrimary = [
+ 'user' => 'test',
+ 'password' => 'topsecret',
+ 'host' => 'testprimary',
+ ];
+ $connectionParamsReplica = [
+ 'user' => 'test',
+ 'password' => 'topsecret',
+ 'host' => 'testreplica',
+ ];
+ $adapter = $this->createMock(Adapter::class);
+ $driver = $this->createMock(Driver::class);
+ $configuration = $this->createMock(Configuration::class);
+ $connection = $this->getMockBuilder(Connection::class)
+ ->onlyMethods(['connectTo'])
+ ->setConstructorArgs([
+ [
+ 'adapter' => $adapter,
+ 'platform' => new MySQLPlatform(),
+ 'tablePrefix' => 'nctest',
+ 'primary' => $connectionParamsPrimary,
+ 'replica' => [
+ $connectionParamsReplica,
+ ],
+ ],
+ $driver,
+ $configuration,
+ ])
+ ->getMock();
+ $driverConnection = $this->createMock(DriverConnection::class);
+ $connection->expects(self::exactly(2))
+ ->method('connectTo')
+ ->willReturn($driverConnection);
+
+ $connection->ensureConnectedToReplica();
+ $connection->ensureConnectedToPrimary();
+ $connection->ensureConnectedToReplica();
+ }
+
+}
diff --git a/tests/lib/DB/Exception/DbalExceptionTest.php b/tests/lib/DB/Exception/DbalExceptionTest.php
index 97f0efa4b65..470beff9080 100644
--- a/tests/lib/DB/Exception/DbalExceptionTest.php
+++ b/tests/lib/DB/Exception/DbalExceptionTest.php
@@ -17,6 +17,7 @@ use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\Exception\InvalidFieldNameException;
+use Doctrine\DBAL\Exception\LockWaitTimeoutException;
use Doctrine\DBAL\Exception\NonUniqueFieldNameException;
use Doctrine\DBAL\Exception\NotNullConstraintViolationException;
use Doctrine\DBAL\Exception\ServerException;
@@ -45,6 +46,7 @@ class DbalExceptionTest extends \Test\TestCase {
public function dataDriverException(): array {
return [
+ [LockWaitTimeoutException::class, DbalException::REASON_LOCK_WAIT_TIMEOUT],
[ForeignKeyConstraintViolationException::class, DbalException::REASON_FOREIGN_KEY_VIOLATION],
[NotNullConstraintViolationException::class, DbalException::REASON_NOT_NULL_CONSTRAINT_VIOLATION],
[UniqueConstraintViolationException::class, DbalException::REASON_UNIQUE_CONSTRAINT_VIOLATION],
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/FileChunkingTest.php b/tests/lib/FileChunkingTest.php
deleted file mode 100644
index b69154ea1c3..00000000000
--- a/tests/lib/FileChunkingTest.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-/**
- * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
- * SPDX-License-Identifier: AGPL-3.0-only
- */
-
-namespace Test;
-
-use OCP\ICache;
-
-class FileChunkingTest extends \Test\TestCase {
- public function dataIsComplete() {
- return [
- [1, [], false],
- [1, [0], true],
- [2, [], false],
- [2, [0], false],
- [2, [1], false],
- [2, [0,1], true],
- [10, [], false],
- [10, [0,1,2,3,4,5,6,7,8], false],
- [10, [1,2,3,4,5,6,7,8,9], false],
- [10, [0,1,2,3,5,6,7,8,9], false],
- [10, [0,1,2,3,4,5,6,7,8,9], true],
- ];
- }
-
- /**
- * @dataProvider dataIsComplete
- * @param $total
- * @param array $present
- * @param $expected
- */
- public function testIsComplete($total, array $present, $expected) {
- $fileChunking = $this->getMockBuilder(\OC_FileChunking::class)
- ->setMethods(['getCache'])
- ->setConstructorArgs([[
- 'name' => 'file',
- 'transferid' => '42',
- 'chunkcount' => $total,
- ]])
- ->getMock();
-
- $cache = $this->createMock(ICache::class);
-
- $cache->expects($this->atLeastOnce())
- ->method('hasKey')
- ->willReturnCallback(function ($key) use ($present) {
- $data = explode('-', $key);
- return in_array($data[3], $present);
- });
-
- $fileChunking->method('getCache')->willReturn($cache);
-
- $this->assertEquals($expected, $fileChunking->isComplete());
- }
-}
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/Lockdown/Filesystem/NoFSTest.php b/tests/lib/Lockdown/Filesystem/NoFSTest.php
index 08429228647..7a636fbaaaa 100644
--- a/tests/lib/Lockdown/Filesystem/NoFSTest.php
+++ b/tests/lib/Lockdown/Filesystem/NoFSTest.php
@@ -9,6 +9,7 @@ namespace Test\Lockdown\Filesystem;
use OC\Authentication\Token\PublicKeyToken;
use OC\Files\Filesystem;
use OC\Lockdown\Filesystem\NullStorage;
+use OCP\Authentication\Token\IToken;
use Test\Traits\UserTrait;
/**
@@ -20,7 +21,7 @@ class NoFSTest extends \Test\TestCase {
protected function tearDown(): void {
$token = new PublicKeyToken();
$token->setScope([
- 'filesystem' => true
+ IToken::SCOPE_FILESYSTEM => true
]);
\OC::$server->get('LockdownManager')->setToken($token);
parent::tearDown();
@@ -30,7 +31,7 @@ class NoFSTest extends \Test\TestCase {
parent::setUp();
$token = new PublicKeyToken();
$token->setScope([
- 'filesystem' => false
+ IToken::SCOPE_FILESYSTEM => false
]);
\OC::$server->get('LockdownManager')->setToken($token);
diff --git a/tests/lib/Lockdown/LockdownManagerTest.php b/tests/lib/Lockdown/LockdownManagerTest.php
index 5ff5a84e800..bb71a6e63de 100644
--- a/tests/lib/Lockdown/LockdownManagerTest.php
+++ b/tests/lib/Lockdown/LockdownManagerTest.php
@@ -8,6 +8,7 @@ namespace Test\Lockdown;
use OC\Authentication\Token\PublicKeyToken;
use OC\Lockdown\LockdownManager;
+use OCP\Authentication\Token\IToken;
use OCP\ISession;
use Test\TestCase;
@@ -29,7 +30,7 @@ class LockdownManagerTest extends TestCase {
public function testCanAccessFilesystemAllowed() {
$token = new PublicKeyToken();
- $token->setScope(['filesystem' => true]);
+ $token->setScope([IToken::SCOPE_FILESYSTEM => true]);
$manager = new LockdownManager($this->sessionCallback);
$manager->setToken($token);
$this->assertTrue($manager->canAccessFilesystem());
@@ -37,7 +38,7 @@ class LockdownManagerTest extends TestCase {
public function testCanAccessFilesystemNotAllowed() {
$token = new PublicKeyToken();
- $token->setScope(['filesystem' => false]);
+ $token->setScope([IToken::SCOPE_FILESYSTEM => false]);
$manager = new LockdownManager($this->sessionCallback);
$manager->setToken($token);
$this->assertFalse($manager->canAccessFilesystem());
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/Repair/RepairMimeTypesTest.php b/tests/lib/Repair/RepairMimeTypesTest.php
index b7076b32e77..fbccd393fd0 100644
--- a/tests/lib/Repair/RepairMimeTypesTest.php
+++ b/tests/lib/Repair/RepairMimeTypesTest.php
@@ -39,10 +39,12 @@ class RepairMimeTypesTest extends \Test\TestCase {
$config = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock();
- $config->expects($this->any())
- ->method('getSystemValueString')
+ $config->method('getSystemValueString')
->with('version')
->willReturn('11.0.0.0');
+ $config->method('getAppValue')
+ ->with('files', 'mimetype_version')
+ ->willReturn('11.0.0.0');
$this->storage = new \OC\Files\Storage\Temporary([]);
diff --git a/tests/lib/Route/RouterTest.php b/tests/lib/Route/RouterTest.php
index 87d4afbc7b5..713d90d3c20 100644
--- a/tests/lib/Route/RouterTest.php
+++ b/tests/lib/Route/RouterTest.php
@@ -25,7 +25,9 @@ use Test\TestCase;
* @package Test\Route
*/
class RouterTest extends TestCase {
- public function testGenerateConsecutively(): void {
+ private Router $router;
+ protected function setUp(): void {
+ parent::setUp();
/** @var LoggerInterface $logger */
$logger = $this->createMock(LoggerInterface::class);
$logger->method('info')
@@ -34,7 +36,7 @@ class RouterTest extends TestCase {
$this->fail('Unexpected info log: '.(string)($data['exception'] ?? $message));
}
);
- $router = new Router(
+ $this->router = new Router(
$logger,
$this->createMock(IRequest::class),
$this->createMock(IConfig::class),
@@ -42,13 +44,20 @@ class RouterTest extends TestCase {
$this->createMock(ContainerInterface::class),
$this->createMock(IAppManager::class),
);
+ }
+
+ public function testHeartbeat(): void {
+ $this->assertEquals('/index.php/heartbeat', $this->router->generate('heartbeat'));
+ }
+
+ public function testGenerateConsecutively(): void {
- $this->assertEquals('/index.php/apps/files/', $router->generate('files.view.index'));
+ $this->assertEquals('/index.php/apps/files/', $this->router->generate('files.view.index'));
// the OCS route is the prefixed one for the AppFramework - see /ocs/v1.php for routing details
- $this->assertEquals('/index.php/ocsapp/apps/dav/api/v1/direct', $router->generate('ocs.dav.direct.getUrl'));
+ $this->assertEquals('/index.php/ocsapp/apps/dav/api/v1/direct', $this->router->generate('ocs.dav.direct.getUrl'));
// test caching
- $this->assertEquals('/index.php/apps/files/', $router->generate('files.view.index'));
+ $this->assertEquals('/index.php/apps/files/', $this->router->generate('files.view.index'));
}
}
diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php
index 72ef83331e9..e138f2f576b 100644
--- a/tests/lib/Share20/DefaultShareProviderTest.php
+++ b/tests/lib/Share20/DefaultShareProviderTest.php
@@ -38,31 +38,31 @@ class DefaultShareProviderTest extends \Test\TestCase {
/** @var IDBConnection */
protected $dbConn;
- /** @var IUserManager | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IUserManager | MockObject */
protected $userManager;
- /** @var IGroupManager | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IGroupManager | MockObject */
protected $groupManager;
- /** @var IRootFolder | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IRootFolder | MockObject */
protected $rootFolder;
/** @var DefaultShareProvider */
protected $provider;
- /** @var \PHPUnit\Framework\MockObject\MockObject|IMailer */
+ /** @var MockObject|IMailer */
protected $mailer;
/** @var IFactory|MockObject */
protected $l10nFactory;
- /** @var \PHPUnit\Framework\MockObject\MockObject|IL10N */
+ /** @var MockObject|IL10N */
protected $l10n;
- /** @var \PHPUnit\Framework\MockObject\MockObject|Defaults */
+ /** @var MockObject|Defaults */
protected $defaults;
- /** @var \PHPUnit\Framework\MockObject\MockObject|IURLGenerator */
+ /** @var MockObject|IURLGenerator */
protected $urlGenerator;
/** @var ITimeFactory|MockObject */
@@ -1035,7 +1035,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
['shareOwner', $owner],
['sharedBy', $initiator],
]);
- $this->groupManager->method('getUserGroupIds')->with($user)->willReturn($groups);
+ $this->groupManager
+ ->method('getUserGroupIds')
+ ->willReturnCallback(fn (IUser $user) => ($user->getUID() === 'sharedWith' ? $groups : []));
$file = $this->createMock(File::class);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
@@ -1123,7 +1125,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
['shareOwner', $owner],
['sharedBy', $initiator],
]);
- $this->groupManager->method('getUserGroupIds')->with($user)->willReturn($groups);
+ $this->groupManager
+ ->method('getUserGroupIds')
+ ->willReturnCallback(fn (IUser $user) => ($user->getUID() === 'user' ? $groups : []));
$file = $this->createMock(File::class);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
@@ -1206,7 +1210,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
['user1', $user1],
]);
- $this->groupManager->method('getUserGroupIds')->with($user0)->willReturn(['group0']);
+ $this->groupManager
+ ->method('getUserGroupIds')
+ ->willReturnCallback(fn (IUser $user) => ($user->getUID() === 'user0' ? ['group0'] : []));
$node = $this->createMock(Folder::class);
$node->method('getId')->willReturn($fileId2);
@@ -1283,7 +1289,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
['shareOwner', $owner],
['sharedBy', $initiator],
]);
- $this->groupManager->method('getUserGroupIds')->with($user)->willReturn($groups);
+ $this->groupManager
+ ->method('getUserGroupIds')
+ ->willReturnCallback(fn (IUser $user) => ($user->getUID() === 'sharedWith' ? $groups : []));
$share = $this->provider->getSharedWith('sharedWith', $shareType, null, 1, 0);
$this->assertCount(0, $share);
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() {