File indexing completed on 2024-12-15 04:53:05
0001 /* 0002 autotests/editdirectoryservicedialogtest.cpp 0003 0004 This file is part of libkleopatra's test suite. 0005 SPDX-FileCopyrightText: 2021 g10 Code GmbH 0006 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include <Libkleo/EditDirectoryServiceDialog> 0012 #include <Libkleo/KeyserverConfig> 0013 0014 #include <KCollapsibleGroupBox> 0015 #include <KPasswordLineEdit> 0016 0017 #include <QButtonGroup> 0018 #include <QCheckBox> 0019 #include <QDialogButtonBox> 0020 #include <QLineEdit> 0021 #include <QObject> 0022 #include <QPushButton> 0023 #include <QSpinBox> 0024 #include <QTest> 0025 #include <QWidget> 0026 0027 #include <memory> 0028 0029 using namespace Kleo; 0030 0031 namespace QTest 0032 { 0033 template<> 0034 char *toString(const KeyserverAuthentication &authentication) 0035 { 0036 return QTest::toString(static_cast<int>(authentication)); 0037 } 0038 0039 template<> 0040 char *toString(const KeyserverConnection &connection) 0041 { 0042 return QTest::toString(static_cast<int>(connection)); 0043 } 0044 } 0045 0046 #define ASSERT_HOST_IS(expected) \ 0047 do { \ 0048 const auto w = dialog->findChild<QLineEdit *>(QStringLiteral("hostEdit")); \ 0049 QVERIFY(w); \ 0050 QCOMPARE(w->text(), expected); \ 0051 } while (false) 0052 0053 #define ASSERT_PORT_IS(expected) \ 0054 do { \ 0055 const auto w = dialog->findChild<QSpinBox *>(QStringLiteral("portSpinBox")); \ 0056 QVERIFY(w); \ 0057 QCOMPARE(w->value(), expected); \ 0058 } while (false) 0059 0060 #define ASSERT_USE_DEFAULT_PORT_IS(expected) \ 0061 do { \ 0062 const auto w = dialog->findChild<QCheckBox *>(QStringLiteral("useDefaultPortCheckBox")); \ 0063 QVERIFY(w); \ 0064 QCOMPARE(w->isChecked(), expected); \ 0065 } while (false) 0066 0067 #define ASSERT_AUTHENTICATION_IS(expected) \ 0068 do { \ 0069 const auto w = dialog->findChild<QButtonGroup *>(QStringLiteral("authenticationGroup")); \ 0070 QVERIFY(w); \ 0071 QCOMPARE(w->checkedId(), static_cast<int>(expected)); \ 0072 } while (false) 0073 0074 #define ASSERT_USER_IS(expected) \ 0075 do { \ 0076 const auto w = dialog->findChild<QLineEdit *>(QStringLiteral("userEdit")); \ 0077 QVERIFY(w); \ 0078 QCOMPARE(w->text(), expected); \ 0079 } while (false) 0080 0081 #define ASSERT_PASSWORD_IS(expected) \ 0082 do { \ 0083 const auto w = dialog->findChild<KPasswordLineEdit *>(QStringLiteral("passwordEdit")); \ 0084 QVERIFY(w); \ 0085 QCOMPARE(w->password(), expected); \ 0086 } while (false) 0087 0088 #define ASSERT_CONNECTION_IS(expected) \ 0089 do { \ 0090 const auto w = dialog->findChild<QButtonGroup *>(QStringLiteral("connectionGroup")); \ 0091 QVERIFY(w); \ 0092 QCOMPARE(w->checkedId(), static_cast<int>(expected)); \ 0093 } while (false) 0094 0095 #define ASSERT_BASE_DN_IS(expected) \ 0096 do { \ 0097 const auto w = dialog->findChild<QLineEdit *>(QStringLiteral("baseDnEdit")); \ 0098 QVERIFY(w); \ 0099 QCOMPARE(w->text(), expected); \ 0100 } while (false) 0101 0102 #define ASSERT_ADDITONAL_FLAGS_ARE(expected) \ 0103 do { \ 0104 const auto w = dialog->findChild<QLineEdit *>(QStringLiteral("additionalFlagsEdit")); \ 0105 QVERIFY(w); \ 0106 QCOMPARE(w->text(), expected); \ 0107 } while (false) 0108 0109 #define ASSERT_WIDGET_IS_ENABLED(objectName) \ 0110 do { \ 0111 const auto w = dialog->findChild<QWidget *>(QStringLiteral(objectName)); \ 0112 QVERIFY(w); \ 0113 QVERIFY(w->isEnabled()); \ 0114 } while (false) 0115 0116 #define ASSERT_WIDGET_IS_DISABLED(objectName) \ 0117 do { \ 0118 const auto w = dialog->findChild<QWidget *>(QStringLiteral(objectName)); \ 0119 QVERIFY(w); \ 0120 QVERIFY(!w->isEnabled()); \ 0121 } while (false) 0122 0123 #define ASSERT_ADVANCED_SETTINGS_ARE_EXPANDED() \ 0124 do { \ 0125 const auto w = dialog->findChild<KCollapsibleGroupBox *>(QStringLiteral("advancedSettings")); \ 0126 QVERIFY(w); \ 0127 QVERIFY(w->isExpanded()); \ 0128 } while (false) 0129 0130 #define ASSERT_ADVANCED_SETTINGS_ARE_COLLAPSED() \ 0131 do { \ 0132 const auto w = dialog->findChild<KCollapsibleGroupBox *>(QStringLiteral("advancedSettings")); \ 0133 QVERIFY(w); \ 0134 QVERIFY(!w->isExpanded()); \ 0135 } while (false) 0136 0137 #define ASSERT_OK_BUTTON_IS_ENABLED() \ 0138 do { \ 0139 const auto o = dialog->findChild<QDialogButtonBox *>(QStringLiteral("buttonBox")); \ 0140 QVERIFY(o); \ 0141 QVERIFY(o->button(QDialogButtonBox::Ok)); \ 0142 QVERIFY(o->button(QDialogButtonBox::Ok)->isEnabled()); \ 0143 } while (false) 0144 0145 #define ASSERT_OK_BUTTON_IS_DISABLED() \ 0146 do { \ 0147 const auto o = dialog->findChild<QDialogButtonBox *>(QStringLiteral("buttonBox")); \ 0148 QVERIFY(o); \ 0149 QVERIFY(o->button(QDialogButtonBox::Ok)); \ 0150 QVERIFY(!o->button(QDialogButtonBox::Ok)->isEnabled()); \ 0151 } while (false) 0152 0153 #define WHEN_USER_SETS_LINEEDIT_VALUE_TO(objectName, value) \ 0154 do { \ 0155 const auto w = dialog->findChild<QLineEdit *>(QStringLiteral(objectName)); \ 0156 QVERIFY(w); \ 0157 w->selectAll(); \ 0158 w->del(); \ 0159 QTest::keyClicks(w, value); \ 0160 } while (false) 0161 0162 #define WHEN_USER_SETS_PASSWORD_TO(objectName, value) \ 0163 do { \ 0164 const auto w = dialog->findChild<KPasswordLineEdit *>(QStringLiteral(objectName)); \ 0165 QVERIFY(w); \ 0166 w->setPassword(value); \ 0167 } while (false) 0168 0169 #define WHEN_USER_TOGGLES_BUTTON(objectName) \ 0170 do { \ 0171 const auto w = dialog->findChild<QAbstractButton *>(QStringLiteral(objectName)); \ 0172 QVERIFY(w); \ 0173 QVERIFY(w->isCheckable()); \ 0174 w->toggle(); \ 0175 } while (false) 0176 0177 #define WHEN_USER_SETS_SPINBOX_VALUE_TO(objectName, value) \ 0178 do { \ 0179 const auto w = dialog->findChild<QSpinBox *>(QStringLiteral(objectName)); \ 0180 QVERIFY(w); \ 0181 w->setValue(value); \ 0182 } while (false) 0183 0184 #define WHEN_USER_SELECTS_BUTTON_WITH_ID_IN_BUTTON_GROUP(objectName, buttonId) \ 0185 do { \ 0186 const auto w = dialog->findChild<QButtonGroup *>(QStringLiteral(objectName)); \ 0187 QVERIFY(w); \ 0188 const auto button = w->button(buttonId); \ 0189 QVERIFY(button); \ 0190 button->setChecked(true); \ 0191 } while (false) 0192 0193 #define WHEN_USER_SELECTS_AUTHENTICATION(authentication) \ 0194 do { \ 0195 WHEN_USER_SELECTS_BUTTON_WITH_ID_IN_BUTTON_GROUP("authenticationGroup", static_cast<int>(authentication)); \ 0196 } while (false) 0197 0198 #define WHEN_USER_SELECTS_CONNECTION(connection) \ 0199 do { \ 0200 WHEN_USER_SELECTS_BUTTON_WITH_ID_IN_BUTTON_GROUP("connectionGroup", static_cast<int>(connection)); \ 0201 } while (false) 0202 0203 class EditDirectoryServiceDialogTest : public QObject 0204 { 0205 Q_OBJECT 0206 0207 private: 0208 std::unique_ptr<EditDirectoryServiceDialog> dialog; 0209 0210 private Q_SLOTS: 0211 void init() 0212 { 0213 dialog = std::make_unique<EditDirectoryServiceDialog>(); 0214 } 0215 0216 void cleanup() 0217 { 0218 dialog.reset(); 0219 } 0220 0221 void test__initialization() 0222 { 0223 dialog->show(); 0224 0225 ASSERT_HOST_IS(""); 0226 ASSERT_USE_DEFAULT_PORT_IS(true); 0227 ASSERT_WIDGET_IS_DISABLED("portSpinBox"); 0228 ASSERT_PORT_IS(389); 0229 ASSERT_AUTHENTICATION_IS(KeyserverAuthentication::Anonymous); 0230 ASSERT_WIDGET_IS_DISABLED("userEdit"); 0231 ASSERT_USER_IS(""); 0232 ASSERT_WIDGET_IS_DISABLED("passwordEdit"); 0233 ASSERT_PASSWORD_IS(""); 0234 ASSERT_CONNECTION_IS(KeyserverConnection::Default); 0235 ASSERT_ADVANCED_SETTINGS_ARE_COLLAPSED(); 0236 ASSERT_BASE_DN_IS(""); 0237 ASSERT_ADDITONAL_FLAGS_ARE(""); 0238 ASSERT_OK_BUTTON_IS_DISABLED(); 0239 } 0240 0241 void test__setKeyserver_new_server() 0242 { 0243 KeyserverConfig keyserver; 0244 0245 dialog->setKeyserver(keyserver); 0246 dialog->show(); 0247 0248 ASSERT_HOST_IS(""); 0249 ASSERT_USE_DEFAULT_PORT_IS(true); 0250 ASSERT_WIDGET_IS_DISABLED("portSpinBox"); 0251 ASSERT_PORT_IS(389); 0252 ASSERT_AUTHENTICATION_IS(keyserver.authentication()); 0253 ASSERT_WIDGET_IS_DISABLED("userEdit"); 0254 ASSERT_USER_IS(""); 0255 ASSERT_WIDGET_IS_DISABLED("passwordEdit"); 0256 ASSERT_PASSWORD_IS(""); 0257 ASSERT_CONNECTION_IS(keyserver.connection()); 0258 ASSERT_ADVANCED_SETTINGS_ARE_COLLAPSED(); 0259 ASSERT_BASE_DN_IS(""); 0260 ASSERT_ADDITONAL_FLAGS_ARE(""); 0261 ASSERT_OK_BUTTON_IS_DISABLED(); 0262 } 0263 0264 void test__setKeyserver_existing_server() 0265 { 0266 KeyserverConfig keyserver; 0267 keyserver.setHost(QStringLiteral("ldap.example.com")); 0268 0269 dialog->setKeyserver(keyserver); 0270 dialog->show(); 0271 0272 ASSERT_HOST_IS("ldap.example.com"); 0273 ASSERT_OK_BUTTON_IS_ENABLED(); 0274 } 0275 0276 void test__setKeyserver_anonymous_ldap_server() 0277 { 0278 KeyserverConfig keyserver; 0279 keyserver.setAuthentication(KeyserverAuthentication::Anonymous); 0280 0281 dialog->setKeyserver(keyserver); 0282 dialog->show(); 0283 0284 ASSERT_AUTHENTICATION_IS(KeyserverAuthentication::Anonymous); 0285 ASSERT_WIDGET_IS_DISABLED("userEdit"); 0286 ASSERT_WIDGET_IS_DISABLED("passwordEdit"); 0287 } 0288 0289 void test__setKeyserver_authentication_via_active_directory() 0290 { 0291 KeyserverConfig keyserver; 0292 keyserver.setAuthentication(KeyserverAuthentication::ActiveDirectory); 0293 0294 dialog->setKeyserver(keyserver); 0295 dialog->show(); 0296 0297 ASSERT_AUTHENTICATION_IS(KeyserverAuthentication::ActiveDirectory); 0298 ASSERT_WIDGET_IS_DISABLED("userEdit"); 0299 ASSERT_WIDGET_IS_DISABLED("passwordEdit"); 0300 } 0301 0302 void test__setKeyserver_authentication_with_password() 0303 { 0304 KeyserverConfig keyserver; 0305 keyserver.setHost(QStringLiteral("ldap.example.com")); 0306 keyserver.setAuthentication(KeyserverAuthentication::Password); 0307 keyserver.setUser(QStringLiteral("bind dn")); 0308 keyserver.setPassword(QStringLiteral("abc123")); 0309 0310 dialog->setKeyserver(keyserver); 0311 dialog->show(); 0312 0313 ASSERT_AUTHENTICATION_IS(KeyserverAuthentication::Password); 0314 ASSERT_WIDGET_IS_ENABLED("userEdit"); 0315 ASSERT_USER_IS("bind dn"); 0316 ASSERT_WIDGET_IS_ENABLED("passwordEdit"); 0317 ASSERT_PASSWORD_IS("abc123"); 0318 ASSERT_OK_BUTTON_IS_ENABLED(); 0319 } 0320 0321 void test__setKeyserver_authentication_with_password_requires_user() 0322 { 0323 KeyserverConfig keyserver; 0324 keyserver.setHost(QStringLiteral("ldap.example.com")); 0325 keyserver.setAuthentication(KeyserverAuthentication::Password); 0326 keyserver.setPassword(QStringLiteral("abc123")); 0327 0328 dialog->setKeyserver(keyserver); 0329 dialog->show(); 0330 0331 ASSERT_AUTHENTICATION_IS(KeyserverAuthentication::Password); 0332 ASSERT_USER_IS(""); 0333 ASSERT_PASSWORD_IS("abc123"); 0334 ASSERT_OK_BUTTON_IS_DISABLED(); 0335 } 0336 0337 void test__setKeyserver_authentication_with_password_requires_password() 0338 { 0339 KeyserverConfig keyserver; 0340 keyserver.setHost(QStringLiteral("ldap.example.com")); 0341 keyserver.setAuthentication(KeyserverAuthentication::Password); 0342 keyserver.setUser(QStringLiteral("bind dn")); 0343 0344 dialog->setKeyserver(keyserver); 0345 dialog->show(); 0346 0347 ASSERT_AUTHENTICATION_IS(KeyserverAuthentication::Password); 0348 ASSERT_USER_IS("bind dn"); 0349 ASSERT_PASSWORD_IS(""); 0350 ASSERT_OK_BUTTON_IS_DISABLED(); 0351 } 0352 0353 void test__setKeyserver_plain_connection() 0354 { 0355 KeyserverConfig keyserver; 0356 keyserver.setConnection(KeyserverConnection::Plain); 0357 0358 dialog->setKeyserver(keyserver); 0359 dialog->show(); 0360 0361 ASSERT_USE_DEFAULT_PORT_IS(true); 0362 ASSERT_PORT_IS(389); 0363 ASSERT_CONNECTION_IS(KeyserverConnection::Plain); 0364 } 0365 0366 void test__setKeyserver_starttls_connection() 0367 { 0368 KeyserverConfig keyserver; 0369 keyserver.setConnection(KeyserverConnection::UseSTARTTLS); 0370 0371 dialog->setKeyserver(keyserver); 0372 dialog->show(); 0373 0374 ASSERT_USE_DEFAULT_PORT_IS(true); 0375 ASSERT_PORT_IS(389); 0376 ASSERT_CONNECTION_IS(KeyserverConnection::UseSTARTTLS); 0377 } 0378 0379 void test__setKeyserver_ldaptls_connection() 0380 { 0381 KeyserverConfig keyserver; 0382 keyserver.setConnection(KeyserverConnection::TunnelThroughTLS); 0383 0384 dialog->setKeyserver(keyserver); 0385 dialog->show(); 0386 0387 ASSERT_USE_DEFAULT_PORT_IS(true); 0388 ASSERT_PORT_IS(636); 0389 ASSERT_CONNECTION_IS(KeyserverConnection::TunnelThroughTLS); 0390 } 0391 0392 void test__setKeyserver_non_default_port() 0393 { 0394 KeyserverConfig keyserver; 0395 keyserver.setPort(1234); 0396 0397 dialog->setKeyserver(keyserver); 0398 dialog->show(); 0399 0400 ASSERT_USE_DEFAULT_PORT_IS(false); 0401 ASSERT_WIDGET_IS_ENABLED("portSpinBox"); 0402 ASSERT_PORT_IS(1234); 0403 } 0404 0405 void test__setKeyserver_base_dn() 0406 { 0407 KeyserverConfig keyserver; 0408 keyserver.setLdapBaseDn(QStringLiteral("o=Organization,c=DE")); 0409 0410 dialog->setKeyserver(keyserver); 0411 dialog->show(); 0412 0413 ASSERT_ADVANCED_SETTINGS_ARE_EXPANDED(); 0414 ASSERT_BASE_DN_IS("o=Organization,c=DE"); 0415 } 0416 0417 void test__setKeyserver_additional_flags() 0418 { 0419 KeyserverConfig keyserver; 0420 keyserver.setAdditionalFlags({QStringLiteral("ldaps"), QStringLiteral("foo")}); 0421 0422 dialog->setKeyserver(keyserver); 0423 dialog->show(); 0424 0425 ASSERT_ADVANCED_SETTINGS_ARE_EXPANDED(); 0426 ASSERT_ADDITONAL_FLAGS_ARE("ldaps,foo"); 0427 } 0428 0429 void test__user_sets_or_clears_host() 0430 { 0431 dialog->show(); 0432 0433 ASSERT_OK_BUTTON_IS_DISABLED(); 0434 0435 WHEN_USER_SETS_LINEEDIT_VALUE_TO("hostEdit", "ldap.example.com"); 0436 ASSERT_OK_BUTTON_IS_ENABLED(); 0437 0438 WHEN_USER_SETS_LINEEDIT_VALUE_TO("hostEdit", ""); 0439 ASSERT_OK_BUTTON_IS_DISABLED(); 0440 } 0441 0442 void test__user_enables_or_disables_use_of_default_port() 0443 { 0444 dialog->show(); 0445 0446 ASSERT_USE_DEFAULT_PORT_IS(true); 0447 ASSERT_WIDGET_IS_DISABLED("portSpinBox"); 0448 ASSERT_PORT_IS(389); 0449 0450 WHEN_USER_TOGGLES_BUTTON("useDefaultPortCheckBox"); 0451 ASSERT_WIDGET_IS_ENABLED("portSpinBox"); 0452 ASSERT_PORT_IS(389); 0453 0454 WHEN_USER_SETS_SPINBOX_VALUE_TO("portSpinBox", 1234); 0455 ASSERT_PORT_IS(1234); 0456 0457 WHEN_USER_TOGGLES_BUTTON("useDefaultPortCheckBox"); 0458 ASSERT_USE_DEFAULT_PORT_IS(true); 0459 ASSERT_WIDGET_IS_DISABLED("portSpinBox"); 0460 ASSERT_PORT_IS(389); 0461 } 0462 0463 void test__user_changes_authentication() 0464 { 0465 dialog->show(); 0466 WHEN_USER_SETS_LINEEDIT_VALUE_TO("hostEdit", "ldap.example.com"); 0467 0468 ASSERT_AUTHENTICATION_IS(KeyserverAuthentication::Anonymous); 0469 ASSERT_WIDGET_IS_DISABLED("userEdit"); 0470 ASSERT_WIDGET_IS_DISABLED("passwordEdit"); 0471 ASSERT_OK_BUTTON_IS_ENABLED(); 0472 0473 WHEN_USER_SELECTS_AUTHENTICATION(KeyserverAuthentication::ActiveDirectory); 0474 ASSERT_WIDGET_IS_DISABLED("userEdit"); 0475 ASSERT_WIDGET_IS_DISABLED("passwordEdit"); 0476 ASSERT_OK_BUTTON_IS_ENABLED(); 0477 0478 WHEN_USER_SELECTS_AUTHENTICATION(KeyserverAuthentication::Password); 0479 ASSERT_WIDGET_IS_ENABLED("userEdit"); 0480 ASSERT_WIDGET_IS_ENABLED("passwordEdit"); 0481 ASSERT_OK_BUTTON_IS_DISABLED(); 0482 0483 WHEN_USER_SELECTS_AUTHENTICATION(KeyserverAuthentication::Anonymous); 0484 ASSERT_WIDGET_IS_DISABLED("userEdit"); 0485 ASSERT_WIDGET_IS_DISABLED("passwordEdit"); 0486 ASSERT_OK_BUTTON_IS_ENABLED(); 0487 } 0488 0489 void test__user_changes_user_and_password() 0490 { 0491 dialog->show(); 0492 WHEN_USER_SETS_LINEEDIT_VALUE_TO("hostEdit", "ldap.example.com"); 0493 WHEN_USER_SELECTS_AUTHENTICATION(KeyserverAuthentication::Password); 0494 0495 ASSERT_WIDGET_IS_ENABLED("userEdit"); 0496 ASSERT_WIDGET_IS_ENABLED("passwordEdit"); 0497 ASSERT_OK_BUTTON_IS_DISABLED(); 0498 0499 WHEN_USER_SETS_LINEEDIT_VALUE_TO("userEdit", "user"); 0500 ASSERT_OK_BUTTON_IS_DISABLED(); 0501 0502 WHEN_USER_SETS_PASSWORD_TO("passwordEdit", "abc123"); 0503 ASSERT_OK_BUTTON_IS_ENABLED(); 0504 0505 WHEN_USER_SETS_LINEEDIT_VALUE_TO("userEdit", ""); 0506 ASSERT_OK_BUTTON_IS_DISABLED(); 0507 0508 WHEN_USER_SETS_LINEEDIT_VALUE_TO("userEdit", "user"); 0509 ASSERT_OK_BUTTON_IS_ENABLED(); 0510 } 0511 0512 void test__user_changes_connection() 0513 { 0514 dialog->show(); 0515 0516 ASSERT_CONNECTION_IS(KeyserverConnection::Default); 0517 ASSERT_USE_DEFAULT_PORT_IS(true); 0518 ASSERT_PORT_IS(389); 0519 0520 WHEN_USER_SELECTS_CONNECTION(KeyserverConnection::TunnelThroughTLS); 0521 ASSERT_PORT_IS(636); 0522 0523 WHEN_USER_SELECTS_CONNECTION(KeyserverConnection::Plain); 0524 ASSERT_PORT_IS(389); 0525 0526 WHEN_USER_SELECTS_CONNECTION(KeyserverConnection::TunnelThroughTLS); 0527 ASSERT_PORT_IS(636); 0528 0529 WHEN_USER_SELECTS_CONNECTION(KeyserverConnection::UseSTARTTLS); 0530 ASSERT_PORT_IS(389); 0531 0532 WHEN_USER_TOGGLES_BUTTON("useDefaultPortCheckBox"); 0533 ASSERT_USE_DEFAULT_PORT_IS(false); 0534 WHEN_USER_SETS_SPINBOX_VALUE_TO("portSpinBox", 1234); 0535 0536 WHEN_USER_SELECTS_CONNECTION(KeyserverConnection::TunnelThroughTLS); 0537 ASSERT_PORT_IS(1234); 0538 0539 WHEN_USER_SELECTS_CONNECTION(KeyserverConnection::UseSTARTTLS); 0540 ASSERT_PORT_IS(1234); 0541 0542 WHEN_USER_TOGGLES_BUTTON("useDefaultPortCheckBox"); 0543 ASSERT_USE_DEFAULT_PORT_IS(true); 0544 ASSERT_PORT_IS(389); 0545 } 0546 0547 void test__result() 0548 { 0549 dialog->show(); 0550 0551 WHEN_USER_SETS_LINEEDIT_VALUE_TO("hostEdit", " ldap.example.com "); 0552 QCOMPARE(dialog->keyserver().host(), "ldap.example.com"); 0553 0554 QCOMPARE(dialog->keyserver().port(), -1); 0555 WHEN_USER_TOGGLES_BUTTON("useDefaultPortCheckBox"); 0556 QCOMPARE(dialog->keyserver().port(), 389); 0557 WHEN_USER_SETS_SPINBOX_VALUE_TO("portSpinBox", 1234); 0558 QCOMPARE(dialog->keyserver().port(), 1234); 0559 0560 WHEN_USER_SELECTS_AUTHENTICATION(KeyserverAuthentication::Anonymous); 0561 QCOMPARE(dialog->keyserver().authentication(), KeyserverAuthentication::Anonymous); 0562 WHEN_USER_SELECTS_AUTHENTICATION(KeyserverAuthentication::ActiveDirectory); 0563 QCOMPARE(dialog->keyserver().authentication(), KeyserverAuthentication::ActiveDirectory); 0564 WHEN_USER_SELECTS_AUTHENTICATION(KeyserverAuthentication::Password); 0565 QCOMPARE(dialog->keyserver().authentication(), KeyserverAuthentication::Password); 0566 0567 QCOMPARE(dialog->keyserver().user(), ""); 0568 WHEN_USER_SETS_LINEEDIT_VALUE_TO("userEdit", " user "); 0569 QCOMPARE(dialog->keyserver().user(), "user"); 0570 0571 QCOMPARE(dialog->keyserver().password(), ""); 0572 WHEN_USER_SETS_PASSWORD_TO("passwordEdit", " abc123 "); 0573 QCOMPARE(dialog->keyserver().password(), " abc123 "); // the entered password is not trimmed 0574 0575 WHEN_USER_SELECTS_CONNECTION(KeyserverConnection::Default); 0576 QCOMPARE(dialog->keyserver().connection(), KeyserverConnection::Default); 0577 WHEN_USER_SELECTS_CONNECTION(KeyserverConnection::Plain); 0578 QCOMPARE(dialog->keyserver().connection(), KeyserverConnection::Plain); 0579 WHEN_USER_SELECTS_CONNECTION(KeyserverConnection::UseSTARTTLS); 0580 QCOMPARE(dialog->keyserver().connection(), KeyserverConnection::UseSTARTTLS); 0581 WHEN_USER_SELECTS_CONNECTION(KeyserverConnection::TunnelThroughTLS); 0582 QCOMPARE(dialog->keyserver().connection(), KeyserverConnection::TunnelThroughTLS); 0583 0584 QCOMPARE(dialog->keyserver().ldapBaseDn(), ""); 0585 WHEN_USER_SETS_LINEEDIT_VALUE_TO("baseDnEdit", " o=Organization,c=DE "); 0586 QCOMPARE(dialog->keyserver().ldapBaseDn(), "o=Organization,c=DE"); 0587 0588 QCOMPARE(dialog->keyserver().additionalFlags(), {}); 0589 WHEN_USER_SETS_LINEEDIT_VALUE_TO("additionalFlagsEdit", " flag1 , flag 2 "); 0590 const QStringList expectedFlags{"flag1", "flag 2"}; 0591 QCOMPARE(dialog->keyserver().additionalFlags(), expectedFlags); 0592 } 0593 }; 0594 0595 QTEST_MAIN(EditDirectoryServiceDialogTest) 0596 #include "editdirectoryservicedialogtest.moc"