diff options
author | Vincent Petry <vincent@nextcloud.com> | 2021-04-19 15:25:26 +0200 |
---|---|---|
committer | Vincent Petry <vincent@nextcloud.com> | 2021-04-20 10:35:58 +0200 |
commit | 4b5a05cfee5b6ab7a3b179c86f1eaf530e048c27 (patch) | |
tree | f932616359542c331f229735b45795b7439e4b4f | |
parent | 9b86f5f674064a4c414bb82ea7d1fd122cf70051 (diff) | |
download | nextcloud-server-4b5a05cfee5b6ab7a3b179c86f1eaf530e048c27.tar.gz nextcloud-server-4b5a05cfee5b6ab7a3b179c86f1eaf530e048c27.zip |
Fix empty password check for mail shares
Signed-off-by: Vincent Petry <vincent@nextcloud.com>
-rw-r--r-- | lib/private/Share20/Manager.php | 9 | ||||
-rw-r--r-- | tests/lib/Share20/ManagerTest.php | 4 |
2 files changed, 9 insertions, 4 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 1fad23f6d26..d09db144cf4 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1000,7 +1000,8 @@ class Manager implements IManager { // The new password is not set again if it is the same as the old // one. $plainTextPassword = $share->getPassword(); - if (!empty($plainTextPassword) && !$this->updateSharePasswordIfNeeded($share, $originalShare)) { + $updatedPassword = $this->updateSharePasswordIfNeeded($share, $originalShare); + if (!empty($plainTextPassword) && !$updatedPassword) { $plainTextPassword = null; } if (empty($plainTextPassword) && !$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) { @@ -1108,10 +1109,14 @@ class Manager implements IManager { $this->verifyPassword($share->getPassword()); // If a password is set. Hash it! - if ($share->getPassword() !== null) { + if (!empty($share->getPassword())) { $share->setPassword($this->hasher->hash($share->getPassword())); return true; + } else { + // Empty string and null are seen as NOT password protected + $share->setPassword(null); + return true; } } else { // Reset the password to the original one, as it is either the same diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 6c4effab427..50e7006274e 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -3499,7 +3499,7 @@ class ManagerTest extends \Test\TestCase { $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->once())->method('verifyPassword'); $manager->expects($this->never())->method('pathCreateChecks'); $manager->expects($this->never())->method('linkCreateChecks'); $manager->expects($this->never())->method('validateExpirationDateLink'); @@ -3571,7 +3571,7 @@ class ManagerTest extends \Test\TestCase { $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->once())->method('verifyPassword'); $manager->expects($this->never())->method('pathCreateChecks'); $manager->expects($this->never())->method('linkCreateChecks'); $manager->expects($this->never())->method('validateExpirationDateLink'); |