Skip to content

Commit 536edbf

Browse files
committed
feat(ldapselectfield): remove ldap connection test when saving question
prevents running unit tests connection and rendering test can be done in preview
1 parent 46c689e commit 536edbf

File tree

2 files changed

+2
-47
lines changed

2 files changed

+2
-47
lines changed

inc/field/ldapselectfield.class.php

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
use RuleRightParameter;
4040
use Glpi\Application\View\TemplateRenderer;
4141
use PluginFormcreatorAbstractField;
42-
use Toolbox;
4342

4443
class LdapselectField extends SelectField
4544
{
@@ -187,53 +186,17 @@ public function prepareQuestionInputForSave($input) {
187186
}
188187

189188
$ldap_values['ldap_attribute'] = $input['ldap_attribute'] ?? ($ldap_values['ldap_attribute'] ?? null);
190-
$attribute = [];
191189
if (isset($ldap_values['ldap_attribute'])) {
192190
$ldap_dropdown = RuleRightParameter::getById((int) $ldap_values['ldap_attribute']);
193191
if (!($ldap_dropdown instanceof RuleRightParameter)) {
194192
return [];
195193
}
196-
$attribute = [$ldap_dropdown->fields['value']];
197194
}
198195

199196
if (isset($input['ldap_filter'])) {
200197
$input['ldap_filter'] = html_entity_decode($input['ldap_filter']);
201198
}
202199
$ldap_values['ldap_filter'] = $input['ldap_filter'] ?? ($ldap_values['ldap_filter'] ?? '');
203-
set_error_handler([self::class, 'ldapErrorHandler'], E_WARNING);
204-
205-
try {
206-
$cookie = '';
207-
$ds = $config_ldap->connect();
208-
if ($ds === false) {
209-
Session::addMessageAfterRedirect(__('Connection to the directory failed.', 'formcreator'), false, ERROR);
210-
}
211-
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
212-
if (AuthLDAP::isLdapPageSizeAvailable($config_ldap)) {
213-
$controls = [
214-
[
215-
'oid' => LDAP_CONTROL_PAGEDRESULTS,
216-
'iscritical' => true,
217-
'value' => [
218-
'size' => $config_ldap->fields['pagesize'],
219-
'cookie' => $cookie
220-
]
221-
]
222-
];
223-
$result = ldap_search($ds, $config_ldap->fields['basedn'], $ldap_values->ldap_filter, $attribute, 0, -1, -1, LDAP_DEREF_NEVER, $controls);
224-
ldap_parse_result($ds, $result, $errcode, $matcheddn, $errmsg, $referrals, $controls);
225-
$cookie = $controls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] ?? '';
226-
} else {
227-
$result = ldap_search($ds, $config_ldap->fields['basedn'], $ldap_values->ldap_filter, $attribute);
228-
}
229-
ldap_get_entries($ds, $result);
230-
} catch (Exception $e) {
231-
restore_error_handler();
232-
trigger_error($e->getMessage(), E_USER_WARNING);
233-
Session::addMessageAfterRedirect(__('Cannot recover LDAP informations!', 'formcreator'), false, ERROR);
234-
}
235-
236-
restore_error_handler();
237200

238201
$input['values'] = json_encode($ldap_values, JSON_UNESCAPED_UNICODE);
239202
unset($input['ldap_auth']);

tests/3-unit/GlpiPlugin/Formcreator/Field/LdapSelectField.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ public function providerPrepareQuestionInputForSave() {
157157
]),
158158
'input' => [
159159
'ldap_auth' => $authLdap->getID(),
160-
'ldap_filter' => 'по', // Some cyrillic sample
160+
'ldap_filter' => 'по',
161161
'ldap_attribute' => '1',
162162
],
163163
'expected' => [
164164
'values' => json_encode([
165165
'ldap_auth' => $authLdap->getID(),
166+
'ldap_attribute' => '1',
166167
'ldap_filter' => 'по',
167-
'ldap_attribute' => '',
168168
], JSON_UNESCAPED_UNICODE),
169169
]
170170
],
@@ -180,14 +180,6 @@ public function providerPrepareQuestionInputForSave() {
180180
* @return void
181181
*/
182182
public function testPrepareQuestionInputForSave(\PluginFormcreatorQuestion $question, array $input, array $expected) {
183-
// Make the form private
184-
$question = $this->getQuestion([
185-
'ldap_auth' => $input['ldap_auth'],
186-
'fieldtype' => 'ldapselect',
187-
'ldap_filter' => '',
188-
'ldap_attribute' => '',
189-
]);
190-
191183
$instance = $this->newTestedInstance($question);
192184

193185
$output = $instance->prepareQuestionInputForSave($input);

0 commit comments

Comments
 (0)