From d440667a0044abe55527502f95c1c40ae445a4cc Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Sat, 15 Jun 2024 09:30:00 +0200 Subject: [PATCH] Refactor request methods in test files The commit updates the request methods in the 'NonSecuredAreaTest.php' and 'SecuredAreaTest.php' test files. Specifically, hardcoded 'GET' and 'POST' strings have been replaced with their equivalents from the Request class for better consistency and potential type safety. --- .../functional/Firewall/NonSecuredAreaTest.php | 3 ++- tests/symfony/functional/Firewall/SecuredAreaTest.php | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/symfony/functional/Firewall/NonSecuredAreaTest.php b/tests/symfony/functional/Firewall/NonSecuredAreaTest.php index 5821c330..70e477b2 100644 --- a/tests/symfony/functional/Firewall/NonSecuredAreaTest.php +++ b/tests/symfony/functional/Firewall/NonSecuredAreaTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\Attributes\Test; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\HttpFoundation\Request; /** * @internal @@ -16,7 +17,7 @@ final class NonSecuredAreaTest extends WebTestCase public function aClientWantsToAccessOnNonSecuredResource(): void { $client = static::createClient(); - $client->request('GET', '/', [], [], [ + $client->request(Request::METHOD_GET, '/', [], [], [ 'HTTPS' => 'on', ]); diff --git a/tests/symfony/functional/Firewall/SecuredAreaTest.php b/tests/symfony/functional/Firewall/SecuredAreaTest.php index a610edf3..d166714d 100644 --- a/tests/symfony/functional/Firewall/SecuredAreaTest.php +++ b/tests/symfony/functional/Firewall/SecuredAreaTest.php @@ -7,6 +7,7 @@ use ParagonIE\ConstantTime\Base64UrlSafe; use PHPUnit\Framework\Attributes\Test; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Webauthn\Bundle\Security\Storage\Item; use Webauthn\PublicKeyCredentialDescriptor; @@ -26,7 +27,7 @@ public function aClientCannotAccessToTheResourceIfUserIsNotAuthenticated(): void $client = static::createClient([], [ 'HTTPS' => 'on', ]); - $client->request('GET', '/admin', [], [], [ + $client->request(Request::METHOD_GET, '/admin', [], [], [ 'HTTPS' => 'on', ]); @@ -42,7 +43,7 @@ public function aClientCanSubmitUsernameToGetWebauthnOptions(): void $client = static::createClient([], [ 'HTTPS' => 'on', ]); - $client->request('POST', '/api/login/options', [], [], [ + $client->request(Request::METHOD_POST, '/api/login/options', [], [], [ 'CONTENT_TYPE' => 'application/json', 'HTTP_HOST' => 'test.com', 'HTTPS' => 'on', @@ -65,7 +66,7 @@ public function aUserCannotBeBeAuthenticatedInAbsenceOfOptions(): void $client = static::createClient([], [ 'HTTPS' => 'on', ]); - $client->request('POST', '/api/login', [], [], [ + $client->request(Request::METHOD_POST, '/api/login', [], [], [ 'CONTENT_TYPE' => 'application/json', 'HTTP_HOST' => 'test.com', ], $assertion); @@ -107,7 +108,7 @@ public function aUserCanBeAuthenticatedAndAccessToTheProtectedResource(): void $assertion = '{"id":"eHouz_Zi7-BmByHjJ_tx9h4a1WZsK4IzUmgGjkhyOodPGAyUqUp_B9yUkflXY3yHWsNtsrgCXQ3HjAIFUeZB-w","type":"public-key","rawId":"eHouz/Zi7+BmByHjJ/tx9h4a1WZsK4IzUmgGjkhyOodPGAyUqUp/B9yUkflXY3yHWsNtsrgCXQ3HjAIFUeZB+w==","response":{"authenticatorData":"SZYN5YgOjGh0NBcPZHZgW4_krrmihjLHmVzzuoMdl2MBAAAAew","clientDataJSON":"eyJjaGFsbGVuZ2UiOiJHMEpiTExuZGVmM2EwSXkzUzJzU1FBOHVPNFNPX3plNkZaTUF1UEk2LXhJIiwiY2xpZW50RXh0ZW5zaW9ucyI6e30sImhhc2hBbGdvcml0aG0iOiJTSEEtMjU2Iiwib3JpZ2luIjoiaHR0cHM6Ly9sb2NhbGhvc3Q6ODQ0MyIsInR5cGUiOiJ3ZWJhdXRobi5nZXQifQ","signature":"MEUCIEY/vcNkbo/LdMTfLa24ZYLlMMVMRd8zXguHBvqud9AJAiEAwCwpZpvcMaqCrwv85w/8RGiZzE+gOM61ffxmgEDeyhM=","userHandle":null}}'; - $client->request('POST', '/api/login', [], [], [ + $client->request(Request::METHOD_POST, '/api/login', [], [], [ 'CONTENT_TYPE' => 'application/json', 'HTTP_HOST' => 'localhost', ], $assertion); @@ -120,7 +121,7 @@ public function aUserCanBeAuthenticatedAndAccessToTheProtectedResource(): void ); static::assertTrue($client->getRequest()->getSession()->has('_security_main')); - $client->request('GET', '/admin'); + $client->request(Request::METHOD_GET, '/admin'); static::assertSame('["Hello admin"]', $client->getResponse()->getContent()); static::assertResponseIsSuccessful();