|
|
|
|
@@ -14,7 +14,8 @@ use App\Configuration\SystemConfiguration;
|
|
|
|
|
use App\Entity\User;
|
|
|
|
|
use App\Ldap\LdapAuthenticationProvider;
|
|
|
|
|
use App\Ldap\LdapManager;
|
|
|
|
|
use App\Ldap\LdapUserProvider;
|
|
|
|
|
use App\Repository\UserRepository;
|
|
|
|
|
use App\Security\DoctrineUserProvider;
|
|
|
|
|
use App\Tests\Configuration\TestConfigLoader;
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
|
|
|
|
@@ -28,6 +29,11 @@ use Symfony\Component\Security\Core\User\UserChecker;
|
|
|
|
|
*/
|
|
|
|
|
class LdapAuthenticationProviderTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
private function getUserProvider(): DoctrineUserProvider
|
|
|
|
|
{
|
|
|
|
|
return new DoctrineUserProvider($this->createMock(UserRepository::class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getConfiguration(bool $active = true): LdapConfiguration
|
|
|
|
|
{
|
|
|
|
|
$systemConfig = new SystemConfiguration(new TestConfigLoader([]), ['ldap' => ['activate' => $active]]);
|
|
|
|
|
@@ -40,7 +46,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
$config = $this->getConfiguration(false);
|
|
|
|
|
$userProvider = new LdapUserProvider($manager);
|
|
|
|
|
$userProvider = $this->getUserProvider();
|
|
|
|
|
$providerKey = 'secured_area';
|
|
|
|
|
$userChecker = new UserChecker();
|
|
|
|
|
|
|
|
|
|
@@ -55,7 +61,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
$config = $this->getConfiguration(true);
|
|
|
|
|
$userProvider = new LdapUserProvider($manager);
|
|
|
|
|
$userProvider = $this->getUserProvider();
|
|
|
|
|
$providerKey = 'secured_area';
|
|
|
|
|
$userChecker = new UserChecker();
|
|
|
|
|
|
|
|
|
|
@@ -73,7 +79,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|
|
|
|
|
|
|
|
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
$config = $this->getConfiguration(true);
|
|
|
|
|
$userProvider = new LdapUserProvider($manager);
|
|
|
|
|
$userProvider = $this->getUserProvider();
|
|
|
|
|
$providerKey = 'secured_area';
|
|
|
|
|
$userChecker = new UserChecker();
|
|
|
|
|
|
|
|
|
|
@@ -92,7 +98,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|
|
|
|
$user = (new User())->setUsername('foo')->setEnabled(true);
|
|
|
|
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
$config = $this->getConfiguration(true);
|
|
|
|
|
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->onlyMethods(['loadUserByUsername'])->getMock();
|
|
|
|
|
$userProvider = $this->getMockBuilder(DoctrineUserProvider::class)->disableOriginalConstructor()->onlyMethods(['loadUserByUsername'])->getMock();
|
|
|
|
|
$userProvider->expects($this->once())->method('loadUserByUsername')->willReturn($user);
|
|
|
|
|
$providerKey = 'secured_area';
|
|
|
|
|
$userChecker = new UserChecker();
|
|
|
|
|
@@ -112,7 +118,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|
|
|
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->onlyMethods(['bind'])->getMock();
|
|
|
|
|
$manager->expects($this->once())->method('bind')->willReturn(false);
|
|
|
|
|
$config = $this->getConfiguration(true);
|
|
|
|
|
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->onlyMethods(['loadUserByUsername'])->getMock();
|
|
|
|
|
$userProvider = $this->getMockBuilder(DoctrineUserProvider::class)->disableOriginalConstructor()->onlyMethods(['loadUserByUsername'])->getMock();
|
|
|
|
|
$userProvider->expects($this->once())->method('loadUserByUsername')->willReturn($user);
|
|
|
|
|
$providerKey = 'secured_area';
|
|
|
|
|
$userChecker = new UserChecker();
|
|
|
|
|
@@ -132,7 +138,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|
|
|
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->onlyMethods(['bind'])->getMock();
|
|
|
|
|
$manager->expects($this->once())->method('bind')->willReturn(false);
|
|
|
|
|
$config = $this->getConfiguration(true);
|
|
|
|
|
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->onlyMethods(['loadUserByUsername'])->getMock();
|
|
|
|
|
$userProvider = $this->getMockBuilder(DoctrineUserProvider::class)->disableOriginalConstructor()->onlyMethods(['loadUserByUsername'])->getMock();
|
|
|
|
|
$userProvider->expects($this->never())->method('loadUserByUsername');
|
|
|
|
|
$providerKey = 'secured_area';
|
|
|
|
|
$userChecker = new UserChecker();
|
|
|
|
|
@@ -153,7 +159,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|
|
|
|
self::assertSame($updateUser, $user);
|
|
|
|
|
});
|
|
|
|
|
$config = $this->getConfiguration(true);
|
|
|
|
|
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->onlyMethods(['loadUserByUsername'])->getMock();
|
|
|
|
|
$userProvider = $this->getMockBuilder(DoctrineUserProvider::class)->disableOriginalConstructor()->onlyMethods(['loadUserByUsername'])->getMock();
|
|
|
|
|
$userProvider->expects($this->once())->method('loadUserByUsername')->willReturn($user);
|
|
|
|
|
$providerKey = 'secured_area';
|
|
|
|
|
$userChecker = new UserChecker();
|
|
|
|
|
@@ -175,7 +181,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|
|
|
|
self::assertSame($updateUser, $user);
|
|
|
|
|
});
|
|
|
|
|
$config = $this->getConfiguration(true);
|
|
|
|
|
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->onlyMethods(['loadUserByUsername'])->getMock();
|
|
|
|
|
$userProvider = $this->getMockBuilder(DoctrineUserProvider::class)->disableOriginalConstructor()->onlyMethods(['loadUserByUsername'])->getMock();
|
|
|
|
|
$userProvider->expects($this->never())->method('loadUserByUsername');
|
|
|
|
|
$providerKey = 'secured_area';
|
|
|
|
|
$userChecker = new UserChecker();
|
|
|
|
|
@@ -194,7 +200,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|
|
|
|
|
|
|
|
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
$config = $this->getConfiguration(true);
|
|
|
|
|
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->onlyMethods(['loadUserByUsername'])->getMock();
|
|
|
|
|
$userProvider = $this->getMockBuilder(DoctrineUserProvider::class)->disableOriginalConstructor()->onlyMethods(['loadUserByUsername'])->getMock();
|
|
|
|
|
$userProvider->expects($this->once())->method('loadUserByUsername')->willThrowException(new UsernameNotFoundException('blub foo bar'));
|
|
|
|
|
$providerKey = 'secured_area';
|
|
|
|
|
$userChecker = new UserChecker();
|
|
|
|
|
@@ -213,7 +219,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|
|
|
|
|
|
|
|
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
$config = $this->getConfiguration(true);
|
|
|
|
|
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->onlyMethods(['loadUserByUsername'])->getMock();
|
|
|
|
|
$userProvider = $this->getMockBuilder(DoctrineUserProvider::class)->disableOriginalConstructor()->onlyMethods(['loadUserByUsername'])->getMock();
|
|
|
|
|
$userProvider->expects($this->once())->method('loadUserByUsername')->willThrowException(new \Exception('server away', 1234));
|
|
|
|
|
$providerKey = 'secured_area';
|
|
|
|
|
$userChecker = new UserChecker();
|
|
|
|
|
|