aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Heinecke <[email protected]>2019-10-29 15:36:45 +0000
committerAndre Heinecke <[email protected]>2019-10-29 15:36:45 +0000
commit1f3ca698f16465761649d402b999f0e2c9184344 (patch)
treec1ce1720f9ca01151f3cf6ef7d3660f9209d4723
parentqt: Extend signkeyjob to handle remarks and dups (diff)
downloadgpgme-1f3ca698f16465761649d402b999f0e2c9184344.tar.gz
gpgme-1f3ca698f16465761649d402b999f0e2c9184344.zip
qt,tests: Add test for remarks
* lang/qt/tests/t-various.cpp (testRemark): New.
-rw-r--r--lang/qt/tests/t-various.cpp111
1 files changed, 111 insertions, 0 deletions
diff --git a/lang/qt/tests/t-various.cpp b/lang/qt/tests/t-various.cpp
index 76e68063..75df8f6b 100644
--- a/lang/qt/tests/t-various.cpp
+++ b/lang/qt/tests/t-various.cpp
@@ -46,6 +46,7 @@
#include "dn.h"
#include "data.h"
#include "dataprovider.h"
+#include "signkeyjob.h"
#include "t-support.h"
@@ -170,6 +171,116 @@ private Q_SLOTS:
QVERIFY(id_revoked);
}
+ void testRemark()
+ {
+ // Get the signing key (alfa)
+ auto ctx = Context::create(OpenPGP);
+ QVERIFY (ctx);
+ Error err;
+ auto seckey = ctx->key("A0FF4590BB6122EDEF6E3C542D727CC768697734", err, true);
+ QVERIFY (!seckey.isNull());
+ QVERIFY (!err);
+
+ // Get the target key (mallory / mike)
+ auto target = ctx->key("2686AA191A278013992C72EBBE794852BE5CF886", err, false);
+ QVERIFY (!target.isNull());
+ QVERIFY (!err);
+ QVERIFY (target.numUserIDs());
+
+ // Create the job
+ auto job = openpgp()->signKeyJob();
+ QVERIFY (job);
+
+ // Hack in the passphrase provider
+ auto jobCtx = Job::context(job);
+ TestPassphraseProvider provider;
+ jobCtx->setPassphraseProvider(&provider);
+ jobCtx->setPinentryMode(Context::PinentryLoopback);
+
+ // Setup the job
+ job->setExportable(false);
+ std::vector<unsigned int> uids;
+ uids.push_back(0);
+ job->setUserIDsToSign(uids);
+ job->setSigningKey(seckey);
+ job->setRemark(QStringLiteral("Mallory is evil 😠"));
+
+ connect(job, &SignKeyJob::result, this, [this] (const GpgME::Error &err2,
+ const QString,
+ const GpgME::Error) {
+ Q_EMIT asyncDone();
+ QVERIFY(!err2);
+ });
+
+ job->start(target);
+ QSignalSpy spy (this, SIGNAL(asyncDone()));
+ QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT));
+
+ // At this point the remark should have been added.
+ target.update();
+ const char *remark = target.userID(0).remark(seckey, err);
+ QVERIFY(!err);
+ Q_ASSERT(remark);
+ QCOMPARE(QString::fromUtf8(remark), QStringLiteral("Mallory is evil 😠"));
+
+ // Try to replace it without dupeOK
+ auto job2 = openpgp()->signKeyJob();
+ QVERIFY (job2);
+
+ // Hack in the passphrase provider
+ auto jobCtx2 = Job::context(job2);
+ jobCtx2->setPassphraseProvider(&provider);
+ jobCtx2->setPinentryMode(Context::PinentryLoopback);
+
+ // Setup the job
+ job2->setExportable(false);
+ job2->setUserIDsToSign(uids);
+ job2->setSigningKey(seckey);
+ job2->setRemark(QStringLiteral("Mallory is nice"));
+
+ connect(job2, &SignKeyJob::result, this, [this] (const GpgME::Error &err2,
+ const QString,
+ const GpgME::Error) {
+ Q_EMIT asyncDone();
+ QVERIFY(err2);
+ });
+
+ job2->start(target);
+ QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT));
+
+ // Now replace the remark
+ auto job3 = openpgp()->signKeyJob();
+ QVERIFY (job3);
+
+ // Hack in the passphrase provider
+ auto jobCtx3 = Job::context(job3);
+ jobCtx3->setPassphraseProvider(&provider);
+ jobCtx3->setPinentryMode(Context::PinentryLoopback);
+
+ // Setup the job
+ job3->setExportable(false);
+ job3->setUserIDsToSign(uids);
+ job3->setSigningKey(seckey);
+ job3->setDupeOk(true);
+ job3->setRemark(QStringLiteral("Mallory is nice"));
+
+ connect(job3, &SignKeyJob::result, this, [this] (const GpgME::Error &err2,
+ const QString,
+ const GpgME::Error) {
+ Q_EMIT asyncDone();
+ QVERIFY(!err2);
+ });
+
+ job3->start(target);
+ QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT));
+
+ target.update();
+ remark = target.userID(0).remark(seckey, err);
+ QVERIFY(!err);
+ Q_ASSERT(remark);
+ Q_ASSERT(QString::fromUtf8(remark) == QStringLiteral("Mallory is nice"));
+ }
+
void testVersion()
{
QVERIFY(EngineInfo::Version("2.1.0") < EngineInfo::Version("2.1.1"));