2021-02-19 15:23:43 +04:00
/*
* ADMC - AD Management Center
*
2025-01-09 15:46:38 +04:00
* Copyright ( C ) 2020 - 2025 BaseALT Ltd .
* Copyright ( C ) 2020 - 2025 Dmitry Degtyarev
2021-02-19 15:23:43 +04:00
*
* 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/>.
*/
# include "admc_test_unlock_edit.h"
2021-11-09 16:35:31 +04:00
# include "attribute_edits/unlock_edit.h"
2021-02-19 15:23:43 +04:00
# include <QCheckBox>
2021-06-10 16:34:06 +04:00
# include <QFormLayout>
2021-02-19 15:23:43 +04:00
// NOTE: this doesn't really "lock" accounts. Accounts can
// only be locked by the server and lockout time only
// displays the state. Since unlock edit modifies lockout
// time, test it like this.
# define LOCKOUT_LOCKED_VALUE "1"
void ADMCTestUnlockEdit : : init ( ) {
ADMCTest : : init ( ) ;
2021-10-05 17:01:33 +04:00
checkbox = new QCheckBox ( parent_widget ) ;
2021-02-19 15:23:43 +04:00
2021-12-22 16:26:03 +04:00
unlock_edit = new UnlockEdit ( checkbox , parent_widget ) ;
2021-02-19 15:23:43 +04:00
// Create test user
const QString name = TEST_USER ;
dn = test_object_dn ( name , CLASS_USER ) ;
const bool create_success = ad . object_add ( dn , CLASS_USER ) ;
QVERIFY ( create_success ) ;
}
// edited() signal should be emitted when checkbox is toggled
void ADMCTestUnlockEdit : : test_emit_edited_signal ( ) {
bool edited_signal_emitted = false ;
connect (
unlock_edit , & AttributeEdit : : edited ,
2021-11-17 12:22:24 +04:00
this ,
2021-02-19 15:23:43 +04:00
[ & edited_signal_emitted ] ( ) {
edited_signal_emitted = true ;
} ) ;
// Check checkbox
checkbox - > setChecked ( true ) ;
QVERIFY ( edited_signal_emitted ) ;
// Unheck checkbox
edited_signal_emitted = false ;
checkbox - > setChecked ( false ) ;
QVERIFY ( edited_signal_emitted ) ;
}
// Edit should start out as unchecked after loading user
void ADMCTestUnlockEdit : : unchecked_after_load ( ) {
load_locked_user_into_edit ( ) ;
const bool apply_success = unlock_edit - > apply ( ad , dn ) ;
QVERIFY ( apply_success ) ;
const bool checkbox_is_unchecked = ( ! checkbox - > isChecked ( ) ) ;
QVERIFY2 ( checkbox_is_unchecked , " Checkbox wasn't unchecked after load() call " ) ;
}
2021-07-14 12:35:00 +04:00
void ADMCTestUnlockEdit : : apply_unmodified ( ) {
test_edit_apply_unmodified ( unlock_edit , dn ) ;
}
2021-02-19 15:23:43 +04:00
// Edit should do nothing if checkbox is unchecked (locked
// user stays locked)
void ADMCTestUnlockEdit : : test_apply_unchecked ( ) {
load_locked_user_into_edit ( ) ;
checkbox - > setChecked ( false ) ;
const bool apply_success = unlock_edit - > apply ( ad , dn ) ;
QVERIFY ( apply_success ) ;
QVERIFY2 ( ! user_is_unlocked ( ) , " Edit unlocked user when the checkbox was unchecked. Edit should've done nothing. " ) ;
}
// Edit should unlock locked user if checkbox is checked
void ADMCTestUnlockEdit : : test_apply_checked ( ) {
load_locked_user_into_edit ( ) ;
checkbox - > setChecked ( true ) ;
const bool apply_success = unlock_edit - > apply ( ad , dn ) ;
QVERIFY ( apply_success ) ;
QVERIFY2 ( user_is_unlocked ( ) , " Edit failed to unlock user. " ) ;
}
// Edit should uncheck the checkbox after applying
void ADMCTestUnlockEdit : : uncheck_after_apply ( ) {
checkbox - > setChecked ( true ) ;
const bool apply_success = unlock_edit - > apply ( ad , dn ) ;
QVERIFY ( apply_success ) ;
const bool checkbox_is_unchecked = ( ! checkbox - > isChecked ( ) ) ;
QVERIFY2 ( checkbox_is_unchecked , " Checkbox wasn't unchecked after apply() call " ) ;
}
bool ADMCTestUnlockEdit : : user_is_unlocked ( ) {
const AdObject object = ad . search_object ( dn ) ;
const QString lockout_time = object . get_string ( ATTRIBUTE_LOCKOUT_TIME ) ;
const bool is_unlocked = ( lockout_time = = LOCKOUT_UNLOCKED_VALUE ) ;
return is_unlocked ;
}
void ADMCTestUnlockEdit : : load_locked_user_into_edit ( ) {
// Lock test user
ad . attribute_replace_string ( dn , ATTRIBUTE_LOCKOUT_TIME , LOCKOUT_LOCKED_VALUE ) ;
// Load user into edit
const AdObject object = ad . search_object ( dn ) ;
2021-03-26 17:19:58 +04:00
unlock_edit - > load ( ad , object ) ;
2021-02-19 15:23:43 +04:00
}
QTEST_MAIN ( ADMCTestUnlockEdit )