diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2015-09-23 16:52:48 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2015-09-23 17:27:40 +0200 |
commit | 002b6bf059377853dc174c1d49792e62983c4bec (patch) | |
tree | ef32e287f2fa472ff33154c79f0f03c48a10e070 /apps | |
parent | 845485cfe637c3a7fdb72a110cb68c769b2f8d4b (diff) | |
download | nextcloud-server-002b6bf059377853dc174c1d49792e62983c4bec.tar.gz nextcloud-server-002b6bf059377853dc174c1d49792e62983c4bec.zip |
do not throw exception when no attribute is specified
Diffstat (limited to 'apps')
-rw-r--r-- | apps/user_ldap/lib/user/user.php | 5 | ||||
-rw-r--r-- | apps/user_ldap/tests/user/user.php | 103 |
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(); + } } |