Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #26370 [Security] added userChecker to SimpleAuthenticationProvid…
…er (i3or1s) This PR was submitted for the 2.8 branch but it was squashed and merged into the 2.7 branch instead (closes #26370). Discussion ---------- [Security] added userChecker to SimpleAuthenticationProvider [Security] added userChecker to SimpleAuthenticationProvider [SecurityBundle] [DependencyInjection] updated SimpleFormFactory | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26314 | License | MIT | Doc PR | no Introduces user checker to the simple authentication provider. Commits ------- cb9c92d [Security] added userChecker to SimpleAuthenticationProvider
- Loading branch information
Showing
3 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...omponent/Security/Core/Tests/Authentication/Provider/SimpleAuthenticationProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Security\Core\Tests\Authentication\Provider; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Security\Core\Exception\DisabledException; | ||
use Symfony\Component\Security\Core\Authentication\Provider\SimpleAuthenticationProvider; | ||
use Symfony\Component\Security\Core\Exception\LockedException; | ||
|
||
class SimpleAuthenticationProviderTest extends TestCase | ||
{ | ||
/** | ||
* @expectedException \Symfony\Component\Security\Core\Exception\DisabledException | ||
*/ | ||
public function testAuthenticateWhenPreChecksFails() | ||
{ | ||
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock(); | ||
|
||
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock(); | ||
$token->expects($this->any()) | ||
->method('getUser') | ||
->will($this->returnValue($user)); | ||
|
||
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock(); | ||
$userChecker->expects($this->once()) | ||
->method('checkPreAuth') | ||
->will($this->throwException(new DisabledException())); | ||
|
||
$authenticator = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface')->getMock(); | ||
$authenticator->expects($this->once()) | ||
->method('authenticateToken') | ||
->will($this->returnValue($token)); | ||
|
||
$provider = $this->getProvider($authenticator, null, $userChecker); | ||
|
||
$provider->authenticate($token); | ||
} | ||
|
||
/** | ||
* @expectedException \Symfony\Component\Security\Core\Exception\LockedException | ||
*/ | ||
public function testAuthenticateWhenPostChecksFails() | ||
{ | ||
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock(); | ||
|
||
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock(); | ||
$token->expects($this->any()) | ||
->method('getUser') | ||
->will($this->returnValue($user)); | ||
|
||
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock(); | ||
$userChecker->expects($this->once()) | ||
->method('checkPostAuth') | ||
->will($this->throwException(new LockedException())); | ||
|
||
$authenticator = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface')->getMock(); | ||
$authenticator->expects($this->once()) | ||
->method('authenticateToken') | ||
->will($this->returnValue($token)); | ||
|
||
$provider = $this->getProvider($authenticator, null, $userChecker); | ||
|
||
$provider->authenticate($token); | ||
} | ||
|
||
protected function getProvider($simpleAuthenticator = null, $userProvider = null, $userChecker = null, $key = 'test') | ||
{ | ||
if (null === $userChecker) { | ||
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock(); | ||
} | ||
if (null === $simpleAuthenticator) { | ||
$simpleAuthenticator = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface')->getMock(); | ||
} | ||
if (null === $userProvider) { | ||
$userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock(); | ||
} | ||
|
||
return new SimpleAuthenticationProvider($simpleAuthenticator, $userProvider, $key, $userChecker); | ||
} | ||
} |