Skip to content

Commit 1e542be

Browse files
authored
Merge pull request #26625 from nextcloud/bugfix/noid/fix-sharemail-empty-password-check
[stable21] Fix empty password check for mail shares
2 parents 44bbc24 + fe0f1c7 commit 1e542be

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

build/psalm-baseline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4851,6 +4851,7 @@
48514851
</UndefinedInterfaceMethod>
48524852
</file>
48534853
<file src="lib/private/Share20/Manager.php">
4854+
<NullArgument occurrences="1"/>
48544855
<InvalidArgument occurrences="7">
48554856
<code>$data</code>
48564857
<code>'OCP\Share::postAcceptShare'</code>

lib/private/Share20/Manager.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,8 @@ public function updateShare(IShare $share) {
10081008
// The new password is not set again if it is the same as the old
10091009
// one.
10101010
$plainTextPassword = $share->getPassword();
1011-
if (!empty($plainTextPassword) && !$this->updateSharePasswordIfNeeded($share, $originalShare)) {
1011+
$updatedPassword = $this->updateSharePasswordIfNeeded($share, $originalShare);
1012+
if (!empty($plainTextPassword) && !$updatedPassword) {
10121013
$plainTextPassword = null;
10131014
}
10141015
if (empty($plainTextPassword) && !$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) {
@@ -1116,9 +1117,13 @@ private function updateSharePasswordIfNeeded(IShare $share, IShare $originalShar
11161117
$this->verifyPassword($share->getPassword());
11171118

11181119
// If a password is set. Hash it!
1119-
if ($share->getPassword() !== null) {
1120+
if (!empty($share->getPassword())) {
11201121
$share->setPassword($this->hasher->hash($share->getPassword()));
11211122

1123+
return true;
1124+
} else {
1125+
// Empty string and null are seen as NOT password protected
1126+
$share->setPassword(null);
11221127
return true;
11231128
}
11241129
} else {

tests/lib/Share20/ManagerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3515,7 +3515,7 @@ public function testUpdateShareMailEnableSendPasswordByTalkRemovingPassword() {
35153515
$manager->expects($this->once())->method('canShare')->willReturn(true);
35163516
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
35173517
$manager->expects($this->once())->method('generalCreateChecks')->with($share);
3518-
$manager->expects($this->never())->method('verifyPassword');
3518+
$manager->expects($this->once())->method('verifyPassword');
35193519
$manager->expects($this->never())->method('pathCreateChecks');
35203520
$manager->expects($this->never())->method('linkCreateChecks');
35213521
$manager->expects($this->never())->method('validateExpirationDateLink');
@@ -3587,7 +3587,7 @@ public function testUpdateShareMailEnableSendPasswordByTalkRemovingPasswordWithE
35873587
$manager->expects($this->once())->method('canShare')->willReturn(true);
35883588
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
35893589
$manager->expects($this->once())->method('generalCreateChecks')->with($share);
3590-
$manager->expects($this->never())->method('verifyPassword');
3590+
$manager->expects($this->once())->method('verifyPassword');
35913591
$manager->expects($this->never())->method('pathCreateChecks');
35923592
$manager->expects($this->never())->method('linkCreateChecks');
35933593
$manager->expects($this->never())->method('validateExpirationDateLink');

0 commit comments

Comments
 (0)