From baa49cd58a670ca7fdd9211cf057b2257d86eff9 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 25 Jun 2014 14:04:06 +0200 Subject: [PATCH 1/7] Wizad: email attribute detection --- apps/user_ldap/lib/wizard.php | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php index 0cec493d9ed..9a7f7520f56 100644 --- a/apps/user_ldap/lib/wizard.php +++ b/apps/user_ldap/lib/wizard.php @@ -128,6 +128,69 @@ class Wizard extends LDAPUtility { return $this->result; } + /** + * counts users with a specified attribute + * @param string $attr + * @return int|bool + */ + public function countUsersWithAttribute($attr) { + if(!$this->checkRequirements(array('ldapHost', + 'ldapPort', + 'ldapBase', + 'ldapUserFilter', + ))) { + return false; + } + + $access = $this->getAccess(); + $filter = $access->combineFilterWithAnd(array( + $this->configuration->ldapUserFilter, + $attr . '=*' + )); + + return $access->countUsers($filter); + } + + /** + * detects the most often used email attribute for users applying to the + * user list filter. If a setting is already present that returns at least + * one hit, the detection will be canceled. + * @return bool + */ + public function detectEmailAttribute() { + if(!$this->checkRequirements(array('ldapHost', + 'ldapPort', + 'ldapBase', + 'ldapUserFilter', + ))) { + return false; + } + + $attr = $this->configuration->ldapEmailAttribute; + if(!empty($attr)) { + $count = intval($this->countUsersWithAttribute($attr)); + if($count > 0) { + return false; + } + } + + $emailAttributes = array('mail', 'mailPrimaryAddress'); + $winner = ''; + $maxUsers = 0; + foreach($emailAttributes as $attr) { + $count = $this->countUsersWithAttribute($attr); + if($count > $maxUsers) { + $maxUsers = $count; + $winner = $attr; + } + } + + if($winner !== '') { + $this->result->addChange('ldap_email_attr', $winner); + } + + } + /** * @return WizardResult * @throws \Exception @@ -749,6 +812,7 @@ class Wizard extends LDAPUtility { if(empty($filter)) { $filter = '(objectclass=*)'; } + $this->detectEmailAttribute(); break; case self::LFILTER_GROUP_LIST: From 441c600c906a2ec55bdab123840be5d1d63bb679 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 25 Jun 2014 17:36:19 +0200 Subject: [PATCH 2/7] remove Access as hard dependency, inject it instead --- apps/user_ldap/ajax/wizard.php | 19 +++++++++++++-- apps/user_ldap/lib/wizard.php | 42 ++++++++------------------------- apps/user_ldap/tests/wizard.php | 17 ++++++++++--- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/apps/user_ldap/ajax/wizard.php b/apps/user_ldap/ajax/wizard.php index ad75a384369..d5759c597a2 100644 --- a/apps/user_ldap/ajax/wizard.php +++ b/apps/user_ldap/ajax/wizard.php @@ -39,9 +39,24 @@ if(!isset($_POST['ldap_serverconfig_chooser'])) { } $prefix = $_POST['ldap_serverconfig_chooser']; -$ldapWrapper = new OCA\user_ldap\lib\LDAP(); +$ldapWrapper = new \OCA\user_ldap\lib\LDAP(); $configuration = new \OCA\user_ldap\lib\Configuration($prefix); -$wizard = new \OCA\user_ldap\lib\Wizard($configuration, $ldapWrapper); + +$con = new \OCA\user_ldap\lib\Connection($ldapWrapper, '', null); +$con->setConfiguration($configuration->getConfiguration()); +$con->ldapConfigurationActive = true; +$con->setIgnoreValidation(true); + +$userManager = new \OCA\user_ldap\lib\user\Manager( + \OC::$server->getConfig(), + new \OCA\user_ldap\lib\FilesystemHelper(), + new \OCA\user_ldap\lib\LogWrapper(), + \OC::$server->getAvatarManager(), + new \OCP\Image()); + +$access = new \OCA\user_ldap\lib\Access($con, $ldapWrapper, $userManager); + +$wizard = new \OCA\user_ldap\lib\Wizard($configuration, $ldapWrapper, $access); switch($action) { case 'guessPortAndTLS': diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php index 9a7f7520f56..25dc4598ffb 100644 --- a/apps/user_ldap/lib/wizard.php +++ b/apps/user_ldap/lib/wizard.php @@ -25,6 +25,7 @@ namespace OCA\user_ldap\lib; class Wizard extends LDAPUtility { static protected $l; + protected $access; protected $cr; protected $configuration; protected $result; @@ -48,12 +49,13 @@ class Wizard extends LDAPUtility { * @param Configuration $configuration an instance of Configuration * @param ILDAPWrapper $ldap an instance of ILDAPWrapper */ - public function __construct(Configuration $configuration, ILDAPWrapper $ldap) { + public function __construct(Configuration $configuration, ILDAPWrapper $ldap, Access $access) { parent::__construct($ldap); $this->configuration = $configuration; if(is_null(Wizard::$l)) { Wizard::$l = \OC_L10N::get('user_ldap'); } + $this->access = $access; $this->result = new WizardResult; } @@ -78,11 +80,10 @@ class Wizard extends LDAPUtility { throw new \Exception('Requirements not met', 400); } - $ldapAccess = $this->getAccess(); if($type === 'groups') { - $result = $ldapAccess->countGroups($filter); + $result = $this->access->countGroups($filter); } else if($type === 'users') { - $result = $ldapAccess->countUsers($filter); + $result = $this->access->countUsers($filter); } else { throw new \Exception('internal error: invald object type', 500); } @@ -142,13 +143,12 @@ class Wizard extends LDAPUtility { return false; } - $access = $this->getAccess(); - $filter = $access->combineFilterWithAnd(array( + $filter = $this->access->combineFilterWithAnd(array( $this->configuration->ldapUserFilter, $attr . '=*' )); - return $access->countUsers($filter); + return $this->access->countUsers($filter); } /** @@ -352,7 +352,6 @@ class Wizard extends LDAPUtility { */ public function fetchGroups($dbKey, $confKey) { $obclasses = array('posixGroup', 'group', 'zimbraDistributionList', 'groupOfNames'); - $ldapAccess = $this->getAccess(); $filterParts = array(); foreach($obclasses as $obclass) { @@ -361,15 +360,15 @@ class Wizard extends LDAPUtility { //we filter for everything //- that looks like a group and //- has the group display name set - $filter = $ldapAccess->combineFilterWithOr($filterParts); - $filter = $ldapAccess->combineFilterWithAnd(array($filter, 'cn=*')); + $filter = $this->access->combineFilterWithOr($filterParts); + $filter = $this->access->combineFilterWithAnd(array($filter, 'cn=*')); $groupNames = array(); $groupEntries = array(); $limit = 400; $offset = 0; do { - $result = $ldapAccess->searchGroups($filter, array('cn','dn'), $limit, $offset); + $result = $this->access->searchGroups($filter, array('cn'), $limit, $offset); foreach($result as $item) { $groupNames[] = $item['cn']; $groupEntries[] = $item; @@ -1168,27 +1167,6 @@ class Wizard extends LDAPUtility { } } - /** - * creates and returns an Access instance - * @return \OCA\user_ldap\lib\Access - */ - private function getAccess() { - $con = new Connection($this->ldap, '', null); - $con->setConfiguration($this->configuration->getConfiguration()); - $con->ldapConfigurationActive = true; - $con->setIgnoreValidation(true); - - $userManager = new user\Manager( - \OC::$server->getConfig(), - new FilesystemHelper(), - new LogWrapper(), - \OC::$server->getAvatarManager(), - new \OCP\Image()); - - $ldapAccess = new Access($con, $this->ldap, $userManager); - return $ldapAccess; - } - /** * @return bool|mixed */ diff --git a/apps/user_ldap/tests/wizard.php b/apps/user_ldap/tests/wizard.php index 50461432c42..fcf4d71087f 100644 --- a/apps/user_ldap/tests/wizard.php +++ b/apps/user_ldap/tests/wizard.php @@ -46,13 +46,24 @@ class Test_Wizard extends \PHPUnit_Framework_TestCase { static $conMethods; if(is_null($conMethods)) { - $conMethods = get_class_methods('\OCA\user_ldap\lib\Configuration'); + $confMethods = get_class_methods('\OCA\user_ldap\lib\Configuration'); + $connMethods = get_class_methods('\OCA\user_ldap\lib\Connection'); + $accMethods = get_class_methods('\OCA\user_ldap\lib\Access'); } $lw = $this->getMock('\OCA\user_ldap\lib\ILDAPWrapper'); $conf = $this->getMock('\OCA\user_ldap\lib\Configuration', - $conMethods, + $confMethods, array($lw, null, null)); - return array(new Wizard($conf, $lw), $conf, $lw); + + $connector = $this->getMock('\OCA\user_ldap\lib\Connection', + $connMethods, array($lw, null, null)); + $um = $this->getMockBuilder('\OCA\user_ldap\lib\user\Manager') + ->disableOriginalConstructor() + ->getMock(); + $access = $this->getMock('\OCA\user_ldap\lib\Access', + $accMethods, array($connector, $lw, $um)); + + return array(new Wizard($conf, $lw, $access), $conf, $lw); } private function prepareLdapWrapperForConnections(&$ldap) { From f47a4a8c158f538d5febedec7282f576360a4d02 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 25 Jun 2014 18:01:04 +0200 Subject: [PATCH 3/7] add unit test for mail detection --- apps/user_ldap/lib/wizard.php | 3 +- apps/user_ldap/tests/wizard.php | 138 +++++++++++++++++++++++++++++++- lib/private/log/owncloud.php | 2 +- 3 files changed, 140 insertions(+), 3 deletions(-) diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php index 25dc4598ffb..36b855e83f6 100644 --- a/apps/user_ldap/lib/wizard.php +++ b/apps/user_ldap/lib/wizard.php @@ -155,7 +155,7 @@ class Wizard extends LDAPUtility { * detects the most often used email attribute for users applying to the * user list filter. If a setting is already present that returns at least * one hit, the detection will be canceled. - * @return bool + * @return bool|string */ public function detectEmailAttribute() { if(!$this->checkRequirements(array('ldapHost', @@ -189,6 +189,7 @@ class Wizard extends LDAPUtility { $this->result->addChange('ldap_email_attr', $winner); } + return $winner; } /** diff --git a/apps/user_ldap/tests/wizard.php b/apps/user_ldap/tests/wizard.php index fcf4d71087f..d6de83bbdd6 100644 --- a/apps/user_ldap/tests/wizard.php +++ b/apps/user_ldap/tests/wizard.php @@ -63,7 +63,7 @@ class Test_Wizard extends \PHPUnit_Framework_TestCase { $access = $this->getMock('\OCA\user_ldap\lib\Access', $accMethods, array($connector, $lw, $um)); - return array(new Wizard($conf, $lw, $access), $conf, $lw); + return array(new Wizard($conf, $lw, $access), $conf, $lw, $access); } private function prepareLdapWrapperForConnections(&$ldap) { @@ -218,6 +218,142 @@ class Test_Wizard extends \PHPUnit_Framework_TestCase { unset($uidnumber); } + public function testDetectEmailAttributeAlreadySet() { + list($wizard, $configuration, $ldap, $access) + = $this->getWizardAndMocks(); + + $configuration->expects($this->any()) + ->method('__get') + ->will($this->returnCallback(function ($name) { + if($name === 'ldapEmailAttribute') { + return 'myEmailAttribute'; + } else { + //for requirement checks + return 'let me pass'; + } + })); + + $access->expects($this->once()) + ->method('countUsers') + ->will($this->returnValue(42)); + + $wizard->detectEmailAttribute(); + } + + public function testDetectEmailAttributeOverrideSet() { + list($wizard, $configuration, $ldap, $access) + = $this->getWizardAndMocks(); + + $configuration->expects($this->any()) + ->method('__get') + ->will($this->returnCallback(function ($name) { + if($name === 'ldapEmailAttribute') { + return 'myEmailAttribute'; + } else { + //for requirement checks + return 'let me pass'; + } + })); + + $access->expects($this->exactly(3)) + ->method('combineFilterWithAnd') + ->will($this->returnCallback(function ($filterParts) { + return str_replace('=*', '', array_pop($filterParts)); + })); + + $access->expects($this->exactly(3)) + ->method('countUsers') + ->will($this->returnCallback(function ($filter) { + if($filter === 'myEmailAttribute') { + return 0; + } else if($filter === 'mail') { + return 3; + } else if($filter === 'mailPrimaryAddress') { + return 17; + } + var_dump($filter); + })); + + $resultAttribute = $wizard->detectEmailAttribute(); + $this->assertSame('mailPrimaryAddress', $resultAttribute); + } + + public function testDetectEmailAttributeFind() { + list($wizard, $configuration, $ldap, $access) + = $this->getWizardAndMocks(); + + $configuration->expects($this->any()) + ->method('__get') + ->will($this->returnCallback(function ($name) { + if($name === 'ldapEmailAttribute') { + return ''; + } else { + //for requirement checks + return 'let me pass'; + } + })); + + $access->expects($this->exactly(2)) + ->method('combineFilterWithAnd') + ->will($this->returnCallback(function ($filterParts) { + return str_replace('=*', '', array_pop($filterParts)); + })); + + $access->expects($this->exactly(2)) + ->method('countUsers') + ->will($this->returnCallback(function ($filter) { + if($filter === 'myEmailAttribute') { + return 0; + } else if($filter === 'mail') { + return 3; + } else if($filter === 'mailPrimaryAddress') { + return 17; + } + var_dump($filter); + })); + + $resultAttribute = $wizard->detectEmailAttribute(); + $this->assertSame('mailPrimaryAddress', $resultAttribute); + } + + public function testDetectEmailAttributeFindNothing() { + list($wizard, $configuration, $ldap, $access) + = $this->getWizardAndMocks(); + + $configuration->expects($this->any()) + ->method('__get') + ->will($this->returnCallback(function ($name) { + if($name === 'ldapEmailAttribute') { + return 'myEmailAttribute'; + } else { + //for requirement checks + return 'let me pass'; + } + })); + + $access->expects($this->exactly(3)) + ->method('combineFilterWithAnd') + ->will($this->returnCallback(function ($filterParts) { + return str_replace('=*', '', array_pop($filterParts)); + })); + + $access->expects($this->exactly(3)) + ->method('countUsers') + ->will($this->returnCallback(function ($filter) { + if($filter === 'myEmailAttribute') { + return 0; + } else if($filter === 'mail') { + return 0; + } else if($filter === 'mailPrimaryAddress') { + return 0; + } + var_dump($filter); + })); + + $resultAttribute = $wizard->detectEmailAttribute(); + $this->assertSame('', $resultAttribute); + } + public function testCumulativeSearchOnAttributeSkipReadDN() { // tests that there is no infinite loop, when skipping already processed // DNs (they can be returned multiple times for multiple filters ) diff --git a/lib/private/log/owncloud.php b/lib/private/log/owncloud.php index 08d0b7d5f93..9fcfccd48c2 100644 --- a/lib/private/log/owncloud.php +++ b/lib/private/log/owncloud.php @@ -85,7 +85,7 @@ class OC_Log_Owncloud { } $entry = json_encode($entry); $handle = @fopen(self::$logFile, 'a'); - @chmod(self::$logFile, 0640); +// @chmod(self::$logFile, 0640); if ($handle) { fwrite($handle, $entry."\n"); fclose($handle); From 34761dabb17a2ee06924f34679316c7889b456a7 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 25 Jun 2014 18:08:05 +0200 Subject: [PATCH 4/7] write log message, if original value was changed --- apps/user_ldap/lib/wizard.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php index 36b855e83f6..8e6e47b1f6b 100644 --- a/apps/user_ldap/lib/wizard.php +++ b/apps/user_ldap/lib/wizard.php @@ -172,6 +172,9 @@ class Wizard extends LDAPUtility { if($count > 0) { return false; } + $writeLog = true; + } else { + $writeLog = false; } $emailAttributes = array('mail', 'mailPrimaryAddress'); @@ -187,6 +190,11 @@ class Wizard extends LDAPUtility { if($winner !== '') { $this->result->addChange('ldap_email_attr', $winner); + if($writeLog) { + \OCP\Util::writeLog('user_ldap', 'The mail attribute has ' . + 'automatically been reset, because the original value ' . + 'did not return any results.', \OCP\Util::INFO); + } } return $winner; From 6958033db9f6bd2ff7e69b05a6cb064206957a65 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 25 Jun 2014 18:12:35 +0200 Subject: [PATCH 5/7] undo falsely changed log file --- lib/private/log/owncloud.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/log/owncloud.php b/lib/private/log/owncloud.php index 9fcfccd48c2..08d0b7d5f93 100644 --- a/lib/private/log/owncloud.php +++ b/lib/private/log/owncloud.php @@ -85,7 +85,7 @@ class OC_Log_Owncloud { } $entry = json_encode($entry); $handle = @fopen(self::$logFile, 'a'); -// @chmod(self::$logFile, 0640); + @chmod(self::$logFile, 0640); if ($handle) { fwrite($handle, $entry."\n"); fclose($handle); From 371cab367d2b786c0fadb3a76daeb3ba9138e164 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 25 Jun 2014 19:38:54 +0200 Subject: [PATCH 6/7] trigger email detection by Wizard upon any user filter filter change. before it happenend only upon user automatic list filter creation, but not on manual editing --- apps/user_ldap/ajax/wizard.php | 1 + apps/user_ldap/js/ldapFilter.js | 5 ++++- apps/user_ldap/js/settings.js | 18 +++++++++++++++--- apps/user_ldap/lib/wizard.php | 5 ++--- apps/user_ldap/tests/wizard.php | 14 ++++++++------ 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/apps/user_ldap/ajax/wizard.php b/apps/user_ldap/ajax/wizard.php index d5759c597a2..adbcf6ff414 100644 --- a/apps/user_ldap/ajax/wizard.php +++ b/apps/user_ldap/ajax/wizard.php @@ -61,6 +61,7 @@ $wizard = new \OCA\user_ldap\lib\Wizard($configuration, $ldapWrapper, $access); switch($action) { case 'guessPortAndTLS': case 'guessBaseDN': + case 'detectEmailAttribute': case 'determineGroupMemberAssoc': case 'determineUserObjectClasses': case 'determineGroupObjectClasses': diff --git a/apps/user_ldap/js/ldapFilter.js b/apps/user_ldap/js/ldapFilter.js index df3bd67aec2..e9f60e7ba3c 100644 --- a/apps/user_ldap/js/ldapFilter.js +++ b/apps/user_ldap/js/ldapFilter.js @@ -14,7 +14,7 @@ function LdapFilter(target) { } } -LdapFilter.prototype.compose = function() { +LdapFilter.prototype.compose = function(callback) { var action; if(this.locked) { @@ -50,6 +50,9 @@ LdapFilter.prototype.compose = function() { LdapWizard.countGroups(); LdapWizard.detectGroupMemberAssoc(); } + if(typeof callback !== 'undefined') { + callback(); + } }, function () { console.log('LDAP Wizard: could not compose filter. '+ diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index 87d755697cb..fd84ca1980b 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -340,6 +340,14 @@ var LdapWizard = { LdapWizard._countThings('countUsers'); }, + detectEmailAttribute: function() { + param = 'action=detectEmailAttribute'+ + '&ldap_serverconfig_chooser='+ + encodeURIComponent($('#ldap_serverconfig_chooser').val()); + //runs in the background, no callbacks necessary + LdapWizard.ajax(param, LdapWizard.applyChanges, function(){}); + }, + detectGroupMemberAssoc: function() { param = 'action=determineGroupMemberAssoc'+ '&ldap_serverconfig_chooser='+ @@ -577,7 +585,7 @@ var LdapWizard = { postInitUserFilter: function() { if(LdapWizard.userFilterObjectClassesHasRun && LdapWizard.userFilterAvailableGroupsHasRun) { - LdapWizard.userFilter.compose(); + LdapWizard.userFilter.compose(LdapWizard.detectEmailAttribute); LdapWizard.countUsers(); } }, @@ -619,6 +627,7 @@ var LdapWizard = { if(triggerObj.id == 'ldap_userlist_filter') { LdapWizard.countUsers(); + LdapWizard.detectEmailAttribute(); } else if(triggerObj.id == 'ldap_group_filter') { LdapWizard.countGroups(); LdapWizard.detectGroupMemberAssoc(); @@ -656,9 +665,12 @@ var LdapWizard = { LdapWizard._save($('#'+originalObj)[0], $.trim(values)); if(originalObj == 'ldap_userfilter_objectclass' || originalObj == 'ldap_userfilter_groups') { - LdapWizard.userFilter.compose(); + LdapWizard.userFilter.compose(LdapWizard.detectEmailAttribute); //when user filter is changed afterwards, login filter needs to //be adjusted, too + if(!LdapWizard.loginFilter) { + LdapWizard.initLoginFilter(); + } LdapWizard.loginFilter.compose(); } else if(originalObj == 'ldap_loginfilter_attributes') { LdapWizard.loginFilter.compose(); @@ -720,7 +732,7 @@ var LdapWizard = { LdapWizard._save({ id: modeKey }, LdapWizard.filterModeAssisted); if(moc.indexOf('user') >= 0) { LdapWizard.blacklistRemove('ldap_userlist_filter'); - LdapWizard.userFilter.compose(); + LdapWizard.userFilter.compose(LdapWizard.detectEmailAttribute); } else { LdapWizard.blacklistRemove('ldap_group_filter'); LdapWizard.groupFilter.compose(); diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php index 8e6e47b1f6b..4118b45bc35 100644 --- a/apps/user_ldap/lib/wizard.php +++ b/apps/user_ldap/lib/wizard.php @@ -155,7 +155,7 @@ class Wizard extends LDAPUtility { * detects the most often used email attribute for users applying to the * user list filter. If a setting is already present that returns at least * one hit, the detection will be canceled. - * @return bool|string + * @return WizardResult|bool */ public function detectEmailAttribute() { if(!$this->checkRequirements(array('ldapHost', @@ -197,7 +197,7 @@ class Wizard extends LDAPUtility { } } - return $winner; + return $this->result; } /** @@ -820,7 +820,6 @@ class Wizard extends LDAPUtility { if(empty($filter)) { $filter = '(objectclass=*)'; } - $this->detectEmailAttribute(); break; case self::LFILTER_GROUP_LIST: diff --git a/apps/user_ldap/tests/wizard.php b/apps/user_ldap/tests/wizard.php index d6de83bbdd6..867fba11f27 100644 --- a/apps/user_ldap/tests/wizard.php +++ b/apps/user_ldap/tests/wizard.php @@ -274,8 +274,9 @@ class Test_Wizard extends \PHPUnit_Framework_TestCase { var_dump($filter); })); - $resultAttribute = $wizard->detectEmailAttribute(); - $this->assertSame('mailPrimaryAddress', $resultAttribute); + $result = $wizard->detectEmailAttribute()->getResultArray(); + $this->assertSame('mailPrimaryAddress', + $result['changes']['ldap_email_attr']); } public function testDetectEmailAttributeFind() { @@ -312,8 +313,9 @@ class Test_Wizard extends \PHPUnit_Framework_TestCase { var_dump($filter); })); - $resultAttribute = $wizard->detectEmailAttribute(); - $this->assertSame('mailPrimaryAddress', $resultAttribute); + $result = $wizard->detectEmailAttribute()->getResultArray(); + $this->assertSame('mailPrimaryAddress', + $result['changes']['ldap_email_attr']); } public function testDetectEmailAttributeFindNothing() { @@ -350,8 +352,8 @@ class Test_Wizard extends \PHPUnit_Framework_TestCase { var_dump($filter); })); - $resultAttribute = $wizard->detectEmailAttribute(); - $this->assertSame('', $resultAttribute); + $result = $wizard->detectEmailAttribute(); + $this->assertSame(false, $result->hasChanges()); } public function testCumulativeSearchOnAttributeSkipReadDN() { From aa0ddf21b5b94d52804c81f35f82890ffeeabf1a Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 11 Aug 2014 16:05:43 +0200 Subject: [PATCH 7/7] adjust static method vars as well --- apps/user_ldap/tests/wizard.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/user_ldap/tests/wizard.php b/apps/user_ldap/tests/wizard.php index 867fba11f27..1f420f9ee8a 100644 --- a/apps/user_ldap/tests/wizard.php +++ b/apps/user_ldap/tests/wizard.php @@ -43,9 +43,11 @@ class Test_Wizard extends \PHPUnit_Framework_TestCase { } private function getWizardAndMocks() { - static $conMethods; + static $confMethods; + static $connMethods; + static $accMethods; - if(is_null($conMethods)) { + if(is_null($confMethods)) { $confMethods = get_class_methods('\OCA\user_ldap\lib\Configuration'); $connMethods = get_class_methods('\OCA\user_ldap\lib\Connection'); $accMethods = get_class_methods('\OCA\user_ldap\lib\Access');