Rewrite of the authentication and authorization system
This commit is contained in:
@@ -49,6 +49,13 @@ class ClientTest extends \Base
|
||||
self::$functions = null;
|
||||
}
|
||||
|
||||
public function testGetLdapServerNotConfigured()
|
||||
{
|
||||
$this->setExpectedException('\LogicException');
|
||||
$ldap = new Client;
|
||||
$ldap->getLdapServer();
|
||||
}
|
||||
|
||||
public function testConnectSuccess()
|
||||
{
|
||||
self::$functions
|
||||
@@ -61,7 +68,8 @@ class ClientTest extends \Base
|
||||
->will($this->returnValue('my_ldap_resource'));
|
||||
|
||||
$ldap = new Client;
|
||||
$this->assertEquals('my_ldap_resource', $ldap->getConnection('my_ldap_server'));
|
||||
$ldap->open('my_ldap_server');
|
||||
$this->assertEquals('my_ldap_resource', $ldap->getConnection());
|
||||
}
|
||||
|
||||
public function testConnectFailure()
|
||||
@@ -78,7 +86,8 @@ class ClientTest extends \Base
|
||||
$this->setExpectedException('\Kanboard\Core\Ldap\ClientException');
|
||||
|
||||
$ldap = new Client;
|
||||
$this->assertNotEquals('my_ldap_resource', $ldap->getConnection('my_ldap_server'));
|
||||
$ldap->open('my_ldap_server');
|
||||
$this->assertNotEquals('my_ldap_resource', $ldap->getConnection());
|
||||
}
|
||||
|
||||
public function testConnectSuccessWithTLS()
|
||||
@@ -101,7 +110,8 @@ class ClientTest extends \Base
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$ldap = new Client;
|
||||
$this->assertEquals('my_ldap_resource', $ldap->getConnection('my_ldap_server', 389, true));
|
||||
$ldap->open('my_ldap_server', 389, true);
|
||||
$this->assertEquals('my_ldap_resource', $ldap->getConnection());
|
||||
}
|
||||
|
||||
public function testConnectFailureWithTLS()
|
||||
@@ -126,7 +136,8 @@ class ClientTest extends \Base
|
||||
$this->setExpectedException('\Kanboard\Core\Ldap\ClientException');
|
||||
|
||||
$ldap = new Client;
|
||||
$this->assertNotEquals('my_ldap_resource', $ldap->getConnection('my_ldap_server', 389, true));
|
||||
$ldap->open('my_ldap_server', 389, true);
|
||||
$this->assertNotEquals('my_ldap_resource', $ldap->getConnection());
|
||||
}
|
||||
|
||||
public function testAnonymousAuthenticationSuccess()
|
||||
@@ -134,13 +145,10 @@ class ClientTest extends \Base
|
||||
self::$functions
|
||||
->expects($this->once())
|
||||
->method('ldap_bind')
|
||||
->with(
|
||||
$this->equalTo('my_ldap_resource')
|
||||
)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$ldap = new Client;
|
||||
$this->assertTrue($ldap->useAnonymousAuthentication('my_ldap_resource'));
|
||||
$this->assertTrue($ldap->useAnonymousAuthentication());
|
||||
}
|
||||
|
||||
public function testAnonymousAuthenticationFailure()
|
||||
@@ -148,19 +156,25 @@ class ClientTest extends \Base
|
||||
self::$functions
|
||||
->expects($this->once())
|
||||
->method('ldap_bind')
|
||||
->with(
|
||||
$this->equalTo('my_ldap_resource')
|
||||
)
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->setExpectedException('\Kanboard\Core\Ldap\ClientException');
|
||||
|
||||
$ldap = new Client;
|
||||
$ldap->useAnonymousAuthentication('my_ldap_resource');
|
||||
$ldap->useAnonymousAuthentication();
|
||||
}
|
||||
|
||||
public function testUserAuthenticationSuccess()
|
||||
{
|
||||
self::$functions
|
||||
->expects($this->once())
|
||||
->method('ldap_connect')
|
||||
->with(
|
||||
$this->equalTo('my_ldap_server'),
|
||||
$this->equalTo(389)
|
||||
)
|
||||
->will($this->returnValue('my_ldap_resource'));
|
||||
|
||||
self::$functions
|
||||
->expects($this->once())
|
||||
->method('ldap_bind')
|
||||
@@ -172,11 +186,21 @@ class ClientTest extends \Base
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$ldap = new Client;
|
||||
$this->assertTrue($ldap->authenticate('my_ldap_resource', 'my_ldap_user', 'my_ldap_password'));
|
||||
$ldap->open('my_ldap_server');
|
||||
$this->assertTrue($ldap->authenticate('my_ldap_user', 'my_ldap_password'));
|
||||
}
|
||||
|
||||
public function testUserAuthenticationFailure()
|
||||
{
|
||||
self::$functions
|
||||
->expects($this->once())
|
||||
->method('ldap_connect')
|
||||
->with(
|
||||
$this->equalTo('my_ldap_server'),
|
||||
$this->equalTo(389)
|
||||
)
|
||||
->will($this->returnValue('my_ldap_resource'));
|
||||
|
||||
self::$functions
|
||||
->expects($this->once())
|
||||
->method('ldap_bind')
|
||||
@@ -190,6 +214,7 @@ class ClientTest extends \Base
|
||||
$this->setExpectedException('\Kanboard\Core\Ldap\ClientException');
|
||||
|
||||
$ldap = new Client;
|
||||
$ldap->authenticate('my_ldap_resource', 'my_ldap_user', 'my_ldap_password');
|
||||
$ldap->open('my_ldap_server');
|
||||
$ldap->authenticate('my_ldap_user', 'my_ldap_password');
|
||||
}
|
||||
}
|
||||
|
||||
55
tests/units/Core/Ldap/EntriesTest.php
Normal file
55
tests/units/Core/Ldap/EntriesTest.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../../Base.php';
|
||||
|
||||
use Kanboard\Core\Ldap\Entries;
|
||||
|
||||
class EntriesTest extends Base
|
||||
{
|
||||
private $entries = array(
|
||||
'count' => 2,
|
||||
0 => array(
|
||||
'cn' => array(
|
||||
'count' => 1,
|
||||
0 => 'Kanboard Other Group',
|
||||
),
|
||||
0 => 'cn',
|
||||
'count' => 1,
|
||||
'dn' => 'CN=Kanboard Other Group,CN=Users,DC=kanboard,DC=local',
|
||||
),
|
||||
1 => array(
|
||||
'cn' => array(
|
||||
'count' => 1,
|
||||
0 => 'Kanboard Users',
|
||||
),
|
||||
0 => 'cn',
|
||||
'count' => 1,
|
||||
'dn' => 'CN=Kanboard Users,CN=Users,DC=kanboard,DC=local',
|
||||
),
|
||||
);
|
||||
|
||||
public function testGetAll()
|
||||
{
|
||||
$entries = new Entries(array());
|
||||
$this->assertEmpty($entries->getAll());
|
||||
|
||||
$entries = new Entries($this->entries);
|
||||
$result = $entries->getAll();
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertInstanceOf('Kanboard\Core\Ldap\Entry', $result[0]);
|
||||
$this->assertEquals('CN=Kanboard Users,CN=Users,DC=kanboard,DC=local', $result[1]->getDn());
|
||||
$this->assertEquals('Kanboard Users', $result[1]->getFirstValue('cn'));
|
||||
}
|
||||
|
||||
public function testGetFirst()
|
||||
{
|
||||
$entries = new Entries(array());
|
||||
$this->assertEquals('', $entries->getFirstEntry()->getDn());
|
||||
|
||||
$entries = new Entries($this->entries);
|
||||
$result = $entries->getFirstEntry();
|
||||
$this->assertInstanceOf('Kanboard\Core\Ldap\Entry', $result);
|
||||
$this->assertEquals('CN=Kanboard Other Group,CN=Users,DC=kanboard,DC=local', $result->getDn());
|
||||
$this->assertEquals('Kanboard Other Group', $result->getFirstValue('cn'));
|
||||
}
|
||||
}
|
||||
71
tests/units/Core/Ldap/EntryTest.php
Normal file
71
tests/units/Core/Ldap/EntryTest.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../../Base.php';
|
||||
|
||||
use Kanboard\Core\Ldap\Entry;
|
||||
|
||||
class EntryTest extends Base
|
||||
{
|
||||
private $entry = array(
|
||||
'count' => 2,
|
||||
'dn' => 'uid=my_user,ou=People,dc=kanboard,dc=local',
|
||||
'displayname' => array(
|
||||
'count' => 1,
|
||||
0 => 'My LDAP user',
|
||||
),
|
||||
'broken' => array(
|
||||
),
|
||||
'mail' => array(
|
||||
'count' => 2,
|
||||
0 => 'user1@localhost',
|
||||
1 => 'user2@localhost',
|
||||
),
|
||||
'samaccountname' => array(
|
||||
'count' => 1,
|
||||
0 => 'my_ldap_user',
|
||||
),
|
||||
0 => 'displayname',
|
||||
1 => 'mail',
|
||||
2 => 'samaccountname',
|
||||
);
|
||||
|
||||
public function testGetAll()
|
||||
{
|
||||
$expected = array(
|
||||
'user1@localhost',
|
||||
'user2@localhost',
|
||||
);
|
||||
|
||||
$entry = new Entry($this->entry);
|
||||
$this->assertEquals($expected, $entry->getAll('mail'));
|
||||
$this->assertEmpty($entry->getAll('not found'));
|
||||
$this->assertEmpty($entry->getAll('broken'));
|
||||
}
|
||||
|
||||
public function testGetFirst()
|
||||
{
|
||||
$entry = new Entry($this->entry);
|
||||
$this->assertEquals('user1@localhost', $entry->getFirstValue('mail'));
|
||||
$this->assertEquals('', $entry->getFirstValue('not found'));
|
||||
$this->assertEquals('default', $entry->getFirstValue('not found', 'default'));
|
||||
$this->assertEquals('default', $entry->getFirstValue('broken', 'default'));
|
||||
}
|
||||
|
||||
public function testGetDn()
|
||||
{
|
||||
$entry = new Entry($this->entry);
|
||||
$this->assertEquals('uid=my_user,ou=People,dc=kanboard,dc=local', $entry->getDn());
|
||||
|
||||
$entry = new Entry(array());
|
||||
$this->assertEquals('', $entry->getDn());
|
||||
}
|
||||
|
||||
public function testHasValue()
|
||||
{
|
||||
$entry = new Entry($this->entry);
|
||||
$this->assertTrue($entry->hasValue('mail', 'user2@localhost'));
|
||||
$this->assertFalse($entry->hasValue('mail', 'user3@localhost'));
|
||||
$this->assertTrue($entry->hasValue('displayname', 'My LDAP user'));
|
||||
$this->assertFalse($entry->hasValue('displayname', 'Something else'));
|
||||
}
|
||||
}
|
||||
160
tests/units/Core/Ldap/LdapGroupTest.php
Normal file
160
tests/units/Core/Ldap/LdapGroupTest.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../../Base.php';
|
||||
|
||||
use Kanboard\Core\Ldap\Group;
|
||||
use Kanboard\Core\Ldap\Entries;
|
||||
use Kanboard\Core\Security\Role;
|
||||
|
||||
class LdapGroupTest extends Base
|
||||
{
|
||||
private $query;
|
||||
private $client;
|
||||
private $group;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->client = $this
|
||||
->getMockBuilder('\Kanboard\Core\Ldap\Client')
|
||||
->setMethods(array(
|
||||
'getConnection',
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$this->query = $this
|
||||
->getMockBuilder('\Kanboard\Core\Ldap\Query')
|
||||
->setConstructorArgs(array($this->client))
|
||||
->setMethods(array(
|
||||
'execute',
|
||||
'hasResult',
|
||||
'getEntries',
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$this->group = $this
|
||||
->getMockBuilder('\Kanboard\Core\Ldap\Group')
|
||||
->setConstructorArgs(array($this->query))
|
||||
->setMethods(array(
|
||||
'getAttributeName',
|
||||
'getBasDn',
|
||||
))
|
||||
->getMock();
|
||||
}
|
||||
|
||||
public function testGetGroups()
|
||||
{
|
||||
$entries = new Entries(array(
|
||||
'count' => 2,
|
||||
0 => array(
|
||||
'cn' => array(
|
||||
'count' => 1,
|
||||
0 => 'Kanboard Other Group',
|
||||
),
|
||||
0 => 'cn',
|
||||
'count' => 1,
|
||||
'dn' => 'CN=Kanboard Other Group,CN=Users,DC=kanboard,DC=local',
|
||||
),
|
||||
1 => array(
|
||||
'cn' => array(
|
||||
'count' => 1,
|
||||
0 => 'Kanboard Users',
|
||||
),
|
||||
0 => 'cn',
|
||||
'count' => 1,
|
||||
'dn' => 'CN=Kanboard Users,CN=Users,DC=kanboard,DC=local',
|
||||
),
|
||||
));
|
||||
|
||||
$this->client
|
||||
->expects($this->any())
|
||||
->method('getConnection')
|
||||
->will($this->returnValue('my_ldap_resource'));
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->with(
|
||||
$this->equalTo('CN=Users,DC=kanboard,DC=local'),
|
||||
$this->equalTo('(&(objectClass=group)(sAMAccountName=Kanboard*))')
|
||||
);
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('hasResult')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('getEntries')
|
||||
->will($this->returnValue($entries));
|
||||
|
||||
$this->group
|
||||
->expects($this->any())
|
||||
->method('getAttributeName')
|
||||
->will($this->returnValue('cn'));
|
||||
|
||||
$this->group
|
||||
->expects($this->any())
|
||||
->method('getBasDn')
|
||||
->will($this->returnValue('CN=Users,DC=kanboard,DC=local'));
|
||||
|
||||
$groups = $this->group->find('(&(objectClass=group)(sAMAccountName=Kanboard*))');
|
||||
$this->assertCount(2, $groups);
|
||||
$this->assertInstanceOf('Kanboard\Group\LdapGroupProvider', $groups[0]);
|
||||
$this->assertInstanceOf('Kanboard\Group\LdapGroupProvider', $groups[1]);
|
||||
$this->assertEquals('Kanboard Other Group', $groups[0]->getName());
|
||||
$this->assertEquals('Kanboard Users', $groups[1]->getName());
|
||||
$this->assertEquals('CN=Kanboard Other Group,CN=Users,DC=kanboard,DC=local', $groups[0]->getExternalId());
|
||||
$this->assertEquals('CN=Kanboard Users,CN=Users,DC=kanboard,DC=local', $groups[1]->getExternalId());
|
||||
}
|
||||
|
||||
public function testGetGroupsWithNoResult()
|
||||
{
|
||||
$entries = new Entries(array());
|
||||
|
||||
$this->client
|
||||
->expects($this->any())
|
||||
->method('getConnection')
|
||||
->will($this->returnValue('my_ldap_resource'));
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->with(
|
||||
$this->equalTo('CN=Users,DC=kanboard,DC=local'),
|
||||
$this->equalTo('(&(objectClass=group)(sAMAccountName=Kanboard*))')
|
||||
);
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('hasResult')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->query
|
||||
->expects($this->never())
|
||||
->method('getEntries');
|
||||
|
||||
$this->group
|
||||
->expects($this->any())
|
||||
->method('getAttributeName')
|
||||
->will($this->returnValue('cn'));
|
||||
|
||||
$this->group
|
||||
->expects($this->any())
|
||||
->method('getBasDn')
|
||||
->will($this->returnValue('CN=Users,DC=kanboard,DC=local'));
|
||||
|
||||
$groups = $this->group->find('(&(objectClass=group)(sAMAccountName=Kanboard*))');
|
||||
$this->assertCount(0, $groups);
|
||||
}
|
||||
|
||||
public function testGetBaseDnNotConfigured()
|
||||
{
|
||||
$this->setExpectedException('\LogicException');
|
||||
|
||||
$group = new Group($this->query);
|
||||
$group->getBasDn();
|
||||
}
|
||||
}
|
||||
379
tests/units/Core/Ldap/LdapUserTest.php
Normal file
379
tests/units/Core/Ldap/LdapUserTest.php
Normal file
@@ -0,0 +1,379 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../../Base.php';
|
||||
|
||||
use Kanboard\Core\Ldap\User;
|
||||
use Kanboard\Core\Ldap\Entries;
|
||||
use Kanboard\Core\Security\Role;
|
||||
|
||||
class LdapUserTest extends Base
|
||||
{
|
||||
private $query;
|
||||
private $client;
|
||||
private $user;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->client = $this
|
||||
->getMockBuilder('\Kanboard\Core\Ldap\Client')
|
||||
->setMethods(array(
|
||||
'getConnection',
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$this->query = $this
|
||||
->getMockBuilder('\Kanboard\Core\Ldap\Query')
|
||||
->setConstructorArgs(array($this->client))
|
||||
->setMethods(array(
|
||||
'execute',
|
||||
'hasResult',
|
||||
'getEntries',
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$this->user = $this
|
||||
->getMockBuilder('\Kanboard\Core\Ldap\User')
|
||||
->setConstructorArgs(array($this->query))
|
||||
->setMethods(array(
|
||||
'getAttributeUsername',
|
||||
'getAttributeEmail',
|
||||
'getAttributeName',
|
||||
'getAttributeGroup',
|
||||
'getGroupAdminDn',
|
||||
'getGroupManagerDn',
|
||||
'getBasDn',
|
||||
))
|
||||
->getMock();
|
||||
}
|
||||
|
||||
public function testGetUser()
|
||||
{
|
||||
$entries = new Entries(array(
|
||||
'count' => 1,
|
||||
0 => array(
|
||||
'count' => 2,
|
||||
'dn' => 'uid=my_ldap_user,ou=People,dc=kanboard,dc=local',
|
||||
'displayname' => array(
|
||||
'count' => 1,
|
||||
0 => 'My LDAP user',
|
||||
),
|
||||
'mail' => array(
|
||||
'count' => 2,
|
||||
0 => 'user1@localhost',
|
||||
1 => 'user2@localhost',
|
||||
),
|
||||
'samaccountname' => array(
|
||||
'count' => 1,
|
||||
0 => 'my_ldap_user',
|
||||
),
|
||||
0 => 'displayname',
|
||||
1 => 'mail',
|
||||
2 => 'samaccountname',
|
||||
)
|
||||
));
|
||||
|
||||
$this->client
|
||||
->expects($this->any())
|
||||
->method('getConnection')
|
||||
->will($this->returnValue('my_ldap_resource'));
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->with(
|
||||
$this->equalTo('ou=People,dc=kanboard,dc=local'),
|
||||
$this->equalTo('(uid=my_ldap_user)')
|
||||
);
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('hasResult')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('getEntries')
|
||||
->will($this->returnValue($entries));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getAttributeUsername')
|
||||
->will($this->returnValue('samaccountname'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getAttributeName')
|
||||
->will($this->returnValue('displayname'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getAttributeEmail')
|
||||
->will($this->returnValue('mail'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getBasDn')
|
||||
->will($this->returnValue('ou=People,dc=kanboard,dc=local'));
|
||||
|
||||
$user = $this->user->find('(uid=my_ldap_user)');
|
||||
$this->assertInstanceOf('Kanboard\User\LdapUserProvider', $user);
|
||||
$this->assertEquals('uid=my_ldap_user,ou=People,dc=kanboard,dc=local', $user->getDn());
|
||||
$this->assertEquals('my_ldap_user', $user->getUsername());
|
||||
$this->assertEquals('My LDAP user', $user->getName());
|
||||
$this->assertEquals('user1@localhost', $user->getEmail());
|
||||
$this->assertEquals(Role::APP_USER, $user->getRole());
|
||||
$this->assertEquals(array(), $user->getExternalGroupIds());
|
||||
$this->assertEquals(array('is_ldap_user' => 1), $user->getExtraAttributes());
|
||||
}
|
||||
|
||||
public function testGetUserWithAdminRole()
|
||||
{
|
||||
$entries = new Entries(array(
|
||||
'count' => 1,
|
||||
0 => array(
|
||||
'count' => 2,
|
||||
'dn' => 'uid=my_ldap_user,ou=People,dc=kanboard,dc=local',
|
||||
'displayname' => array(
|
||||
'count' => 1,
|
||||
0 => 'My LDAP user',
|
||||
),
|
||||
'mail' => array(
|
||||
'count' => 2,
|
||||
0 => 'user1@localhost',
|
||||
1 => 'user2@localhost',
|
||||
),
|
||||
'samaccountname' => array(
|
||||
'count' => 1,
|
||||
0 => 'my_ldap_user',
|
||||
),
|
||||
'memberof' => array(
|
||||
'count' => 1,
|
||||
0 => 'CN=Kanboard-Admins,CN=Users,DC=kanboard,DC=local',
|
||||
),
|
||||
0 => 'displayname',
|
||||
1 => 'mail',
|
||||
2 => 'samaccountname',
|
||||
3 => 'memberof',
|
||||
)
|
||||
));
|
||||
|
||||
$this->client
|
||||
->expects($this->any())
|
||||
->method('getConnection')
|
||||
->will($this->returnValue('my_ldap_resource'));
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->with(
|
||||
$this->equalTo('ou=People,dc=kanboard,dc=local'),
|
||||
$this->equalTo('(uid=my_ldap_user)')
|
||||
);
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('hasResult')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('getEntries')
|
||||
->will($this->returnValue($entries));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getAttributeUsername')
|
||||
->will($this->returnValue('samaccountname'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getAttributeName')
|
||||
->will($this->returnValue('displayname'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getAttributeEmail')
|
||||
->will($this->returnValue('mail'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getAttributeGroup')
|
||||
->will($this->returnValue('memberof'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getGroupAdminDn')
|
||||
->will($this->returnValue('CN=Kanboard-Admins,CN=Users,DC=kanboard,DC=local'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getBasDn')
|
||||
->will($this->returnValue('ou=People,dc=kanboard,dc=local'));
|
||||
|
||||
$user = $this->user->find('(uid=my_ldap_user)');
|
||||
$this->assertInstanceOf('Kanboard\User\LdapUserProvider', $user);
|
||||
$this->assertEquals('uid=my_ldap_user,ou=People,dc=kanboard,dc=local', $user->getDn());
|
||||
$this->assertEquals('my_ldap_user', $user->getUsername());
|
||||
$this->assertEquals('My LDAP user', $user->getName());
|
||||
$this->assertEquals('user1@localhost', $user->getEmail());
|
||||
$this->assertEquals(Role::APP_ADMIN, $user->getRole());
|
||||
$this->assertEquals(array('CN=Kanboard-Admins,CN=Users,DC=kanboard,DC=local'), $user->getExternalGroupIds());
|
||||
$this->assertEquals(array('is_ldap_user' => 1), $user->getExtraAttributes());
|
||||
}
|
||||
|
||||
public function testGetUserWithManagerRole()
|
||||
{
|
||||
$entries = new Entries(array(
|
||||
'count' => 1,
|
||||
0 => array(
|
||||
'count' => 2,
|
||||
'dn' => 'uid=my_ldap_user,ou=People,dc=kanboard,dc=local',
|
||||
'displayname' => array(
|
||||
'count' => 1,
|
||||
0 => 'My LDAP user',
|
||||
),
|
||||
'mail' => array(
|
||||
'count' => 2,
|
||||
0 => 'user1@localhost',
|
||||
1 => 'user2@localhost',
|
||||
),
|
||||
'samaccountname' => array(
|
||||
'count' => 1,
|
||||
0 => 'my_ldap_user',
|
||||
),
|
||||
'memberof' => array(
|
||||
'count' => 2,
|
||||
0 => 'CN=Kanboard-Users,CN=Users,DC=kanboard,DC=local',
|
||||
1 => 'CN=Kanboard-Managers,CN=Users,DC=kanboard,DC=local',
|
||||
),
|
||||
0 => 'displayname',
|
||||
1 => 'mail',
|
||||
2 => 'samaccountname',
|
||||
3 => 'memberof',
|
||||
)
|
||||
));
|
||||
|
||||
$this->client
|
||||
->expects($this->any())
|
||||
->method('getConnection')
|
||||
->will($this->returnValue('my_ldap_resource'));
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->with(
|
||||
$this->equalTo('ou=People,dc=kanboard,dc=local'),
|
||||
$this->equalTo('(uid=my_ldap_user)')
|
||||
);
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('hasResult')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('getEntries')
|
||||
->will($this->returnValue($entries));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getAttributeUsername')
|
||||
->will($this->returnValue('samaccountname'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getAttributeName')
|
||||
->will($this->returnValue('displayname'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getAttributeEmail')
|
||||
->will($this->returnValue('mail'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getAttributeGroup')
|
||||
->will($this->returnValue('memberof'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getGroupManagerDn')
|
||||
->will($this->returnValue('CN=Kanboard-Managers,CN=Users,DC=kanboard,DC=local'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getBasDn')
|
||||
->will($this->returnValue('ou=People,dc=kanboard,dc=local'));
|
||||
|
||||
$user = $this->user->find('(uid=my_ldap_user)');
|
||||
$this->assertInstanceOf('Kanboard\User\LdapUserProvider', $user);
|
||||
$this->assertEquals('uid=my_ldap_user,ou=People,dc=kanboard,dc=local', $user->getDn());
|
||||
$this->assertEquals('my_ldap_user', $user->getUsername());
|
||||
$this->assertEquals('My LDAP user', $user->getName());
|
||||
$this->assertEquals('user1@localhost', $user->getEmail());
|
||||
$this->assertEquals(Role::APP_MANAGER, $user->getRole());
|
||||
$this->assertEquals(array('CN=Kanboard-Users,CN=Users,DC=kanboard,DC=local', 'CN=Kanboard-Managers,CN=Users,DC=kanboard,DC=local'), $user->getExternalGroupIds());
|
||||
$this->assertEquals(array('is_ldap_user' => 1), $user->getExtraAttributes());
|
||||
}
|
||||
|
||||
public function testGetUserNotFound()
|
||||
{
|
||||
$entries = new Entries(array());
|
||||
|
||||
$this->client
|
||||
->expects($this->any())
|
||||
->method('getConnection')
|
||||
->will($this->returnValue('my_ldap_resource'));
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->with(
|
||||
$this->equalTo('ou=People,dc=kanboard,dc=local'),
|
||||
$this->equalTo('(uid=my_ldap_user)')
|
||||
);
|
||||
|
||||
$this->query
|
||||
->expects($this->once())
|
||||
->method('hasResult')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->query
|
||||
->expects($this->never())
|
||||
->method('getEntries');
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getAttributeUsername')
|
||||
->will($this->returnValue('samaccountname'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getAttributeName')
|
||||
->will($this->returnValue('displayname'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getAttributeEmail')
|
||||
->will($this->returnValue('mail'));
|
||||
|
||||
$this->user
|
||||
->expects($this->any())
|
||||
->method('getBasDn')
|
||||
->will($this->returnValue('ou=People,dc=kanboard,dc=local'));
|
||||
|
||||
$user = $this->user->find('(uid=my_ldap_user)');
|
||||
$this->assertEquals(null, $user);
|
||||
}
|
||||
|
||||
public function testGetBaseDnNotConfigured()
|
||||
{
|
||||
$this->setExpectedException('\LogicException');
|
||||
|
||||
$user = new User($this->query);
|
||||
$user->getBasDn();
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ function ldap_get_entries($link_identifier, $result_identifier)
|
||||
class QueryTest extends \Base
|
||||
{
|
||||
public static $functions;
|
||||
private $client;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
@@ -29,6 +30,13 @@ class QueryTest extends \Base
|
||||
'ldap_get_entries',
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$this->client = $this
|
||||
->getMockBuilder('\Kanboard\Core\Ldap\Client')
|
||||
->setMethods(array(
|
||||
'getConnection',
|
||||
))
|
||||
->getMock();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
@@ -58,6 +66,11 @@ class QueryTest extends \Base
|
||||
)
|
||||
);
|
||||
|
||||
$this->client
|
||||
->expects($this->any())
|
||||
->method('getConnection')
|
||||
->will($this->returnValue('my_ldap_resource'));
|
||||
|
||||
self::$functions
|
||||
->expects($this->once())
|
||||
->method('ldap_search')
|
||||
@@ -78,20 +91,25 @@ class QueryTest extends \Base
|
||||
)
|
||||
->will($this->returnValue($entries));
|
||||
|
||||
$query = new Query;
|
||||
$query->execute('my_ldap_resource', 'ou=People,dc=kanboard,dc=local', 'uid=my_user', array('displayname'));
|
||||
$query = new Query($this->client);
|
||||
$query->execute('ou=People,dc=kanboard,dc=local', 'uid=my_user', array('displayname'));
|
||||
$this->assertTrue($query->hasResult());
|
||||
|
||||
$this->assertEquals('My user', $query->getAttributeValue('displayname'));
|
||||
$this->assertEquals('user1@localhost', $query->getAttributeValue('mail'));
|
||||
$this->assertEquals('', $query->getAttributeValue('not_found'));
|
||||
$this->assertEquals('My user', $query->getEntries()->getFirstEntry()->getFirstValue('displayname'));
|
||||
$this->assertEquals('user1@localhost', $query->getEntries()->getFirstEntry()->getFirstValue('mail'));
|
||||
$this->assertEquals('', $query->getEntries()->getFirstEntry()->getFirstValue('not_found'));
|
||||
|
||||
$this->assertEquals('uid=my_user,ou=People,dc=kanboard,dc=local', $query->getAttribute('dn'));
|
||||
$this->assertEquals(null, $query->getAttribute('missing'));
|
||||
$this->assertEquals('uid=my_user,ou=People,dc=kanboard,dc=local', $query->getEntries()->getFirstEntry()->getDn());
|
||||
$this->assertEquals('', $query->getEntries()->getFirstEntry()->getFirstValue('missing'));
|
||||
}
|
||||
|
||||
public function testExecuteQueryNotFound()
|
||||
{
|
||||
$this->client
|
||||
->expects($this->any())
|
||||
->method('getConnection')
|
||||
->will($this->returnValue('my_ldap_resource'));
|
||||
|
||||
self::$functions
|
||||
->expects($this->once())
|
||||
->method('ldap_search')
|
||||
@@ -112,13 +130,18 @@ class QueryTest extends \Base
|
||||
)
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
$query = new Query;
|
||||
$query->execute('my_ldap_resource', 'ou=People,dc=kanboard,dc=local', 'uid=my_user', array('displayname'));
|
||||
$query = new Query($this->client);
|
||||
$query->execute('ou=People,dc=kanboard,dc=local', 'uid=my_user', array('displayname'));
|
||||
$this->assertFalse($query->hasResult());
|
||||
}
|
||||
|
||||
public function testExecuteQueryFailed()
|
||||
{
|
||||
$this->client
|
||||
->expects($this->once())
|
||||
->method('getConnection')
|
||||
->will($this->returnValue('my_ldap_resource'));
|
||||
|
||||
self::$functions
|
||||
->expects($this->once())
|
||||
->method('ldap_search')
|
||||
@@ -130,8 +153,8 @@ class QueryTest extends \Base
|
||||
)
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$query = new Query;
|
||||
$query->execute('my_ldap_resource', 'ou=People,dc=kanboard,dc=local', 'uid=my_user', array('displayname'));
|
||||
$query = new Query($this->client);
|
||||
$query->execute('ou=People,dc=kanboard,dc=local', 'uid=my_user', array('displayname'));
|
||||
$this->assertFalse($query->hasResult());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Core\Ldap;
|
||||
|
||||
require_once __DIR__.'/../../Base.php';
|
||||
|
||||
class UserTest extends \Base
|
||||
{
|
||||
public function testGetProfile()
|
||||
{
|
||||
$entries = array(
|
||||
'count' => 1,
|
||||
0 => array(
|
||||
'count' => 2,
|
||||
'dn' => 'uid=my_user,ou=People,dc=kanboard,dc=local',
|
||||
'displayname' => array(
|
||||
'count' => 1,
|
||||
0 => 'My LDAP user',
|
||||
),
|
||||
'mail' => array(
|
||||
'count' => 2,
|
||||
0 => 'user1@localhost',
|
||||
1 => 'user2@localhost',
|
||||
),
|
||||
'samaccountname' => array(
|
||||
'count' => 1,
|
||||
0 => 'my_ldap_user',
|
||||
),
|
||||
0 => 'displayname',
|
||||
1 => 'mail',
|
||||
2 => 'samaccountname',
|
||||
)
|
||||
);
|
||||
|
||||
$expected = array(
|
||||
'ldap_id' => 'uid=my_user,ou=People,dc=kanboard,dc=local',
|
||||
'username' => 'my_ldap_user',
|
||||
'name' => 'My LDAP user',
|
||||
'email' => 'user1@localhost',
|
||||
'is_admin' => 0,
|
||||
'is_project_admin' => 0,
|
||||
'is_ldap_user' => 1,
|
||||
);
|
||||
|
||||
$query = $this
|
||||
->getMockBuilder('\Kanboard\Core\Ldap\Query')
|
||||
->setConstructorArgs(array($entries))
|
||||
->setMethods(array(
|
||||
'execute',
|
||||
'hasResult',
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$query
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->with(
|
||||
$this->equalTo('my_ldap_resource'),
|
||||
$this->equalTo('ou=People,dc=kanboard,dc=local'),
|
||||
$this->equalTo('(uid=my_user)')
|
||||
);
|
||||
|
||||
$query
|
||||
->expects($this->once())
|
||||
->method('hasResult')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$user = $this
|
||||
->getMockBuilder('\Kanboard\Core\Ldap\User')
|
||||
->setConstructorArgs(array($query))
|
||||
->setMethods(array(
|
||||
'getAttributeUsername',
|
||||
'getAttributeEmail',
|
||||
'getAttributeName',
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$user
|
||||
->expects($this->any())
|
||||
->method('getAttributeUsername')
|
||||
->will($this->returnValue('samaccountname'));
|
||||
|
||||
$user
|
||||
->expects($this->any())
|
||||
->method('getAttributeName')
|
||||
->will($this->returnValue('displayname'));
|
||||
|
||||
$user
|
||||
->expects($this->any())
|
||||
->method('getAttributeEmail')
|
||||
->will($this->returnValue('mail'));
|
||||
|
||||
$this->assertEquals($expected, $user->getProfile('my_ldap_resource', 'ou=People,dc=kanboard,dc=local', '(uid=my_user)'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user