From bd431e2e5988a5d33c8f883c06f1988b0e98c1d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Wed, 11 Nov 2020 19:34:26 +0100 Subject: [PATCH 01/15] Fix typos in method names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- tests/lib/Share20/ManagerTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index f2086e388d..464709645f 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -765,7 +765,7 @@ class ManagerTest extends \Test\TestCase { } - public function testvalidateExpirationDateInPast() { + public function testValidateExpirationDateInPast() { $this->expectException(\OCP\Share\Exceptions\GenericShareException::class); $this->expectExceptionMessage('Expiration date is in the past'); @@ -781,7 +781,7 @@ class ManagerTest extends \Test\TestCase { } - public function testvalidateExpirationDateEnforceButNotSet() { + public function testValidateExpirationDateEnforceButNotSet() { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Expiration date is enforced'); @@ -797,7 +797,7 @@ class ManagerTest extends \Test\TestCase { self::invokePrivate($this->manager, 'validateExpirationDate', [$share]); } - public function testvalidateExpirationDateEnforceButNotEnabledAndNotSet() { + public function testValidateExpirationDateEnforceButNotEnabledAndNotSet() { $share = $this->manager->newShare(); $share->setProviderId('foo')->setId('bar'); @@ -811,7 +811,7 @@ class ManagerTest extends \Test\TestCase { $this->assertNull($share->getExpirationDate()); } - public function testvalidateExpirationDateEnforceButNotSetNewShare() { + public function testValidateExpirationDateEnforceButNotSetNewShare() { $share = $this->manager->newShare(); $this->config->method('getAppValue') @@ -832,7 +832,7 @@ class ManagerTest extends \Test\TestCase { $this->assertEquals($expected, $share->getExpirationDate()); } - public function testvalidateExpirationDateEnforceToFarIntoFuture() { + public function testValidateExpirationDateEnforceTooFarIntoFuture() { // Expire date in the past $future = new \DateTime(); $future->add(new \DateInterval('P7D')); @@ -856,7 +856,7 @@ class ManagerTest extends \Test\TestCase { } } - public function testvalidateExpirationDateEnforceValid() { + public function testValidateExpirationDateEnforceValid() { // Expire date in the past $future = new \DateTime(); $future->add(new \DateInterval('P2D')); @@ -885,7 +885,7 @@ class ManagerTest extends \Test\TestCase { $this->assertEquals($expected, $share->getExpirationDate()); } - public function testvalidateExpirationDateNoDateNoDefaultNull() { + public function testValidateExpirationDateNoDateNoDefaultNull() { $date = new \DateTime(); $date->add(new \DateInterval('P5D')); @@ -906,7 +906,7 @@ class ManagerTest extends \Test\TestCase { $this->assertEquals($expected, $share->getExpirationDate()); } - public function testvalidateExpirationDateNoDateNoDefault() { + public function testValidateExpirationDateNoDateNoDefault() { $hookListner = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListner, 'listener'); $hookListner->expects($this->once())->method('listener')->with($this->callback(function ($data) { @@ -921,7 +921,7 @@ class ManagerTest extends \Test\TestCase { $this->assertNull($share->getExpirationDate()); } - public function testvalidateExpirationDateNoDateDefault() { + public function testValidateExpirationDateNoDateDefault() { $future = new \DateTime(); $future->add(new \DateInterval('P3D')); $future->setTime(0,0,0); From 53e73dc46fc72290cd6687f6c31384fa5346470c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Wed, 11 Nov 2020 19:55:20 +0100 Subject: [PATCH 02/15] Fix typo in variable name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- tests/lib/Share20/ManagerTest.php | 258 +++++++++++++++--------------- 1 file changed, 129 insertions(+), 129 deletions(-) diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 464709645f..248c687230 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -874,9 +874,9 @@ class ManagerTest extends \Test\TestCase { ['core', 'shareapi_expire_after_n_days', '7', '3'], ]); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); - \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListner, 'listener'); - $hookListner->expects($this->once())->method('listener')->with($this->callback(function ($data) use ($future) { + $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) use ($future) { return $data['expirationDate'] == $future; })); @@ -895,9 +895,9 @@ class ManagerTest extends \Test\TestCase { $share = $this->manager->newShare(); $share->setExpirationDate($date); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); - \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListner, 'listener'); - $hookListner->expects($this->once())->method('listener')->with($this->callback(function ($data) use ($expected) { + $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) use ($expected) { return $data['expirationDate'] == $expected && $data['passwordSet'] === false; })); @@ -907,9 +907,9 @@ class ManagerTest extends \Test\TestCase { } public function testValidateExpirationDateNoDateNoDefault() { - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); - \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListner, 'listener'); - $hookListner->expects($this->once())->method('listener')->with($this->callback(function ($data) { + $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) { return $data['expirationDate'] === null && $data['passwordSet'] === true; })); @@ -937,9 +937,9 @@ class ManagerTest extends \Test\TestCase { ['core', 'shareapi_expire_after_n_days', '7', '3'], ]); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); - \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListner, 'listener'); - $hookListner->expects($this->once())->method('listener')->with($this->callback(function ($data) use ($expected) { + $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) use ($expected) { return $data['expirationDate'] == $expected; })); @@ -955,9 +955,9 @@ class ManagerTest extends \Test\TestCase { $save = clone $nextWeek; - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); - \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListner, 'listener'); - $hookListner->expects($this->once())->method('listener')->willReturnCallback(function ($data) { + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); + \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); + $hookListener->expects($this->once())->method('listener')->willReturnCallback(function ($data) { $data['expirationDate']->sub(new \DateInterval('P2D')); }); @@ -982,9 +982,9 @@ class ManagerTest extends \Test\TestCase { $share = $this->manager->newShare(); $share->setExpirationDate($nextWeek); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); - \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListner, 'listener'); - $hookListner->expects($this->once())->method('listener')->willReturnCallback(function ($data) { + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); + \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); + $hookListener->expects($this->once())->method('listener')->willReturnCallback(function ($data) { $data['accepted'] = false; $data['message'] = 'Invalid date!'; }); @@ -2606,16 +2606,16 @@ class ManagerTest extends \Test\TestCase { ->with($share) ->willReturn($share); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); - $hookListner->expects($this->never())->method('post'); + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); + $hookListener->expects($this->never())->method('post'); $this->rootFolder->method('getUserFolder')->with('newUser')->willReturnSelf(); $this->rootFolder->method('getRelativePath')->with('/newUser/files/myPath')->willReturn('/myPath'); - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner2, 'post'); - $hookListner2->expects($this->once())->method('post')->with([ + $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener2, 'post'); + $hookListener2->expects($this->once())->method('post')->with([ 'itemType' => 'file', 'itemSource' => 100, 'shareType' => \OCP\Share::SHARE_TYPE_USER, @@ -2663,13 +2663,13 @@ class ManagerTest extends \Test\TestCase { ->with($share) ->willReturn($share); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); - $hookListner->expects($this->never())->method('post'); + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); + $hookListener->expects($this->never())->method('post'); - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner2, 'post'); - $hookListner2->expects($this->never())->method('post'); + $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener2, 'post'); + $hookListener2->expects($this->never())->method('post'); $manager->updateShare($share); } @@ -2725,18 +2725,18 @@ class ManagerTest extends \Test\TestCase { ->with($share) ->willReturn($share); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); - $hookListner->expects($this->once())->method('post')->with([ + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); + $hookListener->expects($this->once())->method('post')->with([ 'itemType' => 'file', 'itemSource' => 100, 'date' => $tomorrow, 'uidOwner' => 'owner', ]); - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListner2, 'post'); - $hookListner2->expects($this->once())->method('post')->with([ + $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post'); + $hookListener2->expects($this->once())->method('post')->with([ 'itemType' => 'file', 'itemSource' => 100, 'uidOwner' => 'owner', @@ -2744,9 +2744,9 @@ class ManagerTest extends \Test\TestCase { 'disabled' => false, ]); - $hookListner3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner3, 'post'); - $hookListner3->expects($this->never())->method('post'); + $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post'); + $hookListener3->expects($this->never())->method('post'); $manager->updateShare($share); @@ -2806,17 +2806,17 @@ class ManagerTest extends \Test\TestCase { $this->defaultProvider->expects($this->never()) ->method('update'); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); - $hookListner->expects($this->never())->method('post'); + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); + $hookListener->expects($this->never())->method('post'); - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListner2, 'post'); - $hookListner2->expects($this->never())->method('post'); + $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post'); + $hookListener2->expects($this->never())->method('post'); - $hookListner3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner3, 'post'); - $hookListner3->expects($this->never())->method('post'); + $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post'); + $hookListener3->expects($this->never())->method('post'); $manager->updateShare($share); } @@ -2875,13 +2875,13 @@ class ManagerTest extends \Test\TestCase { ->with($share, 'password') ->willReturn($share); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); - $hookListner->expects($this->never())->method('post'); + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); + $hookListener->expects($this->never())->method('post'); - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListner2, 'post'); - $hookListner2->expects($this->once())->method('post')->with([ + $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post'); + $hookListener2->expects($this->once())->method('post')->with([ 'itemType' => 'file', 'itemSource' => 100, 'uidOwner' => 'owner', @@ -2889,9 +2889,9 @@ class ManagerTest extends \Test\TestCase { 'disabled' => false, ]); - $hookListner3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner3, 'post'); - $hookListner3->expects($this->never())->method('post'); + $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post'); + $hookListener3->expects($this->never())->method('post'); $manager->updateShare($share); } @@ -2953,13 +2953,13 @@ class ManagerTest extends \Test\TestCase { ->with($share, 'password') ->willReturn($share); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); - $hookListner->expects($this->never())->method('post'); + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); + $hookListener->expects($this->never())->method('post'); - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListner2, 'post'); - $hookListner2->expects($this->once())->method('post')->with([ + $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post'); + $hookListener2->expects($this->once())->method('post')->with([ 'itemType' => 'file', 'itemSource' => 100, 'uidOwner' => 'owner', @@ -2967,9 +2967,9 @@ class ManagerTest extends \Test\TestCase { 'disabled' => false, ]); - $hookListner3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner3, 'post'); - $hookListner3->expects($this->never())->method('post'); + $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post'); + $hookListener3->expects($this->never())->method('post'); $manager->updateShare($share); } @@ -3036,13 +3036,13 @@ class ManagerTest extends \Test\TestCase { ->with($share, 'password') ->willReturn($share); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); - $hookListner->expects($this->never())->method('post'); + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); + $hookListener->expects($this->never())->method('post'); - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListner2, 'post'); - $hookListner2->expects($this->once())->method('post')->with([ + $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post'); + $hookListener2->expects($this->once())->method('post')->with([ 'itemType' => 'file', 'itemSource' => 100, 'uidOwner' => 'owner', @@ -3050,9 +3050,9 @@ class ManagerTest extends \Test\TestCase { 'disabled' => false, ]); - $hookListner3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner3, 'post'); - $hookListner3->expects($this->never())->method('post'); + $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post'); + $hookListener3->expects($this->never())->method('post'); $manager->updateShare($share); } @@ -3113,17 +3113,17 @@ class ManagerTest extends \Test\TestCase { $this->defaultProvider->expects($this->never()) ->method('update'); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); - $hookListner->expects($this->never())->method('post'); + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); + $hookListener->expects($this->never())->method('post'); - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListner2, 'post'); - $hookListner2->expects($this->never())->method('post'); + $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post'); + $hookListener2->expects($this->never())->method('post'); - $hookListner3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner3, 'post'); - $hookListner3->expects($this->never())->method('post'); + $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post'); + $hookListener3->expects($this->never())->method('post'); $manager->updateShare($share); } @@ -3185,17 +3185,17 @@ class ManagerTest extends \Test\TestCase { $this->defaultProvider->expects($this->never()) ->method('update'); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); - $hookListner->expects($this->never())->method('post'); + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); + $hookListener->expects($this->never())->method('post'); - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListner2, 'post'); - $hookListner2->expects($this->never())->method('post'); + $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post'); + $hookListener2->expects($this->never())->method('post'); - $hookListner3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner3, 'post'); - $hookListner3->expects($this->never())->method('post'); + $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post'); + $hookListener3->expects($this->never())->method('post'); $manager->updateShare($share); } @@ -3257,17 +3257,17 @@ class ManagerTest extends \Test\TestCase { $this->defaultProvider->expects($this->never()) ->method('update'); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); - $hookListner->expects($this->never())->method('post'); + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); + $hookListener->expects($this->never())->method('post'); - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListner2, 'post'); - $hookListner2->expects($this->never())->method('post'); + $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post'); + $hookListener2->expects($this->never())->method('post'); - $hookListner3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner3, 'post'); - $hookListner3->expects($this->never())->method('post'); + $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post'); + $hookListener3->expects($this->never())->method('post'); $manager->updateShare($share); } @@ -3334,17 +3334,17 @@ class ManagerTest extends \Test\TestCase { $this->defaultProvider->expects($this->never()) ->method('update'); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); - $hookListner->expects($this->never())->method('post'); + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); + $hookListener->expects($this->never())->method('post'); - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListner2, 'post'); - $hookListner2->expects($this->never())->method('post'); + $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post'); + $hookListener2->expects($this->never())->method('post'); - $hookListner3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner3, 'post'); - $hookListner3->expects($this->never())->method('post'); + $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post'); + $hookListener3->expects($this->never())->method('post'); $manager->updateShare($share); } @@ -3410,17 +3410,17 @@ class ManagerTest extends \Test\TestCase { $this->defaultProvider->expects($this->never()) ->method('update'); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); - $hookListner->expects($this->never())->method('post'); + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); + $hookListener->expects($this->never())->method('post'); - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListner2, 'post'); - $hookListner2->expects($this->never())->method('post'); + $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post'); + $hookListener2->expects($this->never())->method('post'); - $hookListner3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner3, 'post'); - $hookListner3->expects($this->never())->method('post'); + $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post'); + $hookListener3->expects($this->never())->method('post'); $manager->updateShare($share); } @@ -3484,17 +3484,17 @@ class ManagerTest extends \Test\TestCase { $this->defaultProvider->expects($this->never()) ->method('update'); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); - $hookListner->expects($this->never())->method('post'); + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); + $hookListener->expects($this->never())->method('post'); - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListner2, 'post'); - $hookListner2->expects($this->never())->method('post'); + $hookListener2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListener2, 'post'); + $hookListener2->expects($this->never())->method('post'); - $hookListner3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner3, 'post'); - $hookListner3->expects($this->never())->method('post'); + $hookListener3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); + \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener3, 'post'); + $hookListener3->expects($this->never())->method('post'); $manager->updateShare($share); } From 9e84664f216b72e317bb33c1004feb10d047e463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 12 Nov 2020 09:38:20 +0100 Subject: [PATCH 03/15] Remove extra spaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- tests/lib/Share20/ManagerTest.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 248c687230..6f5a9c8f5b 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -769,7 +769,6 @@ class ManagerTest extends \Test\TestCase { $this->expectException(\OCP\Share\Exceptions\GenericShareException::class); $this->expectExceptionMessage('Expiration date is in the past'); - // Expire date in the past $past = new \DateTime(); $past->sub(new \DateInterval('P1D')); @@ -780,7 +779,6 @@ class ManagerTest extends \Test\TestCase { self::invokePrivate($this->manager, 'validateExpirationDate', [$share]); } - public function testValidateExpirationDateEnforceButNotSet() { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Expiration date is enforced'); @@ -875,7 +873,7 @@ class ManagerTest extends \Test\TestCase { ]); $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); - \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); + \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); $hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) use ($future) { return $data['expirationDate'] == $future; })); @@ -896,7 +894,7 @@ class ManagerTest extends \Test\TestCase { $share->setExpirationDate($date); $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); - \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); + \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); $hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) use ($expected) { return $data['expirationDate'] == $expected && $data['passwordSet'] === false; })); @@ -908,7 +906,7 @@ class ManagerTest extends \Test\TestCase { public function testValidateExpirationDateNoDateNoDefault() { $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); - \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); + \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); $hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) { return $data['expirationDate'] === null && $data['passwordSet'] === true; })); @@ -938,7 +936,7 @@ class ManagerTest extends \Test\TestCase { ]); $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); - \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); + \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); $hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) use ($expected) { return $data['expirationDate'] == $expected; })); @@ -956,7 +954,7 @@ class ManagerTest extends \Test\TestCase { $save = clone $nextWeek; $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); - \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); + \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); $hookListener->expects($this->once())->method('listener')->willReturnCallback(function ($data) { $data['expirationDate']->sub(new \DateInterval('P2D')); }); @@ -970,7 +968,6 @@ class ManagerTest extends \Test\TestCase { $this->assertEquals($save, $share->getExpirationDate()); } - public function testValidateExpirationDateHookException() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Invalid date!'); @@ -983,7 +980,7 @@ class ManagerTest extends \Test\TestCase { $share->setExpirationDate($nextWeek); $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); - \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); + \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); $hookListener->expects($this->once())->method('listener')->willReturnCallback(function ($data) { $data['accepted'] = false; $data['message'] = 'Invalid date!'; @@ -1008,7 +1005,6 @@ class ManagerTest extends \Test\TestCase { $this->assertEquals(null, $share->getExpirationDate()); } - public function testUserCreateChecksShareWithGroupMembersOnlyDifferentGroups() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Sharing is only allowed with group members'); From 24f067bdaf8fe8316282b4ee71a2155462e24572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Wed, 11 Nov 2020 20:27:01 +0100 Subject: [PATCH 04/15] Remove wrong and misleading comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- tests/lib/Share20/ManagerTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 6f5a9c8f5b..19232504eb 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -831,7 +831,6 @@ class ManagerTest extends \Test\TestCase { } public function testValidateExpirationDateEnforceTooFarIntoFuture() { - // Expire date in the past $future = new \DateTime(); $future->add(new \DateInterval('P7D')); @@ -855,7 +854,6 @@ class ManagerTest extends \Test\TestCase { } public function testValidateExpirationDateEnforceValid() { - // Expire date in the past $future = new \DateTime(); $future->add(new \DateInterval('P2D')); $future->setTime(0,0,0); From 94648f1ecdc567b3ed2a09299d69c487c65811c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Wed, 11 Nov 2020 19:36:04 +0100 Subject: [PATCH 05/15] Add unit tests to enforce a relaxed default share expiration date MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- tests/lib/Share20/ManagerTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 19232504eb..aa3f1e93ff 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -830,6 +830,27 @@ class ManagerTest extends \Test\TestCase { $this->assertEquals($expected, $share->getExpirationDate()); } + public function testValidateExpirationDateEnforceRelaxedDefaultButNotSetNewShare() { + $share = $this->manager->newShare(); + + $this->config->method('getAppValue') + ->willReturnMap([ + ['core', 'shareapi_enforce_expire_date', 'no', 'yes'], + ['core', 'shareapi_expire_after_n_days', '7', '3'], + ['core', 'shareapi_default_expire_date', 'no', 'yes'], + ['core', 'link_defaultExpDays', 3, '1'], + ]); + + $expected = new \DateTime(); + $expected->setTime(0,0,0); + $expected->add(new \DateInterval('P1D')); + + self::invokePrivate($this->manager, 'validateExpirationDate', [$share]); + + $this->assertNotNull($share->getExpirationDate()); + $this->assertEquals($expected, $share->getExpirationDate()); + } + public function testValidateExpirationDateEnforceTooFarIntoFuture() { $future = new \DateTime(); $future->add(new \DateInterval('P7D')); From 42782ceeba97e0953e2d62a4eb68238203ccd3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Wed, 11 Nov 2020 20:50:23 +0100 Subject: [PATCH 06/15] Fix unit test for verifying enforced expire date too far in the future MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test should fail if no exception was thrown, and no exception was thrown due to a missing configuration parameter. However, the use of "addToAssertionCount(1)" made the test pass even if no exception was thrown and, therefore, to silently fail. Now the missing configuration parameter was added and the test will fail if the expected exception is not thrown. Signed-off-by: Daniel Calviño Sánchez --- tests/lib/Share20/ManagerTest.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index aa3f1e93ff..6a7d629086 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -852,6 +852,9 @@ class ManagerTest extends \Test\TestCase { } public function testValidateExpirationDateEnforceTooFarIntoFuture() { + $this->expectException(\OCP\Share\Exceptions\GenericShareException::class); + $this->expectExceptionMessage('Can’t set expiration date more than 3 days in the future'); + $future = new \DateTime(); $future->add(new \DateInterval('P7D')); @@ -862,16 +865,10 @@ class ManagerTest extends \Test\TestCase { ->willReturnMap([ ['core', 'shareapi_enforce_expire_date', 'no', 'yes'], ['core', 'shareapi_expire_after_n_days', '7', '3'], + ['core', 'shareapi_default_expire_date', 'no', 'yes'], ]); - try { - self::invokePrivate($this->manager, 'validateExpirationDate', [$share]); - $this->addToAssertionCount(1); - } catch (\OCP\Share\Exceptions\GenericShareException $e) { - $this->assertEquals('Cannot set expiration date more than 3 days in the future', $e->getMessage()); - $this->assertEquals('Cannot set expiration date more than 3 days in the future', $e->getHint()); - $this->assertEquals(404, $e->getCode()); - } + self::invokePrivate($this->manager, 'validateExpirationDate', [$share]); } public function testValidateExpirationDateEnforceValid() { From e13c5ece4f811da8f89259294af7944af5e1ce81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 12 Nov 2020 08:25:36 +0100 Subject: [PATCH 07/15] Fix unit test for verifying enforced valid expiration date. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The enforced expiration date was not actually enabled, as for that "shareapi_default_expire_date" needs to be explicitly set to "yes". Signed-off-by: Daniel Calviño Sánchez --- tests/lib/Share20/ManagerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 6a7d629086..88dfc8bd64 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -886,6 +886,7 @@ class ManagerTest extends \Test\TestCase { ->willReturnMap([ ['core', 'shareapi_enforce_expire_date', 'no', 'yes'], ['core', 'shareapi_expire_after_n_days', '7', '3'], + ['core', 'shareapi_default_expire_date', 'no', 'yes'], ]); $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); From 2e0352182b08977f4db521ae42a5e65dba30e748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 12 Nov 2020 08:46:37 +0100 Subject: [PATCH 08/15] Fix unit test method name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- tests/lib/Share20/ManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 88dfc8bd64..ac4cc15a50 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -900,7 +900,7 @@ class ManagerTest extends \Test\TestCase { $this->assertEquals($expected, $share->getExpirationDate()); } - public function testValidateExpirationDateNoDateNoDefaultNull() { + public function testValidateExpirationDateNoDefault() { $date = new \DateTime(); $date->add(new \DateInterval('P5D')); From 1aed47693716b8066081955de8d7d0e0fc6794a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 12 Nov 2020 09:34:58 +0100 Subject: [PATCH 09/15] Fix unit test for expiration date without date but with default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The expiration date was explicitly given, so it was not testing what it should. Moreover, "link_defaultExpDays" needs to be mapped when testing the default value (even if it will just fallback to the value of "shareapi_expire_after_n_days"). Signed-off-by: Daniel Calviño Sánchez --- tests/lib/Share20/ManagerTest.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index ac4cc15a50..d76b76f8b0 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -937,19 +937,17 @@ class ManagerTest extends \Test\TestCase { } public function testValidateExpirationDateNoDateDefault() { - $future = new \DateTime(); - $future->add(new \DateInterval('P3D')); - $future->setTime(0,0,0); - - $expected = clone $future; - $share = $this->manager->newShare(); - $share->setExpirationDate($future); + + $expected = new \DateTime(); + $expected->add(new \DateInterval('P3D')); + $expected->setTime(0,0,0); $this->config->method('getAppValue') ->willReturnMap([ ['core', 'shareapi_default_expire_date', 'no', 'yes'], ['core', 'shareapi_expire_after_n_days', '7', '3'], + ['core', 'link_defaultExpDays', 3, '3'], ]); $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); From 16b1b655cf283633128f290776105557d84d2e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 12 Nov 2020 09:35:34 +0100 Subject: [PATCH 10/15] Add unit test for expiration date with date and with default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds back what was being actually tested in the unit test fixed in the previous commit. Signed-off-by: Daniel Calviño Sánchez --- tests/lib/Share20/ManagerTest.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index d76b76f8b0..12b36af64d 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -961,6 +961,34 @@ class ManagerTest extends \Test\TestCase { $this->assertEquals($expected, $share->getExpirationDate()); } + public function testValidateExpirationDateDefault() { + $future = new \DateTime(); + $future->add(new \DateInterval('P5D')); + $future->setTime(0,0,0); + + $expected = clone $future; + + $share = $this->manager->newShare(); + $share->setExpirationDate($future); + + $this->config->method('getAppValue') + ->willReturnMap([ + ['core', 'shareapi_default_expire_date', 'no', 'yes'], + ['core', 'shareapi_expire_after_n_days', '7', '3'], + ['core', 'link_defaultExpDays', 3, '1'], + ]); + + $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) use ($expected) { + return $data['expirationDate'] == $expected; + })); + + self::invokePrivate($this->manager, 'validateExpirationDate', [$share]); + + $this->assertEquals($expected, $share->getExpirationDate()); + } + public function testValidateExpirationDateHookModification() { $nextWeek = new \DateTime(); $nextWeek->add(new \DateInterval('P7D')); From ca133ea2cc08fd0e6df4608d63e9f3f7be95de39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 12 Nov 2020 08:43:03 +0100 Subject: [PATCH 11/15] Add explicit time to test date for clarity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This shows in a clearer way that the expected expiration date is the original one, but without time. Signed-off-by: Daniel Calviño Sánchez --- tests/lib/Share20/ManagerTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 12b36af64d..735e62d843 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -874,10 +874,10 @@ class ManagerTest extends \Test\TestCase { public function testValidateExpirationDateEnforceValid() { $future = new \DateTime(); $future->add(new \DateInterval('P2D')); - $future->setTime(0,0,0); + $future->setTime(1,2,3); $expected = clone $future; - $future->setTime(1,2,3); + $expected->setTime(0,0,0); $share = $this->manager->newShare(); $share->setExpirationDate($future); @@ -903,6 +903,7 @@ class ManagerTest extends \Test\TestCase { public function testValidateExpirationDateNoDefault() { $date = new \DateTime(); $date->add(new \DateInterval('P5D')); + $date->setTime(1,2,3); $expected = clone $date; $expected->setTime(0,0,0); @@ -964,9 +965,10 @@ class ManagerTest extends \Test\TestCase { public function testValidateExpirationDateDefault() { $future = new \DateTime(); $future->add(new \DateInterval('P5D')); - $future->setTime(0,0,0); + $future->setTime(1,2,3); $expected = clone $future; + $expected->setTime(0,0,0); $share = $this->manager->newShare(); $share->setExpirationDate($future); From dd70a20da0a59c5af847ca9df3acaa783bb1a7c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 12 Nov 2020 11:49:40 +0100 Subject: [PATCH 12/15] Fix default internal expiration date MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The default expiration date for internal shares was set from the default link expiration date instead of the internal one. Signed-off-by: Daniel Calviño Sánchez --- lib/private/Share20/Manager.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 18f2643485..35374fd167 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -409,9 +409,9 @@ class Manager implements IManager { $expirationDate = new \DateTime(); $expirationDate->setTime(0,0,0); - $days = (int)$this->config->getAppValue('core', 'internal_defaultExpDays', $this->shareApiLinkDefaultExpireDays()); - if ($days > $this->shareApiLinkDefaultExpireDays()) { - $days = $this->shareApiLinkDefaultExpireDays(); + $days = (int)$this->config->getAppValue('core', 'internal_defaultExpDays', (string)$this->shareApiInternalDefaultExpireDays()); + if ($days > $this->shareApiInternalDefaultExpireDays()) { + $days = $this->shareApiInternalDefaultExpireDays(); } $expirationDate->add(new \DateInterval('P'.$days.'D')); } From a50132e4e18ee4b8c6e5ee1b65f877b7ddda491d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 12 Nov 2020 11:50:16 +0100 Subject: [PATCH 13/15] Add unit tests for "validateExpirationDateInternal" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They were copied and adjusted as needed from the tests for "validateExpirationDate". Signed-off-by: Daniel Calviño Sánchez --- tests/lib/Share20/ManagerTest.php | 284 ++++++++++++++++++++++++++++++ 1 file changed, 284 insertions(+) diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 735e62d843..adb283a2db 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -764,6 +764,290 @@ class ManagerTest extends \Test\TestCase { self::invokePrivate($this->manager, 'generalCreateChecks', [$share]); } + public function testValidateExpirationDateInternalInPast() { + $this->expectException(\OCP\Share\Exceptions\GenericShareException::class); + $this->expectExceptionMessage('Expiration date is in the past'); + + // Expire date in the past + $past = new \DateTime(); + $past->sub(new \DateInterval('P1D')); + + $share = $this->manager->newShare(); + $share->setExpirationDate($past); + + self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); + } + + public function testValidateExpirationDateInternalEnforceButNotSet() { + $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'], + ]); + + self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); + } + + public function testValidateExpirationDateInternalEnforceButNotEnabledAndNotSet() { + $share = $this->manager->newShare(); + $share->setProviderId('foo')->setId('bar'); + + $this->config->method('getAppValue') + ->willReturnMap([ + ['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'], + ]); + + self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); + + $this->assertNull($share->getExpirationDate()); + } + + public function testValidateExpirationDateInternalEnforceButNotSetNewShare() { + $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'], + ]); + + $expected = new \DateTime(); + $expected->setTime(0,0,0); + $expected->add(new \DateInterval('P3D')); + + self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); + + $this->assertNotNull($share->getExpirationDate()); + $this->assertEquals($expected, $share->getExpirationDate()); + } + + public function testValidateExpirationDateInternalEnforceRelaxedDefaultButNotSetNewShare() { + $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'], + ]); + + $expected = new \DateTime(); + $expected->setTime(0,0,0); + $expected->add(new \DateInterval('P1D')); + + self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); + + $this->assertNotNull($share->getExpirationDate()); + $this->assertEquals($expected, $share->getExpirationDate()); + } + + public function testValidateExpirationDateInternalEnforceTooFarIntoFuture() { + $this->expectException(\OCP\Share\Exceptions\GenericShareException::class); + $this->expectExceptionMessage('Can’t set expiration date more than 3 days in the future'); + + $future = new \DateTime(); + $future->add(new \DateInterval('P7D')); + + $share = $this->manager->newShare(); + $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'], + ]); + + self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); + } + + public function testValidateExpirationDateInternalEnforceValid() { + $future = new \DateTime(); + $future->add(new \DateInterval('P2D')); + $future->setTime(1,2,3); + + $expected = clone $future; + $expected->setTime(0,0,0); + + $share = $this->manager->newShare(); + $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'], + ]); + + $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) use ($future) { + return $data['expirationDate'] == $future; + })); + + self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); + + $this->assertEquals($expected, $share->getExpirationDate()); + } + + public function testValidateExpirationDateInternalNoDefault() { + $date = new \DateTime(); + $date->add(new \DateInterval('P5D')); + $date->setTime(1,2,3); + + $expected = clone $date; + $expected->setTime(0,0,0); + + $share = $this->manager->newShare(); + $share->setExpirationDate($date); + + $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) use ($expected) { + return $data['expirationDate'] == $expected && $data['passwordSet'] === false; + })); + + self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); + + $this->assertEquals($expected, $share->getExpirationDate()); + } + + public function testValidateExpirationDateInternalNoDateNoDefault() { + $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) { + return $data['expirationDate'] === null && $data['passwordSet'] === true; + })); + + $share = $this->manager->newShare(); + $share->setPassword('password'); + + self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); + + $this->assertNull($share->getExpirationDate()); + } + + public function testValidateExpirationDateInternalNoDateDefault() { + $share = $this->manager->newShare(); + + $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'], + ]); + + $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) use ($expected) { + return $data['expirationDate'] == $expected; + })); + + self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); + + $this->assertEquals($expected, $share->getExpirationDate()); + } + + public function testValidateExpirationDateInternalDefault() { + $future = new \DateTime(); + $future->add(new \DateInterval('P5D')); + $future->setTime(1,2,3); + + $expected = clone $future; + $expected->setTime(0,0,0); + + $share = $this->manager->newShare(); + $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'], + ]); + + $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) use ($expected) { + return $data['expirationDate'] == $expected; + })); + + self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); + + $this->assertEquals($expected, $share->getExpirationDate()); + } + + public function testValidateExpirationDateInternalHookModification() { + $nextWeek = new \DateTime(); + $nextWeek->add(new \DateInterval('P7D')); + $nextWeek->setTime(0,0,0); + + $save = clone $nextWeek; + + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); + \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); + $hookListener->expects($this->once())->method('listener')->willReturnCallback(function ($data) { + $data['expirationDate']->sub(new \DateInterval('P2D')); + }); + + $share = $this->manager->newShare(); + $share->setExpirationDate($nextWeek); + + self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); + + $save->sub(new \DateInterval('P2D')); + $this->assertEquals($save, $share->getExpirationDate()); + } + + public function testValidateExpirationDateInternalHookException() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Invalid date!'); + + $nextWeek = new \DateTime(); + $nextWeek->add(new \DateInterval('P7D')); + $nextWeek->setTime(0,0,0); + + $share = $this->manager->newShare(); + $share->setExpirationDate($nextWeek); + + $hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock(); + \OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener'); + $hookListener->expects($this->once())->method('listener')->willReturnCallback(function ($data) { + $data['accepted'] = false; + $data['message'] = 'Invalid date!'; + }); + + self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); + } + + public function testValidateExpirationDateInternalExistingShareNoDefault() { + $share = $this->manager->newShare(); + + $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'], + ]); + + self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); + + $this->assertEquals(null, $share->getExpirationDate()); + } public function testValidateExpirationDateInPast() { $this->expectException(\OCP\Share\Exceptions\GenericShareException::class); From 8832d15069bb2cd0af3c7021f3d9f547b52ee679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 12 Nov 2020 11:51:37 +0100 Subject: [PATCH 14/15] Reset app configs by deleting the values instead of setting the defaults MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids the need to keep the default values in the integration tests in sync with the code, and also makes possible to reset values with "dynamic" defaults (defaults that depend on other values). Signed-off-by: Daniel Calviño Sánchez --- .../features/bootstrap/AppConfiguration.php | 13 +++++++++++ .../bootstrap/CapabilitiesContext.php | 22 +++++++++---------- .../features/bootstrap/FederationContext.php | 4 ++-- .../features/bootstrap/ShareesContext.php | 6 ++--- .../features/bootstrap/SharingContext.php | 4 ++-- 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/build/integration/features/bootstrap/AppConfiguration.php b/build/integration/features/bootstrap/AppConfiguration.php index b893637ba6..fe8308fd59 100644 --- a/build/integration/features/bootstrap/AppConfiguration.php +++ b/build/integration/features/bootstrap/AppConfiguration.php @@ -72,6 +72,19 @@ trait AppConfiguration { } } + /** + * @param string $app + * @param string $parameter + * @param string $value + */ + protected function deleteServerConfig($app, $parameter) { + $this->sendingTo('DELETE', "/apps/testing/api/v1/app/{$app}/{$parameter}"); + $this->theHTTPStatusCodeShouldBe('200'); + if ($this->apiVersion === 1) { + $this->theOCSStatusCodeShouldBe('100'); + } + } + protected function setStatusTestingApp($enabled) { $this->sendingTo(($enabled ? 'post' : 'delete'), '/cloud/apps/testing'); $this->theHTTPStatusCodeShouldBe('200'); diff --git a/build/integration/features/bootstrap/CapabilitiesContext.php b/build/integration/features/bootstrap/CapabilitiesContext.php index 19da7bc62c..7d450fa9cd 100644 --- a/build/integration/features/bootstrap/CapabilitiesContext.php +++ b/build/integration/features/bootstrap/CapabilitiesContext.php @@ -61,16 +61,16 @@ class CapabilitiesContext implements Context, SnippetAcceptingContext { } protected function resetAppConfigs() { - $this->modifyServerConfig('core', 'shareapi_enabled', 'yes'); - $this->modifyServerConfig('core', 'shareapi_allow_links', 'yes'); - $this->modifyServerConfig('core', 'shareapi_allow_public_upload', 'yes'); - $this->modifyServerConfig('core', 'shareapi_allow_resharing', 'yes'); - $this->modifyServerConfig('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); - $this->modifyServerConfig('files_sharing', 'incoming_server2server_share_enabled', 'yes'); - $this->modifyServerConfig('core', 'shareapi_enforce_links_password', 'no'); - $this->modifyServerConfig('core', 'shareapi_allow_public_notification', 'no'); - $this->modifyServerConfig('core', 'shareapi_default_expire_date', 'no'); - $this->modifyServerConfig('core', 'shareapi_enforce_expire_date', 'no'); - $this->modifyServerConfig('core', 'shareapi_allow_group_sharing', 'yes'); + $this->deleteServerConfig('core', 'shareapi_enabled'); + $this->deleteServerConfig('core', 'shareapi_allow_links'); + $this->deleteServerConfig('core', 'shareapi_allow_public_upload'); + $this->deleteServerConfig('core', 'shareapi_allow_resharing'); + $this->deleteServerConfig('files_sharing', 'outgoing_server2server_share_enabled'); + $this->deleteServerConfig('files_sharing', 'incoming_server2server_share_enabled'); + $this->deleteServerConfig('core', 'shareapi_enforce_links_password'); + $this->deleteServerConfig('core', 'shareapi_allow_public_notification'); + $this->deleteServerConfig('core', 'shareapi_default_expire_date'); + $this->deleteServerConfig('core', 'shareapi_enforce_expire_date'); + $this->deleteServerConfig('core', 'shareapi_allow_group_sharing'); } } diff --git a/build/integration/features/bootstrap/FederationContext.php b/build/integration/features/bootstrap/FederationContext.php index 13e0de4618..e119f950a4 100644 --- a/build/integration/features/bootstrap/FederationContext.php +++ b/build/integration/features/bootstrap/FederationContext.php @@ -97,7 +97,7 @@ class FederationContext implements Context, SnippetAcceptingContext { } protected function resetAppConfigs() { - $this->modifyServerConfig('files_sharing', 'incoming_server2server_group_share_enabled', 'no'); - $this->modifyServerConfig('files_sharing', 'outgoing_server2server_group_share_enabled', 'no'); + $this->deleteServerConfig('files_sharing', 'incoming_server2server_group_share_enabled'); + $this->deleteServerConfig('files_sharing', 'outgoing_server2server_group_share_enabled'); } } diff --git a/build/integration/features/bootstrap/ShareesContext.php b/build/integration/features/bootstrap/ShareesContext.php index 64896a8200..adfc63c063 100644 --- a/build/integration/features/bootstrap/ShareesContext.php +++ b/build/integration/features/bootstrap/ShareesContext.php @@ -36,8 +36,8 @@ class ShareesContext implements Context, SnippetAcceptingContext { use AppConfiguration; protected function resetAppConfigs() { - $this->modifyServerConfig('core', 'shareapi_only_share_with_group_members', 'no'); - $this->modifyServerConfig('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'); - $this->modifyServerConfig('core', 'shareapi_allow_group_sharing', 'yes'); + $this->deleteServerConfig('core', 'shareapi_only_share_with_group_members'); + $this->deleteServerConfig('core', 'shareapi_allow_share_dialog_user_enumeration'); + $this->deleteServerConfig('core', 'shareapi_allow_group_sharing'); } } diff --git a/build/integration/features/bootstrap/SharingContext.php b/build/integration/features/bootstrap/SharingContext.php index 4f497629a4..ef6c0508bc 100644 --- a/build/integration/features/bootstrap/SharingContext.php +++ b/build/integration/features/bootstrap/SharingContext.php @@ -36,7 +36,7 @@ class SharingContext implements Context, SnippetAcceptingContext { use CommandLine; protected function resetAppConfigs() { - $this->modifyServerConfig('core', 'shareapi_default_permissions', '31'); - $this->modifyServerConfig('sharebymail', 'enforcePasswordProtection', 'no'); + $this->deleteServerConfig('core', 'shareapi_default_permissions'); + $this->deleteServerConfig('sharebymail', 'enforcePasswordProtection'); } } From 4e094b71b67d60b966135adb80ef6b37585fef30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 12 Nov 2020 11:52:53 +0100 Subject: [PATCH 15/15] Add integration tests for creating shares with default expiration dates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- .../features/bootstrap/SharingContext.php | 6 + .../sharing_features/sharing-v1.feature | 106 ++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/build/integration/features/bootstrap/SharingContext.php b/build/integration/features/bootstrap/SharingContext.php index ef6c0508bc..eb109049c6 100644 --- a/build/integration/features/bootstrap/SharingContext.php +++ b/build/integration/features/bootstrap/SharingContext.php @@ -37,6 +37,12 @@ class SharingContext implements Context, SnippetAcceptingContext { protected function resetAppConfigs() { $this->deleteServerConfig('core', 'shareapi_default_permissions'); + $this->deleteServerConfig('core', 'shareapi_default_internal_expire_date'); + $this->deleteServerConfig('core', 'shareapi_internal_expire_after_n_days'); + $this->deleteServerConfig('core', 'internal_defaultExpDays'); + $this->deleteServerConfig('core', 'shareapi_default_expire_date'); + $this->deleteServerConfig('core', 'shareapi_expire_after_n_days'); + $this->deleteServerConfig('core', 'link_defaultExpDays'); $this->deleteServerConfig('sharebymail', 'enforcePasswordProtection'); } } diff --git a/build/integration/sharing_features/sharing-v1.feature b/build/integration/sharing_features/sharing-v1.feature index 38eb2d8a81..b5b4f5341a 100644 --- a/build/integration/sharing_features/sharing-v1.feature +++ b/build/integration/sharing_features/sharing-v1.feature @@ -391,6 +391,112 @@ Feature: sharing And Share fields of last share match with | permissions | 7 | + Scenario: Creating a new internal share with default expiration date + Given user "user0" exists + And user "user1" exists + And As an "user0" + And parameter "shareapi_default_internal_expire_date" of app "core" is set to "yes" + And parameter "shareapi_internal_expire_after_n_days" of app "core" is set to "3" + When creating a share with + | path | welcome.txt | + | shareWith | user1 | + | shareType | 0 | + And the OCS status code should be "100" + And the HTTP status code should be "200" + And Getting info of last share + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And Share fields of last share match with + | expiration | +3 days | + + Scenario: Creating a new internal share with relaxed default expiration date + Given user "user0" exists + And user "user1" exists + And As an "user0" + And parameter "shareapi_default_internal_expire_date" of app "core" is set to "yes" + And parameter "shareapi_internal_expire_after_n_days" of app "core" is set to "3" + And parameter "internal_defaultExpDays" of app "core" is set to "1" + When creating a share with + | path | welcome.txt | + | shareWith | user1 | + | shareType | 0 | + And the OCS status code should be "100" + And the HTTP status code should be "200" + And Getting info of last share + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And Share fields of last share match with + | expiration | +1 days | + + Scenario: Creating a new internal share with relaxed default expiration date too large + Given user "user0" exists + And user "user1" exists + And As an "user0" + And parameter "shareapi_default_internal_expire_date" of app "core" is set to "yes" + And parameter "shareapi_internal_expire_after_n_days" of app "core" is set to "3" + And parameter "internal_defaultExpDays" of app "core" is set to "10" + When creating a share with + | path | welcome.txt | + | shareWith | user1 | + | shareType | 0 | + And the OCS status code should be "100" + And the HTTP status code should be "200" + And Getting info of last share + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And Share fields of last share match with + | expiration | +3 days | + + Scenario: Creating a new link share with default expiration date + Given user "user0" exists + And As an "user0" + And parameter "shareapi_default_expire_date" of app "core" is set to "yes" + And parameter "shareapi_expire_after_n_days" of app "core" is set to "3" + When creating a share with + | path | welcome.txt | + | shareType | 3 | + And the OCS status code should be "100" + And the HTTP status code should be "200" + And Getting info of last share + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And Share fields of last share match with + | expiration | +3 days | + + Scenario: Creating a new link share with relaxed default expiration date + Given user "user0" exists + And As an "user0" + And parameter "shareapi_default_expire_date" of app "core" is set to "yes" + And parameter "shareapi_expire_after_n_days" of app "core" is set to "3" + And parameter "link_defaultExpDays" of app "core" is set to "1" + When creating a share with + | path | welcome.txt | + | shareType | 3 | + And the OCS status code should be "100" + And the HTTP status code should be "200" + And Getting info of last share + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And Share fields of last share match with + | expiration | +1 days | + + Scenario: Creating a new link share with relaxed default expiration date too large + Given user "user0" exists + And As an "user0" + And parameter "shareapi_default_expire_date" of app "core" is set to "yes" + And parameter "shareapi_expire_after_n_days" of app "core" is set to "3" + And parameter "link_defaultExpDays" of app "core" is set to "10" + When creating a share with + | path | welcome.txt | + | shareType | 3 | + And the OCS status code should be "100" + And the HTTP status code should be "200" + And Getting info of last share + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And Share fields of last share match with + | expiration | +3 days | + Scenario: getting all shares of a user using that user Given user "user0" exists And user "user1" exists