[Pkg-gnupg-commit] [gpgme] 195/412: Qt: Add testTofuSignCount

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Sep 22 21:26:46 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gpgme.

commit 8fa9b5696ca9f8386971e6f36646536f9579ceaa
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Mon Jul 4 11:42:30 2016 +0200

    Qt: Add testTofuSignCount
    
    * src/lang/qt/tests/t-tofuinfo.cpp(testTofuSignCount): New.
    (initTestCase): Set gpg-agent loopback pinentry config.
    (signAndVerify): Helper for tofuTestSignCount.
    
    --
    Also needs the wait code because of GnuPG-Bug-Id: 2405
---
 lang/qt/tests/t-tofuinfo.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 83 insertions(+), 1 deletion(-)

diff --git a/lang/qt/tests/t-tofuinfo.cpp b/lang/qt/tests/t-tofuinfo.cpp
index 0257359..a27dd93 100644
--- a/lang/qt/tests/t-tofuinfo.cpp
+++ b/lang/qt/tests/t-tofuinfo.cpp
@@ -35,6 +35,12 @@
 #include "tofuinfo.h"
 #include "verifyopaquejob.h"
 #include "verificationresult.h"
+#include "signingresult.h"
+#include "keylistjob.h"
+#include "keylistresult.h"
+#include "qgpgmesignjob.h"
+#include "key.h"
+#include "t-support.h"
 #include <iostream>
 
 using namespace QGpgME;
@@ -64,6 +70,40 @@ class TofuInfoTest: public QObject
         Q_ASSERT(orig.policy() == other.policy());
     }
 
+    void signAndVerify(const QString &what, const GpgME::Key &key, int expected)
+    {
+        Context *ctx = Context::createForProtocol(OpenPGP);
+        ctx->setPassphraseProvider(new TestPassphraseProvider);
+        ctx->setPinentryMode(Context::PinentryLoopback);
+        auto *job = new QGpgMESignJob(ctx);
+
+        std::vector<Key> keys;
+        keys.push_back(key);
+        QByteArray signedData;
+        auto sigResult = job->exec(keys, what.toUtf8(), NormalSignatureMode, signedData);
+
+        Q_ASSERT(!sigResult.error());
+
+        auto verifyJob = openpgp()->verifyOpaqueJob();
+        QByteArray verified;
+
+        auto result = verifyJob->exec(signedData, verified);
+
+        Q_ASSERT(!result.error());
+        Q_ASSERT(verified == what.toUtf8());
+
+        Q_ASSERT(result.numSignatures() == 1);
+        auto sig = result.signatures()[0];
+
+        Q_FOREACH(const TofuInfo stats, sig.tofuInfo()) {
+            Q_ASSERT(!stats.isNull());
+            Q_ASSERT(!strcmp(stats.fingerprint(), sig.fingerprint()));
+            Q_ASSERT(stats.signCount() == expected);
+        }
+        /* FIXME: GnuPG-Bug-Id 2405 makes the wait necessary. */
+        QTest::qWait(1000);
+    }
+
 private:
     QTemporaryDir mDir;
 
@@ -90,9 +130,9 @@ private Q_SLOTS:
 
         auto result = job->exec(data1, plaintext);
 
-        Q_ASSERT(!strcmp(plaintext.constData(), "Just GNU it!\n"));
         Q_ASSERT(!result.isNull());
         Q_ASSERT(!result.error());
+        Q_ASSERT(!strcmp(plaintext.constData(), "Just GNU it!\n"));
 
         Q_ASSERT(result.numSignatures() == 1);
         Signature sig = result.signatures()[0];
@@ -138,6 +178,44 @@ private Q_SLOTS:
             Q_ASSERT(stats.policy() == TofuInfo::PolicyAuto);
             Q_ASSERT(stats.validity() == TofuInfo::LittleHistory);
         }
+
+        /* Verify that another call yields the same result */
+        job = openpgp()->verifyOpaqueJob(true);
+        result = job->exec(data1, plaintext);
+
+        Q_ASSERT(!result.isNull());
+        Q_ASSERT(!result.error());
+
+        Q_ASSERT(result.numSignatures() == 1);
+        sig = result.signatures()[0];
+        /* TOFU is always marginal */
+        Q_ASSERT(sig.validity() == Signature::Marginal);
+
+        Q_ASSERT(!sig.tofuInfo().empty());
+        Q_FOREACH(const TofuInfo stats, sig.tofuInfo()) {
+            Q_ASSERT(!stats.isNull());
+            Q_ASSERT(!strcmp(stats.fingerprint(), sig.fingerprint()));
+            Q_ASSERT(stats.signCount() == 1);
+            Q_ASSERT(stats.address());
+            Q_ASSERT(stats.policy() == TofuInfo::PolicyAuto);
+            Q_ASSERT(stats.validity() == TofuInfo::LittleHistory);
+        }
+    }
+
+    void testTofuSignCount()
+    {
+        auto *job = openpgp()->keyListJob(false, false, false);
+        std::vector<GpgME::Key> keys;
+        GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("zulu at example.net"),
+                                                true, keys);
+        Q_ASSERT(!keys.empty());
+        Key key = keys[0];
+        Q_ASSERT(!key.isNull());
+
+        signAndVerify(QStringLiteral("Hello"), key, 0);
+        signAndVerify(QStringLiteral("Hello2"), key, 1);
+        signAndVerify(QStringLiteral("Hello3"), key, 2);
+        signAndVerify(QStringLiteral("Hello4"), key, 3);
     }
 
     void initTestCase()
@@ -150,6 +228,10 @@ private Q_SLOTS:
         Q_ASSERT(conf.open(QIODevice::WriteOnly));
         conf.write("trust-model tofu+pgp");
         conf.close();
+        QFile agentConf(mDir.path() + QStringLiteral("/gpg-agent.conf"));
+        Q_ASSERT(agentConf.open(QIODevice::WriteOnly));
+        agentConf.write("allow-loopback-pinentry");
+        agentConf.close();
         Q_ASSERT(QFile::copy(gpgHome + QStringLiteral("/pubring.gpg"),
                  mDir.path() + QStringLiteral("/pubring.gpg")));
         Q_ASSERT(QFile::copy(gpgHome + QStringLiteral("/secring.gpg"),

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list