Skip to content

Commit

Permalink
Merge pull request #49822 from nextcloud/backport/49361/stable30
Browse files Browse the repository at this point in the history
[stable30] fix(files_sharing): Fix error messages from password policy
  • Loading branch information
provokateurin authored Dec 12, 2024
2 parents 5c28f70 + 2546bc5 commit c2e9e07
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\HintException;
use OCP\IConfig;
use OCP\IDateTimeZone;
use OCP\IGroupManager;
Expand All @@ -46,7 +47,6 @@
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;
Expand Down Expand Up @@ -810,7 +810,7 @@ public function createShare(

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) {
Expand Down Expand Up @@ -1351,7 +1351,7 @@ public function updateShare(

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) {
Expand Down Expand Up @@ -1439,7 +1439,7 @@ public function acceptShare(string $id): DataResponse {

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) {
Expand Down
6 changes: 4 additions & 2 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private function splitFullId($id) {
* Verify if a password meets all requirements
*
* @param string $password
* @throws \Exception
* @throws HintException
*/
protected function verifyPassword($password) {
if ($password === null) {
Expand All @@ -113,7 +113,8 @@ protected function verifyPassword($password) {
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);
}
}

Expand Down Expand Up @@ -772,6 +773,7 @@ public function createShare(IShare $share) {
* @param IShare $share
* @return IShare The share object
* @throws \InvalidArgumentException
* @throws HintException
*/
public function updateShare(IShare $share) {
$expirationDateUpdated = false;
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ public function testVerifyPasswordHookFails() {
$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');
}
);

Expand Down

0 comments on commit c2e9e07

Please sign in to comment.