2017-11-02 15:40:38 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2017 EITA Cooperative (eita.org.br)
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Vinicius Cubas Brand <vinicius@eita.org.br>
|
2017-11-02 15:40:38 +03:00
|
|
|
*
|
2017-11-06 17:56:42 +03:00
|
|
|
* @license GNU AGPL version 3 or any later version
|
2017-11-02 15:40:38 +03:00
|
|
|
*
|
2017-11-06 17:56:42 +03:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-11-02 15:40:38 +03:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-11-06 17:56:42 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-11-02 15:40:38 +03:00
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
2017-11-06 17:56:42 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-11-02 15:40:38 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\User_LDAP\Tests;
|
|
|
|
|
|
|
|
use OCA\User_LDAP\GroupPluginManager;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\GroupInterface;
|
2017-11-02 15:40:38 +03:00
|
|
|
|
|
|
|
class GroupLDAPPluginTest extends \Test\TestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return GroupPluginManager
|
|
|
|
*/
|
|
|
|
private function getGroupPluginManager() {
|
|
|
|
return new GroupPluginManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testImplementsActions() {
|
|
|
|
$pluginManager = $this->getGroupPluginManager();
|
|
|
|
|
|
|
|
$plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
|
|
|
|
->setMethods(['respondToActions'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$plugin->expects($this->any())
|
|
|
|
->method('respondToActions')
|
2017-11-03 01:19:03 +03:00
|
|
|
->willReturn(GroupInterface::CREATE_GROUP);
|
2017-11-02 15:40:38 +03:00
|
|
|
|
|
|
|
$plugin2 = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
|
|
|
|
->setMethods(['respondToActions'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$plugin2->expects($this->any())
|
|
|
|
->method('respondToActions')
|
2017-11-03 01:19:03 +03:00
|
|
|
->willReturn(GroupInterface::ADD_TO_GROUP);
|
2017-11-02 15:40:38 +03:00
|
|
|
|
|
|
|
$pluginManager->register($plugin);
|
|
|
|
$pluginManager->register($plugin2);
|
|
|
|
|
2017-11-03 01:19:03 +03:00
|
|
|
$this->assertEquals($pluginManager->getImplementedActions(), GroupInterface::CREATE_GROUP | GroupInterface::ADD_TO_GROUP);
|
|
|
|
$this->assertTrue($pluginManager->implementsActions(GroupInterface::CREATE_GROUP));
|
|
|
|
$this->assertTrue($pluginManager->implementsActions(GroupInterface::ADD_TO_GROUP));
|
2017-11-02 15:40:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateGroup() {
|
|
|
|
$pluginManager = $this->getGroupPluginManager();
|
|
|
|
|
|
|
|
$plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
|
|
|
|
->setMethods(['respondToActions', 'createGroup'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$plugin->expects($this->any())
|
|
|
|
->method('respondToActions')
|
2017-11-03 01:19:03 +03:00
|
|
|
->willReturn(GroupInterface::CREATE_GROUP);
|
2017-11-02 15:40:38 +03:00
|
|
|
|
|
|
|
$plugin->expects($this->once())
|
|
|
|
->method('createGroup')
|
|
|
|
->with(
|
|
|
|
$this->equalTo('group')
|
|
|
|
);
|
|
|
|
|
|
|
|
$pluginManager->register($plugin);
|
|
|
|
$pluginManager->createGroup('group');
|
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2017-11-02 15:40:38 +03:00
|
|
|
public function testCreateGroupNotRegistered() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
$this->expectExceptionMessage('No plugin implements createGroup in this LDAP Backend.');
|
|
|
|
|
2017-11-02 15:40:38 +03:00
|
|
|
$pluginManager = $this->getGroupPluginManager();
|
|
|
|
$pluginManager->createGroup('foo');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteGroup() {
|
|
|
|
$pluginManager = $this->getGroupPluginManager();
|
|
|
|
|
|
|
|
$plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
|
|
|
|
->setMethods(['respondToActions', 'deleteGroup'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$plugin->expects($this->any())
|
|
|
|
->method('respondToActions')
|
2017-11-03 01:19:03 +03:00
|
|
|
->willReturn(GroupInterface::DELETE_GROUP);
|
2017-11-02 15:40:38 +03:00
|
|
|
|
|
|
|
$plugin->expects($this->once())
|
|
|
|
->method('deleteGroup')
|
|
|
|
->with(
|
|
|
|
$this->equalTo('group')
|
|
|
|
);
|
|
|
|
|
|
|
|
$pluginManager->register($plugin);
|
|
|
|
$pluginManager->deleteGroup('group');
|
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2017-11-02 15:40:38 +03:00
|
|
|
public function testDeleteGroupNotRegistered() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
$this->expectExceptionMessage('No plugin implements deleteGroup in this LDAP Backend.');
|
|
|
|
|
2017-11-02 15:40:38 +03:00
|
|
|
$pluginManager = $this->getGroupPluginManager();
|
|
|
|
$pluginManager->deleteGroup('foo');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddToGroup() {
|
|
|
|
$pluginManager = $this->getGroupPluginManager();
|
|
|
|
|
|
|
|
$plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
|
|
|
|
->setMethods(['respondToActions', 'addToGroup'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$plugin->expects($this->any())
|
|
|
|
->method('respondToActions')
|
2017-11-03 01:19:03 +03:00
|
|
|
->willReturn(GroupInterface::ADD_TO_GROUP);
|
2017-11-02 15:40:38 +03:00
|
|
|
|
|
|
|
$plugin->expects($this->once())
|
|
|
|
->method('addToGroup')
|
|
|
|
->with(
|
|
|
|
$this->equalTo('uid'),
|
|
|
|
$this->equalTo('gid')
|
|
|
|
);
|
|
|
|
|
|
|
|
$pluginManager->register($plugin);
|
|
|
|
$pluginManager->addToGroup('uid', 'gid');
|
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2017-11-02 15:40:38 +03:00
|
|
|
public function testAddToGroupNotRegistered() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
$this->expectExceptionMessage('No plugin implements addToGroup in this LDAP Backend.');
|
|
|
|
|
2017-11-02 15:40:38 +03:00
|
|
|
$pluginManager = $this->getGroupPluginManager();
|
|
|
|
$pluginManager->addToGroup('foo', 'bar');
|
2020-04-09 17:07:47 +03:00
|
|
|
}
|
2017-11-02 15:40:38 +03:00
|
|
|
|
|
|
|
public function testRemoveFromGroup() {
|
|
|
|
$pluginManager = $this->getGroupPluginManager();
|
|
|
|
|
|
|
|
$plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
|
|
|
|
->setMethods(['respondToActions', 'removeFromGroup'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$plugin->expects($this->any())
|
|
|
|
->method('respondToActions')
|
2017-11-03 01:19:03 +03:00
|
|
|
->willReturn(GroupInterface::REMOVE_FROM_GROUP);
|
2017-11-02 15:40:38 +03:00
|
|
|
|
|
|
|
$plugin->expects($this->once())
|
|
|
|
->method('removeFromGroup')
|
|
|
|
->with(
|
|
|
|
$this->equalTo('uid'),
|
|
|
|
$this->equalTo('gid')
|
|
|
|
);
|
|
|
|
|
|
|
|
$pluginManager->register($plugin);
|
|
|
|
$pluginManager->removeFromGroup('uid', 'gid');
|
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2017-11-02 15:40:38 +03:00
|
|
|
public function testRemoveFromGroupNotRegistered() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
$this->expectExceptionMessage('No plugin implements removeFromGroup in this LDAP Backend.');
|
|
|
|
|
2017-11-02 15:40:38 +03:00
|
|
|
$pluginManager = $this->getGroupPluginManager();
|
|
|
|
$pluginManager->removeFromGroup('foo', 'bar');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCountUsersInGroup() {
|
|
|
|
$pluginManager = $this->getGroupPluginManager();
|
|
|
|
|
|
|
|
$plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
|
|
|
|
->setMethods(['respondToActions', 'countUsersInGroup'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$plugin->expects($this->any())
|
|
|
|
->method('respondToActions')
|
2017-11-03 01:19:03 +03:00
|
|
|
->willReturn(GroupInterface::COUNT_USERS);
|
2017-11-02 15:40:38 +03:00
|
|
|
|
|
|
|
$plugin->expects($this->once())
|
|
|
|
->method('countUsersInGroup')
|
|
|
|
->with(
|
|
|
|
$this->equalTo('gid'),
|
|
|
|
$this->equalTo('search')
|
|
|
|
);
|
|
|
|
|
|
|
|
$pluginManager->register($plugin);
|
|
|
|
$pluginManager->countUsersInGroup('gid', 'search');
|
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2017-11-02 15:40:38 +03:00
|
|
|
public function testCountUsersInGroupNotRegistered() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
$this->expectExceptionMessage('No plugin implements countUsersInGroup in this LDAP Backend.');
|
|
|
|
|
2017-11-02 15:40:38 +03:00
|
|
|
$pluginManager = $this->getGroupPluginManager();
|
|
|
|
$pluginManager->countUsersInGroup('foo', 'bar');
|
2020-04-09 17:07:47 +03:00
|
|
|
}
|
2017-11-02 15:40:38 +03:00
|
|
|
|
|
|
|
public function testgetGroupDetails() {
|
|
|
|
$pluginManager = $this->getGroupPluginManager();
|
|
|
|
|
|
|
|
$plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy')
|
|
|
|
->setMethods(['respondToActions', 'getGroupDetails'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$plugin->expects($this->any())
|
|
|
|
->method('respondToActions')
|
2017-11-03 01:19:03 +03:00
|
|
|
->willReturn(GroupInterface::GROUP_DETAILS);
|
2017-11-02 15:40:38 +03:00
|
|
|
|
|
|
|
$plugin->expects($this->once())
|
|
|
|
->method('getGroupDetails')
|
|
|
|
->with(
|
|
|
|
$this->equalTo('gid')
|
|
|
|
);
|
|
|
|
|
|
|
|
$pluginManager->register($plugin);
|
|
|
|
$pluginManager->getGroupDetails('gid');
|
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2017-11-02 15:40:38 +03:00
|
|
|
public function testgetGroupDetailsNotRegistered() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
$this->expectExceptionMessage('No plugin implements getGroupDetails in this LDAP Backend.');
|
|
|
|
|
2017-11-02 15:40:38 +03:00
|
|
|
$pluginManager = $this->getGroupPluginManager();
|
|
|
|
$pluginManager->getGroupDetails('foo');
|
|
|
|
}
|
|
|
|
}
|