mirror of
https://github.com/altlinux/admc.git
synced 2025-02-12 13:57:27 +03:00
test UpnEdit::verify()
This commit is contained in:
parent
0ac60292e0
commit
69b3126837
@ -26,6 +26,8 @@
|
||||
#include <QTest>
|
||||
#include <QModelIndex>
|
||||
#include <QTreeView>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
|
||||
#define PRINT_FOCUS_WIDGET_BEFORE_TAB false
|
||||
#define PRINT_FOCUS_WIDGET_AFTER_TAB false
|
||||
@ -176,3 +178,17 @@ void ADMCTest::wait_for_find_results_to_load(QTreeView *view) {
|
||||
QVERIFY2((timer < 1000), "Find results failed to load, took too long");
|
||||
}
|
||||
}
|
||||
|
||||
void ADMCTest::close_message_box_later() {
|
||||
QTimer::singleShot(100, this, &ADMCTest::close_message_box_slot);
|
||||
}
|
||||
|
||||
void ADMCTest::close_message_box_slot() {
|
||||
const QList<QWidget *> top_widgets = QApplication::topLevelWidgets();
|
||||
for (QWidget *widget : top_widgets) {
|
||||
QMessageBox *message_box = qobject_cast<QMessageBox *>(widget);
|
||||
if (message_box != nullptr) {
|
||||
QTest::keyClick(message_box, Qt::Key_Enter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,6 +87,15 @@ protected:
|
||||
// because find results are loaded in separate thread.
|
||||
void wait_for_find_results_to_load(QTreeView *view);
|
||||
|
||||
// Message boxes block executation because they are
|
||||
// opened using exec(). Therefore when testing f-ns that
|
||||
// can open messageboxes, call this to to close
|
||||
// messageboxes later.
|
||||
void close_message_box_later();
|
||||
|
||||
private:
|
||||
void close_message_box_slot();
|
||||
|
||||
};
|
||||
|
||||
void navigate_until_object(QTreeView *view, const QString &target_dn);
|
||||
|
@ -141,15 +141,18 @@ void ADMCTestUpnEdit::test_reset() {
|
||||
QVERIFY2(edit_state_equals_to_server_state(), "Failed to reset");
|
||||
}
|
||||
|
||||
QString ADMCTestUpnEdit::get_current_upn() {
|
||||
const QString prefix = prefix_edit->text();
|
||||
const QString suffix = suffix_edit->currentText();
|
||||
const QString upn = QString("%1@%2").arg(prefix, suffix);
|
||||
|
||||
return upn;
|
||||
}
|
||||
|
||||
bool ADMCTestUpnEdit::edit_state_equals_to_server_state() {
|
||||
const AdObject object = ad.search_object(dn);
|
||||
const QString server_upn = object.get_string(ATTRIBUTE_USER_PRINCIPAL_NAME);
|
||||
const QString edit_upn =
|
||||
[this]() {
|
||||
const QString prefix = prefix_edit->text();
|
||||
const QString suffix = suffix_edit->currentText();
|
||||
return QString("%1@%2").arg(prefix, suffix);
|
||||
}();
|
||||
const QString edit_upn = get_current_upn();
|
||||
|
||||
return (edit_upn == server_upn);
|
||||
}
|
||||
@ -174,4 +177,22 @@ void ADMCTestUpnEdit::change_suffix_in_edit() {
|
||||
suffix_edit->setCurrentIndex(new_suffix_index);
|
||||
}
|
||||
|
||||
// verify() must return false if there's a user with the
|
||||
// same upn
|
||||
void ADMCTestUpnEdit::test_verify() {
|
||||
// Create user with conflicting upn
|
||||
const QString conflict_name = "conflicting-upn-test-user";
|
||||
const QString conflict_dn = test_object_dn(conflict_name, CLASS_USER);
|
||||
const bool create_success = ad.object_add(conflict_dn, CLASS_USER);
|
||||
QVERIFY(create_success);
|
||||
const QString conflicting_upn = get_current_upn();
|
||||
ad.attribute_replace_string(conflict_dn, ATTRIBUTE_USER_PRINCIPAL_NAME, conflicting_upn);
|
||||
|
||||
// Verify should fail
|
||||
close_message_box_later();
|
||||
const bool verify_success = upn_edit->verify(ad, dn);
|
||||
|
||||
QVERIFY2(!verify_success, "verify() didn't notice upn conflict");
|
||||
}
|
||||
|
||||
QTEST_MAIN(ADMCTestUpnEdit)
|
||||
|
@ -38,6 +38,7 @@ private slots:
|
||||
void test_apply_prefix();
|
||||
void test_apply_prefix_and_suffix();
|
||||
void test_reset();
|
||||
void test_verify();
|
||||
|
||||
private:
|
||||
UpnEdit *upn_edit;
|
||||
@ -46,6 +47,7 @@ private:
|
||||
QString dn;
|
||||
|
||||
QString get_upn();
|
||||
QString get_current_upn();
|
||||
bool edit_state_equals_to_server_state();
|
||||
void change_suffix_in_edit();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user