1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
<?php
/**
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Joas Schilling <nickvergessen@owncloud.com>
*
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @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,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\User_LDAP\Tests\Integration\Lib;
use OCA\User_LDAP\User\Manager as LDAPUserManager;
use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User_LDAP;
require_once __DIR__ . '/../../../../../lib/base.php';
class IntegrationTestUserHome extends AbstractIntegrationTest {
/** @var UserMapping */
protected $mapping;
/** @var User_LDAP */
protected $backend;
/**
* 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);
$this->backend = new \OCA\User_LDAP\User_LDAP($this->access, \OC::$server->getConfig());
}
/**
* sets up the LDAP configuration to be used for the test
*/
protected function initConnection() {
parent::initConnection();
$this->connection->setConfiguration([
'homeFolderNamingRule' => 'homeDirectory',
]);
}
/**
* initializes an LDAP user manager instance
* @return LDAPUserManager
*/
protected function initUserManager() {
$this->userManager = new LDAPUserManager(
\OC::$server->getConfig(),
new \OCA\User_LDAP\FilesystemHelper(),
new \OCA\User_LDAP\LogWrapper(),
\OC::$server->getAvatarManager(),
new \OCP\Image(),
\OC::$server->getDatabaseConnection(),
\OC::$server->getUserManager()
);
}
/**
* homeDirectory on LDAP is empty. Return values of getHome should be
* identical to user name, following ownCloud default.
*
* @return bool
*/
protected function case1() {
\OC::$server->getConfig()->setAppValue('user_ldap', 'enforce_home_folder_naming_rule', false);
$userManager = \OC::$server->getUserManager();
$userManager->clearBackends();
$userManager->registerBackend($this->backend);
$users = $userManager->search('', 5, 0);
foreach($users as $user) {
$home = $user->getHome();
$uid = $user->getUID();
$posFound = strpos($home, '/' . $uid);
$posExpected = strlen($home) - (strlen($uid) + 1);
if($posFound === false || $posFound !== $posExpected) {
print('"' . $user->getUID() . '" was not found in "' . $home . '" or does not end with it.' . PHP_EOL);
return false;
}
}
return true;
}
/**
* homeDirectory on LDAP is empty. Having the attributes set is enforced.
*
* @return bool
*/
protected function case2() {
\OC::$server->getConfig()->setAppValue('user_ldap', 'enforce_home_folder_naming_rule', true);
$userManager = \oc::$server->getUserManager();
// clearing backends is critical, otherwise the userManager will have
// the user objects cached and the value from case1 returned
$userManager->clearBackends();
$userManager->registerBackend($this->backend);
$users = $userManager->search('', 5, 0);
try {
foreach ($users as $user) {
$user->getHome();
print('User home was retrieved without throwing an Exception!' . PHP_EOL);
return false;
}
} catch (\Exception $e) {
if(strpos($e->getMessage(), 'Home dir attribute') === 0) {
return true;
}
}
return false;
}
/**
* homeDirectory on LDAP is set to "attr:" which is effectively empty.
* Return values of getHome should be ownCloud default.
*
* @return bool
*/
protected function case3() {
\OC::$server->getConfig()->setAppValue('user_ldap', 'enforce_home_folder_naming_rule', true);
$this->connection->setConfiguration([
'homeFolderNamingRule' => 'attr:',
]);
$userManager = \oc::$server->getUserManager();
$userManager->clearBackends();
$userManager->registerBackend($this->backend);
$users = $userManager->search('', 5, 0);
try {
foreach ($users as $user) {
$home = $user->getHome();
$uid = $user->getUID();
$posFound = strpos($home, '/' . $uid);
$posExpected = strlen($home) - (strlen($uid) + 1);
if ($posFound === false || $posFound !== $posExpected) {
print('"' . $user->getUID() . '" was not found in "' . $home . '" or does not end with it.' . PHP_EOL);
return false;
}
}
} catch (\Exception $e) {
print("Unexpected Exception: " . $e->getMessage() . PHP_EOL);
return false;
}
return true;
}
}
require_once(__DIR__ . '/../setup-scripts/config.php');
$test = new IntegrationTestUserHome($host, $port, $adn, $apwd, $bdn);
$test->init();
$test->run();
|