Skip to content

Commit 418dab9

Browse files
authored
Merge pull request #26646 from nextcloud/backport/26625/stable19
[stable19] Fix empty password check for mail shares
2 parents 489ddb4 + 4b5a05c commit 418dab9

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

lib/private/Share20/Manager.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,8 @@ public function updateShare(\OCP\Share\IShare $share) {
10001000
// The new password is not set again if it is the same as the old
10011001
// one.
10021002
$plainTextPassword = $share->getPassword();
1003-
if (!empty($plainTextPassword) && !$this->updateSharePasswordIfNeeded($share, $originalShare)) {
1003+
$updatedPassword = $this->updateSharePasswordIfNeeded($share, $originalShare);
1004+
if (!empty($plainTextPassword) && !$updatedPassword) {
10041005
$plainTextPassword = null;
10051006
}
10061007
if (empty($plainTextPassword) && !$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) {
@@ -1108,9 +1109,13 @@ private function updateSharePasswordIfNeeded(\OCP\Share\IShare $share, \OCP\Shar
11081109
$this->verifyPassword($share->getPassword());
11091110

11101111
// If a password is set. Hash it!
1111-
if ($share->getPassword() !== null) {
1112+
if (!empty($share->getPassword())) {
11121113
$share->setPassword($this->hasher->hash($share->getPassword()));
11131114

1115+
return true;
1116+
} else {
1117+
// Empty string and null are seen as NOT password protected
1118+
$share->setPassword(null);
11141119
return true;
11151120
}
11161121
} else {

tests/lib/Share20/ManagerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3499,7 +3499,7 @@ public function testUpdateShareMailEnableSendPasswordByTalkRemovingPassword() {
34993499
$manager->expects($this->once())->method('canShare')->willReturn(true);
35003500
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
35013501
$manager->expects($this->once())->method('generalCreateChecks')->with($share);
3502-
$manager->expects($this->never())->method('verifyPassword');
3502+
$manager->expects($this->once())->method('verifyPassword');
35033503
$manager->expects($this->never())->method('pathCreateChecks');
35043504
$manager->expects($this->never())->method('linkCreateChecks');
35053505
$manager->expects($this->never())->method('validateExpirationDateLink');
@@ -3571,7 +3571,7 @@ public function testUpdateShareMailEnableSendPasswordByTalkRemovingPasswordWithE
35713571
$manager->expects($this->once())->method('canShare')->willReturn(true);
35723572
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
35733573
$manager->expects($this->once())->method('generalCreateChecks')->with($share);
3574-
$manager->expects($this->never())->method('verifyPassword');
3574+
$manager->expects($this->once())->method('verifyPassword');
35753575
$manager->expects($this->never())->method('pathCreateChecks');
35763576
$manager->expects($this->never())->method('linkCreateChecks');
35773577
$manager->expects($this->never())->method('validateExpirationDateLink');

0 commit comments

Comments
 (0)