aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2015-07-08 02:16:01 +0200
committerArthur Schiwon <blizzz@owncloud.com>2015-07-27 17:27:00 +0200
commit85b7bde7d443e473d6980c9b86ab75017a469c44 (patch)
treeb4537479184451b1472750fc442a8c30c3c402b5
parent68706de45bda77d61327c3288ec6b4210de51532 (diff)
downloadnextcloud-server-85b7bde7d443e473d6980c9b86ab75017a469c44.tar.gz
nextcloud-server-85b7bde7d443e473d6980c9b86ab75017a469c44.zip
add integration tests for avatar update
-rw-r--r--apps/user_ldap/tests/integration/abstractintegrationtest.php16
-rw-r--r--apps/user_ldap/tests/integration/data/avatar-invalid.gifbin0 -> 48702 bytes
-rw-r--r--apps/user_ldap/tests/integration/data/avatar-valid.jpgbin0 -> 95495 bytes
-rw-r--r--apps/user_ldap/tests/integration/lib/user/IntegrationTestUserAvatar.php128
-rw-r--r--apps/user_ldap/tests/integration/setup-scripts/createExplicitUsers.php2
5 files changed, 144 insertions, 2 deletions
diff --git a/apps/user_ldap/tests/integration/abstractintegrationtest.php b/apps/user_ldap/tests/integration/abstractintegrationtest.php
index f24106fcbfb..f0f5e2de0a4 100644
--- a/apps/user_ldap/tests/integration/abstractintegrationtest.php
+++ b/apps/user_ldap/tests/integration/abstractintegrationtest.php
@@ -24,6 +24,7 @@ namespace OCA\user_ldap\tests\integration;
use OCA\user_ldap\lib\Access;
use OCA\user_ldap\lib\Connection;
use OCA\user_ldap\lib\LDAP;
+use OCA\user_ldap\lib\user\Manager;
abstract class AbstractIntegrationTest {
/** @var LDAP */
@@ -35,6 +36,9 @@ abstract class AbstractIntegrationTest {
/** @var Access */
protected $access;
+ /** @var Manager */
+ protected $userManager;
+
/** @var string */
protected $base;
@@ -58,7 +62,9 @@ abstract class AbstractIntegrationTest {
public function init() {
$this->initLDAPWrapper();
$this->initConnection();
+ $this->initUserManager();
$this->initAccess();
+
}
/**
@@ -89,10 +95,18 @@ abstract class AbstractIntegrationTest {
}
/**
+ * initializes an LDAP user manager instance
+ * @return Manager
+ */
+ protected function initUserManager() {
+ $this->userManager = new FakeManager();
+ }
+
+ /**
* initializes the Access test instance
*/
protected function initAccess() {
- $this->access = new Access($this->connection, $this->ldap, new FakeManager());
+ $this->access = new Access($this->connection, $this->ldap, $this->userManager);
}
/**
diff --git a/apps/user_ldap/tests/integration/data/avatar-invalid.gif b/apps/user_ldap/tests/integration/data/avatar-invalid.gif
new file mode 100644
index 00000000000..000108834d8
--- /dev/null
+++ b/apps/user_ldap/tests/integration/data/avatar-invalid.gif
Binary files differ
diff --git a/apps/user_ldap/tests/integration/data/avatar-valid.jpg b/apps/user_ldap/tests/integration/data/avatar-valid.jpg
new file mode 100644
index 00000000000..61b5ec2e730
--- /dev/null
+++ b/apps/user_ldap/tests/integration/data/avatar-valid.jpg
Binary files differ
diff --git a/apps/user_ldap/tests/integration/lib/user/IntegrationTestUserAvatar.php b/apps/user_ldap/tests/integration/lib/user/IntegrationTestUserAvatar.php
new file mode 100644
index 00000000000..a03d6b0c0c6
--- /dev/null
+++ b/apps/user_ldap/tests/integration/lib/user/IntegrationTestUserAvatar.php
@@ -0,0 +1,128 @@
+<?php
+
+use OCA\user_ldap\lib\user\User;
+use OCA\User_LDAP\Mapping\UserMapping;
+use OCA\user_ldap\tests\integration\AbstractIntegrationTest;
+
+require_once __DIR__ . '/../../../../../../lib/base.php';
+
+class IntegrationTestUserAvatar extends AbstractIntegrationTest {
+ /** @var UserMapping */
+ protected $mapping;
+
+ /**
+ * prepares the LDAP environment and sets up a test configuration for
+ * the LDAP backend.
+ */
+ public function init() {
+ require(__DIR__ . '/../../setup-scripts/createExplicitUsers.php');
+ parent::init();
+ $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
+ $this->mapping->clear();
+ $this->access->setUserMapper($this->mapping);
+ $userBackend = new OCA\user_ldap\USER_LDAP($this->access, \OC::$server->getConfig());
+ \OC_User::useBackend($userBackend);
+ }
+
+ /**
+ * A method that does the common steps of test cases 1 and 2. The evaluation
+ * is not happening here.
+ *
+ * @param string $dn
+ * @param string $username
+ * @param string $image
+ */
+ private function execFetchTest($dn, $username, $image) {
+ $this->setJpegPhotoAttribute($dn, $image);
+
+ // assigns our self-picked oc username to the dn
+ $this->mapping->map($dn, $username, 'fakeUUID-' . $username);
+
+ // initialize home folder and make sure that the user will update
+ // also remove an possibly existing avatar
+ \OC_Util::tearDownFS();
+ \OC_Util::setupFS($username);
+ \OC::$server->getUserFolder($username);
+ \OC::$server->getConfig()->deleteUserValue($username, 'user_ldap', User::USER_PREFKEY_LASTREFRESH);
+ if(\OC::$server->getAvatarManager()->getAvatar($username)->exists()) {
+ \OC::$server->getAvatarManager()->getAvatar($username)->remove();
+ }
+
+ // finally attempt to get the avatar set
+ $user = $this->userManager->get($dn);
+ $user->updateAvatar();
+ }
+
+ /**
+ * tests whether an avatar can be retrieved from LDAP and stored correctly
+ *
+ * @return bool
+ */
+ protected function case1() {
+ $image = file_get_contents(__DIR__ . '/../../data/avatar-valid.jpg');
+ $dn = 'uid=alice,ou=Users,' . $this->base;
+ $username = 'alice1337';
+
+ $this->execFetchTest($dn, $username, $image);
+
+ return \OC::$server->getAvatarManager()->getAvatar($username)->exists();
+ }
+
+ /**
+ * tests whether an image received from LDAP which is of an invalid file
+ * type is dealt with properly (i.e. not set and not dying).
+ *
+ * @return bool
+ */
+ protected function case2() {
+ // gif by Pmspinner from https://commons.wikimedia.org/wiki/File:Avatar2469_3.gif
+ $image = file_get_contents(__DIR__ . '/../../data/avatar-invalid.gif');
+ $dn = 'uid=boris,ou=Users,' . $this->base;
+ $username = 'boris7844';
+
+ $this->execFetchTest($dn, $username, $image);
+
+ return !\OC::$server->getAvatarManager()->getAvatar($username)->exists();
+ }
+
+ /**
+ * This writes an image to the 'jpegPhoto' attribute on LDAP.
+ *
+ * @param string $dn
+ * @param string $image An image read via file_get_contents
+ * @throws \OC\ServerNotAvailableException
+ */
+ private function setJpegPhotoAttribute($dn, $image) {
+ $changeSet = ['jpegphoto' => $image];
+ ldap_mod_add($this->connection->getConnectionResource(), $dn, $changeSet);
+ }
+
+ protected function initUserManager() {
+ $this->userManager = new \OCA\user_ldap\lib\user\Manager(
+ \OC::$server->getConfig(),
+ new \OCA\user_ldap\lib\FilesystemHelper(),
+ new \OCA\user_ldap\lib\LogWrapper(),
+ \OC::$server->getAvatarManager(),
+ new \OCP\Image(),
+ \OC::$server->getDatabaseConnection()
+ );
+ }
+
+ /**
+ * sets up the LDAP configuration to be used for the test
+ */
+ protected function initConnection() {
+ parent::initConnection();
+ $this->connection->setConfiguration([
+ 'ldapUserFilter' => 'objectclass=inetOrgPerson',
+ 'ldapUserDisplayName' => 'displayName',
+ 'ldapGroupDisplayName' => 'cn',
+ 'ldapLoginFilter' => 'uid=%uid',
+ ]);
+ }
+}
+
+require_once(__DIR__ . '/../../setup-scripts/config.php');
+$test = new IntegrationTestUserAvatar($host, $port, $adn, $apwd, $bdn);
+$test->init();
+$test->run();
diff --git a/apps/user_ldap/tests/integration/setup-scripts/createExplicitUsers.php b/apps/user_ldap/tests/integration/setup-scripts/createExplicitUsers.php
index ac21d48fd16..bb784d60f7b 100644
--- a/apps/user_ldap/tests/integration/setup-scripts/createExplicitUsers.php
+++ b/apps/user_ldap/tests/integration/setup-scripts/createExplicitUsers.php
@@ -30,7 +30,7 @@ if (true) {
}
}
-$users = ['alice'];
+$users = ['alice', 'boris'];
foreach ($users as $uid) {
$newDN = 'uid=' . $uid . ',' . $ouDN;