diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b7559225..f4c67566 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,44 +1,45 @@ find_package(Qt5Test REQUIRED) set(test_LIBS kgpg_lib Qt5::Test) set(COMMON common.h common.cpp) function(create_test name) add_executable(${name} ${ARGN} ${COMMON}) target_link_libraries(${name} ${test_LIBS}) add_test(NAME ${name} COMMAND ${name}) set_property(TEST ${name} PROPERTY ENVIRONMENT "XDG_CONFIG_HOME=${CMAKE_BINARY_DIR}/tests") set_property(TEST ${name} PROPERTY RUN_SERIAL TRUE) #since gpg config home is shared between each test add_dependencies(${name} test-data) endfunction() create_test(kgpg-import kgpgimport.h kgpgimport.cpp) create_test(kgpg-verify kgpgverify.h kgpgverify.cpp) create_test(kgpg-change-trust kgpgchangetrust.h kgpgchangetrust.cpp) +create_test(kgpg-disable kgpgchangedisable.h kgpgchangedisable.cpp) set(GpgConf .gnupg/gpg.conf) set(KgpgConf kgpgrc) set(Keys keys/kgpgtest_BA7695F3C550DF14.asc keys/kgpgtest_BA7695F3C550DF14.pass keys/kgpgtest_BA7695F3C550DF14_pub.asc keys/signed_bad_sig keys/signed_text keys/encrypted_text.txt keys/encrypted_text_hide_key_id.txt ) add_custom_target(test-data) add_custom_command(TARGET test-data PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/tests/.gnupg ${CMAKE_BINARY_DIR}/tests/gnupg) add_custom_command(TARGET test-data PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/tests/keys ${CMAKE_BINARY_DIR}/tests/keys) add_custom_command(TARGET test-data PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/tests/kgpgrc ${CMAKE_BINARY_DIR}/tests/kgpgrc) diff --git a/tests/kgpgchangedisable.cpp b/tests/kgpgchangedisable.cpp new file mode 100644 index 00000000..5e8c1238 --- /dev/null +++ b/tests/kgpgchangedisable.cpp @@ -0,0 +1,49 @@ +#include "kgpgchangedisable.h" +#include "../transactions/kgpgchangedisable.h" +#include "../kgpginterface.h" +#include "common.h" + +#include + +void KGpgChangeDisableTest::init() +{ + QVERIFY(resetGpgConf()); + addGpgKey(QLatin1String("keys/kgpgtest_BA7695F3C550DF14_pub.asc")); +} + +void KGpgChangeDisableTest::testDisableKey() +{ + const QString keyID = QLatin1String("FBAF08DD7D9D0921C15DDA9FBA7695F3C550DF14"); + KGpgChangeDisable *transaction = new KGpgChangeDisable(this, keyID, true); + QSignalSpy spy(transaction, &KGpgChangeDisable::done); + QObject::connect(transaction, &KGpgChangeDisable::done, [](int result) { + // QEXPECT_FAIL("", "Test is broken. Possible bug!", Continue); + QCOMPARE(result, KGpgTransaction::TS_OK); + }); + transaction->start(); + QVERIFY(spy.wait()); + KgpgCore::KgpgKeyList keyList = KgpgInterface::readPublicKeys(QStringList(keyID)); + QVERIFY(!keyList.isEmpty()); + QVERIFY(!keyList.first().valid()); +} + +void KGpgChangeDisableTest::testEnableKey() +{ + const QString keyID = QLatin1String("FBAF08DD7D9D0921C15DDA9FBA7695F3C550DF14"); + KGpgChangeDisable *transaction = new KGpgChangeDisable(this, keyID, true); + QSignalSpy spy(transaction, &KGpgChangeDisable::done); + transaction->start(); + QVERIFY(spy.wait()); + QObject::connect(transaction, &KGpgChangeDisable::done, [](int result) { + // QEXPECT_FAIL("", "Test is broken. Possible bug!", Continue); + QCOMPARE(result, KGpgTransaction::TS_OK); + }); + transaction->setDisable(false); + transaction->start(); + QVERIFY(spy.wait()); + KgpgCore::KgpgKeyList keyList = KgpgInterface::readPublicKeys(QStringList(keyID)); + QVERIFY(!keyList.isEmpty()); + QVERIFY(keyList.first().valid()); +} + +QTEST_MAIN(KGpgChangeDisableTest) diff --git a/tests/kgpgchangedisable.h b/tests/kgpgchangedisable.h new file mode 100644 index 00000000..246d0ad1 --- /dev/null +++ b/tests/kgpgchangedisable.h @@ -0,0 +1,13 @@ +#ifndef KGPGCHANGEDISABLE_TEST_H +#define KGPGCHANGEDISABLE_TEST_H +#include + +class KGpgChangeDisableTest : public QObject { + Q_OBJECT +private slots: + void init(); + void testDisableKey(); + void testEnableKey(); +}; + +#endif