Honour "sendPasswordByTalk" property in mail shares
When a password was set for a mail share an e-mail was sent to the recipient with the password. Now the e-mail is no longer sent if the password is meant to be sent by Talk. However, before the e-mail was not sent when the share was updated but the password was not changed. Now an e-mail is sent in that case too if switching from a password sent by Talk to a password sent by mail. On the other hand, when switching from a password sent by mail to a password sent by Talk it is mandatory to change the password; otherwise the recipient would already have access to the share without having to call the sharer to verify her identity. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
parent
dd0c5e297e
commit
d582a66bea
|
@ -454,7 +454,7 @@ class ShareByMailProvider implements IShareProvider {
|
||||||
$initiator = $share->getSharedBy();
|
$initiator = $share->getSharedBy();
|
||||||
$shareWith = $share->getSharedWith();
|
$shareWith = $share->getSharedWith();
|
||||||
|
|
||||||
if ($password === '' || $this->settingsManager->sendPasswordByMail() === false) {
|
if ($password === '' || $this->settingsManager->sendPasswordByMail() === false || $share->getSendPasswordByTalk()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -707,7 +707,8 @@ class ShareByMailProvider implements IShareProvider {
|
||||||
// a real password was given
|
// a real password was given
|
||||||
$validPassword = $plainTextPassword !== null && $plainTextPassword !== '';
|
$validPassword = $plainTextPassword !== null && $plainTextPassword !== '';
|
||||||
|
|
||||||
if($validPassword && $originalShare->getPassword() !== $share->getPassword()) {
|
if($validPassword && ($originalShare->getPassword() !== $share->getPassword() ||
|
||||||
|
($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk()))) {
|
||||||
$this->sendPassword($share, $plainTextPassword);
|
$this->sendPassword($share, $plainTextPassword);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -38,6 +38,7 @@ use OCP\IUser;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use OCP\Mail\IEMailTemplate;
|
use OCP\Mail\IEMailTemplate;
|
||||||
use OCP\Mail\IMailer;
|
use OCP\Mail\IMailer;
|
||||||
|
use OCP\Mail\IMessage;
|
||||||
use OCP\Security\IHasher;
|
use OCP\Security\IHasher;
|
||||||
use OCP\Security\ISecureRandom;
|
use OCP\Security\ISecureRandom;
|
||||||
use OCP\Share\IManager;
|
use OCP\Share\IManager;
|
||||||
|
@ -204,6 +205,107 @@ class ShareByMailProviderTest extends TestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCreateSendPasswordByMailWithoutEnforcedPasswordProtection() {
|
||||||
|
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||||
|
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
|
||||||
|
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
|
||||||
|
$share->expects($this->any())->method('getSharedBy')->willReturn('owner');
|
||||||
|
|
||||||
|
$node = $this->getMockBuilder(File::class)->getMock();
|
||||||
|
$node->expects($this->any())->method('getName')->willReturn('filename');
|
||||||
|
|
||||||
|
$instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity']);
|
||||||
|
|
||||||
|
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
|
||||||
|
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
|
||||||
|
$instance->expects($this->once())->method('createShareActivity')->with($share);
|
||||||
|
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
|
||||||
|
$instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
|
||||||
|
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||||
|
|
||||||
|
// The autogenerated password should not be mailed.
|
||||||
|
$this->settingsManager->expects($this->any())->method('enforcePasswordProtection')->willReturn(false);
|
||||||
|
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
|
||||||
|
$instance->expects($this->never())->method('autoGeneratePassword');
|
||||||
|
|
||||||
|
$this->mailer->expects($this->never())->method('send');
|
||||||
|
|
||||||
|
$this->assertSame('shareObject',
|
||||||
|
$instance->create($share)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateSendPasswordByMailWithEnforcedPasswordProtection() {
|
||||||
|
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||||
|
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
|
||||||
|
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
|
||||||
|
$share->expects($this->any())->method('getSharedBy')->willReturn('owner');
|
||||||
|
|
||||||
|
$node = $this->getMockBuilder(File::class)->getMock();
|
||||||
|
$node->expects($this->any())->method('getName')->willReturn('filename');
|
||||||
|
|
||||||
|
$instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity']);
|
||||||
|
|
||||||
|
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
|
||||||
|
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
|
||||||
|
$instance->expects($this->once())->method('createShareActivity')->with($share);
|
||||||
|
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
|
||||||
|
$instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
|
||||||
|
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||||
|
|
||||||
|
// The autogenerated password should be mailed to the receiver of the share.
|
||||||
|
$this->settingsManager->expects($this->any())->method('enforcePasswordProtection')->willReturn(true);
|
||||||
|
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
|
||||||
|
$instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('password');
|
||||||
|
|
||||||
|
$message = $this->createMock(IMessage::class);
|
||||||
|
$message->expects($this->once())->method('setTo')->with(['receiver@example.com']);
|
||||||
|
$this->mailer->expects($this->once())->method('createMessage')->willReturn($message);
|
||||||
|
$this->mailer->expects($this->once())->method('send');
|
||||||
|
|
||||||
|
$this->assertSame('shareObject',
|
||||||
|
$instance->create($share)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateSendPasswordByTalkWithEnforcedPasswordProtection() {
|
||||||
|
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||||
|
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
|
||||||
|
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(true);
|
||||||
|
$share->expects($this->any())->method('getSharedBy')->willReturn('owner');
|
||||||
|
|
||||||
|
$node = $this->getMockBuilder(File::class)->getMock();
|
||||||
|
$node->expects($this->any())->method('getName')->willReturn('filename');
|
||||||
|
|
||||||
|
$instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity']);
|
||||||
|
|
||||||
|
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
|
||||||
|
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
|
||||||
|
$instance->expects($this->once())->method('createShareActivity')->with($share);
|
||||||
|
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
|
||||||
|
$instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
|
||||||
|
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||||
|
|
||||||
|
// The autogenerated password should be mailed to the owner of the share.
|
||||||
|
$this->settingsManager->expects($this->any())->method('enforcePasswordProtection')->willReturn(true);
|
||||||
|
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
|
||||||
|
$instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('password');
|
||||||
|
|
||||||
|
$message = $this->createMock(IMessage::class);
|
||||||
|
$message->expects($this->once())->method('setTo')->with(['owner@example.com' => 'Owner display name']);
|
||||||
|
$this->mailer->expects($this->once())->method('createMessage')->willReturn($message);
|
||||||
|
$this->mailer->expects($this->once())->method('send');
|
||||||
|
|
||||||
|
$user = $this->createMock(IUser::class);
|
||||||
|
$this->userManager->expects($this->once())->method('get')->with('owner')->willReturn($user);
|
||||||
|
$user->expects($this->once())->method('getDisplayName')->willReturn('Owner display name');
|
||||||
|
$user->expects($this->once())->method('getEMailAddress')->willReturn('owner@example.com');
|
||||||
|
|
||||||
|
$this->assertSame('shareObject',
|
||||||
|
$instance->create($share)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Exception
|
* @expectedException \Exception
|
||||||
*/
|
*/
|
||||||
|
@ -380,6 +482,60 @@ class ShareByMailProviderTest extends TestCase {
|
||||||
$this->assertSame($note, $result[0]['note']);
|
$this->assertSame($note, $result[0]['note']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataUpdateSendPassword() {
|
||||||
|
return [
|
||||||
|
['password', 'hashed', 'hashed new', false, false, true],
|
||||||
|
['', 'hashed', 'hashed new', false, false, false],
|
||||||
|
[null, 'hashed', 'hashed new', false, false, false],
|
||||||
|
['password', 'hashed', 'hashed', false, false, false],
|
||||||
|
['password', 'hashed', 'hashed new', false, true, false],
|
||||||
|
['password', 'hashed', 'hashed new', true, false, true],
|
||||||
|
['password', 'hashed', 'hashed', true, false, true],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataUpdateSendPassword
|
||||||
|
*
|
||||||
|
* @param string|null plainTextPassword
|
||||||
|
* @param string originalPassword
|
||||||
|
* @param string newPassword
|
||||||
|
* @param string originalSendPasswordByTalk
|
||||||
|
* @param string newSendPasswordByTalk
|
||||||
|
* @param bool sendMail
|
||||||
|
*/
|
||||||
|
public function testUpdateSendPassword($plainTextPassword, string $originalPassword, string $newPassword, string $originalSendPasswordByTalk, string $newSendPasswordByTalk, bool $sendMail) {
|
||||||
|
$node = $this->getMockBuilder(File::class)->getMock();
|
||||||
|
$node->expects($this->any())->method('getName')->willReturn('filename');
|
||||||
|
|
||||||
|
$originalShare = $this->getMockBuilder(IShare::class)->getMock();
|
||||||
|
$originalShare->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
|
||||||
|
$originalShare->expects($this->any())->method('getNode')->willReturn($node);
|
||||||
|
$originalShare->expects($this->any())->method('getId')->willReturn(42);
|
||||||
|
$originalShare->expects($this->any())->method('getPassword')->willReturn($originalPassword);
|
||||||
|
$originalShare->expects($this->any())->method('getSendPasswordByTalk')->willReturn($originalSendPasswordByTalk);
|
||||||
|
|
||||||
|
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||||
|
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
|
||||||
|
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||||
|
$share->expects($this->any())->method('getId')->willReturn(42);
|
||||||
|
$share->expects($this->any())->method('getPassword')->willReturn($newPassword);
|
||||||
|
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn($newSendPasswordByTalk);
|
||||||
|
|
||||||
|
if ($sendMail) {
|
||||||
|
$this->mailer->expects($this->once())->method('send');
|
||||||
|
} else {
|
||||||
|
$this->mailer->expects($this->never())->method('send');
|
||||||
|
}
|
||||||
|
|
||||||
|
$instance = $this->getInstance(['getShareById', 'createPasswordSendActivity']);
|
||||||
|
$instance->expects($this->once())->method('getShareById')->willReturn($originalShare);
|
||||||
|
|
||||||
|
$this->assertSame($share,
|
||||||
|
$instance->update($share, $plainTextPassword)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testDelete() {
|
public function testDelete() {
|
||||||
$instance = $this->getInstance(['removeShareFromTable']);
|
$instance = $this->getInstance(['removeShareFromTable']);
|
||||||
$this->share->expects($this->once())->method('getId')->willReturn(42);
|
$this->share->expects($this->once())->method('getId')->willReturn(42);
|
||||||
|
|
|
@ -827,10 +827,20 @@ class Manager implements IManager {
|
||||||
$expirationDateUpdated = true;
|
$expirationDateUpdated = true;
|
||||||
}
|
}
|
||||||
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
|
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
|
||||||
|
// The new password is not set again if it is the same as the old
|
||||||
|
// one, unless when switching from sending by Talk to sending by
|
||||||
|
// mail.
|
||||||
$plainTextPassword = $share->getPassword();
|
$plainTextPassword = $share->getPassword();
|
||||||
if (!$this->updateSharePasswordIfNeeded($share, $originalShare)) {
|
if (!empty($plainTextPassword) && !$this->updateSharePasswordIfNeeded($share, $originalShare) &&
|
||||||
|
!($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk())) {
|
||||||
$plainTextPassword = null;
|
$plainTextPassword = null;
|
||||||
}
|
}
|
||||||
|
if (empty($plainTextPassword) && !$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) {
|
||||||
|
// If the same password was already sent by mail the recipient
|
||||||
|
// would already have access to the share without having to call
|
||||||
|
// the sharer to verify her identity
|
||||||
|
throw new \InvalidArgumentException('Can’t enable sending the password by Talk without setting a new password');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pathCreateChecks($share->getNode());
|
$this->pathCreateChecks($share->getNode());
|
||||||
|
|
|
@ -2716,6 +2716,442 @@ class ManagerTest extends \Test\TestCase {
|
||||||
$manager->updateShare($share);
|
$manager->updateShare($share);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUpdateShareMailEnableSendPasswordByTalk() {
|
||||||
|
$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(null)
|
||||||
|
->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('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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
* @expectedExceptionMessage Can’t enable sending the password by Talk without setting a new password
|
||||||
|
*/
|
||||||
|
public function testUpdateShareMailEnableSendPasswordByTalkWithNoPassword() {
|
||||||
|
$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(null)
|
||||||
|
->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(null)
|
||||||
|
->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->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('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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
* @expectedExceptionMessage Can’t enable sending the password by Talk without setting a new password
|
||||||
|
*/
|
||||||
|
public function testUpdateShareMailEnableSendPasswordByTalkRemovingPassword() {
|
||||||
|
$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('password')
|
||||||
|
->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(null)
|
||||||
|
->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->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('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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
* @expectedExceptionMessage Can’t enable sending the password by Talk without setting a new password
|
||||||
|
*/
|
||||||
|
public function testUpdateShareMailEnableSendPasswordByTalkRemovingPasswordWithEmptyString() {
|
||||||
|
$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('password')
|
||||||
|
->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('')
|
||||||
|
->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->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('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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
* @expectedExceptionMessage Can’t enable sending the password by Talk without setting a new password
|
||||||
|
*/
|
||||||
|
public function testUpdateShareMailEnableSendPasswordByTalkWithPreviousPassword() {
|
||||||
|
$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('password')
|
||||||
|
->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->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('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 testUpdateShareMailDisableSendPasswordByTalkWithPreviousPassword() {
|
||||||
|
$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('password')
|
||||||
|
->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('password')
|
||||||
|
->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->once())->method('pathCreateChecks')->with($file);
|
||||||
|
$manager->expects($this->never())->method('verifyPassword');
|
||||||
|
$manager->expects($this->never())->method('linkCreateChecks');
|
||||||
|
$manager->expects($this->never())->method('validateExpirationDate');
|
||||||
|
|
||||||
|
$this->hasher->expects($this->never())
|
||||||
|
->method('hash');
|
||||||
|
|
||||||
|
$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->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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException \InvalidArgumentException
|
||||||
* @expectedExceptionMessage Can’t change target of link share
|
* @expectedExceptionMessage Can’t change target of link share
|
||||||
|
|
Loading…
Reference in New Issue