aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKate <26026535+provokateurin@users.noreply.github.com>2024-12-12 21:13:04 +0100
committerGitHub <noreply@github.com>2024-12-12 21:13:04 +0100
commitc2e9e078e10b2a10003d62c7907f5a340062622c (patch)
tree8304e0015d9e0dcc6751e422043b3dce812aa03a
parent5c28f70647a018ed88cd8ea396282eedcd2c718c (diff)
parent2546bc5f5956803334b76d1d923acd129029b93d (diff)
downloadnextcloud-server-c2e9e078e10b2a10003d62c7907f5a340062622c.tar.gz
nextcloud-server-c2e9e078e10b2a10003d62c7907f5a340062622c.zip
Merge pull request #49822 from nextcloud/backport/49361/stable30
[stable30] fix(files_sharing): Fix error messages from password policy
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php8
-rw-r--r--lib/private/Share20/Manager.php6
-rw-r--r--tests/lib/Share20/ManagerTest.php2
3 files changed, 9 insertions, 7 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index 616c175a9b4..f6c106b9b08 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -34,6 +34,7 @@ use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
+use OCP\HintException;
use OCP\IConfig;
use OCP\IDateTimeZone;
use OCP\IGroupManager;
@@ -46,7 +47,6 @@ use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use OCP\Mail\IMailer;
use OCP\Server;
-use OCP\Share\Exceptions\GenericShareException;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IProviderFactory;
@@ -810,7 +810,7 @@ class ShareAPIController extends OCSController {
try {
$share = $this->shareManager->createShare($share);
- } catch (GenericShareException $e) {
+ } catch (HintException $e) {
$code = $e->getCode() === 0 ? 403 : $e->getCode();
throw new OCSException($e->getHint(), $code);
} catch (\Exception $e) {
@@ -1351,7 +1351,7 @@ class ShareAPIController extends OCSController {
try {
$share = $this->shareManager->updateShare($share);
- } catch (GenericShareException $e) {
+ } catch (HintException $e) {
$code = $e->getCode() === 0 ? 403 : $e->getCode();
throw new OCSException($e->getHint(), (int)$code);
} catch (\Exception $e) {
@@ -1439,7 +1439,7 @@ class ShareAPIController extends OCSController {
try {
$this->shareManager->acceptShare($share, $this->currentUser);
- } catch (GenericShareException $e) {
+ } catch (HintException $e) {
$code = $e->getCode() === 0 ? 403 : $e->getCode();
throw new OCSException($e->getHint(), (int)$code);
} catch (\Exception $e) {
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index ce0dbd9b17a..2cc11c2c634 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -97,7 +97,7 @@ class Manager implements IManager {
* Verify if a password meets all requirements
*
* @param string $password
- * @throws \Exception
+ * @throws HintException
*/
protected function verifyPassword($password) {
if ($password === null) {
@@ -113,7 +113,8 @@ class Manager implements IManager {
try {
$this->dispatcher->dispatchTyped(new ValidatePasswordPolicyEvent($password));
} catch (HintException $e) {
- throw new \Exception($e->getHint());
+ /* Wrap in a 400 bad request error */
+ throw new HintException($e->getMessage(), $e->getHint(), 400, $e);
}
}
@@ -772,6 +773,7 @@ class Manager implements IManager {
* @param IShare $share
* @return IShare The share object
* @throws \InvalidArgumentException
+ * @throws HintException
*/
public function updateShare(IShare $share) {
$expirationDateUpdated = false;
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index 15ecc839451..c0cf0ca9c12 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -594,7 +594,7 @@ class ManagerTest extends \Test\TestCase {
$this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event);
/** @var ValidatePasswordPolicyEvent $event */
$this->assertSame('password', $event->getPassword());
- throw new HintException('message', 'password not accepted');
+ throw new HintException('password not accepted');
}
);