mirror of
https://github.com/altlinux/admc.git
synced 2025-02-13 17:57:25 +03:00
add more tests for policy ou results
tests for remove_link(), move_up(), move_down() move column enum to private header so it can be shared with tests check for policy_root validity in results widget because test \ runs without policy tree in console
This commit is contained in:
parent
aa0e773dbf
commit
fe0a8148fd
@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "policy_ou_results_widget.h"
|
||||
#include "policy_ou_results_widget_p.h"
|
||||
#include "ui_policy_ou_results_widget.h"
|
||||
|
||||
#include "adldap.h"
|
||||
@ -42,15 +43,6 @@
|
||||
#include <QStandardItemModel>
|
||||
#include <QTreeView>
|
||||
|
||||
enum PolicyOUResultsColumn {
|
||||
PolicyOUResultsColumn_Order,
|
||||
PolicyOUResultsColumn_Name,
|
||||
PolicyOUResultsColumn_Enforced,
|
||||
PolicyOUResultsColumn_Disabled,
|
||||
|
||||
PolicyOUResultsColumn_COUNT,
|
||||
};
|
||||
|
||||
enum PolicyOUResultsRole {
|
||||
PolicyOUResultsRole_DN = Qt::UserRole + 1,
|
||||
|
||||
@ -267,14 +259,16 @@ void PolicyOUResultsWidget::remove_link() {
|
||||
|
||||
// Also remove gpo from OU in console
|
||||
const QModelIndex policy_root = get_policy_tree_root(console);
|
||||
const QModelIndex ou_index = console->search_item(policy_root, PolicyOURole_DN, ou_dn, {ItemType_PolicyOU});
|
||||
if (policy_root.isValid()) {
|
||||
const QModelIndex ou_index = console->search_item(policy_root, PolicyOURole_DN, ou_dn, {ItemType_PolicyOU});
|
||||
|
||||
if (ou_index.isValid()) {
|
||||
for (const QString &gpo_dn : gpo_dn_list) {
|
||||
const QModelIndex gpo_index = console->search_item(ou_index, PolicyRole_DN, gpo_dn, {ItemType_Policy});
|
||||
if (ou_index.isValid()) {
|
||||
for (const QString &gpo_dn : gpo_dn_list) {
|
||||
const QModelIndex gpo_index = console->search_item(ou_index, PolicyRole_DN, gpo_dn, {ItemType_Policy});
|
||||
|
||||
if (gpo_index.isValid()) {
|
||||
console->delete_item(gpo_index);
|
||||
if (gpo_index.isValid()) {
|
||||
console->delete_item(gpo_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ class QStandardItem;
|
||||
class QMenu;
|
||||
class ResultsView;
|
||||
class ConsoleWidget;
|
||||
class ADMCTestPolicyOUResultsWidget;
|
||||
|
||||
namespace Ui {
|
||||
class PolicyOUResultsWidget;
|
||||
@ -69,6 +70,8 @@ private:
|
||||
void move_down();
|
||||
void reload_gplink();
|
||||
void modify_gplink(void (*modify_function)(Gplink&, const QString&));
|
||||
|
||||
friend ADMCTestPolicyOUResultsWidget;
|
||||
};
|
||||
|
||||
#endif /* POLICY_OU_RESULTS_WIDGET_H */
|
||||
|
33
src/admc/policy_ou_results_widget_p.h
Normal file
33
src/admc/policy_ou_results_widget_p.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* ADMC - AD Management Center
|
||||
*
|
||||
* Copyright (C) 2020-2022 BaseALT Ltd.
|
||||
* Copyright (C) 2020-2022 Dmitry Degtyarev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef POLICY_OU_RESULTS_WIDGET_P_H
|
||||
#define POLICY_OU_RESULTS_WIDGET_P_H
|
||||
|
||||
enum PolicyOUResultsColumn {
|
||||
PolicyOUResultsColumn_Order,
|
||||
PolicyOUResultsColumn_Name,
|
||||
PolicyOUResultsColumn_Enforced,
|
||||
PolicyOUResultsColumn_Disabled,
|
||||
|
||||
PolicyOUResultsColumn_COUNT,
|
||||
};
|
||||
|
||||
#endif /* POLICY_OU_RESULTS_WIDGET_P_H */
|
@ -25,10 +25,12 @@
|
||||
#include "globals.h"
|
||||
#include "gplink.h"
|
||||
#include "policy_ou_results_widget.h"
|
||||
#include "policy_ou_results_widget_p.h"
|
||||
#include "console_widget/console_widget.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <QStandardItemModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QTreeView>
|
||||
|
||||
// NOTE: unlike other tests, here we have to create the test
|
||||
@ -53,6 +55,31 @@ void ADMCTestPolicyOUResultsWidget::initTestCase() {
|
||||
|
||||
for (int i = 0; i < gpo_name_list.size(); i++) {
|
||||
const QString gpo_name = gpo_name_list[i];
|
||||
|
||||
// Delete test gpo's if they failed to be deleted from
|
||||
// previous run
|
||||
const QString old_gpo_dn = [&]() {
|
||||
const QString base = ad.adconfig()->policies_dn();
|
||||
const QString filter = filter_CONDITION(Condition_Equals, ATTRIBUTE_DISPLAY_NAME, gpo_name);
|
||||
const QList<QString> attributes = QList<QString>();
|
||||
const QHash<QString, AdObject> search_results = ad.search(base, SearchScope_Children, filter, attributes);
|
||||
|
||||
if (!search_results.isEmpty()) {
|
||||
const AdObject object = search_results[0];
|
||||
const QString out = object.get_dn();
|
||||
|
||||
return out;
|
||||
} else {
|
||||
return QString();
|
||||
}
|
||||
}();
|
||||
|
||||
if (!old_gpo_dn.isEmpty()) {
|
||||
bool deleted_object;
|
||||
const bool delete_success = ad.gpo_delete(old_gpo_dn, &deleted_object);
|
||||
QVERIFY(delete_success);
|
||||
}
|
||||
|
||||
QString created_dn;
|
||||
const bool gpo_add_success = ad.gpo_add(gpo_name, created_dn);
|
||||
gpo_dn_list[i] = created_dn;
|
||||
@ -86,11 +113,15 @@ void ADMCTestPolicyOUResultsWidget::init() {
|
||||
add_widget(widget);
|
||||
|
||||
ResultsView *results_view = widget->get_view();
|
||||
results_view->set_view_type(ResultsViewType_Detail);
|
||||
view = results_view->detail_view();
|
||||
|
||||
model = widget->findChild<QStandardItemModel *>();
|
||||
QVERIFY(model);
|
||||
|
||||
proxy_model = widget->findChild<QSortFilterProxyModel *>();
|
||||
QVERIFY(proxy_model);
|
||||
|
||||
ou_dn = test_object_dn(ou_name, CLASS_OU);
|
||||
const bool create_ou_succes = ad.object_add(ou_dn, CLASS_OU);
|
||||
QVERIFY(create_ou_succes);
|
||||
@ -115,7 +146,7 @@ void ADMCTestPolicyOUResultsWidget::load() {
|
||||
widget->update(ou_dn);
|
||||
|
||||
QCOMPARE(model->rowCount(), 1);
|
||||
QCOMPARE(model->columnCount(), 3);
|
||||
QCOMPARE(model->columnCount(), PolicyOUResultsColumn_COUNT);
|
||||
|
||||
QList<QStandardItem *> item_list;
|
||||
for (int col = 0; col < model->columnCount(); col++) {
|
||||
@ -124,9 +155,117 @@ void ADMCTestPolicyOUResultsWidget::load() {
|
||||
item_list.append(item);
|
||||
}
|
||||
|
||||
QCOMPARE(item_list[0]->text(), gpo_name_list[0]);
|
||||
QCOMPARE(item_list[1]->checkState(), Qt::Checked);
|
||||
QCOMPARE(item_list[2]->checkState(), Qt::Unchecked);
|
||||
QCOMPARE(item_list[PolicyOUResultsColumn_Order]->text(), "0");
|
||||
QCOMPARE(item_list[PolicyOUResultsColumn_Name]->text(), gpo_name_list[0]);
|
||||
QCOMPARE(item_list[PolicyOUResultsColumn_Enforced]->checkState(), Qt::Checked);
|
||||
QCOMPARE(item_list[PolicyOUResultsColumn_Disabled]->checkState(), Qt::Unchecked);
|
||||
}
|
||||
|
||||
void ADMCTestPolicyOUResultsWidget::remove_link() {
|
||||
// Link gpo to ou
|
||||
const AdObject ou_object = ad.search_object(ou_dn);
|
||||
const QString gplink_string = ou_object.get_string(ATTRIBUTE_GPLINK);
|
||||
Gplink gplink = Gplink(gplink_string);
|
||||
gplink.add(gpo_dn_list[0]);
|
||||
gplink.set_option(gpo_dn_list[0], GplinkOption_Enforced, true);
|
||||
const bool modify_gplink_success = ad.attribute_replace_string(ou_dn, ATTRIBUTE_GPLINK, gplink.to_string());
|
||||
QVERIFY(modify_gplink_success);
|
||||
|
||||
widget->update(ou_dn);
|
||||
|
||||
QCOMPARE(model->rowCount(), 1);
|
||||
|
||||
const QStandardItem *gpo_item = model->item(0, 0);
|
||||
|
||||
QVERIFY(gpo_item);
|
||||
|
||||
// Select policy so it's used for remove operation
|
||||
QItemSelectionModel *selection_model = view->selectionModel();
|
||||
const QModelIndex gpo_index_source = gpo_item->index();
|
||||
const QModelIndex gpo_index_proxy = proxy_model->mapFromSource(gpo_index_source);
|
||||
selection_model->select(gpo_index_proxy, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||
|
||||
widget->remove_link();
|
||||
|
||||
QCOMPARE(model->rowCount(), 0);
|
||||
}
|
||||
|
||||
// Link two gpo's, then move up the second one and check
|
||||
// that it did move up
|
||||
void ADMCTestPolicyOUResultsWidget::move_up() {
|
||||
const AdObject ou_object = ad.search_object(ou_dn);
|
||||
const QString gplink_string = ou_object.get_string(ATTRIBUTE_GPLINK);
|
||||
Gplink gplink = Gplink(gplink_string);
|
||||
|
||||
gplink.add(gpo_dn_list[0]);
|
||||
gplink.add(gpo_dn_list[1]);
|
||||
|
||||
const bool modify_gplink_success = ad.attribute_replace_string(ou_dn, ATTRIBUTE_GPLINK, gplink.to_string());
|
||||
QVERIFY(modify_gplink_success);
|
||||
|
||||
widget->update(ou_dn);
|
||||
|
||||
QCOMPARE(model->rowCount(), 2);
|
||||
|
||||
// NOTE: need to sort by order, sorting when test
|
||||
// launches may be different due to settings
|
||||
view->sortByColumn(0, Qt::AscendingOrder);
|
||||
|
||||
const QStandardItem *old_second_item = model->item(1, 1);
|
||||
QVERIFY(old_second_item);
|
||||
|
||||
const QString old_second_item_text = old_second_item->text();
|
||||
|
||||
// Select policy so it's used for remove operation
|
||||
QItemSelectionModel *selection_model = view->selectionModel();
|
||||
const QModelIndex old_second_index_source = old_second_item->index();
|
||||
const QModelIndex old_second_index_proxy = proxy_model->mapFromSource(old_second_index_source);
|
||||
selection_model->select(old_second_index_proxy, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||
|
||||
widget->move_up();
|
||||
|
||||
const QStandardItem *new_first_item = model->item(0, 1);
|
||||
const QString new_first_item_text = new_first_item->text();
|
||||
QCOMPARE(new_first_item_text, old_second_item_text);
|
||||
}
|
||||
|
||||
// Link two gpo's, then move up the second one and check
|
||||
// that it did move up
|
||||
void ADMCTestPolicyOUResultsWidget::move_down() {
|
||||
const AdObject ou_object = ad.search_object(ou_dn);
|
||||
const QString gplink_string = ou_object.get_string(ATTRIBUTE_GPLINK);
|
||||
Gplink gplink = Gplink(gplink_string);
|
||||
|
||||
gplink.add(gpo_dn_list[0]);
|
||||
gplink.add(gpo_dn_list[1]);
|
||||
|
||||
const bool modify_gplink_success = ad.attribute_replace_string(ou_dn, ATTRIBUTE_GPLINK, gplink.to_string());
|
||||
QVERIFY(modify_gplink_success);
|
||||
|
||||
widget->update(ou_dn);
|
||||
|
||||
QCOMPARE(model->rowCount(), 2);
|
||||
|
||||
// NOTE: need to sort by order, sorting when test
|
||||
// launches may be different due to settings
|
||||
view->sortByColumn(0, Qt::AscendingOrder);
|
||||
|
||||
const QStandardItem *old_first_item = model->item(0, PolicyOUResultsColumn_Name);
|
||||
QVERIFY(old_first_item);
|
||||
|
||||
const QString old_first_item_text = old_first_item->text();
|
||||
|
||||
// Select policy so it's used for remove operation
|
||||
QItemSelectionModel *selection_model = view->selectionModel();
|
||||
const QModelIndex old_first_index_source = old_first_item->index();
|
||||
const QModelIndex old_first_index_proxy = proxy_model->mapFromSource(old_first_index_source);
|
||||
selection_model->select(old_first_index_proxy, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||
|
||||
widget->move_down();
|
||||
|
||||
const QStandardItem *new_second_item = model->item(1, PolicyOUResultsColumn_Name);
|
||||
const QString new_second_item_text = new_second_item->text();
|
||||
QCOMPARE(new_second_item_text, old_first_item_text);
|
||||
}
|
||||
|
||||
QTEST_MAIN(ADMCTestPolicyOUResultsWidget)
|
||||
|
@ -26,6 +26,7 @@
|
||||
class PolicyOUResultsWidget;
|
||||
class QTreeView;
|
||||
class QStandardItemModel;
|
||||
class QSortFilterProxyModel;
|
||||
|
||||
class ADMCTestPolicyOUResultsWidget : public ADMCTest {
|
||||
Q_OBJECT
|
||||
@ -38,11 +39,15 @@ private slots:
|
||||
|
||||
void load_empty();
|
||||
void load();
|
||||
void remove_link();
|
||||
void move_up();
|
||||
void move_down();
|
||||
|
||||
private:
|
||||
PolicyOUResultsWidget *widget;
|
||||
QTreeView *view;
|
||||
QStandardItemModel *model;
|
||||
QSortFilterProxyModel *proxy_model;
|
||||
QString ou_dn;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user