summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2018-07-05 11:29:19 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2018-07-05 12:50:08 +0200
commit7f78958056566150e598fef5d05d7804c92f18f4 (patch)
tree5668910949efb646a13d663bc8e81910694eea94
parent37a20cede1837f9bd320a475eb90e0cf6b7371a8 (diff)
downloadnextcloud-server-7f78958056566150e598fef5d05d7804c92f18f4.tar.gz
nextcloud-server-7f78958056566150e598fef5d05d7804c92f18f4.zip
adjust and add more unit tests
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
-rw-r--r--apps/user_ldap/lib/Configuration.php2
-rw-r--r--apps/user_ldap/tests/ConfigurationTest.php1
-rw-r--r--apps/user_ldap/tests/User/UserTest.php90
-rw-r--r--apps/user_ldap/tests/User_LDAPTest.php41
4 files changed, 115 insertions, 19 deletions
diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php
index 3fed3b2f429..ff4d17a5b92 100644
--- a/apps/user_ldap/lib/Configuration.php
+++ b/apps/user_ldap/lib/Configuration.php
@@ -567,7 +567,7 @@ class Configuration {
if($attribute === '') {
return $defaultAttributes;
}
- return [$attribute];
+ return [strtolower($attribute)];
}
if($value !== self::AVATAR_PREFIX_DEFAULT) {
\OC::$server->getLogger()->warning('Invalid config value to ldapUserAvatarRule; falling back to default.');
diff --git a/apps/user_ldap/tests/ConfigurationTest.php b/apps/user_ldap/tests/ConfigurationTest.php
index 26217ea130c..ab1312860fa 100644
--- a/apps/user_ldap/tests/ConfigurationTest.php
+++ b/apps/user_ldap/tests/ConfigurationTest.php
@@ -112,6 +112,7 @@ class ConfigurationTest extends \Test\TestCase {
return [
['none', []],
['data:selfie', ['selfie']],
+ ['data:sELFie', ['selfie']],
['data:', ['jpegphoto', 'thumbnailphoto']],
['default', ['jpegphoto', 'thumbnailphoto']],
['invalid#', ['jpegphoto', 'thumbnailphoto']],
diff --git a/apps/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php
index a8d17554011..29d2ba3829f 100644
--- a/apps/user_ldap/tests/User/UserTest.php
+++ b/apps/user_ldap/tests/User/UserTest.php
@@ -622,7 +622,7 @@ class UserTest extends \Test\TestCase {
$this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
- $this->equalTo('jpegPhoto'))
+ $this->equalTo('jpegphoto'))
->will($this->returnValue(array('this is a photo')));
$image->expects($this->once())
@@ -657,6 +657,10 @@ class UserTest extends \Test\TestCase {
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
+ $this->access->connection->expects($this->any())
+ ->method('resolveRule')
+ ->with('avatar')
+ ->willReturn(['jpegphoto', 'thumbnailphoto']);
$user = new User(
$uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
@@ -672,11 +676,11 @@ class UserTest extends \Test\TestCase {
->method('readAttribute')
->willReturnCallback(function($dn, $attr) {
if($dn === 'uid=alice,dc=foo,dc=bar'
- && $attr === 'jpegPhoto')
+ && $attr === 'jpegphoto')
{
return false;
} elseif($dn === 'uid=alice,dc=foo,dc=bar'
- && $attr === 'thumbnailPhoto')
+ && $attr === 'thumbnailphoto')
{
return ['this is a photo'];
}
@@ -715,6 +719,10 @@ class UserTest extends \Test\TestCase {
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
+ $this->access->connection->expects($this->any())
+ ->method('resolveRule')
+ ->with('avatar')
+ ->willReturn(['jpegphoto', 'thumbnailphoto']);
$user = new User(
$uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
@@ -730,11 +738,11 @@ class UserTest extends \Test\TestCase {
->method('readAttribute')
->willReturnCallback(function($dn, $attr) {
if($dn === $dn
- && $attr === 'jpegPhoto')
+ && $attr === 'jpegphoto')
{
return false;
} elseif($dn === $dn
- && $attr === 'thumbnailPhoto')
+ && $attr === 'thumbnailphoto')
{
return ['this is a photo'];
}
@@ -765,6 +773,10 @@ class UserTest extends \Test\TestCase {
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
+ $this->access->connection->expects($this->any())
+ ->method('resolveRule')
+ ->with('avatar')
+ ->willReturn(['jpegphoto', 'thumbnailphoto']);
$user = new User(
$uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
@@ -783,11 +795,11 @@ class UserTest extends \Test\TestCase {
->method('readAttribute')
->willReturnCallback(function($dn, $attr) {
if($dn === $dn
- && $attr === 'jpegPhoto')
+ && $attr === 'jpegphoto')
{
return false;
} elseif($dn === $dn
- && $attr === 'thumbnailPhoto')
+ && $attr === 'thumbnailphoto')
{
return ['this is a photo'];
}
@@ -825,6 +837,11 @@ class UserTest extends \Test\TestCase {
->with($this->equalTo($uid))
->will($this->returnValue($avatar));
+ $this->access->connection->expects($this->any())
+ ->method('resolveRule')
+ ->with('avatar')
+ ->willReturn(['jpegphoto', 'thumbnailphoto']);
+
$user = new User(
$uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
@@ -867,6 +884,10 @@ class UserTest extends \Test\TestCase {
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
+ $this->access->connection->expects($this->any())
+ ->method('resolveRule')
+ ->with('avatar')
+ ->willReturn(['jpegphoto', 'thumbnailphoto']);
$user = new User(
$uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
@@ -931,6 +952,10 @@ class UserTest extends \Test\TestCase {
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
+ $this->access->connection->expects($this->any())
+ ->method('resolveRule')
+ ->with('avatar')
+ ->willReturn(['jpegphoto', 'thumbnailphoto']);
$user = new User(
$uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
@@ -1003,8 +1028,12 @@ class UserTest extends \Test\TestCase {
$this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
- $this->equalTo('jpegPhoto'))
+ $this->equalTo('jpegphoto'))
->will($this->returnValue(array('this is a photo')));
+ $this->connection->expects($this->any())
+ ->method('resolveRule')
+ ->with('avatar')
+ ->willReturn(['jpegphoto', 'thumbnailphoto']);
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
@@ -1016,7 +1045,28 @@ class UserTest extends \Test\TestCase {
$this->assertSame('this is a photo', $photo);
//make sure readAttribute is not called again but the already fetched
//photo is returned
- $photo = $user->getAvatarImage();
+ $user->getAvatarImage();
+ }
+
+ public function testGetAvatarImageDisabled() {
+ list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) =
+ $this->getTestInstances();
+
+ $uid = 'alice';
+ $dn = 'uid=alice,dc=foo,dc=bar';
+
+ $this->access->expects($this->never())
+ ->method('readAttribute')
+ ->with($this->equalTo($dn), $this->anything());
+ $this->access->connection->expects($this->any())
+ ->method('resolveRule')
+ ->with('avatar')
+ ->willReturn([]);
+
+ $user = new User(
+ $uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+
+ $this->assertFalse($user->getAvatarImage());
}
public function imageDataProvider() {
@@ -1062,16 +1112,20 @@ class UserTest extends \Test\TestCase {
}
return $name;
}));
-
- $record = array(
- strtolower($this->connection->ldapQuotaAttribute) => array('4096'),
- strtolower($this->connection->ldapEmailAttribute) => array('alice@wonderland.org'),
- strtolower($this->connection->ldapUserDisplayName) => array('Aaaaalice'),
+ $this->connection->expects($this->any())
+ ->method('resolveRule')
+ ->with('avatar')
+ ->willReturn(['jpegphoto', 'thumbnailphoto']);
+
+ $record = [
+ strtolower($this->connection->ldapQuotaAttribute) => ['4096'],
+ strtolower($this->connection->ldapEmailAttribute) => ['alice@wonderland.org'],
+ strtolower($this->connection->ldapUserDisplayName) => ['Aaaaalice'],
'uid' => array($uid),
- 'homedirectory' => array('Alice\'s Folder'),
- 'memberof' => array('cn=groupOne', 'cn=groupTwo'),
- 'jpegphoto' => array('here be an image')
- );
+ 'homedirectory' => ['Alice\'s Folder'],
+ 'memberof' => ['cn=groupOne', 'cn=groupTwo'],
+ 'jpegphoto' => ['here be an image']
+ ];
foreach($requiredMethods as $method) {
$userMock->expects($this->once())
diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php
index d84cb52c5e6..5136e62e7d1 100644
--- a/apps/user_ldap/tests/User_LDAPTest.php
+++ b/apps/user_ldap/tests/User_LDAPTest.php
@@ -1663,4 +1663,45 @@ class User_LDAPTest extends TestCase {
$this->assertFalse($ldap->createUser('uid', 'password'));
}
+
+ public function actionProvider() {
+ return [
+ [ 'ldapUserAvatarRule', 'default', Backend::PROVIDE_AVATAR, true] ,
+ [ 'ldapUserAvatarRule', 'data:selfiePhoto', Backend::PROVIDE_AVATAR, true],
+ [ 'ldapUserAvatarRule', 'none', Backend::PROVIDE_AVATAR, false],
+ [ 'turnOnPasswordChange', 0, Backend::SET_PASSWORD, false],
+ [ 'turnOnPasswordChange', 1, Backend::SET_PASSWORD, true],
+ ];
+ }
+
+ /**
+ * @dataProvider actionProvider
+ */
+ public function testImplementsAction($configurable, $value, $actionCode, $expected) {
+ $pluginManager = $this->createMock(UserPluginManager::class);
+ $pluginManager->expects($this->once())
+ ->method('getImplementedActions')
+ ->willReturn(0);
+
+ $access = $this->getAccessMock();
+ $access->connection->expects($this->any())
+ ->method('__get')
+ ->willReturnMap([
+ [$configurable, $value],
+ ]);
+
+ $config = $this->createMock(IConfig::class);
+ $noti = $this->createMock(INotificationManager::class);
+ $session = $this->createMock(Session::class);
+
+ $backend = new User_LDAP(
+ $access,
+ $config,
+ $noti,
+ $session,
+ $pluginManager
+ );
+
+ $this->assertSame($expected, $backend->implementsActions($actionCode));
+ }
}