do not throw exception when no attribute is specified

This commit is contained in:
Arthur Schiwon 2015-09-23 16:52:48 +02:00
parent 845485cfe6
commit 002b6bf059
2 changed files with 107 additions and 1 deletions

View file

@ -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());
}

View file

@ -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();
}
}