Skip to content

Commit c46e68e

Browse files
Merge branch '5.4' into 6.2
* 5.4: [FrameworkBundle] Improve error message in MicroKernelTrait when using deprecated configureRoutes(RouteCollectionBuilder) with symfony/routing >= 6.0 Add warning about Symfony 5.2 changing pcntl_async_signals [Tests] Fix static calls and Mock var annotation [FrameworkBundle] Fix checkboxes check assertions [Notifier][WebProfilerBundle] Ignore messages whose `getNotification` returns `null` [HttpClient] Fix over-encoding of URL parts to match browser's behavior Fix Psalm job [HttpClient] Fix data collector [Tests] Migrate tests to static data providers [Semaphore] Fix test Fix: Split and clean up tests Remove unused data provider add Sender to the list of bypassed headers
2 parents d0d23b4 + a906fb4 commit c46e68e

File tree

3 files changed

+217
-10
lines changed

3 files changed

+217
-10
lines changed

Tests/EventListener/PasswordMigratingListenerTest.php

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;
1717
use Symfony\Component\PasswordHasher\PasswordHasherInterface;
18-
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1918
use Symfony\Component\Security\Core\User\InMemoryUser;
2019
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
2120
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
2221
use Symfony\Component\Security\Core\User\UserInterface;
2322
use Symfony\Component\Security\Core\User\UserProviderInterface;
24-
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
2523
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PasswordUpgradeBadge;
2624
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
2725
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
2826
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
2927
use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
3028
use Symfony\Component\Security\Http\EventListener\PasswordMigratingListener;
29+
use Symfony\Component\Security\Http\Tests\Fixtures\DummyAuthenticator;
30+
use Symfony\Component\Security\Http\Tests\Fixtures\DummyToken;
3131

3232
class PasswordMigratingListenerTest extends TestCase
3333
{
@@ -57,18 +57,18 @@ public function testUnsupportedEvents($event)
5757
$this->listener->onLoginSuccess($event);
5858
}
5959

60-
public function provideUnsupportedEvents()
60+
public static function provideUnsupportedEvents()
6161
{
6262
// no password upgrade badge
63-
yield [$this->createEvent(new SelfValidatingPassport(new UserBadge('test', function () { return $this->createMock(UserInterface::class); })))];
63+
yield [self::createEvent(new SelfValidatingPassport(new UserBadge('test', function () { return $this->createMock(UserInterface::class); })))];
6464

6565
// blank password
66-
yield [$this->createEvent(new SelfValidatingPassport(new UserBadge('test', function () { return $this->createMock(TestPasswordAuthenticatedUser::class); }), [new PasswordUpgradeBadge('', $this->createPasswordUpgrader())]))];
66+
yield [self::createEvent(new SelfValidatingPassport(new UserBadge('test', function () { return new DummyTestPasswordAuthenticatedUser(); }), [new PasswordUpgradeBadge('', self::createPasswordUpgrader())]))];
6767
}
6868

6969
public function testUpgradeWithUpgrader()
7070
{
71-
$passwordUpgrader = $this->createPasswordUpgrader();
71+
$passwordUpgrader = $this->getMockForAbstractClass(TestMigratingUserProvider::class);
7272
$passwordUpgrader->expects($this->once())
7373
->method('upgradePassword')
7474
->with($this->user, 'new-hash')
@@ -105,14 +105,14 @@ public function testUserWithoutPassword()
105105
$this->listener->onLoginSuccess($event);
106106
}
107107

108-
private function createPasswordUpgrader()
108+
private static function createPasswordUpgrader()
109109
{
110-
return $this->getMockForAbstractClass(TestMigratingUserProvider::class);
110+
return new DummyTestMigratingUserProvider();
111111
}
112112

113-
private function createEvent(Passport $passport)
113+
private static function createEvent(PassportInterface $passport)
114114
{
115-
return new LoginSuccessEvent($this->createMock(AuthenticatorInterface::class), $passport, $this->createMock(TokenInterface::class), new Request(), null, 'main');
115+
return new LoginSuccessEvent(new DummyAuthenticator(), $passport, new DummyToken(), new Request(), null, 'main');
116116
}
117117
}
118118

@@ -123,9 +123,62 @@ abstract public function upgradePassword(PasswordAuthenticatedUserInterface $use
123123
abstract public function loadUserByIdentifier(string $identifier): UserInterface;
124124
}
125125

126+
class DummyTestMigratingUserProvider extends TestMigratingUserProvider
127+
{
128+
public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
129+
{
130+
}
131+
132+
public function loadUserByIdentifier(string $identifier): UserInterface
133+
{
134+
}
135+
136+
public function refreshUser(UserInterface $user)
137+
{
138+
}
139+
140+
public function supportsClass(string $class)
141+
{
142+
}
143+
144+
public function loadUserByUsername(string $username)
145+
{
146+
}
147+
}
148+
126149
abstract class TestPasswordAuthenticatedUser implements UserInterface, PasswordAuthenticatedUserInterface
127150
{
128151
abstract public function getPassword(): ?string;
129152

130153
abstract public function getSalt(): ?string;
131154
}
155+
156+
class DummyTestPasswordAuthenticatedUser extends TestPasswordAuthenticatedUser
157+
{
158+
public function getPassword(): ?string
159+
{
160+
return null;
161+
}
162+
163+
public function getSalt(): ?string
164+
{
165+
return null;
166+
}
167+
168+
public function getRoles(): array
169+
{
170+
return [];
171+
}
172+
173+
public function eraseCredentials()
174+
{
175+
}
176+
177+
public function getUsername()
178+
{
179+
}
180+
181+
public function getUserIdentifier(): string
182+
{
183+
}
184+
}

Tests/Fixtures/DummyAuthenticator.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Http\Tests\Fixtures;
13+
14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\Response;
16+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
17+
use Symfony\Component\Security\Core\Exception\AuthenticationException;
18+
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
19+
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
20+
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
21+
22+
/**
23+
* @author Alexandre Daubois <alex.daubois@gmail.com>
24+
*/
25+
class DummyAuthenticator implements AuthenticatorInterface
26+
{
27+
public function supports(Request $request): ?bool
28+
{
29+
return null;
30+
}
31+
32+
public function authenticate(Request $request): Passport
33+
{
34+
}
35+
36+
public function createToken(Passport $passport, string $firewallName): TokenInterface
37+
{
38+
}
39+
40+
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
41+
{
42+
return null;
43+
}
44+
45+
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
46+
{
47+
return null;
48+
}
49+
50+
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
51+
{
52+
}
53+
}

Tests/Fixtures/DummyToken.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Http\Tests\Fixtures;
13+
14+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
15+
use Symfony\Component\Security\Core\User\UserInterface;
16+
17+
/**
18+
* @author Alexandre Daubois <alex.daubois@gmail.com>
19+
*/
20+
class DummyToken implements TokenInterface
21+
{
22+
public function serialize()
23+
{
24+
}
25+
26+
public function unserialize($data)
27+
{
28+
}
29+
30+
public function __toString(): string
31+
{
32+
}
33+
34+
public function getRoleNames(): array
35+
{
36+
}
37+
38+
public function getCredentials(): mixed
39+
{
40+
}
41+
42+
public function getUser(): ?UserInterface
43+
{
44+
}
45+
46+
public function setUser($user)
47+
{
48+
}
49+
50+
public function isAuthenticated(): bool
51+
{
52+
}
53+
54+
public function setAuthenticated(bool $isAuthenticated)
55+
{
56+
}
57+
58+
public function eraseCredentials(): void
59+
{
60+
}
61+
62+
public function getAttributes(): array
63+
{
64+
}
65+
66+
public function setAttributes(array $attributes): void
67+
{
68+
}
69+
70+
public function hasAttribute(string $name): bool
71+
{
72+
}
73+
74+
public function getAttribute(string $name): mixed
75+
{
76+
}
77+
78+
public function setAttribute(string $name, $value): void
79+
{
80+
}
81+
82+
public function getUsername(): string
83+
{
84+
}
85+
86+
public function getUserIdentifier(): string
87+
{
88+
}
89+
90+
public function __serialize(): array
91+
{
92+
}
93+
94+
public function __unserialize(array $data): void
95+
{
96+
}
97+
98+
public function __call(string $name, array $arguments)
99+
{
100+
}
101+
}

0 commit comments

Comments
 (0)