Merge pull request #3521 from nextcloud/ldap-fix-uuid-attr-detection
Fix Borken UUID Attribute Detectionpull/3556/merge
commit
a4266f59ae
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\User_LDAP\Migration;
|
||||
|
||||
|
||||
use OC\BackgroundJob\QueuedJob;
|
||||
use OCA\User_LDAP\Mapping\AbstractMapping;
|
||||
use OCA\User_LDAP\Proxy;
|
||||
use OCA\User_LDAP\User_Proxy;
|
||||
|
||||
abstract class UUIDFix extends QueuedJob {
|
||||
/** @var AbstractMapping */
|
||||
protected $mapper;
|
||||
|
||||
/** @var Proxy */
|
||||
protected $proxy;
|
||||
|
||||
public function run($argument) {
|
||||
$isUser = $this->proxy instanceof User_Proxy;
|
||||
foreach($argument['records'] as $record) {
|
||||
$access = $this->proxy->getLDAPAccess($record['name']);
|
||||
$uuid = $access->getUUID($record['dn'], $isUser);
|
||||
if($uuid === false) {
|
||||
// record not found, no prob, continue with the next
|
||||
continue;
|
||||
}
|
||||
if($uuid !== $record['uuid']) {
|
||||
$this->mapper->setUUIDbyDN($uuid, $record['dn']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Proxy $proxy
|
||||
*/
|
||||
public function overrideProxy(Proxy $proxy) {
|
||||
$this->proxy = $proxy;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\User_LDAP\Migration;
|
||||
|
||||
use OCA\User_LDAP\Helper;
|
||||
use OCA\User_LDAP\LDAP;
|
||||
use OCA\User_LDAP\Mapping\GroupMapping;
|
||||
use OCA\User_LDAP\User_Proxy;
|
||||
use OCP\IConfig;
|
||||
|
||||
class UUIDFixGroup extends UUIDFix {
|
||||
public function __construct(GroupMapping $mapper, LDAP $ldap, IConfig $config, Helper $helper) {
|
||||
$this->mapper = $mapper;
|
||||
$this->proxy = new User_Proxy($helper->getServerConfigurationPrefixes(true), $ldap, $config);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\User_LDAP\Migration;
|
||||
|
||||
use OCA\User_LDAP\Mapping\GroupMapping;
|
||||
use OCA\User_LDAP\Mapping\UserMapping;
|
||||
use OCP\BackgroundJob\IJobList;
|
||||
use OCP\IConfig;
|
||||
use OCP\Migration\IOutput;
|
||||
use OCP\Migration\IRepairStep;
|
||||
|
||||
class UUIDFixInsert implements IRepairStep {
|
||||
|
||||
/** @var IConfig */
|
||||
protected $config;
|
||||
|
||||
/** @var UserMapping */
|
||||
protected $userMapper;
|
||||
|
||||
/** @var GroupMapping */
|
||||
protected $groupMapper;
|
||||
|
||||
/** @var IJobList */
|
||||
protected $jobList;
|
||||
|
||||
public function __construct(IConfig $config, UserMapping $userMapper, GroupMapping $groupMapper, IJobList $jobList) {
|
||||
$this->config = $config;
|
||||
$this->userMapper = $userMapper;
|
||||
$this->groupMapper = $groupMapper;
|
||||
$this->jobList = $jobList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the step's name
|
||||
*
|
||||
* @return string
|
||||
* @since 9.1.0
|
||||
*/
|
||||
public function getName() {
|
||||
return 'Insert UUIDFix background job for user and group in batches';
|
||||
}
|
||||
|
||||
/**
|
||||
* Run repair step.
|
||||
* Must throw exception on error.
|
||||
*
|
||||
* @param IOutput $output
|
||||
* @throws \Exception in case of failure
|
||||
* @since 9.1.0
|
||||
*/
|
||||
public function run(IOutput $output) {
|
||||
$installedVersion = $this->config->getAppValue('user_ldap', 'installed_version', '1.2.1');
|
||||
if(version_compare($installedVersion, '1.2.1') !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ([$this->userMapper, $this->groupMapper] as $mapper) {
|
||||
$offset = 0;
|
||||
$batchSize = 50;
|
||||
$jobClass = $mapper instanceof UserMapping ? UUIDFixUser::class : UUIDFixGroup::class;
|
||||
do {
|
||||
$retry = false;
|
||||
$records = $mapper->getList($offset, $batchSize);
|
||||
if(count($records) === 0){
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$this->jobList->add($jobClass, ['records' => $records]);
|
||||
$offset += $batchSize;
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
if(strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) {
|
||||
$batchSize = intval(floor(count($records) * 0.8));
|
||||
$retry = true;
|
||||
}
|
||||
}
|
||||
} while (count($records) === $batchSize || $retry);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\User_LDAP\Migration;
|
||||
|
||||
use OCA\User_LDAP\Helper;
|
||||
use OCA\User_LDAP\LDAP;
|
||||
use OCA\User_LDAP\Mapping\UserMapping;
|
||||
use OCA\User_LDAP\Group_Proxy;
|
||||
use OCP\IConfig;
|
||||
|
||||
class UUIDFixUser extends UUIDFix {
|
||||
public function __construct(UserMapping $mapper, LDAP $ldap, IConfig $config, Helper $helper) {
|
||||
$this->mapper = $mapper;
|
||||
$this->proxy = new Group_Proxy($helper->getServerConfigurationPrefixes(true), $ldap, $config);
|
||||
}
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\User_LDAP\Tests\Integration;
|
||||
|
||||
/**
|
||||
* Class FakeManager
|
||||
*
|
||||
* this is a mock of \OCA\User_LDAP\User\Manager which is a dependency of
|
||||
* Access, that pulls plenty more things in. Because it is not needed in the
|
||||
* scope of these tests, we replace it with a mock.
|
||||
*/
|
||||
class FakeManager extends \OCA\User_LDAP\User\Manager {
|
||||
public function __construct() {
|
||||
$this->ocConfig = \OC::$server->getConfig();
|
||||
$this->image = new \OCP\Image();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\user_ldap\tests\Integration\Lib;
|
||||
|
||||
use OCA\User_LDAP\Group_LDAP;
|
||||
use OCA\User_LDAP\Mapping\GroupMapping;
|
||||
use OCA\User_LDAP\Mapping\UserMapping;
|
||||
use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
|
||||
use OCA\User_LDAP\User_LDAP;
|
||||
|
||||
require_once __DIR__ . '/../Bootstrap.php';
|
||||
|
||||
class IntegrationTestAttributeDetection extends AbstractIntegrationTest {
|
||||
public function init() {
|
||||
require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
|
||||
require(__DIR__ . '/../setup-scripts/createExplicitGroups.php');
|
||||
|
||||
parent::init();
|
||||
|
||||
$this->connection->setConfiguration(['ldapGroupFilter' => 'objectClass=groupOfNames']);
|
||||
$this->connection->setConfiguration(['ldapGroupMemberAssocAttr' => 'member']);
|
||||
|
||||
$userMapper = new UserMapping(\OC::$server->getDatabaseConnection());
|
||||
$userMapper->clear();
|
||||
$this->access->setUserMapper($userMapper);
|
||||
|
||||
$groupMapper = new GroupMapping(\OC::$server->getDatabaseConnection());
|
||||
$groupMapper->clear();
|
||||
$this->access->setGroupMapper($groupMapper);
|
||||
|
||||
$userBackend = new User_LDAP($this->access, \OC::$server->getConfig());
|
||||
$userManager = \OC::$server->getUserManager();
|
||||
$userManager->clearBackends();
|
||||
$userManager->registerBackend($userBackend);
|
||||
|
||||
$groupBackend = new Group_LDAP($this->access);
|
||||
$groupManger = \OC::$server->getGroupManager();
|
||||
$groupManger->clearBackends();
|
||||
$groupManger->addBackend($groupBackend);
|
||||
}
|
||||
|
||||
protected function caseNativeUUIDAttributeUsers() {
|
||||
// trigger importing of users which also triggers UUID attribute detection
|
||||
\OC::$server->getUserManager()->search('', 5, 0);
|
||||
return $this->connection->ldapUuidUserAttribute === 'entryuuid';
|
||||
}
|
||||
|
||||
protected function caseNativeUUIDAttributeGroups() {
|
||||
// essentially the same as 'caseNativeUUIDAttributeUsers', code paths
|
||||
// are similar, but we take no chances.
|
||||
|
||||
// trigger importing of users which also triggers UUID attribute detection
|
||||
\OC::$server->getGroupManager()->search('', 5, 0);
|
||||
return $this->connection->ldapUuidGroupAttribute === 'entryuuid';
|
||||
}
|
||||
}
|
||||
|
||||
/** @var string $host */
|
||||
/** @var int $port */
|
||||
/** @var string $adn */
|
||||
/** @var string $apwd */
|
||||
/** @var string $bdn */
|
||||
$test = new IntegrationTestAttributeDetection($host, $port, $adn, $apwd, $bdn);
|
||||
$test->init();
|
||||
$test->run();
|
||||
@ -0,0 +1,197 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\User_LDAP\Tests\Migration;
|
||||
|
||||
use OCA\User_LDAP\LDAP;
|
||||
use Test\TestCase;
|
||||
use OCA\User_LDAP\Access;
|
||||
use OCA\User_LDAP\Helper;
|
||||
use OCA\User_LDAP\Migration\UUIDFixUser;
|
||||
use OCA\User_LDAP\Mapping\UserMapping;
|
||||
use OCA\User_LDAP\Mapping\GroupMapping;
|
||||
use OCA\User_LDAP\User_Proxy;
|
||||
use OCP\IConfig;
|
||||
|
||||
abstract class AbstractUUIDFixTest extends TestCase {
|
||||
/** @var Helper|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $helper;
|
||||
|
||||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $config;
|
||||
|
||||
/** @var LDAP|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $ldap;
|
||||
|
||||
/** @var UserMapping|GroupMapping|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $mapper;
|
||||
|
||||
/** @var UUIDFixUser */
|
||||
protected $job;
|
||||
|
||||
/** @var User_Proxy|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $proxy;
|
||||
|
||||
/** @var Access|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $access;
|
||||
|
||||
/** @var bool */
|
||||
protected $isUser = true;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->ldap = $this->createMock(LDAP::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->access = $this->createMock(Access::class);
|
||||
|
||||
$this->helper = $this->createMock(Helper::class);
|
||||
$this->helper->expects($this->any())
|
||||
->method('getServerConfigurationPrefixes')
|
||||
->with(true)
|
||||
->willReturn(['s01', 's03']);
|
||||
}
|
||||
|
||||
protected function mockProxy($className) {
|
||||
$this->proxy = $this->createMock($className);
|
||||
$this->proxy->expects($this->any())
|
||||
->method('getLDAPAccess')
|
||||
->willReturn($this->access);
|
||||
}
|
||||
|
||||
protected function instantiateJob($className) {
|
||||
$this->job = new $className($this->mapper, $this->ldap, $this->config, $this->helper);
|
||||
$this->job->overrideProxy($this->proxy);
|
||||
}
|
||||
|
||||
public function testRunSingleRecord() {
|
||||
$args = [
|
||||
'records' => [
|
||||
0 => [
|
||||
'name' => 'Someone',
|
||||
'dn' => 'uid=Someone,dc=Somewhere',
|
||||
'uuid' => 'kaput'
|
||||
]
|
||||
]
|
||||
];
|
||||
$correctUUID = '4355-AED3-9D73-03AD';
|
||||
|
||||
$this->access->expects($this->once())
|
||||
->method('getUUID')
|
||||
->with($args['records'][0]['dn'], $this->isUser)
|
||||
->willReturn($correctUUID);
|
||||
|
||||
$this->mapper->expects($this->once())
|
||||
->method('setUUIDbyDN')
|
||||
->with($correctUUID, $args['records'][0]['dn']);
|
||||
|
||||
$this->job->run($args);
|
||||
}
|
||||
|
||||
public function testRunValidRecord() {
|
||||
$correctUUID = '4355-AED3-9D73-03AD';
|
||||
$args = [
|
||||
'records' => [
|
||||
0 => [
|
||||
'name' => 'Someone',
|
||||
'dn' => 'uid=Someone,dc=Somewhere',
|
||||
'uuid' => $correctUUID
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$this->access->expects($this->once())
|
||||
->method('getUUID')
|
||||
->with($args['records'][0]['dn'], $this->isUser)
|
||||
->willReturn($correctUUID);
|
||||
|
||||
$this->mapper->expects($this->never())
|
||||
->method('setUUIDbyDN');
|
||||
|
||||
$this->job->run($args);
|
||||
}
|
||||
|
||||
public function testRunRemovedRecord() {
|
||||
$args = [
|
||||
'records' => [
|
||||
0 => [
|
||||
'name' => 'Someone',
|
||||
'dn' => 'uid=Someone,dc=Somewhere',
|
||||
'uuid' => 'kaput'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$this->access->expects($this->once())
|
||||
->method('getUUID')
|
||||
->with($args['records'][0]['dn'], $this->isUser)
|
||||
->willReturn(false);
|
||||
|
||||
$this->mapper->expects($this->never())
|
||||
->method('setUUIDbyDN');
|
||||
|
||||
$this->job->run($args);
|
||||
}
|
||||
|
||||
public function testRunManyRecords() {
|
||||
$args = [
|
||||
'records' => [
|
||||
0 => [
|
||||
'name' => 'Someone',
|
||||
'dn' => 'uid=Someone,dc=Somewhere',
|
||||
'uuid' => 'kaput'
|
||||
],
|
||||
1 => [
|
||||
'name' => 'kdslkdsaIdsal',
|
||||
'dn' => 'uid=kdslkdsaIdsal,dc=Somewhere',
|
||||
'uuid' => 'AED3-4355-03AD-9D73'
|
||||
],
|
||||
2 => [
|
||||
'name' => 'Paperboy',
|
||||
'dn' => 'uid=Paperboy,dc=Somewhere',
|
||||
'uuid' => 'kaput'
|
||||
]
|
||||
]
|
||||
];
|
||||
$correctUUIDs = ['4355-AED3-9D73-03AD', 'AED3-4355-03AD-9D73', 'AED3-9D73-4355-03AD'];
|
||||
|
||||
$this->access->expects($this->exactly(3))
|
||||
->method('getUUID')
|
||||
->withConsecutive(
|
||||
[$args['records'][0]['dn'], $this->isUser],
|
||||
[$args['records'][1]['dn'], $this->isUser],
|
||||
[$args['records'][2]['dn'], $this->isUser]
|
||||
)
|
||||
->willReturnOnConsecutiveCalls($correctUUIDs[0], $correctUUIDs[1], $correctUUIDs[2]);
|
||||
|
||||
$this->mapper->expects($this->exactly(2))
|
||||
->method('setUUIDbyDN')
|
||||
->withConsecutive(
|
||||
[$correctUUIDs[0], $args['records'][0]['dn']],
|
||||
[$correctUUIDs[2], $args['records'][2]['dn']]
|
||||
);
|
||||
|
||||
$this->job->run($args);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Group_LDAP\Tests\Migration;
|
||||
|
||||
use OCA\User_LDAP\Migration\UUIDFixGroup;
|
||||
use OCA\User_LDAP\Mapping\GroupMapping;
|
||||
use OCA\User_LDAP\Group_Proxy;
|
||||
use OCA\User_LDAP\Tests\Migration\AbstractUUIDFixTest;
|
||||
|
||||
/**
|
||||
* Class UUIDFixGroupTest
|
||||
*
|
||||
* @package OCA\Group_LDAP\Tests\Migration
|
||||
* @group DB
|
||||
*/
|
||||
class UUIDFixGroupTest extends AbstractUUIDFixTest {
|
||||
public function setUp() {
|
||||
$this->isUser = false;
|
||||
parent::setUp();
|
||||
|
||||
$this->isUser = false;
|
||||
|
||||
$this->mapper = $this->createMock(GroupMapping::class);
|
||||
|
||||
$this->mockProxy(Group_Proxy::class);
|
||||
$this->instantiateJob(UUIDFixGroup::class);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,195 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\User_LDAP\Tests\Migration;
|
||||
|
||||
use OCA\User_LDAP\Migration\UUIDFixInsert;
|
||||
use OCA\User_LDAP\Mapping\UserMapping;
|
||||
use OCA\User_LDAP\Mapping\GroupMapping;
|
||||
use OCP\BackgroundJob\IJobList;
|
||||
use OCP\IConfig;
|
||||
use OCP\Migration\IOutput;
|
||||
use Test\TestCase;
|
||||
|
||||
class UUIDFixInsertTest extends TestCase {
|
||||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $config;
|
||||
|
||||
/** @var UserMapping|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $userMapper;
|
||||
|
||||
/** @var GroupMapping|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $groupMapper;
|
||||
|
||||
/** @var IJobList|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $jobList;
|
||||
|
||||
/** @var UUIDFixInsert */
|
||||
protected $job;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->jobList = $this->createMock(IJobList::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->userMapper = $this->createMock(UserMapping::class);
|
||||
$this->groupMapper = $this->createMock(GroupMapping::class);
|
||||
$this->job = new UUIDFixInsert(
|
||||
$this->config,
|
||||
$this->userMapper,
|
||||
$this->groupMapper,
|
||||
$this->jobList
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetName() {
|
||||
$this->assertSame('Insert UUIDFix background job for user and group in batches', $this->job->getName());
|
||||
}
|
||||
|
||||
public function recordProvider() {
|
||||
$record = [
|
||||
'dn' => 'cn=somerecord,dc=somewhere',
|
||||
'name' => 'Something',
|
||||
'uuid' => 'AB12-3456-CDEF7-8GH9'
|
||||
];
|
||||
array_fill(0, 50, $record);
|
||||
|
||||
$userBatches = [
|
||||
0 => array_fill(0, 50, $record),
|
||||
1 => array_fill(0, 50, $record),
|
||||
2 => array_fill(0, 13, $record),
|
||||
];
|
||||
|
||||
$groupBatches = [
|
||||
0 => array_fill(0, 7, $record),
|
||||
];
|
||||
|
||||
return [
|
||||
['userBatches' => $userBatches, 'groupBatches' => $groupBatches]
|
||||
];
|
||||
}
|
||||
|
||||
public function recordProviderTooLongAndNone() {
|
||||
$record = [
|
||||
'dn' => 'cn=somerecord,dc=somewhere',
|
||||
'name' => 'Something',
|
||||
'uuid' => 'AB12-3456-CDEF7-8GH9'
|
||||
];
|
||||
array_fill(0, 50, $record);
|
||||
|
||||
$userBatches = [
|
||||
0 => array_fill(0, 50, $record),
|
||||
1 => array_fill(0, 40, $record),
|
||||
2 => array_fill(0, 32, $record),
|
||||
3 => array_fill(0, 32, $record),
|
||||
4 => array_fill(0, 23, $record),
|
||||
];
|
||||
|
||||
$groupBatches = [0 => []];
|
||||
|
||||
return [
|
||||
['userBatches' => $userBatches, 'groupBatches' => $groupBatches]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider recordProvider
|
||||
*/
|
||||
public function testRun($userBatches, $groupBatches) {
|
||||
$this->config->expects($this->once())
|
||||
->method('getAppValue')
|
||||
->with('user_ldap', 'installed_version', '1.2.1')
|
||||
->willReturn('1.2.0');
|
||||
|
||||
$this->userMapper->expects($this->exactly(3))
|
||||
->method('getList')
|
||||
->withConsecutive([0, 50], [50, 50], [100, 50])
|
||||
->willReturnOnConsecutiveCalls($userBatches[0], $userBatches[1], $userBatches[2]);
|
||||
|
||||
$this->groupMapper->expects($this->exactly(1))
|
||||
->method('getList')
|
||||
->with(0, 50)
|
||||
->willReturn($groupBatches[0]);
|
||||
|
||||
$this->jobList->expects($this->exactly(4))
|
||||
->method('add');
|
||||
|
||||
/** @var IOutput $out */
|
||||
$out = $this->createMock(IOutput::class);
|
||||
$this->job->run($out);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider recordProviderTooLongAndNone
|
||||
*/
|
||||
public function testRunWithManyAndNone($userBatches, $groupBatches) {
|
||||
$this->config->expects($this->once())
|
||||
->method('getAppValue')
|
||||
->with('user_ldap', 'installed_version', '1.2.1')
|
||||
->willReturn('1.2.0');
|
||||
|
||||
$this->userMapper->expects($this->exactly(5))
|
||||
->method('getList')
|
||||
->withConsecutive([0, 50], [0, 40], [0, 32], [32, 32], [64, 32])
|
||||
->willReturnOnConsecutiveCalls($userBatches[0], $userBatches[1], $userBatches[2], $userBatches[3], $userBatches[4]);
|
||||
|
||||
$this->groupMapper->expects($this->once())
|
||||
->method('getList')
|
||||
->with(0, 50)
|
||||
->willReturn($groupBatches[0]);
|
||||
|
||||
$this->jobList->expects($this->at(0))
|
||||
->method('add')
|
||||
->willThrowException(new \InvalidArgumentException('Background job arguments can\'t exceed 4000 etc'));
|
||||
$this->jobList->expects($this->at(1))
|
||||
->method('add')
|
||||
->willThrowException(new \InvalidArgumentException('Background job arguments can\'t exceed 4000 etc'));
|
||||
$this->jobList->expects($this->at(2))
|
||||
->method('add');
|
||||
$this->jobList->expects($this->at(3))
|
||||
->method('add');
|
||||
$this->jobList->expects($this->at(4))
|
||||
->method('add');
|
||||
|
||||
/** @var IOutput $out */
|
||||
$out = $this->createMock(IOutput::class);
|
||||
$this->job->run($out);
|
||||
}
|
||||
|
||||
public function testDonNotRun() {
|
||||
$this->config->expects($this->once())
|
||||
->method('getAppValue')
|
||||
->with('user_ldap', 'installed_version', '1.2.1')
|
||||
->willReturn('1.2.1');
|
||||
$this->userMapper->expects($this->never())
|
||||
->method('getList');
|
||||
$this->groupMapper->expects($this->never())
|
||||
->method('getList');
|
||||
$this->jobList->expects($this->never())
|
||||
->method('add');
|
||||
|
||||
/** @var IOutput $out */
|
||||
$out = $this->createMock(IOutput::class);
|
||||
$this->job->run($out);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\User_LDAP\Tests\Migration;
|
||||
|
||||
use OCA\User_LDAP\Migration\UUIDFixUser;
|
||||
use OCA\User_LDAP\Mapping\UserMapping;
|
||||
use OCA\User_LDAP\User_Proxy;
|
||||
|
||||
/**
|
||||
* Class UUIDFixUserTest
|
||||
*
|
||||
* @package OCA\User_LDAP\Tests\Migration
|
||||
* @group DB
|
||||
*/
|
||||
class UUIDFixUserTest extends AbstractUUIDFixTest {
|
||||
public function setUp() {
|
||||
$this->isUser = true;
|
||||
parent::setUp();
|
||||
|
||||
$this->mapper = $this->createMock(UserMapping::class);
|
||||
|
||||
$this->mockProxy(User_Proxy::class);
|
||||
$this->instantiateJob(UUIDFixUser::class);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue