Skip to content

fixed UserProvider::refreshUser() not checking the class #1239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Security/UserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public function refreshUser(SecurityUserInterface $user)
throw new UnsupportedUserException(sprintf('Expected an instance of FOS\UserBundle\Model\User, but got "%s".', get_class($user)));
}

if (!$this->supportsClass(get_class($user))) {
throw new UnsupportedUserException(sprintf('Expected an instance of %s, but got "%s".', $this->userManager->getClass(), get_class($user)));
}

if (null === $reloadedUser = $this->userManager->findUserBy(array('id' => $user->getId()))) {
throw new UsernameNotFoundException(sprintf('User with ID "%d" could not be reloaded.', $user->getId()));
}
Expand Down
4 changes: 4 additions & 0 deletions Tests/Security/EmailUserProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function testRefreshUserBy()
->with(array('id' => '123'))
->will($this->returnValue($refreshedUser));

$this->userManager->expects($this->atLeastOnce())
->method('getClass')
->will($this->returnValue(get_class($user)));

$this->assertSame($refreshedUser, $this->userProvider->refreshUser($user));
}

Expand Down
26 changes: 26 additions & 0 deletions Tests/Security/UserProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function testRefreshUserBy()
->with(array('id' => '123'))
->will($this->returnValue($refreshedUser));

$this->userManager->expects($this->atLeastOnce())
->method('getClass')
->will($this->returnValue(get_class($user)));

$this->assertSame($refreshedUser, $this->userProvider->refreshUser($user));
}

Expand All @@ -75,6 +79,10 @@ public function testRefreshDeleted()
->method('findUserBy')
->will($this->returnValue(null));

$this->userManager->expects($this->atLeastOnce())
->method('getClass')
->will($this->returnValue(get_class($user)));

$this->userProvider->refreshUser($user);
}

Expand All @@ -84,7 +92,25 @@ public function testRefreshDeleted()
public function testRefreshInvalidUser()
{
$user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
$this->userManager->expects($this->any())
->method('getClass')
->will($this->returnValue(get_class($user)));

$this->userProvider->refreshUser($user);
}

/**
* @expectedException \Symfony\Component\Security\Core\Exception\UnsupportedUserException
*/
public function testRefreshInvalidUserClass()
{
$user = $this->getMock('FOS\UserBundle\Model\User');
$providedUser = $this->getMock('FOS\UserBundle\Tests\TestUser');

$this->userManager->expects($this->atLeastOnce())
->method('getClass')
->will($this->returnValue(get_class($user)));

$this->userProvider->refreshUser($providedUser);
}
}