Merge pull request #49835 from nextcloud/backport/49822/stable28

[stable28] fix(files_sharing): Fix error messages from password policy
This commit is contained in:
Kate 2024-12-16 15:09:31 +01:00 committed by GitHub
commit cbbedace81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 7 deletions

View file

@ -69,6 +69,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;
@ -80,7 +81,6 @@ use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use OCP\Server;
use OCP\Share\Exceptions\GenericShareException;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IShare;
@ -825,7 +825,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) {
@ -1360,7 +1360,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) {
@ -1452,7 +1452,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) {

View file

@ -129,7 +129,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) {
@ -145,7 +145,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);
}
}
@ -896,6 +897,7 @@ class Manager implements IManager {
* @param IShare $share
* @return IShare The share object
* @throws \InvalidArgumentException
* @throws HintException
*/
public function updateShare(IShare $share) {
$expirationDateUpdated = false;

View file

@ -608,7 +608,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');
}
);