123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <?php
- /**
- * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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\Access;
- use OCA\User_LDAP\Helper;
- use OCA\User_LDAP\LDAP;
- use OCA\User_LDAP\Mapping\GroupMapping;
- use OCA\User_LDAP\Mapping\UserMapping;
- use OCA\User_LDAP\Migration\UUIDFixUser;
- use OCA\User_LDAP\User_Proxy;
- use OCP\IConfig;
- use Test\TestCase;
- 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;
- protected function setUp(): void {
- 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 instantiateJob($className) {
- $this->job = new $className($this->mapper, $this->proxy);
- $this->proxy->expects($this->any())
- ->method('getLDAPAccess')
- ->willReturn($this->access);
- }
- 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);
- }
- }
|