Skip to content

Commit

Permalink
Refactor request methods in test files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Spomky committed Jun 15, 2024
1 parent bdbe5f8 commit d440667
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion tests/symfony/functional/Firewall/NonSecuredAreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;

/**
* @internal
Expand All @@ -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',
]);

Expand Down
11 changes: 6 additions & 5 deletions tests/symfony/functional/Firewall/SecuredAreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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',
]);

Expand All @@ -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',
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit d440667

Please sign in to comment.