LDAP authentication support (#815)

This commit is contained in:
Kevin Papst
2019-06-07 22:48:39 +02:00
committed by GitHub
parent bcf1ebd778
commit 0c0e9c2f71
99 changed files with 3542 additions and 926 deletions

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Security;
use App\Security\RoleService;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Security\RoleService
*/
class RoleServiceTest extends TestCase
{
public function testGetAvailableNames()
{
$real = [
'ROLE_TEAMLEAD' => [0 => 'ROLE_USER'],
'ROLE_ADMIN' => [0 => 'ROLE_TEAMLEAD'],
'ROLE_SUPER_ADMIN' => [0 => 'ROLE_ADMIN']
];
$sut = new RoleService($real);
$expected = ['ROLE_TEAMLEAD', 'ROLE_USER', 'ROLE_ADMIN', 'ROLE_SUPER_ADMIN'];
self::assertEquals($expected, $sut->getAvailableNames());
}
}

View File

@@ -7,51 +7,57 @@
* file that was distributed with this source code.
*/
namespace App\Tests\Model;
namespace App\Tests\Security;
use App\Entity\User;
use App\Security\UserChecker;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\User as SymfonyUser;
/**
* @covers \App\Security\UserChecker
*/
class UserCheckerTest extends TestCase
{
public function testCheckPreAuth()
public function testCheckPreAuthReturnsOnUnknownUserClass()
{
$sut = new UserChecker();
$user = new User();
try {
$sut->checkPreAuth($user);
$sut->checkPreAuth(new SymfonyUser('sdf', null));
} catch (\Exception $ex) {
$this->fail('UserChecker should not throw exception in checkPreAuth()');
$this->fail('UserChecker should not throw exception in checkPreAuth(), ' . $ex->getMessage());
}
$this->assertTrue(true);
}
public function testCheckPostAuthReturnsOnUnknownUserClass()
{
$sut = new UserChecker();
try {
$sut->checkPostAuth(new SymfonyUser('sdf', null));
} catch (\Exception $ex) {
$this->fail('UserChecker should not throw exception in checkPostAuth(), ' . $ex->getMessage());
}
$this->assertTrue(true);
}
/**
* @expectedException \Symfony\Component\Security\Core\Exception\LockedException
* @expectedException \Symfony\Component\Security\Core\Exception\DisabledException
* @expectedExceptionMessage User account is disabled.
*/
public function testDisabledCannotLogin()
public function testDisabledCannotLoginInCheckPreAuth()
{
$sut = new UserChecker();
$user = new User();
$user->setEnabled(false);
$sut->checkPostAuth($user);
(new UserChecker())->checkPreAuth((new User())->setEnabled(false));
}
public function testCheckPostAuth()
/**
* @expectedException \Symfony\Component\Security\Core\Exception\DisabledException
* @expectedExceptionMessage User account is disabled.
*/
public function testDisabledCannotLoginInCheckPostAuth()
{
$sut = new UserChecker();
$mock = $this->getMockBuilder(UserInterface::class)->setMethods(['isEnabled'])->getMockForAbstractClass();
$mock->expects($this->never())->method('isEnabled')->willReturn(false);
$sut->checkPostAuth($mock);
$this->assertTrue(true);
(new UserChecker())->checkPostAuth((new User())->setEnabled(false));
}
}