summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2021-03-18 11:41:10 +0100
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2021-03-22 06:50:47 +0100
commit15767643f253f5e685cb01b2980cfbde0b7aacea (patch)
tree581c2bac717f7123bd21bf7558c165df35904181 /lib
parentf99876997a9119518fe5f7ad3a3a51d33459d4cc (diff)
downloadnextcloud-server-15767643f253f5e685cb01b2980cfbde0b7aacea.tar.gz
nextcloud-server-15767643f253f5e685cb01b2980cfbde0b7aacea.zip
Fix sharebymail tests
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Share20/Manager.php39
1 files changed, 27 insertions, 12 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index d021e57c4dc..49a716e3216 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -193,7 +193,7 @@ class Manager implements IManager {
if ($password === null) {
// No password is set, check if this is allowed.
if ($this->shareApiLinkEnforcePassword()) {
- throw new \InvalidArgumentException('Passwords are enforced for link shares');
+ throw new \InvalidArgumentException('Passwords are enforced for link and mail shares');
}
return;
@@ -765,13 +765,14 @@ class Manager implements IManager {
);
// Verify the expiration date
- $share = $this->validateExpirationDate($share);
+ $share = $this->validateExpirationDateLink($share);
// Verify the password
$this->verifyPassword($share->getPassword());
// If a password is set. Hash it!
- if ($share->getPassword() !== null) {
+ if ($share->getShareType() === IShare::TYPE_LINK
+ && $share->getPassword() !== null) {
$share->setPassword($this->hasher->hash($share->getPassword()));
}
}
@@ -986,14 +987,26 @@ class Manager implements IManager {
|| $share->getShareType() === IShare::TYPE_EMAIL) {
$this->linkCreateChecks($share);
- // The new password is not set again if it is the same as the old one.
+ // The new password is not set again if it is the same as the old
+ // one, unless when switching from sending by Talk to sending by
+ // mail.
$plainTextPassword = $share->getPassword();
+ $updatedPassword = $this->updateSharePasswordIfNeeded($share, $originalShare);
- if (empty($plainTextPassword)) {
+ /**
+ * Cannot enable the getSendPasswordByTalk if there is no password set
+ */
+ if (empty($plainTextPassword) && $share->getSendPasswordByTalk()) {
+ throw new \InvalidArgumentException('Can’t enable sending the password by Talk with an empty password');
+ }
+
+ /**
+ * If we're in a mail share, we need to force a password change
+ * as either the user is not aware of the password or is already (received by mail)
+ * Thus the SendPasswordByTalk feature would not make sense
+ */
+ if (!$updatedPassword && $share->getShareType() === IShare::TYPE_EMAIL) {
if (!$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) {
- // If the same password was already sent by mail the recipient
- // would already have access to the share without having to call
- // the sharer to verify her identity
throw new \InvalidArgumentException('Can’t enable sending the password by Talk without setting a new password');
}
if ($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk()) {
@@ -1001,11 +1014,9 @@ class Manager implements IManager {
}
}
- $this->updateSharePasswordIfNeeded($share, $originalShare);
-
if ($share->getExpirationDate() != $originalShare->getExpirationDate()) {
// Verify the expiration date
- $this->validateExpirationDate($share);
+ $this->validateExpirationDateLink($share);
$expirationDateUpdated = true;
}
}
@@ -1105,10 +1116,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