aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2021-03-25 17:32:49 +0100
committerVincent Petry <vincent@nextcloud.com>2021-04-15 10:06:09 +0200
commitaf61486aea90cfc1a82301ce624dffb59ed01e07 (patch)
tree9b608272439503e0015ece40ae4b77013eabc81f /tests
parent2650da70caa73c8bf3119edebb37e91d67f3a214 (diff)
downloadnextcloud-server-af61486aea90cfc1a82301ce624dffb59ed01e07.tar.gz
nextcloud-server-af61486aea90cfc1a82301ce624dffb59ed01e07.zip
Separate settings for remote share expiration
Added separate settings for default and enforced expiration date for remote shares. Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Share20/ManagerTest.php277
1 files changed, 207 insertions, 70 deletions
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index b5378df074d..e17f179b600 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -772,7 +772,14 @@ class ManagerTest extends \Test\TestCase {
self::invokePrivate($this->manager, 'generalCreateChecks', [$share]);
}
- public function testValidateExpirationDateInternalInPast() {
+ public function validateExpirationDateInternalProvider() {
+ return [[IShare::TYPE_USER], [IShare::TYPE_REMOTE], [IShare::TYPE_REMOTE_GROUP]];
+ }
+
+ /**
+ * @dataProvider validateExpirationDateInternalProvider
+ */
+ public function testValidateExpirationDateInternalInPast($shareType) {
$this->expectException(\OCP\Share\Exceptions\GenericShareException::class);
$this->expectExceptionMessage('Expiration date is in the past');
@@ -781,51 +788,88 @@ class ManagerTest extends \Test\TestCase {
$past->sub(new \DateInterval('P1D'));
$share = $this->manager->newShare();
+ $share->setShareType($shareType);
$share->setExpirationDate($past);
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
}
- public function testValidateExpirationDateInternalEnforceButNotSet() {
+ /**
+ * @dataProvider validateExpirationDateInternalProvider
+ */
+ public function testValidateExpirationDateInternalEnforceButNotSet($shareType) {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Expiration date is enforced');
$share = $this->manager->newShare();
$share->setProviderId('foo')->setId('bar');
-
- $this->config->method('getAppValue')
- ->willReturnMap([
- ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
- ['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
- ]);
+ $share->setShareType($shareType);
+ if ($shareType === IShare::TYPE_USER) {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
+ ]);
+ } else {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_enforce_remote_expire_date', 'no', 'yes'],
+ ]);
+ }
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
}
- public function testValidateExpirationDateInternalEnforceButNotEnabledAndNotSet() {
+ /**
+ * @dataProvider validateExpirationDateInternalProvider
+ */
+ public function testValidateExpirationDateInternalEnforceButNotEnabledAndNotSet($shareType) {
$share = $this->manager->newShare();
$share->setProviderId('foo')->setId('bar');
+ $share->setShareType($shareType);
- $this->config->method('getAppValue')
- ->willReturnMap([
- ['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
- ]);
+ if ($shareType === IShare::TYPE_USER) {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
+ ]);
+ } else {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_enforce_remote_expire_date', 'no', 'yes'],
+ ]);
+ }
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
$this->assertNull($share->getExpirationDate());
}
- public function testValidateExpirationDateInternalEnforceButNotSetNewShare() {
+ /**
+ * @dataProvider validateExpirationDateInternalProvider
+ */
+ public function testValidateExpirationDateInternalEnforceButNotSetNewShare($shareType) {
$share = $this->manager->newShare();
-
- $this->config->method('getAppValue')
- ->willReturnMap([
- ['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
- ['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
- ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
- ['core', 'internal_defaultExpDays', '3', '3'],
- ]);
+ $share->setShareType($shareType);
+
+ if ($shareType === IShare::TYPE_USER) {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
+ ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
+ ['core', 'internal_defaultExpDays', '3', '3'],
+ ]);
+ } else {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_enforce_remote_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_remote_expire_after_n_days', '7', '3'],
+ ['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
+ ['core', 'remote_defaultExpDays', '3', '3'],
+ ]);
+ }
$expected = new \DateTime();
$expected->setTime(0,0,0);
@@ -837,16 +881,30 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($expected, $share->getExpirationDate());
}
- public function testValidateExpirationDateInternalEnforceRelaxedDefaultButNotSetNewShare() {
+ /**
+ * @dataProvider validateExpirationDateInternalProvider
+ */
+ public function testValidateExpirationDateInternalEnforceRelaxedDefaultButNotSetNewShare($shareType) {
$share = $this->manager->newShare();
-
- $this->config->method('getAppValue')
- ->willReturnMap([
- ['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
- ['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
- ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
- ['core', 'internal_defaultExpDays', '3', '1'],
- ]);
+ $share->setShareType($shareType);
+
+ if ($shareType === IShare::TYPE_USER) {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
+ ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
+ ['core', 'internal_defaultExpDays', '3', '1'],
+ ]);
+ } else {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_enforce_remote_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_remote_expire_after_n_days', '7', '3'],
+ ['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
+ ['core', 'remote_defaultExpDays', '3', '1'],
+ ]);
+ }
$expected = new \DateTime();
$expected->setTime(0,0,0);
@@ -858,7 +916,10 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($expected, $share->getExpirationDate());
}
- public function testValidateExpirationDateInternalEnforceTooFarIntoFuture() {
+ /**
+ * @dataProvider validateExpirationDateInternalProvider
+ */
+ public function testValidateExpirationDateInternalEnforceTooFarIntoFuture($shareType) {
$this->expectException(\OCP\Share\Exceptions\GenericShareException::class);
$this->expectExceptionMessage('Can’t set expiration date more than 3 days in the future');
@@ -866,19 +927,32 @@ class ManagerTest extends \Test\TestCase {
$future->add(new \DateInterval('P7D'));
$share = $this->manager->newShare();
+ $share->setShareType($shareType);
$share->setExpirationDate($future);
- $this->config->method('getAppValue')
- ->willReturnMap([
- ['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
- ['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
- ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
- ]);
+ if ($shareType === IShare::TYPE_USER) {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
+ ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
+ ]);
+ } else {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_enforce_remote_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_remote_expire_after_n_days', '7', '3'],
+ ['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
+ ]);
+ }
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
}
- public function testValidateExpirationDateInternalEnforceValid() {
+ /**
+ * @dataProvider validateExpirationDateInternalProvider
+ */
+ public function testValidateExpirationDateInternalEnforceValid($shareType) {
$future = new \DateTime();
$future->add(new \DateInterval('P2D'));
$future->setTime(1,2,3);
@@ -887,14 +961,24 @@ class ManagerTest extends \Test\TestCase {
$expected->setTime(0,0,0);
$share = $this->manager->newShare();
+ $share->setShareType($shareType);
$share->setExpirationDate($future);
- $this->config->method('getAppValue')
- ->willReturnMap([
- ['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
- ['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
- ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
- ]);
+ if ($shareType === IShare::TYPE_USER) {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
+ ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
+ ]);
+ } else {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_enforce_remote_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_remote_expire_after_n_days', '7', '3'],
+ ['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
+ ]);
+ }
$hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
@@ -907,7 +991,10 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($expected, $share->getExpirationDate());
}
- public function testValidateExpirationDateInternalNoDefault() {
+ /**
+ * @dataProvider validateExpirationDateInternalProvider
+ */
+ public function testValidateExpirationDateInternalNoDefault($shareType) {
$date = new \DateTime();
$date->add(new \DateInterval('P5D'));
$date->setTime(1,2,3);
@@ -916,6 +1003,7 @@ class ManagerTest extends \Test\TestCase {
$expected->setTime(0,0,0);
$share = $this->manager->newShare();
+ $share->setShareType($shareType);
$share->setExpirationDate($date);
$hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
@@ -929,7 +1017,10 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($expected, $share->getExpirationDate());
}
- public function testValidateExpirationDateInternalNoDateNoDefault() {
+ /**
+ * @dataProvider validateExpirationDateInternalProvider
+ */
+ public function testValidateExpirationDateInternalNoDateNoDefault($shareType) {
$hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) {
@@ -937,6 +1028,7 @@ class ManagerTest extends \Test\TestCase {
}));
$share = $this->manager->newShare();
+ $share->setShareType($shareType);
$share->setPassword('password');
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
@@ -944,19 +1036,32 @@ class ManagerTest extends \Test\TestCase {
$this->assertNull($share->getExpirationDate());
}
- public function testValidateExpirationDateInternalNoDateDefault() {
+ /**
+ * @dataProvider validateExpirationDateInternalProvider
+ */
+ public function testValidateExpirationDateInternalNoDateDefault($shareType) {
$share = $this->manager->newShare();
+ $share->setShareType($shareType);
$expected = new \DateTime();
$expected->add(new \DateInterval('P3D'));
$expected->setTime(0,0,0);
- $this->config->method('getAppValue')
- ->willReturnMap([
- ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
- ['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
- ['core', 'internal_defaultExpDays', '3', '3'],
- ]);
+ if ($shareType === IShare::TYPE_USER) {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
+ ['core', 'internal_defaultExpDays', '3', '3'],
+ ]);
+ } else {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_remote_expire_after_n_days', '7', '3'],
+ ['core', 'remote_defaultExpDays', '3', '3'],
+ ]);
+ }
$hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
@@ -969,7 +1074,10 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($expected, $share->getExpirationDate());
}
- public function testValidateExpirationDateInternalDefault() {
+ /**
+ * @dataProvider validateExpirationDateInternalProvider
+ */
+ public function testValidateExpirationDateInternalDefault($shareType) {
$future = new \DateTime();
$future->add(new \DateInterval('P5D'));
$future->setTime(1,2,3);
@@ -978,14 +1086,24 @@ class ManagerTest extends \Test\TestCase {
$expected->setTime(0,0,0);
$share = $this->manager->newShare();
+ $share->setShareType($shareType);
$share->setExpirationDate($future);
- $this->config->method('getAppValue')
- ->willReturnMap([
- ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
- ['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
- ['core', 'internal_defaultExpDays', '3', '1'],
- ]);
+ if ($shareType === IShare::TYPE_USER) {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
+ ['core', 'internal_defaultExpDays', '3', '1'],
+ ]);
+ } else {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_remote_expire_after_n_days', '7', '3'],
+ ['core', 'remote_defaultExpDays', '3', '1'],
+ ]);
+ }
$hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
@@ -998,7 +1116,10 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($expected, $share->getExpirationDate());
}
- public function testValidateExpirationDateInternalHookModification() {
+ /**
+ * @dataProvider validateExpirationDateInternalProvider
+ */
+ public function testValidateExpirationDateInternalHookModification($shareType) {
$nextWeek = new \DateTime();
$nextWeek->add(new \DateInterval('P7D'));
$nextWeek->setTime(0,0,0);
@@ -1012,6 +1133,7 @@ class ManagerTest extends \Test\TestCase {
});
$share = $this->manager->newShare();
+ $share->setShareType($shareType);
$share->setExpirationDate($nextWeek);
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
@@ -1020,7 +1142,10 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($save, $share->getExpirationDate());
}
- public function testValidateExpirationDateInternalHookException() {
+ /**
+ * @dataProvider validateExpirationDateInternalProvider
+ */
+ public function testValidateExpirationDateInternalHookException($shareType) {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Invalid date!');
@@ -1029,6 +1154,7 @@ class ManagerTest extends \Test\TestCase {
$nextWeek->setTime(0,0,0);
$share = $this->manager->newShare();
+ $share->setShareType($shareType);
$share->setExpirationDate($nextWeek);
$hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
@@ -1041,16 +1167,27 @@ class ManagerTest extends \Test\TestCase {
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
}
- public function testValidateExpirationDateInternalExistingShareNoDefault() {
+ /**
+ * @dataProvider validateExpirationDateInternalProvider
+ */
+ public function testValidateExpirationDateInternalExistingShareNoDefault($shareType) {
$share = $this->manager->newShare();
-
+ $share->setShareType($shareType);
$share->setId('42')->setProviderId('foo');
- $this->config->method('getAppValue')
- ->willReturnMap([
- ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
- ['core', 'shareapi_internal_expire_after_n_days', '7', '6'],
- ]);
+ if ($shareType === IShare::TYPE_USER) {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_internal_expire_after_n_days', '7', '6'],
+ ]);
+ } else {
+ $this->config->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
+ ['core', 'shareapi_remote_expire_after_n_days', '7', '6'],
+ ]);
+ }
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);