summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-02-17 18:45:33 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-02-17 18:45:33 +0100
commit497ee3e3e64a07c1684f4ec87aa7621d743c37e6 (patch)
tree538d5ee36d20caff89605b86d3ae506afccf7a09 /apps/user_ldap/tests
parent45615cc940acce6ddab4c84b8f0fd38299125f37 (diff)
downloadnextcloud-server-497ee3e3e64a07c1684f4ec87aa7621d743c37e6.tar.gz
nextcloud-server-497ee3e3e64a07c1684f4ec87aa7621d743c37e6.zip
Add repair steps
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap/tests')
-rw-r--r--apps/user_ldap/tests/Mapping/AbstractMappingTest.php22
-rw-r--r--apps/user_ldap/tests/Migration/AbstractUUIDFixTest.php197
-rw-r--r--apps/user_ldap/tests/Migration/UUIDFixGroupTest.php44
-rw-r--r--apps/user_ldap/tests/Migration/UUIDFixInsertTest.php135
-rw-r--r--apps/user_ldap/tests/Migration/UUIDFixUserTest.php40
5 files changed, 437 insertions, 1 deletions
diff --git a/apps/user_ldap/tests/Mapping/AbstractMappingTest.php b/apps/user_ldap/tests/Mapping/AbstractMappingTest.php
index 5c3474d9ad2..c9845bb31e5 100644
--- a/apps/user_ldap/tests/Mapping/AbstractMappingTest.php
+++ b/apps/user_ldap/tests/Mapping/AbstractMappingTest.php
@@ -26,6 +26,7 @@
namespace OCA\User_LDAP\Tests\Mapping;
+use OCA\User_LDAP\Mapping\AbstractMapping;
use OCP\IDBConnection;
abstract class AbstractMappingTest extends \Test\TestCase {
@@ -182,7 +183,7 @@ abstract class AbstractMappingTest extends \Test\TestCase {
/**
* tests setDNbyUUID() for successful and unsuccessful update.
*/
- public function testSetMethod() {
+ public function testSetDNMethod() {
list($mapper, $data) = $this->initTest();
$newDN = 'uid=modified,dc=example,dc=org';
@@ -196,7 +197,26 @@ abstract class AbstractMappingTest extends \Test\TestCase {
$this->assertFalse($done);
$name = $mapper->getNameByDN($newDN);
$this->assertFalse($name);
+ }
+
+ /**
+ * tests setUUIDbyDN() for successful and unsuccessful update.
+ */
+ public function testSetUUIDMethod() {
+ /** @var AbstractMapping $mapper */
+ list($mapper, $data) = $this->initTest();
+ $newUUID = 'ABC737-DEF754';
+
+ $done = $mapper->setUUIDbyDN($newUUID, 'uid=notme,dc=example,dc=org');
+ $this->assertFalse($done);
+ $name = $mapper->getNameByUUID($newUUID);
+ $this->assertFalse($name);
+
+ $done = $mapper->setUUIDbyDN($newUUID, $data[0]['dn']);
+ $this->assertTrue($done);
+ $uuid = $mapper->getUUIDByDN($data[0]['dn']);
+ $this->assertSame($uuid, $newUUID);
}
/**
diff --git a/apps/user_ldap/tests/Migration/AbstractUUIDFixTest.php b/apps/user_ldap/tests/Migration/AbstractUUIDFixTest.php
new file mode 100644
index 00000000000..2b0cb4f20fc
--- /dev/null
+++ b/apps/user_ldap/tests/Migration/AbstractUUIDFixTest.php
@@ -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 Test\TestCase;
+use OCA\User_LDAP\Access;
+use OCA\User_LDAP\Helper;
+use OCA\User_LDAP\ILDAPWrapper;
+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 ILDAPWrapper|\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(ILDAPWrapper::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);
+ }
+
+}
diff --git a/apps/user_ldap/tests/Migration/UUIDFixGroupTest.php b/apps/user_ldap/tests/Migration/UUIDFixGroupTest.php
new file mode 100644
index 00000000000..6a165190096
--- /dev/null
+++ b/apps/user_ldap/tests/Migration/UUIDFixGroupTest.php
@@ -0,0 +1,44 @@
+<?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 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);
+ }
+
+}
diff --git a/apps/user_ldap/tests/Migration/UUIDFixInsertTest.php b/apps/user_ldap/tests/Migration/UUIDFixInsertTest.php
new file mode 100644
index 00000000000..287edd7fdc4
--- /dev/null
+++ b/apps/user_ldap/tests/Migration/UUIDFixInsertTest.php
@@ -0,0 +1,135 @@
+<?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 batches of 500', $this->job->getName());
+ }
+
+ public function recordProvider() {
+ $record = [
+ 'dn' => 'cn=somerecord,dc=somewhere',
+ 'name' => 'Something',
+ 'uuid' => 'AB12-3456-CDEF7-8GH9'
+ ];
+ array_fill(0, 500, $record);
+
+ $userBatches = [
+ 0 => array_fill(0, 500, $record),
+ 1 => array_fill(0, 500, $record),
+ 2 => array_fill(0, 13, $record),
+ ];
+
+ $groupBatches = [
+ 0 => array_fill(0, 7, $record),
+ ];
+
+ 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, 500], [500, 500], [1000, 500])
+ ->willReturnOnConsecutiveCalls($userBatches[0], $userBatches[1], $userBatches[2]);
+
+ $this->groupMapper->expects($this->exactly(1))
+ ->method('getList')
+ ->with(0, 500)
+ ->willReturn($groupBatches[0]);
+
+ $this->jobList->expects($this->exactly(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);
+ }
+}
diff --git a/apps/user_ldap/tests/Migration/UUIDFixUserTest.php b/apps/user_ldap/tests/Migration/UUIDFixUserTest.php
new file mode 100644
index 00000000000..9ab8f973b91
--- /dev/null
+++ b/apps/user_ldap/tests/Migration/UUIDFixUserTest.php
@@ -0,0 +1,40 @@
+<?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 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);
+ }
+}