Skip to content

Commit 53d572f

Browse files
[Security/Http] Fix getting password-upgrader when user-loader is a closure
1 parent 8f21e1c commit 53d572f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

EventListener/PasswordMigratingListener.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ public function onLoginSuccess(LoginSuccessEvent $event): void
7979
$userLoader = $userBadge->getUserLoader();
8080
if (\is_array($userLoader) && $userLoader[0] instanceof PasswordUpgraderInterface) {
8181
$passwordUpgrader = $userLoader[0];
82-
} else {
82+
} elseif (!$userLoader instanceof \Closure
83+
|| !($passwordUpgrader = (new \ReflectionFunction($userLoader))->getClosureThis()) instanceof PasswordUpgraderInterface
84+
) {
8385
return;
8486
}
8587
}

Tests/EventListener/PasswordMigratingListenerTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,16 @@ public function testUpgradeWithoutUpgrader()
111111
$userLoader = $this->getMockForAbstractClass(TestMigratingUserProvider::class);
112112
$userLoader->expects($this->any())->method('loadUserByIdentifier')->willReturn($this->user);
113113

114-
$userLoader->expects($this->once())
114+
$userLoader->expects($this->exactly(2))
115115
->method('upgradePassword')
116116
->with($this->user, 'new-hash')
117117
;
118118

119119
$event = $this->createEvent(new SelfValidatingPassport(new UserBadge('test', [$userLoader, 'loadUserByIdentifier']), [new PasswordUpgradeBadge('pa$$word')]));
120120
$this->listener->onLoginSuccess($event);
121+
122+
$event = $this->createEvent(new SelfValidatingPassport(new UserBadge('test', \Closure::fromCallable([$userLoader, 'loadUserByIdentifier'])), [new PasswordUpgradeBadge('pa$$word')]));
123+
$this->listener->onLoginSuccess($event);
121124
}
122125

123126
public function testUserWithoutPassword()

0 commit comments

Comments
 (0)