From 9939569a24ab85178d9cf5cb681728d66aa40cbe Mon Sep 17 00:00:00 2001 From: konradoboza Date: Tue, 28 May 2024 15:01:25 +0200 Subject: [PATCH] removed CsrfTokenManagerTest as it brings not much value, regenerated PHPStan --- dependencies.json | 4 + phpstan-baseline.neon | 25 ------ tests/integration/UriParser/UriParserTest.php | 23 +++--- .../Server/Security/CsrfTokenManagerTest.php | 79 ------------------- 4 files changed, 17 insertions(+), 114 deletions(-) create mode 100644 dependencies.json delete mode 100644 tests/lib/Server/Security/CsrfTokenManagerTest.php diff --git a/dependencies.json b/dependencies.json new file mode 100644 index 00000000..91fe917f --- /dev/null +++ b/dependencies.json @@ -0,0 +1,4 @@ +{ + "recipesEndpoint": "https://api.github.com/repos/ibexa/recipes-dev/contents/index.json?ref=flex/pull-121", + "packages": [] +} diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index dd968861..1467b995 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6315,11 +6315,6 @@ parameters: count: 1 path: tests/integration/BasicKernelTest.php - - - message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Rest\\\\UriParser\\\\UriParserTest\\:\\:getDataForTestIsRestRequest\\(\\) return type has no value type specified in iterable type iterable\\.$#" - count: 1 - path: tests/integration/UriParser/UriParserTest.php - - message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\FieldTypeProcessor\\\\AuthorProcessorTest\\:\\:fieldSettingsHashes\\(\\) has no return type specified\\.$#" count: 1 @@ -10495,26 +10490,6 @@ parameters: count: 1 path: tests/lib/Server/Output/ValueObjectVisitor/VersionTest.php - - - message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Server\\\\Security\\\\CsrfTokenManagerTest\\:\\:createCsrfTokenManager\\(\\) has no return type specified\\.$#" - count: 1 - path: tests/lib/Server/Security/CsrfTokenManagerTest.php - - - - message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Server\\\\Security\\\\CsrfTokenManagerTest\\:\\:createCsrfTokenManager\\(\\) has parameter \\$https with no type specified\\.$#" - count: 1 - path: tests/lib/Server/Security/CsrfTokenManagerTest.php - - - - message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Server\\\\Security\\\\CsrfTokenManagerTest\\:\\:testHasTokenForHttp\\(\\) has no return type specified\\.$#" - count: 1 - path: tests/lib/Server/Security/CsrfTokenManagerTest.php - - - - message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Server\\\\Security\\\\CsrfTokenManagerTest\\:\\:testHasTokenForHttps\\(\\) has no return type specified\\.$#" - count: 1 - path: tests/lib/Server/Security/CsrfTokenManagerTest.php - - message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\UrlHandler\\\\PatternTest\\:\\:getParseValues\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 diff --git a/tests/integration/UriParser/UriParserTest.php b/tests/integration/UriParser/UriParserTest.php index eb7ba0c2..cc8edb8a 100644 --- a/tests/integration/UriParser/UriParserTest.php +++ b/tests/integration/UriParser/UriParserTest.php @@ -39,11 +39,11 @@ public static function getDataForTestGetAttributeFromUri(): iterable '2', ]; - yield 'Get sessionId attribute from ibexa.rest.refresh_session POST route' => [ + yield 'Get userId attribute from ibexa.rest.assign_user_to_user_group POST route' => [ 'POST', - '/api/ibexa/v2/user/sessions/MySession/refresh', - 'sessionId', - 'MySession', + '/api/ibexa/v2/user/users/14/groups', + 'userId', + '14', ]; } @@ -66,19 +66,19 @@ public function testGetAttributeFromUri( */ public static function getDataForTestGetAttributeFromUriThrowsException(): iterable { - $uri = '/api/ibexa/v2/user/sessions/MySession/refresh'; + $uri = '/api/ibexa/v2/content/sections/1'; yield 'Invalid attribute' => [ - 'POST', + 'GET', $uri, - 'session', + 'sectionId', "No attribute 'session' in route matched from $uri", ]; yield 'Invalid method' => [ - 'GET', + 'POST', $uri, - 'sessionId', - "Method 'GET' is not allowed for '$uri'. Allowed: [POST]", + 'sectionId', + "Method 'POST' is not allowed for '$uri'. Allowed: [GET, PATCH, DELETE]", ]; yield 'Invalid route' => [ @@ -113,6 +113,9 @@ public function testGetAttributeFromUriThrowsException( $this->uriParser->getAttributeFromUri($uri, $attributeName, $method); } + /** + * @return iterable + */ public static function getDataForTestIsRestRequest(): iterable { yield ($uri = '/api/ibexa/v2/foo') => [ diff --git a/tests/lib/Server/Security/CsrfTokenManagerTest.php b/tests/lib/Server/Security/CsrfTokenManagerTest.php deleted file mode 100644 index 7e5b276b..00000000 --- a/tests/lib/Server/Security/CsrfTokenManagerTest.php +++ /dev/null @@ -1,79 +0,0 @@ -tokenStorage = $this->createMock(TokenStorageInterface::class); - $this->requestStack = $this->createMock(RequestStack::class); - } - - public function testHasTokenForHttp() - { - $csrfTokenManager = $this->createCsrfTokenManager(false); - - $this->tokenStorage - ->expects(self::once()) - ->method('hasToken') - ->with(self::CSRF_TOKEN_INTENTION); - - $csrfTokenManager->hasToken(self::CSRF_TOKEN_INTENTION); - } - - public function testHasTokenForHttps() - { - $csrfTokenManager = $this->createCsrfTokenManager(true); - - $this->tokenStorage - ->expects(self::once()) - ->method('hasToken') - ->with('https-' . self::CSRF_TOKEN_INTENTION); - - $csrfTokenManager->hasToken(self::CSRF_TOKEN_INTENTION); - } - - private function createCsrfTokenManager($https = false) - { - $request = new Request(); - if ($https) { - $request->server->set('HTTPS', 'ON'); - } - - $this->requestStack - ->expects(self::once()) - ->method('getMainRequest') - ->willReturn($request); - - return new CsrfTokenManager( - $this->createMock(TokenGeneratorInterface::class), - $this->tokenStorage, - $this->requestStack - ); - } -} - -class_alias(CsrfTokenManagerTest::class, 'EzSystems\EzPlatformRest\Tests\Server\Security\CsrfTokenManagerTest');