Skip to content

Commit c2e9e07

Browse files
Merge pull request #49822 from nextcloud/backport/49361/stable30
[stable30] fix(files_sharing): Fix error messages from password policy
2 parents 5c28f70 + 2546bc5 commit c2e9e07

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use OCP\Files\IRootFolder;
3535
use OCP\Files\Node;
3636
use OCP\Files\NotFoundException;
37+
use OCP\HintException;
3738
use OCP\IConfig;
3839
use OCP\IDateTimeZone;
3940
use OCP\IGroupManager;
@@ -46,7 +47,6 @@
4647
use OCP\Lock\LockedException;
4748
use OCP\Mail\IMailer;
4849
use OCP\Server;
49-
use OCP\Share\Exceptions\GenericShareException;
5050
use OCP\Share\Exceptions\ShareNotFound;
5151
use OCP\Share\IManager;
5252
use OCP\Share\IProviderFactory;
@@ -810,7 +810,7 @@ public function createShare(
810810

811811
try {
812812
$share = $this->shareManager->createShare($share);
813-
} catch (GenericShareException $e) {
813+
} catch (HintException $e) {
814814
$code = $e->getCode() === 0 ? 403 : $e->getCode();
815815
throw new OCSException($e->getHint(), $code);
816816
} catch (\Exception $e) {
@@ -1351,7 +1351,7 @@ public function updateShare(
13511351

13521352
try {
13531353
$share = $this->shareManager->updateShare($share);
1354-
} catch (GenericShareException $e) {
1354+
} catch (HintException $e) {
13551355
$code = $e->getCode() === 0 ? 403 : $e->getCode();
13561356
throw new OCSException($e->getHint(), (int)$code);
13571357
} catch (\Exception $e) {
@@ -1439,7 +1439,7 @@ public function acceptShare(string $id): DataResponse {
14391439

14401440
try {
14411441
$this->shareManager->acceptShare($share, $this->currentUser);
1442-
} catch (GenericShareException $e) {
1442+
} catch (HintException $e) {
14431443
$code = $e->getCode() === 0 ? 403 : $e->getCode();
14441444
throw new OCSException($e->getHint(), (int)$code);
14451445
} catch (\Exception $e) {

lib/private/Share20/Manager.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private function splitFullId($id) {
9797
* Verify if a password meets all requirements
9898
*
9999
* @param string $password
100-
* @throws \Exception
100+
* @throws HintException
101101
*/
102102
protected function verifyPassword($password) {
103103
if ($password === null) {
@@ -113,7 +113,8 @@ protected function verifyPassword($password) {
113113
try {
114114
$this->dispatcher->dispatchTyped(new ValidatePasswordPolicyEvent($password));
115115
} catch (HintException $e) {
116-
throw new \Exception($e->getHint());
116+
/* Wrap in a 400 bad request error */
117+
throw new HintException($e->getMessage(), $e->getHint(), 400, $e);
117118
}
118119
}
119120

@@ -772,6 +773,7 @@ public function createShare(IShare $share) {
772773
* @param IShare $share
773774
* @return IShare The share object
774775
* @throws \InvalidArgumentException
776+
* @throws HintException
775777
*/
776778
public function updateShare(IShare $share) {
777779
$expirationDateUpdated = false;

tests/lib/Share20/ManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ public function testVerifyPasswordHookFails() {
594594
$this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event);
595595
/** @var ValidatePasswordPolicyEvent $event */
596596
$this->assertSame('password', $event->getPassword());
597-
throw new HintException('message', 'password not accepted');
597+
throw new HintException('password not accepted');
598598
}
599599
);
600600

0 commit comments

Comments
 (0)