From bf6251624469c5a44ef292ff7a0fa4ae57d76968 Mon Sep 17 00:00:00 2001 From: konradoboza Date: Fri, 5 Jul 2024 15:16:37 +0200 Subject: [PATCH] cr remarks --- phpstan-baseline.neon | 15 --- ...mberMeRepositoryAuthenticationProvider.php | 44 ------- ...sitoryUserAuthenticationSubscriberTest.php | 2 +- ...MeRepositoryAuthenticationProviderTest.php | 121 ------------------ 4 files changed, 1 insertion(+), 181 deletions(-) delete mode 100644 src/lib/MVC/Symfony/Security/Authentication/RememberMeRepositoryAuthenticationProvider.php delete mode 100644 tests/lib/MVC/Symfony/Security/Authentication/RememberMeRepositoryAuthenticationProviderTest.php diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 234fea55f3..4ca5939148 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -12235,11 +12235,6 @@ parameters: count: 1 path: src/lib/MVC/Symfony/Routing/UrlWildcardRouter.php - - - message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Security\\\\Authentication\\\\RememberMeRepositoryAuthenticationProvider\\:\\:setPermissionResolver\\(\\) has no return type specified\\.$#" - count: 1 - path: src/lib/MVC/Symfony/Security/Authentication/RememberMeRepositoryAuthenticationProvider.php - - message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Security\\\\Authorization\\\\Attribute\\:\\:__construct\\(\\) has parameter \\$function with no type specified\\.$#" count: 1 @@ -47000,16 +46995,6 @@ parameters: count: 1 path: tests/lib/MVC/Symfony/Security/Authentication/GuardRepositoryAuthenticationProviderTest.php - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\Authentication\\\\Token\\\\TokenInterface\\:\\:getFirewallName\\(\\)\\.$#" - count: 1 - path: tests/lib/MVC/Symfony/Security/Authentication/RememberMeRepositoryAuthenticationProviderTest.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\Authentication\\\\Token\\\\TokenInterface\\:\\:getSecret\\(\\)\\.$#" - count: 1 - path: tests/lib/MVC/Symfony/Security/Authentication/RememberMeRepositoryAuthenticationProviderTest.php - - message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\Security\\\\HttpUtilsTest\\:\\:checkRequestPathProvider\\(\\) has no return type specified\\.$#" count: 1 diff --git a/src/lib/MVC/Symfony/Security/Authentication/RememberMeRepositoryAuthenticationProvider.php b/src/lib/MVC/Symfony/Security/Authentication/RememberMeRepositoryAuthenticationProvider.php deleted file mode 100644 index 7e70080f49..0000000000 --- a/src/lib/MVC/Symfony/Security/Authentication/RememberMeRepositoryAuthenticationProvider.php +++ /dev/null @@ -1,44 +0,0 @@ -permissionResolver = $permissionResolver; - } - - /** - * {@inheritdoc} - */ - public function authenticate(TokenInterface $token) - { - $authenticatedToken = parent::authenticate($token); - if (empty($authenticatedToken)) { - throw new AuthenticationException('The token is not supported by this authentication provider.'); - } - - if ($authenticatedToken->getUser() instanceof UserInterface) { - $this->permissionResolver->setCurrentUserReference( - $authenticatedToken->getUser()->getAPIUser() - ); - } - - return $authenticatedToken; - } -} diff --git a/tests/lib/MVC/Symfony/Security/Authentication/EventSubscriber/RepositoryUserAuthenticationSubscriberTest.php b/tests/lib/MVC/Symfony/Security/Authentication/EventSubscriber/RepositoryUserAuthenticationSubscriberTest.php index 3bb189080c..1c53d44fcf 100644 --- a/tests/lib/MVC/Symfony/Security/Authentication/EventSubscriber/RepositoryUserAuthenticationSubscriberTest.php +++ b/tests/lib/MVC/Symfony/Security/Authentication/EventSubscriber/RepositoryUserAuthenticationSubscriberTest.php @@ -80,7 +80,7 @@ public function testAuthenticateInConstantTime(): void $this->getCheckPassportEvent() ); } catch (Exception) { - // We don't care, we just need test execution to continue + self::fail(); } $duration = $stopwatch->stop('authenticate_constant_time_test')->getDuration(); diff --git a/tests/lib/MVC/Symfony/Security/Authentication/RememberMeRepositoryAuthenticationProviderTest.php b/tests/lib/MVC/Symfony/Security/Authentication/RememberMeRepositoryAuthenticationProviderTest.php deleted file mode 100644 index a4bd8d69f1..0000000000 --- a/tests/lib/MVC/Symfony/Security/Authentication/RememberMeRepositoryAuthenticationProviderTest.php +++ /dev/null @@ -1,121 +0,0 @@ -permissionResolver = $this->createMock(PermissionResolver::class); - $this->authProvider = new RememberMeRepositoryAuthenticationProvider( - $this->createMock(UserCheckerInterface::class), - 'my secret', - 'my provider secret' - ); - $this->authProvider->setPermissionResolver($this->permissionResolver); - } - - public function testAuthenticateUnsupportedToken(): void - { - $this->expectException(AuthenticationException::class); - $this->expectExceptionMessage('The token is not supported by this authentication provider.'); - - $anonymousToken = $this - ->getMockBuilder(AnonymousToken::class) - ->setConstructorArgs(['secret', $this->createMock(UserInterface::class)]) - ->getMock(); - $this->authProvider->authenticate($anonymousToken); - } - - public function testAuthenticateWrongProviderKey(): void - { - $this->expectException(AuthenticationException::class); - $this->expectExceptionMessage('The token is not supported by this authentication provider.'); - - $user = $this->createMock(UserInterface::class); - $user - ->expects(self::any()) - ->method('getRoles') - ->will(self::returnValue([])); - - $rememberMeToken = $this - ->getMockBuilder(RememberMeToken::class) - ->setConstructorArgs([$user, 'wrong provider secret', 'my secret']) - ->getMock(); - $rememberMeToken - ->expects(self::any()) - ->method('getProviderKey') - ->will(self::returnValue('wrong provider secret')); - - $this->authProvider->authenticate($rememberMeToken); - } - - public function testAuthenticateWrongSecret(): void - { - $this->expectException(AuthenticationException::class); - - $user = $this->createMock(UserInterface::class); - $user - ->expects(self::any()) - ->method('getRoles') - ->will(self::returnValue([])); - - $rememberMeToken = $this - ->getMockBuilder(RememberMeToken::class) - ->setConstructorArgs([$user, 'my provider secret', 'the wrong secret']) - ->getMock(); - $rememberMeToken - ->expects(self::any()) - ->method('getProviderKey') - ->will(self::returnValue('my provider secret')); - $rememberMeToken - ->expects(self::any()) - ->method('getSecret') - ->will(self::returnValue('the wrong secret')); - - $this->authProvider->authenticate($rememberMeToken); - } - - public function testAuthenticate(): void - { - $apiUser = $this->createMock(ApiUser::class); - $apiUser - ->expects(self::any()) - ->method('getUserId') - ->will(self::returnValue(42)); - - $tokenUser = new User($apiUser); - $rememberMeToken = new RememberMeToken($tokenUser, 'my provider secret', 'my secret'); - - $authenticatedToken = $this->authProvider->authenticate($rememberMeToken); - - self::assertEquals( - [$rememberMeToken->getFirewallName(), $rememberMeToken->getSecret()], - [$authenticatedToken->getFirewallName(), $authenticatedToken->getSecret()] - ); - } -}