From dbbb40578964f073a6c0ad90fd5d544eaf936b80 Mon Sep 17 00:00:00 2001 From: Tavo Nieves J Date: Sun, 16 May 2021 09:41:36 -0500 Subject: [PATCH 1/3] Symfony 5.3 Use PasswordHasher component if available --- .../Symfony/SecurityAssertionsTrait.php | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Codeception/Module/Symfony/SecurityAssertionsTrait.php b/src/Codeception/Module/Symfony/SecurityAssertionsTrait.php index 8ae73d00..674c3153 100644 --- a/src/Codeception/Module/Symfony/SecurityAssertionsTrait.php +++ b/src/Codeception/Module/Symfony/SecurityAssertionsTrait.php @@ -4,6 +4,7 @@ namespace Codeception\Module\Symfony; +use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Core\Security; @@ -64,9 +65,7 @@ public function seeAuthentication(): void { $security = $this->grabSecurityService(); - $user = $security->getUser(); - - if ($user === null) { + if (!$user = $security->getUser()) { $this->fail('There is no user in session'); } @@ -88,9 +87,7 @@ public function seeRememberedAuthentication(): void { $security = $this->grabSecurityService(); - $user = $security->getUser(); - - if ($user === null) { + if ($security->getUser() === null) { $this->fail('There is no user in session'); } @@ -118,17 +115,19 @@ public function seeUserHasRole(string $role): void { $security = $this->grabSecurityService(); - $user = $security->getUser(); - - if ($user === null) { + if (!$user = $security->getUser()) { $this->fail('There is no user in session'); } + $userIdentifier = method_exists($user, 'getUserIdentifier') ? + $user->getUserIdentifier() : + $user->getUsername(); + $this->assertTrue( $security->isGranted($role), sprintf( 'User %s has no role %s', - $user->getUsername(), + $userIdentifier, $role ) ); @@ -169,8 +168,7 @@ public function seeUserPasswordDoesNotNeedRehash(UserInterface $user = null): vo { if ($user === null) { $security = $this->grabSecurityService(); - $user = $security->getUser(); - if ($user === null) { + if (!$user = $security->getUser()) { $this->fail('No user found to validate'); } } @@ -184,8 +182,17 @@ protected function grabSecurityService(): Security return $this->grabService('security.helper'); } - protected function grabPasswordHasherService(): UserPasswordEncoderInterface + /** + * @return UserPasswordHasherInterface|UserPasswordEncoderInterface + */ + protected function grabPasswordHasherService() { - return $this->grabService('security.user_password_encoder.generic'); + $hasher = $this->getService('security.password_hasher') ?: $this->getService('security.password_encoder'); + + if ($hasher === null) { + $this->fail('Password hasher service could not be found.'); + } + + return $hasher; } } \ No newline at end of file From 8f8b50fbdaa2460ffd2ac9fbf06f93b07635c762 Mon Sep 17 00:00:00 2001 From: Tavo Nieves J Date: Sun, 16 May 2021 09:41:47 -0500 Subject: [PATCH 2/3] Symfony 5.3 Don't refer to the session as a service --- .../Module/Symfony/SessionAssertionsTrait.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Codeception/Module/Symfony/SessionAssertionsTrait.php b/src/Codeception/Module/Symfony/SessionAssertionsTrait.php index 92a60fe8..f562fad3 100644 --- a/src/Codeception/Module/Symfony/SessionAssertionsTrait.php +++ b/src/Codeception/Module/Symfony/SessionAssertionsTrait.php @@ -34,7 +34,7 @@ trait SessionAssertionsTrait */ public function amLoggedInAs(UserInterface $user, string $firewallName = 'main', $firewallContext = null): void { - $session = $this->grabSessionService(); + $session = $this->getCurrentSession(); if ($this->config['guard']) { $token = new PostAuthenticationGuardToken($user, $firewallName, $user->getRoles()); @@ -68,7 +68,7 @@ public function amLoggedInAs(UserInterface $user, string $firewallName = 'main', */ public function dontSeeInSession(string $attribute, $value = null): void { - $session = $this->grabSessionService(); + $session = $this->getCurrentSession(); if (null === $value) { if ($session->has($attribute)) { @@ -94,7 +94,7 @@ public function logout(): void $tokenStorage->setToken(); } - $session = $this->grabSessionService(); + $session = $this->getCurrentSession(); $sessionName = $session->getName(); $session->invalidate(); @@ -126,7 +126,7 @@ public function logout(): void */ public function seeInSession(string $attribute, $value = null): void { - $session = $this->grabSessionService(); + $session = $this->getCurrentSession(); if (!$session->has($attribute)) { $this->fail("No session attribute with name '{$attribute}'"); @@ -164,7 +164,7 @@ protected function getTokenStorage(): ?TokenStorageInterface return $this->getService('security.token_storage'); } - protected function grabSessionService(): SessionInterface + protected function getCurrentSession(): SessionInterface { return $this->grabService('session'); } From 5d8b106c6974fd55ac78ca0af9d3cf75a5c048ea Mon Sep 17 00:00:00 2001 From: Tavo Nieves J Date: Mon, 31 May 2021 20:32:26 -0500 Subject: [PATCH 3/3] Update CI jobs --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index da8b8d71..2eb0a711 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: php: [7.3, 7.4, 8.0] - symfony: [4.4, 5.2] + symfony: [4.4, 5.3] steps: - name: Checkout code @@ -31,8 +31,8 @@ jobs: path: framework-tests ref: 4.4 - - name: Checkout Symfony 5.2 Sample - if: matrix.symfony == 5.2 + - name: Checkout Symfony 5.3 Sample + if: matrix.symfony == 5.3 uses: actions/checkout@v2 with: repository: Codeception/symfony-module-tests pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy