]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix enabling send password by Talk with empty password in link shares
authorDaniel Calviño Sánchez <danxuliu@gmail.com>
Thu, 28 May 2020 18:29:28 +0000 (20:29 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Fri, 29 May 2020 19:38:28 +0000 (19:38 +0000)
When "send password by Talk" is enabled in a link share now a non empty
password is enforced.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
lib/private/Share20/Manager.php
tests/lib/Share20/ManagerTest.php

index 73860fd39f42baa344be1c5d6029fa6a2f4bd1af..f88d884c0db569e6b23cd9e467c39104aa8d90bb 100644 (file)
@@ -972,8 +972,14 @@ class Manager implements IManager {
                } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                        $this->linkCreateChecks($share);
 
+                       $plainTextPassword = $share->getPassword();
+
                        $this->updateSharePasswordIfNeeded($share, $originalShare);
 
+                       if (empty($plainTextPassword) && $share->getSendPasswordByTalk()) {
+                               throw new \InvalidArgumentException('Can’t enable sending the password by Talk with an empty password');
+                       }
+
                        if ($share->getExpirationDate() != $originalShare->getExpirationDate()) {
                                //Verify the expiration date
                                $this->validateExpirationDate($share);
index 9bc1531ac7fb9e810478721fda14d4ac4bdc410e..962974b231d5e9ad21d7fa31829ed19a8d2a6a3f 100644 (file)
@@ -2732,6 +2732,75 @@ 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([