diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-07-04 00:10:43 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-07-05 11:12:51 +0200 |
commit | 343036e55c0b41891fc86aafc0cbb3077503ab64 (patch) | |
tree | b35cd53c20dd8e7f0fae928b9167efebed606042 /apps/user_ldap/tests | |
parent | 86d9528bc93402a18a3202bb3ff17c812b94402e (diff) | |
download | nextcloud-server-343036e55c0b41891fc86aafc0cbb3077503ab64.tar.gz nextcloud-server-343036e55c0b41891fc86aafc0cbb3077503ab64.zip |
allow admin to disable fetching of avatars as well as a specific attribute
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap/tests')
-rw-r--r-- | apps/user_ldap/tests/ConfigurationTest.php | 44 | ||||
-rw-r--r-- | apps/user_ldap/tests/User/ManagerTest.php | 34 |
2 files changed, 56 insertions, 22 deletions
diff --git a/apps/user_ldap/tests/ConfigurationTest.php b/apps/user_ldap/tests/ConfigurationTest.php index 797d2598be4..26217ea130c 100644 --- a/apps/user_ldap/tests/ConfigurationTest.php +++ b/apps/user_ldap/tests/ConfigurationTest.php @@ -23,7 +23,16 @@ namespace OCA\User_LDAP\Tests; +use OCA\User_LDAP\Configuration; + class ConfigurationTest extends \Test\TestCase { + /** @var Configuration */ + protected $configuration; + + public function setUp() { + parent::setUp(); + $this->configuration = new Configuration('t01', false); + } public function configurationDataProvider() { $inputWithDN = array( @@ -84,6 +93,10 @@ class ConfigurationTest extends \Test\TestCase { // default behaviour, one case is enough, special needs must be tested // individually 'set string value' => array('ldapHost', $inputString, $expectedString), + + 'set avatar rule, default' => ['ldapUserAvatarRule', 'default', 'default'], + 'set avatar rule, none' => ['ldapUserAvatarRule', 'none', 'none'], + 'set avatar rule, data attribute' => ['ldapUserAvatarRule', 'data:jpegPhoto', 'data:jpegPhoto'], ); } @@ -91,10 +104,35 @@ class ConfigurationTest extends \Test\TestCase { * @dataProvider configurationDataProvider */ public function testSetValue($key, $input, $expected) { - $configuration = new \OCA\User_LDAP\Configuration('t01', false); + $this->configuration->setConfiguration([$key => $input]); + $this->assertSame($this->configuration->$key, $expected); + } + + public function avatarRuleValueProvider() { + return [ + ['none', []], + ['data:selfie', ['selfie']], + ['data:', ['jpegphoto', 'thumbnailphoto']], + ['default', ['jpegphoto', 'thumbnailphoto']], + ['invalid#', ['jpegphoto', 'thumbnailphoto']], + ]; + } - $configuration->setConfiguration([$key => $input]); - $this->assertSame($configuration->$key, $expected); + /** + * @dataProvider avatarRuleValueProvider + */ + public function testGetAvatarAttributes($setting, $expected) { + $this->configuration->setConfiguration(['ldapUserAvatarRule' => $setting]); + $this->assertSame($expected, $this->configuration->getAvatarAttributes()); + } + + /** + * @dataProvider avatarRuleValueProvider + */ + public function testResolveRule($setting, $expected) { + $this->configuration->setConfiguration(['ldapUserAvatarRule' => $setting]); + // so far the only thing that can get resolved :) + $this->assertSame($expected, $this->configuration->resolveRule('avatar')); } } diff --git a/apps/user_ldap/tests/User/ManagerTest.php b/apps/user_ldap/tests/User/ManagerTest.php index da30b210b17..5399aa95a6a 100644 --- a/apps/user_ldap/tests/User/ManagerTest.php +++ b/apps/user_ldap/tests/User/ManagerTest.php @@ -238,7 +238,17 @@ class ManagerTest extends \Test\TestCase { $this->assertNull($user); } - public function testGetAttributesAll() { + public function attributeRequestProvider() { + return [ + [ false ], + [ true ], + ]; + } + + /** + * @dataProvider attributeRequestProvider + */ + public function testGetAttributes($minimal) { list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = $this->getTestInstances(); @@ -246,28 +256,14 @@ class ManagerTest extends \Test\TestCase { $manager->setLdapAccess($access); $connection = $access->getConnection(); - $connection->setConfiguration(array('ldapEmailAttribute' => 'mail')); + $connection->setConfiguration(['ldapEmailAttribute' => 'mail', 'ldapUserAvatarRule' => 'default']); - $attributes = $manager->getAttributes(); + $attributes = $manager->getAttributes($minimal); $this->assertTrue(in_array('dn', $attributes)); $this->assertTrue(in_array($access->getConnection()->ldapEmailAttribute, $attributes)); - $this->assertTrue(in_array('jpegphoto', $attributes)); - $this->assertTrue(in_array('thumbnailphoto', $attributes)); - } - - public function testGetAttributesMinimal() { - list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) = - $this->getTestInstances(); - - $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr); - $manager->setLdapAccess($access); - - $attributes = $manager->getAttributes(true); - - $this->assertTrue(in_array('dn', $attributes)); - $this->assertTrue(!in_array('jpegphoto', $attributes)); - $this->assertTrue(!in_array('thumbnailphoto', $attributes)); + $this->assertSame(!$minimal, in_array('jpegphoto', $attributes)); + $this->assertSame(!$minimal, in_array('thumbnailphoto', $attributes)); } } |