Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Send password to owner when password sending fails, regardless of enforcement #50517

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions apps/sharebymail/lib/ShareByMailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,9 @@ public function sendMailNotification(IShare $share): bool {
// Lastly, if the mail to recipient failed, we send the password to the owner as a fallback.
// If a password expires, the recipient will still be able to request a new one via talk.
$passwordExpire = $this->config->getSystemValue('sharing.enable_mail_link_password_expiration', false);
$passwordEnforced = $this->shareManager->shareApiLinkEnforcePassword();
if ($passwordExpire === false || $share->getSendPasswordByTalk()) {
$send = $this->sendPassword($share, $share->getPassword(), $validEmails);
if ($passwordEnforced && $send === false) {
if ($send === false) {
$this->sendPasswordToOwner($share, $share->getPassword());
}
}
Expand Down Expand Up @@ -567,7 +566,7 @@ protected function sendPasswordToOwner(IShare $share, string $password): bool {
$initiator = $this->userManager->get($share->getSharedBy());
$initiatorEMailAddress = ($initiator instanceof IUser) ? $initiator->getEMailAddress() : null;
$initiatorDisplayName = ($initiator instanceof IUser) ? $initiator->getDisplayName() : $share->getSharedBy();
$shareWith = $share->getSharedWith();
$shareWith = implode(', ', $this->getSharedWithEmails($share));

if ($initiatorEMailAddress === null) {
throw new \Exception(
Expand Down
47 changes: 47 additions & 0 deletions apps/sharebymail/tests/ShareByMailProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswo
->with('sharing.enable_mail_link_password_expiration')
->willReturn(true);

$this->settingsManager->expects($this->once())->method('sendPasswordByMail')->willReturn(true);

// No password has been set and no password sent via talk has been requested,
// but password has been enforced for the whole instance and will be generated.
$instance->expects($this->once())->method('sendEmail')->with($share, ['[email protected]']);
Expand All @@ -323,6 +325,51 @@ public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswo
$instance->sendMailNotification($share);
}


public function testCreateSendPasswordToOwnerWhenSendPasswordByMailIsDisabled(): void {
$expectedShare = $this->createMock(IShare::class);
$node = $this->getMockBuilder(File::class)->getMock();
$node->method('getName')->willReturn('filename');

$share = $this->getMockBuilder(IShare::class)->getMock();
$share->method('getSharedWith')->willReturn('[email protected]');
$share->method('getSendPasswordByTalk')->willReturn(false);
$share->method('getSharedBy')->willReturn('owner');
$share->method('getNode')->willReturn($node);
$share->method('getId')->willReturn(42);
$share->method('getNote')->willReturn('');
$share->method('getToken')->willReturn('token');
$share->method('getPassword')->willReturn('password');

$this->mailer->method('validateMailAddress')->willReturn(true);
$this->hasher->expects($this->once())->method('hash')->with('password')->willReturn('passwordHashed');
$share->expects($this->once())->method('setPassword')->with('passwordHashed');

$instance = $this->getInstance([
'getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject',
'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity',
'sendEmail', 'sendPassword', 'sendPasswordToOwner',
]);

$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', 'password' => 'password']);
$instance->expects($this->once())->method('createShareObject')->with(['rawShare', 'password' => 'password'])->willReturn($expectedShare);

$this->shareManager->method('shareApiLinkEnforcePassword')->willReturn(false);
$this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(true);
$this->settingsManager->expects($this->once())->method('sendPasswordByMail')->willReturn(false);

$instance->expects($this->once())->method('sendPasswordToOwner')->with($share);
$instance->expects($this->once())->method('sendEmail')->with($share, ['[email protected]']);
$instance->expects($this->never())->method('sendPassword');

$this->assertSame($expectedShare, $instance->create($share));
$instance->sendMailNotification($share);
}


public function testCreateSendPasswordByMailWithEnforcedPasswordProtectionWithPermanentPassword(): void {
$expectedShare = $this->createMock(IShare::class);

Expand Down
Loading