From 4d913a8aa5dad1327bed5987dada89e9d7c5d292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Thu, 13 Jan 2022 12:51:38 +0100 Subject: qt: Add job to add existing subkeys to other keys * lang/qt/src/addexistingsubkeyjob.h, lang/qt/src/qgpgmeaddexistingsubkeyjob.cpp, lang/qt/src/qgpgmeaddexistingsubkeyjob.h: New. * lang/qt/src/protocol.h (class Protocol): Add pure virtual member function addExistingSubkeyJob. * lang/qt/src/protocol_p.h (Protocol::addExistingSubkeyJob): Implement. * lang/qt/src/job.cpp, lang/qt/src/Makefile.am: Update accordingly. * lang/qt/tests/Makefile.am (the_tests, moc_files, noinst_PROGRAMS): Add new test. (t_addexistingsubkey_SOURCES): New. * lang/qt/tests/t-addexistingsubkey.cpp: New. * lang/qt/tests/t-support.h (VERIFY_OR_RETURN_VALUE, COMPARE_OR_RETURN_VALUE, VERIFY_OR_OBJECT, COMPARE_OR_OBJECT, VERIFY_OR_FALSE, COMPARE_OR_FALSE): New. * lang/qt/tests/t-support.h, lang/qt/tests/t-support.cpp (class QQGpgMETest): New member function importSecretKeys. -- The new job allows adding existing subkeys to other keys as with the "addkey" edit-key command of gpg. The added subkey will have the same expiration date (+/- 1 second) as the original subkey. GnuPG-bug-id: 5770 --- lang/qt/tests/t-support.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lang/qt/tests/t-support.cpp') diff --git a/lang/qt/tests/t-support.cpp b/lang/qt/tests/t-support.cpp index e827b517..6db082fd 100644 --- a/lang/qt/tests/t-support.cpp +++ b/lang/qt/tests/t-support.cpp @@ -36,7 +36,9 @@ #include "t-support.h" +#include "importjob.h" #include "job.h" +#include "protocol.h" #include @@ -44,9 +46,11 @@ #include #include #include +#include #include "context.h" #include "engineinfo.h" +#include "importresult.h" using namespace GpgME; using namespace QGpgME; @@ -97,6 +101,30 @@ bool QGpgMETest::copyKeyrings(const QString &src, const QString &dest) return true; } +bool QGpgMETest::importSecretKeys(const char *keyData, int expectedKeys) +{ + auto job = std::unique_ptr{openpgp()->importJob()}; + VERIFY_OR_FALSE(job); + hookUpPassphraseProvider(job.get()); + + ImportResult result; + connect(job.get(), &ImportJob::result, + this, [this, &result](const ImportResult &result_) { + result = result_; + Q_EMIT asyncDone(); + }); + VERIFY_OR_FALSE(!job->start(keyData)); + job.release(); // after the job has been started it's on its own + + QSignalSpy spy (this, SIGNAL(asyncDone())); + VERIFY_OR_FALSE(spy.wait(QSIGNALSPY_TIMEOUT)); + VERIFY_OR_FALSE(!result.error()); + VERIFY_OR_FALSE(!result.imports().empty()); + COMPARE_OR_FALSE(result.numSecretKeysImported(), expectedKeys); + + return true; +} + void QGpgMETest::hookUpPassphraseProvider(GpgME::Context *context) { context->setPassphraseProvider(&mPassphraseProvider); -- cgit v1.2.3