aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornfebe <fenn25.fn@gmail.com>2025-01-29 18:21:42 +0100
committernfebe <fenn25.fn@gmail.com>2025-01-29 18:21:42 +0100
commit97645e40bf1827dfec8287842528b2fc1b62cbb0 (patch)
tree24dc7866ac0b066b707cdf7550431fd18855ae43
parent362ba1a10734efea0dfad3637f258bba592ba281 (diff)
downloadnextcloud-server-97645e40bf1827dfec8287842528b2fc1b62cbb0.tar.gz
nextcloud-server-97645e40bf1827dfec8287842528b2fc1b62cbb0.zip
WIP test(share_by_mail): Send password to owner if `send_by_mail` is disabledfix/50512/send-password-2-owner
Signed-off-by: nfebe <fenn25.fn@gmail.com>
-rw-r--r--apps/sharebymail/tests/ShareByMailProviderTest.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php
index 05435b835e0..b226b6ea61b 100644
--- a/apps/sharebymail/tests/ShareByMailProviderTest.php
+++ b/apps/sharebymail/tests/ShareByMailProviderTest.php
@@ -313,6 +313,8 @@ class ShareByMailProviderTest extends TestCase {
->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, ['receiver@example.com']);
@@ -323,6 +325,51 @@ class ShareByMailProviderTest extends TestCase {
$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('receiver@example.com');
+ $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, ['receiver@example.com']);
+ $instance->expects($this->never())->method('sendPassword');
+
+ $this->assertSame($expectedShare, $instance->create($share));
+ $instance->sendMailNotification($share);
+ }
+
+
public function testCreateSendPasswordByMailWithEnforcedPasswordProtectionWithPermanentPassword(): void {
$expectedShare = $this->createMock(IShare::class);