2015-07-08 03:16:01 +03:00
|
|
|
<?php
|
2015-10-05 21:54:56 +03:00
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-10-05 21:54:56 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Roger Szabo <roger.szabo@web.de>
|
2016-03-01 19:25:15 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-10-05 21:54:56 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-10-05 21:54:56 +03:00
|
|
|
*
|
|
|
|
*/
|
2016-05-12 12:25:50 +03:00
|
|
|
|
2016-05-12 18:14:59 +03:00
|
|
|
namespace OCA\User_LDAP\Tests\Integration\Lib\User;
|
|
|
|
|
2017-05-26 12:30:43 +03:00
|
|
|
use OCA\User_LDAP\FilesystemHelper;
|
|
|
|
use OCA\User_LDAP\LogWrapper;
|
2015-07-08 03:16:01 +03:00
|
|
|
use OCA\User_LDAP\Mapping\UserMapping;
|
2016-05-12 18:14:59 +03:00
|
|
|
use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCA\User_LDAP\User\Manager;
|
|
|
|
use OCA\User_LDAP\User\User;
|
2017-05-26 12:30:43 +03:00
|
|
|
use OCA\User_LDAP\User_LDAP;
|
2020-07-13 18:22:19 +03:00
|
|
|
use OCA\User_LDAP\UserPluginManager;
|
2017-05-26 12:30:43 +03:00
|
|
|
use OCP\Image;
|
2015-07-08 03:16:01 +03:00
|
|
|
|
2016-07-25 11:58:03 +03:00
|
|
|
require_once __DIR__ . '/../../Bootstrap.php';
|
2015-07-08 03:16:01 +03:00
|
|
|
|
|
|
|
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);
|
2020-10-05 16:12:57 +03:00
|
|
|
$userBackend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query(UserPluginManager::class));
|
2015-07-08 03:16:01 +03:00
|
|
|
\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);
|
2020-04-10 15:19:56 +03:00
|
|
|
if (\OC::$server->getAvatarManager()->getAvatar($username)->exists()) {
|
2015-07-08 03:16:01 +03:00
|
|
|
\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() {
|
2017-05-26 12:30:43 +03:00
|
|
|
$this->userManager = new Manager(
|
2015-07-08 03:16:01 +03:00
|
|
|
\OC::$server->getConfig(),
|
2017-05-26 12:30:43 +03:00
|
|
|
new FilesystemHelper(),
|
|
|
|
new LogWrapper(),
|
2015-07-08 03:16:01 +03:00
|
|
|
\OC::$server->getAvatarManager(),
|
2017-05-26 12:30:43 +03:00
|
|
|
new Image(),
|
2016-01-19 17:48:38 +03:00
|
|
|
\OC::$server->getDatabaseConnection(),
|
2017-03-31 10:16:22 +03:00
|
|
|
\OC::$server->getUserManager(),
|
|
|
|
\OC::$server->getNotificationManager()
|
2015-07-08 03:16:01 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-26 12:30:43 +03:00
|
|
|
/** @var string $host */
|
|
|
|
/** @var int $port */
|
|
|
|
/** @var string $adn */
|
|
|
|
/** @var string $apwd */
|
|
|
|
/** @var string $bdn */
|
2015-07-08 03:16:01 +03:00
|
|
|
$test = new IntegrationTestUserAvatar($host, $port, $adn, $apwd, $bdn);
|
|
|
|
$test->init();
|
|
|
|
$test->run();
|