Added support for LDAP user photo profile

This commit is contained in:
Frederic Guillot
2016-05-07 12:59:35 -04:00
parent 94989663ec
commit 300dabe6b4
19 changed files with 377 additions and 13 deletions

View File

@@ -52,6 +52,7 @@ class LdapUserTest extends Base
'getAttributeEmail',
'getAttributeName',
'getAttributeGroup',
'getAttributePhoto',
'getGroupUserFilter',
'getGroupAdminDn',
'getGroupManagerDn',
@@ -136,10 +137,79 @@ class LdapUserTest extends Base
$this->assertEquals('My LDAP user', $user->getName());
$this->assertEquals('user1@localhost', $user->getEmail());
$this->assertEquals(Role::APP_USER, $user->getRole());
$this->assertSame('', $user->getPhoto());
$this->assertEquals(array(), $user->getExternalGroupIds());
$this->assertEquals(array('is_ldap_user' => 1), $user->getExtraAttributes());
}
public function testGetUserWithPhoto()
{
$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',
),
'jpegPhoto' => array(
'count' => 1,
0 => 'my photo',
),
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('getAttributePhoto')
->will($this->returnValue('jpegPhoto'));
$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('my photo', $user->getPhoto());
}
public function testGetUserWithAdminRole()
{
$entries = new Entries(array(

View File

@@ -0,0 +1,83 @@
<?php
use Kanboard\Core\Security\Role;
use Kanboard\Event\UserProfileSyncEvent;
use Kanboard\Model\User;
use Kanboard\Subscriber\LdapUserPhotoSubscriber;
use Kanboard\User\DatabaseUserProvider;
use Kanboard\User\LdapUserProvider;
require_once __DIR__.'/../Base.php';
class LdapUserPhotoSubscriberTest extends Base
{
public function testWhenTheProviderIsNotLdap()
{
$userProvider = new DatabaseUserProvider(array());
$subscriber = new LdapUserPhotoSubscriber($this->container);
$userModel = new User($this->container);
$userModel->update(array('id' => 1, 'avatar_path' => 'my avatar'));
$user = $userModel->getById(1);
$subscriber->syncUserPhoto(new UserProfileSyncEvent($user, $userProvider));
$user = $userModel->getById(1);
$this->assertEquals('my avatar', $user['avatar_path']);
}
public function testWhenTheUserHaveLdapPhoto()
{
$userProvider = new LdapUserProvider('dn', 'admin', 'Admin', 'admin@localhost', Role::APP_ADMIN, array(), 'my photo');
$subscriber = new LdapUserPhotoSubscriber($this->container);
$userModel = new User($this->container);
$user = $userModel->getById(1);
$this->container['objectStorage']
->expects($this->once())
->method('put')
->with($this->anything(), 'my photo');
$subscriber->syncUserPhoto(new UserProfileSyncEvent($user, $userProvider));
$user = $userModel->getById(1);
$this->assertStringStartsWith('avatars', $user['avatar_path']);
}
public function testWhenTheUserDoNotHaveLdapPhoto()
{
$userProvider = new LdapUserProvider('dn', 'admin', 'Admin', 'admin@localhost', Role::APP_ADMIN, array());
$subscriber = new LdapUserPhotoSubscriber($this->container);
$userModel = new User($this->container);
$user = $userModel->getById(1);
$this->container['objectStorage']
->expects($this->never())
->method('put');
$subscriber->syncUserPhoto(new UserProfileSyncEvent($user, $userProvider));
$user = $userModel->getById(1);
$this->assertEmpty($user['avatar_path']);
}
public function testWhenTheUserAlreadyHaveAvatar()
{
$userProvider = new LdapUserProvider('dn', 'admin', 'Admin', 'admin@localhost', Role::APP_ADMIN, array(), 'my photo');
$subscriber = new LdapUserPhotoSubscriber($this->container);
$userModel = new User($this->container);
$userModel->update(array('id' => 1, 'avatar_path' => 'my avatar'));
$user = $userModel->getById(1);
$this->container['objectStorage']
->expects($this->never())
->method('put');
$subscriber->syncUserPhoto(new UserProfileSyncEvent($user, $userProvider));
$user = $userModel->getById(1);
$this->assertEquals('my avatar', $user['avatar_path']);
}
}