Sfoglia il codice sorgente

don't skip updating when ajax is set as background job mode

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
tags/v13.0.0beta1
Arthur Schiwon 6 anni fa
parent
commit
ef3cd32916
Nessun account collegato all'indirizzo email del committer

+ 15
- 4
apps/user_ldap/lib/Access.php Vedi File

use OCA\User_LDAP\Mapping\AbstractMapping; use OCA\User_LDAP\Mapping\AbstractMapping;


use OC\ServerNotAvailableException; use OC\ServerNotAvailableException;
use OCP\IServerContainer;


/** /**
* Class Access * Class Access
* @var \OCA\User_LDAP\Helper * @var \OCA\User_LDAP\Helper
*/ */
private $helper; private $helper;

public function __construct(Connection $connection, ILDAPWrapper $ldap,
Manager $userManager, Helper $helper) {
/** @var IServerContainer */
private $c;

public function __construct(
Connection $connection,
ILDAPWrapper $ldap,
Manager $userManager,
Helper $helper,
IServerContainer $c
) {
parent::__construct($ldap); parent::__construct($ldap);
$this->connection = $connection; $this->connection = $connection;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->userManager->setLdapAccess($this); $this->userManager->setLdapAccess($this);
$this->helper = $helper; $this->helper = $helper;
$this->c = $c;
} }


/** /**
*/ */
public function batchApplyUserAttributes(array $ldapRecords){ public function batchApplyUserAttributes(array $ldapRecords){
$displayNameAttribute = strtolower($this->connection->ldapUserDisplayName); $displayNameAttribute = strtolower($this->connection->ldapUserDisplayName);
$config = $this->c->getConfig();
$isBackgroundJobModeAjax = $config->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
foreach($ldapRecords as $userRecord) { foreach($ldapRecords as $userRecord) {
if(!isset($userRecord[$displayNameAttribute])) { if(!isset($userRecord[$displayNameAttribute])) {
// displayName is obligatory // displayName is obligatory
} }
$newlyMapped = false; $newlyMapped = false;
$ocName = $this->dn2ocname($userRecord['dn'][0], null, true, $newlyMapped); $ocName = $this->dn2ocname($userRecord['dn'][0], null, true, $newlyMapped);
if($ocName === false || $newlyMapped === false) {
if($ocName === false || ($newlyMapped === false && !$isBackgroundJobModeAjax)) {
continue; continue;
} }
$this->cacheUserExists($ocName); $this->cacheUserExists($ocName);

+ 1
- 1
apps/user_ldap/lib/Jobs/UpdateGroups.php Vedi File

\OC::$server->getUserManager(), \OC::$server->getUserManager(),
\OC::$server->getNotificationManager()); \OC::$server->getNotificationManager());
$connector = new Connection($ldapWrapper, $configPrefixes[0]); $connector = new Connection($ldapWrapper, $configPrefixes[0]);
$ldapAccess = new Access($connector, $ldapWrapper, $userManager, $helper);
$ldapAccess = new Access($connector, $ldapWrapper, $userManager, $helper, \OC::$server);
$groupMapper = new GroupMapping($dbc); $groupMapper = new GroupMapping($dbc);
$userMapper = new UserMapping($dbc); $userMapper = new UserMapping($dbc);
$ldapAccess->setGroupMapper($groupMapper); $ldapAccess->setGroupMapper($groupMapper);

+ 1
- 1
apps/user_ldap/lib/Proxy.php Vedi File

new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db, new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db,
$coreUserManager, $coreNotificationManager); $coreUserManager, $coreNotificationManager);
$connector = new Connection($this->ldap, $configPrefix); $connector = new Connection($this->ldap, $configPrefix);
$access = new Access($connector, $this->ldap, $userManager, new Helper(\OC::$server->getConfig()));
$access = new Access($connector, $this->ldap, $userManager, new Helper(\OC::$server->getConfig()), \OC::$server);
$access->setUserMapper($userMap); $access->setUserMapper($userMap);
$access->setGroupMapper($groupMap); $access->setGroupMapper($groupMap);
self::$accesses[$configPrefix] = $access; self::$accesses[$configPrefix] = $access;

+ 74
- 4
apps/user_ldap/tests/AccessTest.php Vedi File

use OCP\IConfig; use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\Image; use OCP\Image;
use OCP\IServerContainer;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager; use OCP\Notification\IManager as INotificationManager;
use Test\TestCase; use Test\TestCase;
private $userManager; private $userManager;
/** @var Helper|\PHPUnit_Framework_MockObject_MockObject */ /** @var Helper|\PHPUnit_Framework_MockObject_MockObject */
private $helper; private $helper;
/** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject */
private $c;
/** @var Access */ /** @var Access */
private $access; private $access;


$this->ldap = $this->createMock(LDAP::class); $this->ldap = $this->createMock(LDAP::class);
$this->userManager = $this->createMock(Manager::class); $this->userManager = $this->createMock(Manager::class);
$this->helper = $this->createMock(Helper::class); $this->helper = $this->createMock(Helper::class);
$this->c = $this->createMock(IServerContainer::class);


$this->access = new Access( $this->access = new Access(
$this->connection, $this->connection,
$this->ldap, $this->ldap,
$this->userManager, $this->userManager,
$this->helper
$this->helper,
$this->c
); );
} }


*/ */
public function testStringResemblesDN($case) { public function testStringResemblesDN($case) {
list($lw, $con, $um, $helper) = $this->getConnectorAndLdapMock(); list($lw, $con, $um, $helper) = $this->getConnectorAndLdapMock();
$access = new Access($con, $lw, $um, $helper);
/** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject $c */
$c = $this->createMock(IServerContainer::class);
$access = new Access($con, $lw, $um, $helper, $c);


$lw->expects($this->exactly(1)) $lw->expects($this->exactly(1))
->method('explodeDN') ->method('explodeDN')
*/ */
public function testStringResemblesDNLDAPmod($case) { public function testStringResemblesDNLDAPmod($case) {
list(, $con, $um, $helper) = $this->getConnectorAndLdapMock(); list(, $con, $um, $helper) = $this->getConnectorAndLdapMock();
/** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject $c */
$c = $this->createMock(IServerContainer::class);
$lw = new LDAP(); $lw = new LDAP();
$access = new Access($con, $lw, $um, $helper);
$access = new Access($con, $lw, $um, $helper, $c);


if(!function_exists('ldap_explode_dn')) { if(!function_exists('ldap_explode_dn')) {
$this->markTestSkipped('LDAP Module not available'); $this->markTestSkipped('LDAP Module not available');
->method('get') ->method('get')
->will($this->returnValue($userMock)); ->will($this->returnValue($userMock));


$this->c->expects($this->any())
->method('getConfig')
->willReturn($this->createMock(IConfig::class));

$this->access->batchApplyUserAttributes($data); $this->access->batchApplyUserAttributes($data);
} }


$this->userManager->expects($this->never()) $this->userManager->expects($this->never())
->method('get'); ->method('get');


$this->c->expects($this->any())
->method('getConfig')
->willReturn($this->createMock(IConfig::class));

$this->access->batchApplyUserAttributes($data);
}

public function testBatchApplyUserAttributesDontSkip() {
/** @var UserMapping|\PHPUnit_Framework_MockObject_MockObject $mapperMock */
$mapperMock = $this->createMock(UserMapping::class);
$mapperMock->expects($this->any())
->method('getNameByDN')
->will($this->returnValue('a_username'));

$userMock = $this->createMock(User::class);

$this->access->connection->expects($this->any())
->method('__get')
->will($this->returnValue('displayName'));

$this->access->setUserMapper($mapperMock);

$displayNameAttribute = strtolower($this->access->connection->ldapUserDisplayName);
$data = [
[
'dn' => ['foobar'],
$displayNameAttribute => 'barfoo'
],
[
'dn' => ['foo'],
$displayNameAttribute => 'bar'
],
[
'dn' => ['raboof'],
$displayNameAttribute => 'oofrab'
]
];

$userMock->expects($this->exactly(count($data)))
->method('processAttributes');

$this->userManager->expects($this->exactly(count($data)))
->method('get')
->will($this->returnValue($userMock));

$configMock = $this->createMock(IConfig::class);
$configMock->expects($this->once())
->method('getAppValue')
->with('core', 'backgroundjobs_mode', $this->anything())
->willReturn('ajax');

$this->c->expects($this->any())
->method('getConfig')
->willReturn($configMock);

$this->access->batchApplyUserAttributes($data); $this->access->batchApplyUserAttributes($data);
} }


*/ */
public function testSanitizeDN($attribute) { public function testSanitizeDN($attribute) {
list($lw, $con, $um, $helper) = $this->getConnectorAndLdapMock(); list($lw, $con, $um, $helper) = $this->getConnectorAndLdapMock();
/** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject $c */
$c = $this->createMock(IServerContainer::class);


$dnFromServer = 'cn=Mixed Cases,ou=Are Sufficient To,ou=Test,dc=example,dc=org'; $dnFromServer = 'cn=Mixed Cases,ou=Are Sufficient To,ou=Test,dc=example,dc=org';


$attribute => array('count' => 1, $dnFromServer) $attribute => array('count' => 1, $dnFromServer)
))); )));


$access = new Access($con, $lw, $um, $helper);
$access = new Access($con, $lw, $um, $helper, $c);
$values = $access->readAttribute('uid=whoever,dc=example,dc=org', $attribute); $values = $access->readAttribute('uid=whoever,dc=example,dc=org', $attribute);
$this->assertSame($values[0], strtolower($dnFromServer)); $this->assertSame($values[0], strtolower($dnFromServer));
} }

+ 1
- 1
apps/user_ldap/tests/Integration/AbstractIntegrationTest.php Vedi File

* initializes the Access test instance * initializes the Access test instance
*/ */
protected function initAccess() { protected function initAccess() {
$this->access = new Access($this->connection, $this->ldap, $this->userManager, $this->helper);
$this->access = new Access($this->connection, $this->ldap, $this->userManager, $this->helper, \OC::$server);
} }


/** /**

Loading…
Annulla
Salva