diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-05-29 22:35:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-29 22:35:57 +0300 |
commit | 555108dc65501ba08d0b70c05e0eaebd6379c4b1 (patch) | |
tree | a862562dc159c0f14178c9116d577e2304cbfc90 /tests | |
parent | c31b2d6ce15a71b681eabadcc4fce6d0f98f5cb2 (diff) |
Revert "[stable18] Fix password changes in link and mail shares"
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Share20/ManagerTest.php | 253 |
1 files changed, 9 insertions, 244 deletions
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 946c7192f37..9bc1531ac7f 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -2732,75 +2732,6 @@ class ManagerTest extends \Test\TestCase { $manager->updateShare($share); } - public function testUpdateShareLinkEnableSendPasswordByTalkWithNoPassword() { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Can’t enable sending the password by Talk with an empty password'); - - $manager = $this->createManagerMock() - ->setMethods([ - 'canShare', - 'getShareById', - 'generalCreateChecks', - 'linkCreateChecks', - 'pathCreateChecks', - 'verifyPassword', - 'validateExpirationDate', - ]) - ->getMock(); - - $originalShare = $this->manager->newShare(); - $originalShare->setShareType(\OCP\Share::SHARE_TYPE_LINK) - ->setPermissions(15); - - $tomorrow = new \DateTime(); - $tomorrow->setTime(0,0,0); - $tomorrow->add(new \DateInterval('P1D')); - - $file = $this->createMock(File::class); - $file->method('getId')->willReturn(100); - - $share = $this->manager->newShare(); - $share->setProviderId('foo') - ->setId('42') - ->setShareType(\OCP\Share::SHARE_TYPE_LINK) - ->setToken('token') - ->setSharedBy('owner') - ->setShareOwner('owner') - ->setPassword(null) - ->setSendPasswordByTalk(true) - ->setExpirationDate($tomorrow) - ->setNode($file) - ->setPermissions(15); - - $manager->expects($this->once())->method('canShare')->willReturn(true); - $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); - $manager->expects($this->once())->method('generalCreateChecks')->with($share); - $manager->expects($this->once())->method('linkCreateChecks')->with($share); - $manager->expects($this->never())->method('verifyPassword'); - $manager->expects($this->never())->method('pathCreateChecks'); - $manager->expects($this->never())->method('validateExpirationDate'); - - $this->hasher->expects($this->never()) - ->method('hash'); - - $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'); - - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListner2, 'post'); - $hookListner2->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'); - - $manager->updateShare($share); - } - public function testUpdateShareMail() { $manager = $this->createManagerMock() ->setMethods([ @@ -2954,88 +2885,6 @@ class ManagerTest extends \Test\TestCase { $manager->updateShare($share); } - public function testUpdateShareMailEnableSendPasswordByTalkWithDifferentPassword() { - $manager = $this->createManagerMock() - ->setMethods([ - 'canShare', - 'getShareById', - 'generalCreateChecks', - 'verifyPassword', - 'pathCreateChecks', - 'linkCreateChecks', - 'validateExpirationDate', - ]) - ->getMock(); - - $originalShare = $this->manager->newShare(); - $originalShare->setShareType(\OCP\Share::SHARE_TYPE_EMAIL) - ->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setPassword('anotherPasswordHash') - ->setSendPasswordByTalk(false); - - $tomorrow = new \DateTime(); - $tomorrow->setTime(0,0,0); - $tomorrow->add(new \DateInterval('P1D')); - - $file = $this->createMock(File::class); - $file->method('getId')->willReturn(100); - - $share = $this->manager->newShare(); - $share->setProviderId('foo') - ->setId('42') - ->setShareType(\OCP\Share::SHARE_TYPE_EMAIL) - ->setToken('token') - ->setSharedBy('owner') - ->setShareOwner('owner') - ->setPassword('password') - ->setSendPasswordByTalk(true) - ->setExpirationDate($tomorrow) - ->setNode($file) - ->setPermissions(\OCP\Constants::PERMISSION_ALL); - - $manager->expects($this->once())->method('canShare')->willReturn(true); - $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); - $manager->expects($this->once())->method('generalCreateChecks')->with($share); - $manager->expects($this->once())->method('verifyPassword')->with('password'); - $manager->expects($this->once())->method('pathCreateChecks')->with($file); - $manager->expects($this->never())->method('linkCreateChecks'); - $manager->expects($this->never())->method('validateExpirationDate'); - - $this->hasher->expects($this->once()) - ->method('verify') - ->with('password', 'anotherPasswordHash') - ->willReturn(false); - - $this->hasher->expects($this->once()) - ->method('hash') - ->with('password') - ->willReturn('hashed'); - - $this->defaultProvider->expects($this->once()) - ->method('update') - ->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'); - - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListner2, 'post'); - $hookListner2->expects($this->once())->method('post')->with([ - 'itemType' => 'file', - 'itemSource' => 100, - 'uidOwner' => 'owner', - 'token' => 'token', - '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'); - - $manager->updateShare($share); - } public function testUpdateShareMailEnableSendPasswordByTalkWithNoPassword() { $this->expectException(\InvalidArgumentException::class); @@ -3128,7 +2977,7 @@ class ManagerTest extends \Test\TestCase { $originalShare = $this->manager->newShare(); $originalShare->setShareType(\OCP\Share::SHARE_TYPE_EMAIL) ->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setPassword('passwordHash') + ->setPassword('password') ->setSendPasswordByTalk(false); $tomorrow = new \DateTime(); @@ -3200,7 +3049,7 @@ class ManagerTest extends \Test\TestCase { $originalShare = $this->manager->newShare(); $originalShare->setShareType(\OCP\Share::SHARE_TYPE_EMAIL) ->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setPassword('passwordHash') + ->setPassword('password') ->setSendPasswordByTalk(false); $tomorrow = new \DateTime(); @@ -3272,7 +3121,7 @@ class ManagerTest extends \Test\TestCase { $originalShare = $this->manager->newShare(); $originalShare->setShareType(\OCP\Share::SHARE_TYPE_EMAIL) ->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setPassword('passwordHash') + ->setPassword('password') ->setSendPasswordByTalk(false); $tomorrow = new \DateTime(); @@ -3303,11 +3152,6 @@ class ManagerTest extends \Test\TestCase { $manager->expects($this->never())->method('linkCreateChecks'); $manager->expects($this->never())->method('validateExpirationDate'); - $this->hasher->expects($this->once()) - ->method('verify') - ->with('password', 'passwordHash') - ->willReturn(true); - $this->hasher->expects($this->never()) ->method('hash'); @@ -3330,9 +3174,6 @@ class ManagerTest extends \Test\TestCase { } public function testUpdateShareMailDisableSendPasswordByTalkWithPreviousPassword() { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Can’t disable sending the password by Talk without setting a new password'); - $manager = $this->createManagerMock() ->setMethods([ 'canShare', @@ -3348,7 +3189,7 @@ class ManagerTest extends \Test\TestCase { $originalShare = $this->manager->newShare(); $originalShare->setShareType(\OCP\Share::SHARE_TYPE_EMAIL) ->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setPassword('passwordHash') + ->setPassword('password') ->setSendPasswordByTalk(true); $tomorrow = new \DateTime(); @@ -3374,21 +3215,18 @@ class ManagerTest extends \Test\TestCase { $manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); $manager->expects($this->once())->method('generalCreateChecks')->with($share); + $manager->expects($this->once())->method('pathCreateChecks')->with($file); $manager->expects($this->never())->method('verifyPassword'); - $manager->expects($this->never())->method('pathCreateChecks'); $manager->expects($this->never())->method('linkCreateChecks'); $manager->expects($this->never())->method('validateExpirationDate'); - $this->hasher->expects($this->once()) - ->method('verify') - ->with('password', 'passwordHash') - ->willReturn(true); - $this->hasher->expects($this->never()) ->method('hash'); - $this->defaultProvider->expects($this->never()) - ->method('update'); + $this->defaultProvider->expects($this->once()) + ->method('update') + ->with($share, 'password') + ->willReturn($share); $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); @@ -3405,79 +3243,6 @@ class ManagerTest extends \Test\TestCase { $manager->updateShare($share); } - public function testUpdateShareMailDisableSendPasswordByTalkWithoutChangingPassword() { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Can’t disable sending the password by Talk without setting a new password'); - - $manager = $this->createManagerMock() - ->setMethods([ - 'canShare', - 'getShareById', - 'generalCreateChecks', - 'verifyPassword', - 'pathCreateChecks', - 'linkCreateChecks', - 'validateExpirationDate', - ]) - ->getMock(); - - $originalShare = $this->manager->newShare(); - $originalShare->setShareType(\OCP\Share::SHARE_TYPE_EMAIL) - ->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setPassword('passwordHash') - ->setSendPasswordByTalk(true); - - $tomorrow = new \DateTime(); - $tomorrow->setTime(0,0,0); - $tomorrow->add(new \DateInterval('P1D')); - - $file = $this->createMock(File::class); - $file->method('getId')->willReturn(100); - - $share = $this->manager->newShare(); - $share->setProviderId('foo') - ->setId('42') - ->setShareType(\OCP\Share::SHARE_TYPE_EMAIL) - ->setToken('token') - ->setSharedBy('owner') - ->setShareOwner('owner') - ->setPassword('passwordHash') - ->setSendPasswordByTalk(false) - ->setExpirationDate($tomorrow) - ->setNode($file) - ->setPermissions(\OCP\Constants::PERMISSION_ALL); - - $manager->expects($this->once())->method('canShare')->willReturn(true); - $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); - $manager->expects($this->once())->method('generalCreateChecks')->with($share); - $manager->expects($this->never())->method('verifyPassword'); - $manager->expects($this->never())->method('pathCreateChecks'); - $manager->expects($this->never())->method('linkCreateChecks'); - $manager->expects($this->never())->method('validateExpirationDate'); - - $this->hasher->expects($this->never()) - ->method('verify'); - - $this->hasher->expects($this->never()) - ->method('hash'); - - $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'); - - $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListner2, 'post'); - $hookListner2->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'); - - $manager->updateShare($share); - } public function testMoveShareLink() { $this->expectException(\InvalidArgumentException::class); |