summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Test/Repair/Owncloud/CleanPreviewsBackgroundJobTest.php50
-rw-r--r--tests/Test/Repair/Owncloud/CleanPreviewsTest.php21
-rw-r--r--tests/Test/Repair/Owncloud/UpdateLanguageCodesTest.php30
-rw-r--r--tests/lib/AppFramework/Http/RequestTest.php77
-rw-r--r--tests/lib/DirectEditing/ManagerTest.php4
-rw-r--r--tests/lib/Log/ExceptionSerializerTest.php16
-rw-r--r--tests/lib/Metadata/FileMetadataMapperTest.php6
-rw-r--r--tests/lib/Repair/RepairMimeTypesTest.php1
-rw-r--r--tests/lib/Share20/DefaultShareProviderTest.php31
-rw-r--r--tests/lib/Share20/ManagerTest.php38
-rw-r--r--tests/lib/User/SessionTest.php2
11 files changed, 216 insertions, 60 deletions
diff --git a/tests/Test/Repair/Owncloud/CleanPreviewsBackgroundJobTest.php b/tests/Test/Repair/Owncloud/CleanPreviewsBackgroundJobTest.php
index 8ecef60c35d..3c15d51fd61 100644
--- a/tests/Test/Repair/Owncloud/CleanPreviewsBackgroundJobTest.php
+++ b/tests/Test/Repair/Owncloud/CleanPreviewsBackgroundJobTest.php
@@ -107,12 +107,12 @@ class CleanPreviewsBackgroundJobTest extends TestCase {
$this->equalTo(['uid' => 'myuid'])
);
- $this->logger->expects($this->at(0))
+ $this->logger->expects($this->exactly(2))
->method('info')
- ->with($this->equalTo('Started preview cleanup for myuid'));
- $this->logger->expects($this->at(1))
- ->method('info')
- ->with($this->equalTo('New preview cleanup scheduled for myuid'));
+ ->withConsecutive(
+ [$this->equalTo('Started preview cleanup for myuid')],
+ [$this->equalTo('New preview cleanup scheduled for myuid')],
+ );
$this->job->run(['uid' => 'myuid']);
}
@@ -146,12 +146,12 @@ class CleanPreviewsBackgroundJobTest extends TestCase {
$this->jobList->expects($this->never())
->method('add');
- $this->logger->expects($this->at(0))
- ->method('info')
- ->with($this->equalTo('Started preview cleanup for myuid'));
- $this->logger->expects($this->at(1))
+ $this->logger->expects($this->exactly(2))
->method('info')
- ->with($this->equalTo('Preview cleanup done for myuid'));
+ ->withConsecutive(
+ [$this->equalTo('Started preview cleanup for myuid')],
+ [$this->equalTo('Preview cleanup done for myuid')],
+ );
$thumbnailFolder->expects($this->once())
->method('delete');
@@ -165,12 +165,12 @@ class CleanPreviewsBackgroundJobTest extends TestCase {
->with($this->equalTo('myuid'))
->willThrowException(new NotFoundException());
- $this->logger->expects($this->at(0))
- ->method('info')
- ->with($this->equalTo('Started preview cleanup for myuid'));
- $this->logger->expects($this->at(1))
+ $this->logger->expects($this->exactly(2))
->method('info')
- ->with($this->equalTo('Preview cleanup done for myuid'));
+ ->withConsecutive(
+ [$this->equalTo('Started preview cleanup for myuid')],
+ [$this->equalTo('Preview cleanup done for myuid')],
+ );
$this->job->run(['uid' => 'myuid']);
}
@@ -189,12 +189,12 @@ class CleanPreviewsBackgroundJobTest extends TestCase {
->with($this->equalTo('thumbnails'))
->willThrowException(new NotFoundException());
- $this->logger->expects($this->at(0))
- ->method('info')
- ->with($this->equalTo('Started preview cleanup for myuid'));
- $this->logger->expects($this->at(1))
+ $this->logger->expects($this->exactly(2))
->method('info')
- ->with($this->equalTo('Preview cleanup done for myuid'));
+ ->withConsecutive(
+ [$this->equalTo('Started preview cleanup for myuid')],
+ [$this->equalTo('Preview cleanup done for myuid')],
+ );
$this->job->run(['uid' => 'myuid']);
}
@@ -229,12 +229,12 @@ class CleanPreviewsBackgroundJobTest extends TestCase {
$this->jobList->expects($this->never())
->method('add');
- $this->logger->expects($this->at(0))
+ $this->logger->expects($this->exactly(2))
->method('info')
- ->with($this->equalTo('Started preview cleanup for myuid'));
- $this->logger->expects($this->at(1))
- ->method('info')
- ->with($this->equalTo('Preview cleanup done for myuid'));
+ ->withConsecutive(
+ [$this->equalTo('Started preview cleanup for myuid')],
+ [$this->equalTo('Preview cleanup done for myuid')],
+ );
$thumbnailFolder->expects($this->once())
->method('delete')
diff --git a/tests/Test/Repair/Owncloud/CleanPreviewsTest.php b/tests/Test/Repair/Owncloud/CleanPreviewsTest.php
index abd166057be..7a6c374a2d7 100644
--- a/tests/Test/Repair/Owncloud/CleanPreviewsTest.php
+++ b/tests/Test/Repair/Owncloud/CleanPreviewsTest.php
@@ -79,18 +79,17 @@ class CleanPreviewsTest extends TestCase {
$function($user2);
}));
- $this->jobList->expects($this->at(0))
+ $this->jobList->expects($this->exactly(2))
->method('add')
- ->with(
- $this->equalTo(CleanPreviewsBackgroundJob::class),
- $this->equalTo(['uid' => 'user1'])
- );
-
- $this->jobList->expects($this->at(1))
- ->method('add')
- ->with(
- $this->equalTo(CleanPreviewsBackgroundJob::class),
- $this->equalTo(['uid' => 'user2'])
+ ->withConsecutive(
+ [
+ $this->equalTo(CleanPreviewsBackgroundJob::class),
+ $this->equalTo(['uid' => 'user1'])
+ ],
+ [
+ $this->equalTo(CleanPreviewsBackgroundJob::class),
+ $this->equalTo(['uid' => 'user2'])
+ ],
);
$this->config->expects($this->once())
diff --git a/tests/Test/Repair/Owncloud/UpdateLanguageCodesTest.php b/tests/Test/Repair/Owncloud/UpdateLanguageCodesTest.php
index 3b0b2f57f5f..b5d339eef2f 100644
--- a/tests/Test/Repair/Owncloud/UpdateLanguageCodesTest.php
+++ b/tests/Test/Repair/Owncloud/UpdateLanguageCodesTest.php
@@ -96,27 +96,17 @@ class UpdateLanguageCodesTest extends TestCase {
/** @var IOutput|\PHPUnit_Framework_MockObject_MockObject $outputMock */
$outputMock = $this->createMock(IOutput::class);
- $outputMock->expects($this->at(0))
+ $outputMock->expects($this->exactly(7))
->method('info')
- ->with('Changed 1 setting(s) from "bg_BG" to "bg" in preferences table.');
- $outputMock->expects($this->at(1))
- ->method('info')
- ->with('Changed 0 setting(s) from "cs_CZ" to "cs" in preferences table.');
- $outputMock->expects($this->at(2))
- ->method('info')
- ->with('Changed 1 setting(s) from "fi_FI" to "fi" in preferences table.');
- $outputMock->expects($this->at(3))
- ->method('info')
- ->with('Changed 0 setting(s) from "hu_HU" to "hu" in preferences table.');
- $outputMock->expects($this->at(4))
- ->method('info')
- ->with('Changed 0 setting(s) from "nb_NO" to "nb" in preferences table.');
- $outputMock->expects($this->at(5))
- ->method('info')
- ->with('Changed 0 setting(s) from "sk_SK" to "sk" in preferences table.');
- $outputMock->expects($this->at(6))
- ->method('info')
- ->with('Changed 2 setting(s) from "th_TH" to "th" in preferences table.');
+ ->withConsecutive(
+ ['Changed 1 setting(s) from "bg_BG" to "bg" in preferences table.'],
+ ['Changed 0 setting(s) from "cs_CZ" to "cs" in preferences table.'],
+ ['Changed 1 setting(s) from "fi_FI" to "fi" in preferences table.'],
+ ['Changed 0 setting(s) from "hu_HU" to "hu" in preferences table.'],
+ ['Changed 0 setting(s) from "nb_NO" to "nb" in preferences table.'],
+ ['Changed 0 setting(s) from "sk_SK" to "sk" in preferences table.'],
+ ['Changed 2 setting(s) from "th_TH" to "th" in preferences table.'],
+ );
$this->config->expects($this->once())
->method('getSystemValue')
diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php
index 3289a373a12..cf5ebdca2f0 100644
--- a/tests/lib/AppFramework/Http/RequestTest.php
+++ b/tests/lib/AppFramework/Http/RequestTest.php
@@ -585,6 +585,83 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('192.168.3.99', $request->getRemoteAddress());
}
+ public function testGetRemoteIpv6AddressWithMatchingIpv6CidrTrustedRemote() {
+ $this->config
+ ->expects($this->exactly(2))
+ ->method('getSystemValue')
+ ->withConsecutive(
+ ['trusted_proxies'],
+ ['forwarded_for_headers']
+ )->willReturnOnConsecutiveCalls(
+ ['2001:db8:85a3:8d3:1319:8a20::/95'],
+ ['HTTP_X_FORWARDED_FOR']
+ );
+
+ $request = new Request(
+ [
+ 'server' => [
+ 'REMOTE_ADDR' => '2001:db8:85a3:8d3:1319:8a21:370:7348',
+ 'HTTP_X_FORWARDED' => '10.4.0.5, 10.4.0.4',
+ 'HTTP_X_FORWARDED_FOR' => '192.168.0.233'
+ ],
+ ],
+ $this->requestId,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ );
+
+ $this->assertSame('192.168.0.233', $request->getRemoteAddress());
+ }
+
+ public function testGetRemoteAddressIpv6WithNotMatchingCidrTrustedRemote() {
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValue')
+ ->with('trusted_proxies')
+ ->willReturn(['fd::/8']);
+
+ $request = new Request(
+ [
+ 'server' => [
+ 'REMOTE_ADDR' => '2001:db8:85a3:8d3:1319:8a2e:370:7348',
+ 'HTTP_X_FORWARDED' => '10.4.0.5, 10.4.0.4',
+ 'HTTP_X_FORWARDED_FOR' => '192.168.0.233'
+ ],
+ ],
+ $this->requestId,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ );
+
+ $this->assertSame('2001:db8:85a3:8d3:1319:8a2e:370:7348', $request->getRemoteAddress());
+ }
+
+ public function testGetRemoteAddressIpv6WithInvalidTrustedProxy() {
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValue')
+ ->with('trusted_proxies')
+ ->willReturn(['fx::/8']);
+
+ $request = new Request(
+ [
+ 'server' => [
+ 'REMOTE_ADDR' => '2001:db8:85a3:8d3:1319:8a2e:370:7348',
+ 'HTTP_X_FORWARDED' => '10.4.0.5, 10.4.0.4',
+ 'HTTP_X_FORWARDED_FOR' => '192.168.0.233'
+ ],
+ ],
+ $this->requestId,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ );
+
+ $this->assertSame('2001:db8:85a3:8d3:1319:8a2e:370:7348', $request->getRemoteAddress());
+ }
+
public function testGetRemoteAddressWithXForwardedForIPv6() {
$this->config
->expects($this->exactly(2))
diff --git a/tests/lib/DirectEditing/ManagerTest.php b/tests/lib/DirectEditing/ManagerTest.php
index b00de02bcf5..e19c44b1a06 100644
--- a/tests/lib/DirectEditing/ManagerTest.php
+++ b/tests/lib/DirectEditing/ManagerTest.php
@@ -106,6 +106,10 @@ class ManagerTest extends TestCase {
*/
private $userFolder;
/**
+ * @var MockObject|IL10N
+ */
+ private $l10n;
+ /**
* @var MockObject|IManager
*/
private $encryptionManager;
diff --git a/tests/lib/Log/ExceptionSerializerTest.php b/tests/lib/Log/ExceptionSerializerTest.php
index 70ac80d13e3..209214a6832 100644
--- a/tests/lib/Log/ExceptionSerializerTest.php
+++ b/tests/lib/Log/ExceptionSerializerTest.php
@@ -48,6 +48,10 @@ class ExceptionSerializerTest extends TestCase {
throw new \Exception('my exception');
}
+ private function customMagicAuthThing(string $login, string $parole): void {
+ throw new \Exception('expected custom auth exception');
+ }
+
/**
* this test ensures that the serializer does not overwrite referenced
* variables. It is crafted after a scenario we experienced: the DAV server
@@ -65,4 +69,16 @@ class ExceptionSerializerTest extends TestCase {
$this->assertSame(ExceptionSerializer::SENSITIVE_VALUE_PLACEHOLDER, $serializedData['Trace'][0]['args'][0]);
}
}
+
+ public function testSerializerWithRegisteredMethods() {
+ $this->serializer->enlistSensitiveMethods(self::class, ['customMagicAuthThing']);
+ try {
+ $this->customMagicAuthThing('u57474', 'Secret');
+ } catch (\Exception $e) {
+ $serializedData = $this->serializer->serializeException($e);
+ $this->assertSame('customMagicAuthThing', $serializedData['Trace'][0]['function']);
+ $this->assertSame(ExceptionSerializer::SENSITIVE_VALUE_PLACEHOLDER, $serializedData['Trace'][0]['args'][0]);
+ $this->assertFalse(isset($serializedData['Trace'][0]['args'][1]));
+ }
+ }
}
diff --git a/tests/lib/Metadata/FileMetadataMapperTest.php b/tests/lib/Metadata/FileMetadataMapperTest.php
index 8e385351be2..1a005f24b8a 100644
--- a/tests/lib/Metadata/FileMetadataMapperTest.php
+++ b/tests/lib/Metadata/FileMetadataMapperTest.php
@@ -24,6 +24,7 @@ namespace Test\Metadata;
use OC\Metadata\FileMetadataMapper;
use OC\Metadata\FileMetadata;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* @group DB
@@ -33,9 +34,12 @@ class FileMetadataMapperTest extends \Test\TestCase {
/** @var IDBConnection */
protected $connection;
- /** @var SystemConfig|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var SystemConfig|MockObject */
protected $config;
+ /** @var FileMetadataMapper|MockObject */
+ protected $mapper;
+
protected function setUp(): void {
parent::setUp();
diff --git a/tests/lib/Repair/RepairMimeTypesTest.php b/tests/lib/Repair/RepairMimeTypesTest.php
index 26a52459c24..53c8e53d486 100644
--- a/tests/lib/Repair/RepairMimeTypesTest.php
+++ b/tests/lib/Repair/RepairMimeTypesTest.php
@@ -36,7 +36,6 @@ class RepairMimeTypesTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
- $this->savedMimetypeLoader = \OC::$server->getMimeTypeLoader();
$this->mimetypeLoader = \OC::$server->getMimeTypeLoader();
/** @var IConfig | \PHPUnit\Framework\MockObject\MockObject $config */
diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php
index 03e1bdb4346..ed2bc2a4eda 100644
--- a/tests/lib/Share20/DefaultShareProviderTest.php
+++ b/tests/lib/Share20/DefaultShareProviderTest.php
@@ -23,6 +23,7 @@
namespace Test\Share20;
use OC\Share20\DefaultShareProvider;
+use OC\Share20\ShareAttributes;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Defaults;
use OCP\Files\File;
@@ -703,6 +704,11 @@ class DefaultShareProviderTest extends \Test\TestCase {
$share->setSharedWithDisplayName('Displayed Name');
$share->setSharedWithAvatar('/path/to/image.svg');
$share->setPermissions(1);
+
+ $attrs = new ShareAttributes();
+ $attrs->setAttribute('permissions', 'download', true);
+ $share->setAttributes($attrs);
+
$share->setTarget('/target');
$share2 = $this->provider->create($share);
@@ -723,6 +729,17 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame('/path/to/image.svg', $share->getSharedWithAvatar());
$this->assertSame(null, $share2->getSharedWithDisplayName());
$this->assertSame(null, $share2->getSharedWithAvatar());
+
+ $this->assertSame(
+ [
+ [
+ 'scope' => 'permissions',
+ 'key' => 'download',
+ 'enabled' => true
+ ]
+ ],
+ $share->getAttributes()->toArray()
+ );
}
public function testCreateGroupShare() {
@@ -760,6 +777,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
$share->setSharedWithDisplayName('Displayed Name');
$share->setSharedWithAvatar('/path/to/image.svg');
$share->setTarget('/target');
+ $attrs = new ShareAttributes();
+ $attrs->setAttribute('permissions', 'download', true);
+ $share->setAttributes($attrs);
$share2 = $this->provider->create($share);
@@ -779,6 +799,17 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame('/path/to/image.svg', $share->getSharedWithAvatar());
$this->assertSame(null, $share2->getSharedWithDisplayName());
$this->assertSame(null, $share2->getSharedWithAvatar());
+
+ $this->assertSame(
+ [
+ [
+ 'scope' => 'permissions',
+ 'key' => 'download',
+ 'enabled' => true
+ ]
+ ],
+ $share->getAttributes()->toArray()
+ );
}
public function testCreateLinkShare() {
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index 2ed99519df6..4e613d1cf5c 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -593,7 +593,7 @@ class ManagerTest extends \Test\TestCase {
}
public function createShare($id, $type, $path, $sharedWith, $sharedBy, $shareOwner,
- $permissions, $expireDate = null, $password = null) {
+ $permissions, $expireDate = null, $password = null, $attributes = null) {
$share = $this->createMock(IShare::class);
$share->method('getShareType')->willReturn($type);
@@ -602,6 +602,7 @@ class ManagerTest extends \Test\TestCase {
$share->method('getShareOwner')->willReturn($shareOwner);
$share->method('getNode')->willReturn($path);
$share->method('getPermissions')->willReturn($permissions);
+ $share->method('getAttributes')->willReturn($attributes);
$share->method('getExpirationDate')->willReturn($expireDate);
$share->method('getPassword')->willReturn($password);
@@ -1914,13 +1915,31 @@ class ManagerTest extends \Test\TestCase {
}
- public function testLinkCreateChecksNoPublicUpload() {
+ public function testFileLinkCreateChecksNoPublicUpload() {
+ $share = $this->manager->newShare();
+
+ $share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
+ $share->setNodeType('file');
+
+ $this->config
+ ->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_allow_links', 'yes', 'yes'],
+ ['core', 'shareapi_allow_public_upload', 'yes', 'no']
+ ]);
+
+ self::invokePrivate($this->manager, 'linkCreateChecks', [$share]);
+ $this->addToAssertionCount(1);
+ }
+
+ public function testFolderLinkCreateChecksNoPublicUpload() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Public upload is not allowed');
$share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
+ $share->setNodeType('folder');
$this->config
->method('getAppValue')
@@ -1936,6 +1955,9 @@ class ManagerTest extends \Test\TestCase {
$share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
+ $share->setSharedWith('sharedWith');
+ $folder = $this->createMock(\OC\Files\Node\Folder::class);
+ $share->setNode($folder);
$this->config
->method('getAppValue')
@@ -1952,6 +1974,9 @@ class ManagerTest extends \Test\TestCase {
$share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_READ);
+ $share->setSharedWith('sharedWith');
+ $folder = $this->createMock(\OC\Files\Node\Folder::class);
+ $share->setNode($folder);
$this->config
->method('getAppValue')
@@ -2946,6 +2971,9 @@ class ManagerTest extends \Test\TestCase {
$share = $this->manager->newShare();
$share->setShareType(IShare::TYPE_LINK)
->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
+ $share->setSharedWith('sharedWith');
+ $folder = $this->createMock(\OC\Files\Node\Folder::class);
+ $share->setNode($folder);
$this->config
->expects($this->at(1))
@@ -3039,6 +3067,8 @@ class ManagerTest extends \Test\TestCase {
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
$share = $this->manager->newShare();
+ $attrs = $this->manager->newShare()->newAttributes();
+ $attrs->setAttribute('app1', 'perm1', true);
$share->setProviderId('foo')
->setId('42')
->setShareType(IShare::TYPE_USER);
@@ -3129,6 +3159,8 @@ class ManagerTest extends \Test\TestCase {
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
$share = $this->manager->newShare();
+ $attrs = $this->manager->newShare()->newAttributes();
+ $attrs->setAttribute('app1', 'perm1', true);
$share->setProviderId('foo')
->setId('42')
->setShareType(IShare::TYPE_USER)
@@ -3136,6 +3168,7 @@ class ManagerTest extends \Test\TestCase {
->setShareOwner('newUser')
->setSharedBy('sharer')
->setPermissions(31)
+ ->setAttributes($attrs)
->setNode($node);
$this->defaultProvider->expects($this->once())
@@ -3160,6 +3193,7 @@ class ManagerTest extends \Test\TestCase {
'uidOwner' => 'sharer',
'permissions' => 31,
'path' => '/myPath',
+ 'attributes' => $attrs->toArray(),
]);
$manager->updateShare($share);
diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php
index 0e199e5d5b5..735a3b3d06a 100644
--- a/tests/lib/User/SessionTest.php
+++ b/tests/lib/User/SessionTest.php
@@ -43,6 +43,8 @@ use OC\Security\CSRF\CsrfTokenManager;
class SessionTest extends \Test\TestCase {
/** @var ITimeFactory|MockObject */
private $timeFactory;
+ /** @var IProvider|MockObject */
+ private $tokenProvider;
/** @var IConfig|MockObject */
private $config;
/** @var Throttler|MockObject */