mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 09:13:19 -04:00
Merge pull request #55123 from nextcloud/carl/fix-invalid-unique-contraint-catch
[stable31]: fix(auth): Fix invalid unique constraint violation catch
This commit is contained in:
commit
745ebd6a43
2 changed files with 9 additions and 5 deletions
|
|
@ -7,7 +7,6 @@ declare(strict_types=1);
|
|||
*/
|
||||
namespace OC\Authentication\Token;
|
||||
|
||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
use OC\Authentication\Exceptions\InvalidTokenException as OcInvalidTokenException;
|
||||
use OC\Authentication\Exceptions\PasswordlessTokenException;
|
||||
use OCP\Authentication\Exceptions\ExpiredTokenException;
|
||||
|
|
@ -15,6 +14,7 @@ use OCP\Authentication\Exceptions\InvalidTokenException;
|
|||
use OCP\Authentication\Exceptions\WipeTokenException;
|
||||
use OCP\Authentication\Token\IProvider as OCPIProvider;
|
||||
use OCP\Authentication\Token\IToken as OCPIToken;
|
||||
use OCP\DB\Exception;
|
||||
|
||||
class Manager implements IProvider, OCPIProvider {
|
||||
/** @var PublicKeyTokenProvider */
|
||||
|
|
@ -60,7 +60,10 @@ class Manager implements IProvider, OCPIProvider {
|
|||
$remember,
|
||||
$scope,
|
||||
);
|
||||
} catch (UniqueConstraintViolationException $e) {
|
||||
} catch (Exception $e) {
|
||||
if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
|
||||
throw $e;
|
||||
}
|
||||
// It's rare, but if two requests of the same session (e.g. env-based SAML)
|
||||
// try to create the session token they might end up here at the same time
|
||||
// because we use the session ID as token and the db token is created anew
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ declare(strict_types=1);
|
|||
|
||||
namespace Test\Authentication\Token;
|
||||
|
||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
use OC\Authentication\Exceptions\InvalidTokenException;
|
||||
use OC\Authentication\Token\IToken;
|
||||
use OC\Authentication\Token\Manager;
|
||||
use OC\Authentication\Token\PublicKeyToken;
|
||||
use OC\Authentication\Token\PublicKeyTokenProvider;
|
||||
use OCP\DB\Exception;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
|
|
@ -62,8 +62,9 @@ class ManagerTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testGenerateConflictingToken(): void {
|
||||
/** @var MockObject|UniqueConstraintViolationException $exception */
|
||||
$exception = $this->createMock(UniqueConstraintViolationException::class);
|
||||
/** @var MockObject&Exception $exception */
|
||||
$exception = $this->createMock(Exception::class);
|
||||
$exception->method('getReason')->willReturn(Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION);
|
||||
|
||||
$token = new PublicKeyToken();
|
||||
$token->setUid('uid');
|
||||
|
|
|
|||
Loading…
Reference in a new issue