diff options
author | Daniel Rudolf <github.com@daniel-rudolf.de> | 2021-08-04 18:52:55 +0200 |
---|---|---|
committer | Daniel Rudolf <github.com@daniel-rudolf.de> | 2021-08-04 18:52:55 +0200 |
commit | aa455e71d95c877b0dc758bc5c873d9278e6e112 (patch) | |
tree | 6f1135402c356f68cd940e0b2ca5efd1f8d91a67 /tests | |
parent | b768cade2b2c6664851de6462a17ef3531305971 (diff) | |
parent | 2a632195365be77889428e85801a00c74ab6a836 (diff) | |
download | nextcloud-server-aa455e71d95c877b0dc758bc5c873d9278e6e112.tar.gz nextcloud-server-aa455e71d95c877b0dc758bc5c873d9278e6e112.zip |
Merge branch 'master' into enhancement/noid/IURLGenerator-linkToDefaultPageUrl
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Controller/ChangePasswordControllerTest.php | 2 | ||||
-rwxr-xr-x | tests/drone-wait-objectstore.sh | 6 | ||||
-rw-r--r-- | tests/lib/Collaboration/Collaborators/MailPluginTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Collaboration/Collaborators/RemotePluginTest.php | 3 | ||||
-rw-r--r-- | tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php | 34 | ||||
-rw-r--r-- | tests/lib/Federation/CloudIdManagerTest.php | 36 | ||||
-rw-r--r-- | tests/lib/Files/Cache/Wrapper/CacheJailTest.php | 18 | ||||
-rw-r--r-- | tests/lib/Files/ObjectStore/S3Test.php | 7 | ||||
-rw-r--r-- | tests/lib/Memcache/FactoryTest.php | 2 | ||||
-rw-r--r-- | tests/lib/MemoryInfoTest.php | 7 | ||||
-rw-r--r-- | tests/lib/Share20/LegacyHooksTest.php | 1 | ||||
-rw-r--r-- | tests/lib/Share20/ManagerTest.php | 2 | ||||
-rw-r--r-- | tests/lib/User/DatabaseTest.php | 6 | ||||
-rw-r--r-- | tests/lib/User/UserTest.php | 65 | ||||
-rw-r--r-- | tests/preseed-config.php | 8 |
15 files changed, 169 insertions, 32 deletions
diff --git a/tests/Core/Controller/ChangePasswordControllerTest.php b/tests/Core/Controller/ChangePasswordControllerTest.php index dfd65aed47f..190afd3be47 100644 --- a/tests/Core/Controller/ChangePasswordControllerTest.php +++ b/tests/Core/Controller/ChangePasswordControllerTest.php @@ -22,11 +22,11 @@ namespace Tests\Core\Controller; -use OC\HintException; use OC\User\Session; use OCA\Settings\Controller\ChangePasswordController; use OCP\App\IAppManager; use OCP\AppFramework\Http\JSONResponse; +use OCP\HintException; use OCP\IGroupManager; use OCP\IL10N; use OCP\IRequest; diff --git a/tests/drone-wait-objectstore.sh b/tests/drone-wait-objectstore.sh index 7914d45bed1..7817d946682 100755 --- a/tests/drone-wait-objectstore.sh +++ b/tests/drone-wait-objectstore.sh @@ -12,6 +12,12 @@ function get_swift_token() { fi } +if [ "$OBJECT_STORE" == "s3" ]; then + echo "Waiting for minio to be ready" + timeout 60 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://minio:9000)" != "403" ]]; do sleep 5; done' || ( + echo "Failed to wait for minio to be ready" && exit 1 + ) +fi if [ "$OBJECT_STORE" == "swift" ]; then echo "waiting for keystone" until get_swift_token diff --git a/tests/lib/Collaboration/Collaborators/MailPluginTest.php b/tests/lib/Collaboration/Collaborators/MailPluginTest.php index 3128231a108..ad18666e0ae 100644 --- a/tests/lib/Collaboration/Collaborators/MailPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/MailPluginTest.php @@ -32,7 +32,9 @@ use OCP\Contacts\IManager; use OCP\Federation\ICloudIdManager; use OCP\IConfig; use OCP\IGroupManager; +use OCP\IURLGenerator; use OCP\IUser; +use OCP\IUserManager; use OCP\IUserSession; use OCP\Share\IShare; use Test\TestCase; @@ -70,7 +72,7 @@ class MailPluginTest extends TestCase { $this->groupManager = $this->createMock(IGroupManager::class); $this->knownUserService = $this->createMock(KnownUserService::class); $this->userSession = $this->createMock(IUserSession::class); - $this->cloudIdManager = new CloudIdManager($this->contactsManager); + $this->cloudIdManager = new CloudIdManager($this->contactsManager, $this->createMock(IURLGenerator::class), $this->createMock(IUserManager::class)); $this->searchResult = new SearchResult(); } diff --git a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php index 981260a80dd..4072f3ecde1 100644 --- a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php +++ b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php @@ -30,6 +30,7 @@ use OCP\Collaboration\Collaborators\SearchResultType; use OCP\Contacts\IManager; use OCP\Federation\ICloudIdManager; use OCP\IConfig; +use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; @@ -62,7 +63,7 @@ class RemotePluginTest extends TestCase { $this->userManager = $this->createMock(IUserManager::class); $this->config = $this->createMock(IConfig::class); $this->contactsManager = $this->createMock(IManager::class); - $this->cloudIdManager = new CloudIdManager($this->contactsManager); + $this->cloudIdManager = new CloudIdManager($this->contactsManager, $this->createMock(IURLGenerator::class), $this->createMock(IUserManager::class)); $this->searchResult = new SearchResult(); } diff --git a/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php b/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php index d7f6b4ac115..6a568d7e01b 100644 --- a/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php +++ b/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php @@ -22,6 +22,7 @@ namespace Test\DB\QueryBuilder; use OC\DB\QueryBuilder\Literal; +use OCP\DB\QueryBuilder\IQueryBuilder; use Test\TestCase; /** @@ -109,4 +110,37 @@ class ExpressionBuilderDBTest extends TestCase { $result->closeCursor(); $this->assertEquals($match, $column); } + + public function testCastColumn(): void { + $appId = $this->getUniqueID('testing'); + $this->createConfig($appId, '1', '4'); + + $query = $this->connection->getQueryBuilder(); + $query->update('appconfig') + ->set('configvalue', + $query->expr()->castColumn( + $query->createFunction( + '(' . $query->expr()->castColumn('configvalue', IQueryBuilder::PARAM_INT) + . ' + 1)' + ) + , IQueryBuilder::PARAM_STR + ) + ) + ->where($query->expr()->eq('appid', $query->createNamedParameter($appId))) + ->andWhere($query->expr()->eq('configkey', $query->createNamedParameter('1'))); + + $result = $query->executeStatement(); + $this->assertEquals(1, $result); + } + + protected function createConfig($appId, $key, $value) { + $query = $this->connection->getQueryBuilder(); + $query->insert('appconfig') + ->values([ + 'appid' => $query->createNamedParameter($appId), + 'configkey' => $query->createNamedParameter((string) $key), + 'configvalue' => $query->createNamedParameter((string) $value), + ]) + ->execute(); + } } diff --git a/tests/lib/Federation/CloudIdManagerTest.php b/tests/lib/Federation/CloudIdManagerTest.php index dd68abf0ecb..92f8a5fa8dd 100644 --- a/tests/lib/Federation/CloudIdManagerTest.php +++ b/tests/lib/Federation/CloudIdManagerTest.php @@ -23,20 +23,29 @@ namespace Test\Federation; use OC\Federation\CloudIdManager; use OCP\Contacts\IManager; +use OCP\IURLGenerator; +use OCP\IUserManager; use Test\TestCase; class CloudIdManagerTest extends TestCase { /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ protected $contactsManager; + /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */ + private $urlGenerator; + /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ + private $userManager; /** @var CloudIdManager */ private $cloudIdManager; + protected function setUp(): void { parent::setUp(); $this->contactsManager = $this->createMock(IManager::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->userManager = $this->createMock(IUserManager::class); - $this->cloudIdManager = new CloudIdManager($this->contactsManager); + $this->cloudIdManager = new CloudIdManager($this->contactsManager, $this->urlGenerator, $this->userManager); } public function cloudIdProvider() { @@ -104,6 +113,7 @@ class CloudIdManagerTest extends TestCase { return [ ['test', 'example.com', 'test@example.com'], ['test@example.com', 'example.com', 'test@example.com@example.com'], + ['test@example.com', null, 'test@example.com@example.com'], ]; } @@ -115,15 +125,21 @@ class CloudIdManagerTest extends TestCase { * @param string $id */ public function testGetCloudId($user, $remote, $id) { - $this->contactsManager->expects($this->any()) - ->method('search') - ->with($id, ['CLOUD']) - ->willReturn([ - [ - 'CLOUD' => [$id], - 'FN' => 'Ample Ex', - ] - ]); + if ($remote !== null) { + $this->contactsManager->expects($this->any()) + ->method('search') + ->with($id, ['CLOUD']) + ->willReturn([ + [ + 'CLOUD' => [$id], + 'FN' => 'Ample Ex', + ] + ]); + } else { + $this->urlGenerator->expects(self::once()) + ->method('getAbsoluteUrl') + ->willReturn('https://example.com'); + } $cloudId = $this->cloudIdManager->getCloudId($user, $remote); diff --git a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php index d9f7af1f034..4c3dce74087 100644 --- a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php +++ b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php @@ -200,4 +200,22 @@ class CacheJailTest extends CacheTest { $this->assertCount(1, $result); $this->assertEquals('asd', $result[0]['path']); } + + public function testRootJail() { + $this->storage->getScanner()->scan(''); + $file1 = 'foo'; + $file2 = 'foo/bar'; + $file3 = 'foo/bar/asd'; + $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder']; + + $this->sourceCache->put($file1, $data1); + $this->sourceCache->put($file2, $data1); + $this->sourceCache->put($file3, $data1); + + $nested = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, ''); + + $result = $nested->search('%asd%'); + $this->assertCount(1, $result); + $this->assertEquals('foo/bar/asd', $result[0]['path']); + } } diff --git a/tests/lib/Files/ObjectStore/S3Test.php b/tests/lib/Files/ObjectStore/S3Test.php index 97814212382..25bee9cbdd8 100644 --- a/tests/lib/Files/ObjectStore/S3Test.php +++ b/tests/lib/Files/ObjectStore/S3Test.php @@ -62,7 +62,7 @@ class NonSeekableStream extends Wrapper { class S3Test extends ObjectStoreTest { protected function getInstance() { $config = \OC::$server->getConfig()->getSystemValue('objectstore'); - if (!is_array($config) || $config['class'] !== 'OC\\Files\\ObjectStore\\S3') { + if (!is_array($config) || $config['class'] !== S3::class) { $this->markTestSkipped('objectstore not configured for s3'); } @@ -70,11 +70,6 @@ class S3Test extends ObjectStoreTest { } public function testUploadNonSeekable() { - $config = \OC::$server->getConfig()->getSystemValue('objectstore'); - if (!is_array($config) || $config['class'] !== 'OC\\Files\\ObjectStore\\S3') { - $this->markTestSkipped('objectstore not configured for s3'); - } - $s3 = $this->getInstance(); $s3->writeObject('multiparttest', NonSeekableStream::wrap(fopen(__FILE__, 'r'))); diff --git a/tests/lib/Memcache/FactoryTest.php b/tests/lib/Memcache/FactoryTest.php index 19edf4aa3dd..858bdc5d3ef 100644 --- a/tests/lib/Memcache/FactoryTest.php +++ b/tests/lib/Memcache/FactoryTest.php @@ -129,7 +129,7 @@ class FactoryTest extends \Test\TestCase { * @dataProvider cacheUnavailableProvider */ public function testCacheNotAvailableException($localCache, $distributedCache) { - $this->expectException(\OC\HintException::class); + $this->expectException(\OCP\HintException::class); $logger = $this->getMockBuilder(ILogger::class)->getMock(); new \OC\Memcache\Factory('abc', $logger, $localCache, $distributedCache); diff --git a/tests/lib/MemoryInfoTest.php b/tests/lib/MemoryInfoTest.php index 8feb4b6332d..f6557eed45c 100644 --- a/tests/lib/MemoryInfoTest.php +++ b/tests/lib/MemoryInfoTest.php @@ -60,10 +60,9 @@ class MemoryInfoTest extends TestCase { public function getMemoryLimitTestData(): array { return [ 'unlimited' => ['-1', -1,], - '0' => ['0', 0,], - '134217728 bytes' => ['134217728', 134217728,], - '128M' => ['128M', 134217728,], - '131072K' => ['131072K', 134217728,], + '524288000 bytes' => ['524288000', 524288000,], + '500M' => ['500M', 524288000,], + '512000K' => ['512000K', 524288000,], '2G' => ['2G', 2147483648,], ]; } diff --git a/tests/lib/Share20/LegacyHooksTest.php b/tests/lib/Share20/LegacyHooksTest.php index a615e26afb0..5afee588c34 100644 --- a/tests/lib/Share20/LegacyHooksTest.php +++ b/tests/lib/Share20/LegacyHooksTest.php @@ -342,6 +342,7 @@ class LegacyHooksTest extends TestCase { 'permissions' => Constants::PERMISSION_ALL, 'expiration' => $date, 'token' => 'token', + 'path' => null, ]; $hookListner diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 117adc95186..de8dc9fcc86 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -22,7 +22,6 @@ namespace Test\Share20; use OC\Files\Mount\MoveableMount; -use OC\HintException; use OC\Share20\DefaultShareProvider; use OC\Share20\Exception; use OC\Share20\Manager; @@ -36,6 +35,7 @@ use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountPoint; use OCP\Files\Node; use OCP\Files\Storage; +use OCP\HintException; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; diff --git a/tests/lib/User/DatabaseTest.php b/tests/lib/User/DatabaseTest.php index 6eb4466c69d..49b691cf9bc 100644 --- a/tests/lib/User/DatabaseTest.php +++ b/tests/lib/User/DatabaseTest.php @@ -22,10 +22,10 @@ namespace Test\User; -use OC\HintException; use OC\User\User; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventDispatcher; +use OCP\HintException; use OCP\Security\Events\ValidatePasswordPolicyEvent; use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -82,9 +82,9 @@ class DatabaseTest extends Backend { $this->assertSame($user, $this->backend->checkPassword($user, 'newpass')); } - + public function testVerifyPasswordEventFail() { - $this->expectException(\OC\HintException::class); + $this->expectException(\OCP\HintException::class); $this->expectExceptionMessage('password change failed'); $user = $this->getUser(); diff --git a/tests/lib/User/UserTest.php b/tests/lib/User/UserTest.php index 629a5632d61..2366bf45321 100644 --- a/tests/lib/User/UserTest.php +++ b/tests/lib/User/UserTest.php @@ -724,6 +724,71 @@ class UserTest extends TestCase { $user->setQuota('23 TB'); } + public function testGetDefaultUnlimitedQuota() { + /** + * @var UserInterface | \PHPUnit\Framework\MockObject\MockObject $backend + */ + $backend = $this->createMock(\Test\Util\User\Dummy::class); + + /** @var PublicEmitter|\PHPUnit\Framework\MockObject\MockObject $emitter */ + $emitter = $this->createMock(PublicEmitter::class); + $emitter->expects($this->never()) + ->method('emit'); + + $config = $this->createMock(IConfig::class); + $user = new User('foo', $backend, $this->dispatcher, $emitter, $config); + + $userValueMap = [ + ['foo', 'files', 'quota', 'default', 'default'], + ]; + $appValueMap = [ + ['files', 'default_quota', 'none', 'none'], + // allow unlimited quota + ['files', 'allow_unlimited_quota', '1', '1'], + ]; + $config->method('getUserValue') + ->will($this->returnValueMap($userValueMap)); + $config->method('getAppValue') + ->will($this->returnValueMap($appValueMap)); + + $quota = $user->getQuota(); + $this->assertEquals('none', $quota); + } + + public function testGetDefaultUnlimitedQuotaForbidden() { + /** + * @var UserInterface | \PHPUnit\Framework\MockObject\MockObject $backend + */ + $backend = $this->createMock(\Test\Util\User\Dummy::class); + + /** @var PublicEmitter|\PHPUnit\Framework\MockObject\MockObject $emitter */ + $emitter = $this->createMock(PublicEmitter::class); + $emitter->expects($this->never()) + ->method('emit'); + + $config = $this->createMock(IConfig::class); + $user = new User('foo', $backend, $this->dispatcher, $emitter, $config); + + $userValueMap = [ + ['foo', 'files', 'quota', 'default', 'default'], + ]; + $appValueMap = [ + ['files', 'default_quota', 'none', 'none'], + // do not allow unlimited quota + ['files', 'allow_unlimited_quota', '1', '0'], + ['files', 'quota_preset', '1 GB, 5 GB, 10 GB', '1 GB, 5 GB, 10 GB'], + // expect seeing 1 GB used as fallback value + ['files', 'default_quota', '1 GB', '1 GB'], + ]; + $config->method('getUserValue') + ->will($this->returnValueMap($userValueMap)); + $config->method('getAppValue') + ->will($this->returnValueMap($appValueMap)); + + $quota = $user->getQuota(); + $this->assertEquals('1 GB', $quota); + } + public function testSetQuotaAddressNoChange() { /** * @var UserInterface | \PHPUnit\Framework\MockObject\MockObject $backend diff --git a/tests/preseed-config.php b/tests/preseed-config.php index 97c8a1d11a8..16aea87c8a7 100644 --- a/tests/preseed-config.php +++ b/tests/preseed-config.php @@ -25,10 +25,10 @@ if (getenv('OBJECT_STORE') === 's3') { 'arguments' => [ 'bucket' => 'nextcloud', 'autocreate' => true, - 'key' => 'dummy', - 'secret' => 'dummy', - 'hostname' => getenv('DRONE') === 'true' ? 'fake-s3' : 'localhost', - 'port' => 4569, + 'key' => 'nextcloud', + 'secret' => 'nextcloud', + 'hostname' => getenv('DRONE') === 'true' ? 'minio' : 'localhost', + 'port' => 9000, 'use_ssl' => false, // required for some non amazon s3 implementations 'use_path_style' => true |