Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2015-09-23 17:52:48 +0300
committerArthur Schiwon <blizzz@owncloud.com>2015-09-23 18:27:40 +0300
commit002b6bf059377853dc174c1d49792e62983c4bec (patch)
treeef32e287f2fa472ff33154c79f0f03c48a10e070 /apps/user_ldap
parent845485cfe637c3a7fdb72a110cb68c769b2f8d4b (diff)
do not throw exception when no attribute is specified
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/lib/user/user.php5
-rw-r--r--apps/user_ldap/tests/user/user.php103
2 files changed, 107 insertions, 1 deletions
diff --git a/apps/user_ldap/lib/user/user.php b/apps/user_ldap/lib/user/user.php
index 3bfe0c27077..6498cdf913f 100644
--- a/apps/user_ldap/lib/user/user.php
+++ b/apps/user_ldap/lib/user/user.php
@@ -225,6 +225,7 @@ class User {
*/
public function getHomePath($valueFromLDAP = null) {
$path = $valueFromLDAP;
+ $attr = null;
if( is_null($path)
&& strpos($this->access->connection->homeFolderNamingRule, 'attr:') === 0
@@ -256,7 +257,9 @@ class User {
return $path;
}
- if($this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true)) {
+ if( !is_null($attr)
+ && $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true)
+ ) {
// a naming rule attribute is defined, but it doesn't exist for that LDAP user
throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername());
}
diff --git a/apps/user_ldap/tests/user/user.php b/apps/user_ldap/tests/user/user.php
index c074b2ceb75..1c41eb71ec2 100644
--- a/apps/user_ldap/tests/user/user.php
+++ b/apps/user_ldap/tests/user/user.php
@@ -736,4 +736,107 @@ class Test_User_User extends \Test\TestCase {
$userMock->processAttributes($record);
}
+
+ public function emptyHomeFolderAttributeValueProvider() {
+ return array(
+ 'empty' => array(''),
+ 'prefixOnly' => array('attr:'),
+ );
+ }
+
+ /**
+ * @dataProvider emptyHomeFolderAttributeValueProvider
+ */
+ public function testGetHomePathNotConfigured($attributeValue) {
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
+ $this->getTestInstances();
+
+ list($access, $connection) =
+ $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
+
+ $connection->expects($this->any())
+ ->method('__get')
+ ->with($this->equalTo('homeFolderNamingRule'))
+ ->will($this->returnValue($attributeValue));
+
+ $access->expects($this->never())
+ ->method('readAttribute');
+
+ $config->expects($this->never())
+ ->method('getAppValue');
+
+ $uid = 'alice';
+ $dn = 'uid=alice,dc=foo,dc=bar';
+
+ $user = new User(
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
+
+ $path = $user->getHomePath();
+ $this->assertSame($path, false);
+ }
+
+ public function testGetHomePathConfiguredNotAvailableAllowed() {
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
+ $this->getTestInstances();
+
+ list($access, $connection) =
+ $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
+
+ $connection->expects($this->any())
+ ->method('__get')
+ ->with($this->equalTo('homeFolderNamingRule'))
+ ->will($this->returnValue('attr:foobar'));
+
+ $access->expects($this->once())
+ ->method('readAttribute')
+ ->will($this->returnValue(false));
+
+ // asks for "enforce_home_folder_naming_rule"
+ $config->expects($this->once())
+ ->method('getAppValue')
+ ->will($this->returnValue(false));
+
+ $uid = 'alice';
+ $dn = 'uid=alice,dc=foo,dc=bar';
+
+ $user = new User(
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
+
+ $path = $user->getHomePath();
+
+ $this->assertSame($path, false);
+ }
+
+ /**
+ * @expectedException \Exception
+ */
+ public function testGetHomePathConfiguredNotAvailableNotAllowed() {
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
+ $this->getTestInstances();
+
+ list($access, $connection) =
+ $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
+
+ $connection->expects($this->any())
+ ->method('__get')
+ ->with($this->equalTo('homeFolderNamingRule'))
+ ->will($this->returnValue('attr:foobar'));
+
+ $access->expects($this->once())
+ ->method('readAttribute')
+ ->will($this->returnValue(false));
+
+ // asks for "enforce_home_folder_naming_rule"
+ $config->expects($this->once())
+ ->method('getAppValue')
+ ->will($this->returnValue(true));
+
+ $uid = 'alice';
+ $dn = 'uid=alice,dc=foo,dc=bar';
+
+ $user = new User(
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
+
+ $user->getHomePath();
+ }
}