[Pkg-gnupg-commit] [gpgme] 119/132: qt: Add unittest for decrypt unwrap

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed Apr 26 01:01:37 UTC 2017


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

dkg pushed a commit to branch experimental
in repository gpgme.

commit 5493164f8665fabf795f3b34a7084770a38ae940
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Fri Mar 24 16:58:58 2017 +0100

    qt: Add unittest for decrypt unwrap
    
    * lang/qt/tests/t-encrypt.cpp
    (EncryptTest::testEncryptDecryptNowrap): New.
---
 lang/qt/tests/t-encrypt.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 66 insertions(+), 1 deletion(-)

diff --git a/lang/qt/tests/t-encrypt.cpp b/lang/qt/tests/t-encrypt.cpp
index ba4a1c5..199517f 100644
--- a/lang/qt/tests/t-encrypt.cpp
+++ b/lang/qt/tests/t-encrypt.cpp
@@ -39,6 +39,8 @@
 #include <QBuffer>
 #include "keylistjob.h"
 #include "encryptjob.h"
+#include "signencryptjob.h"
+#include "signingresult.h"
 #include "qgpgmeencryptjob.h"
 #include "encryptionresult.h"
 #include "decryptionresult.h"
@@ -46,6 +48,7 @@
 #include "qgpgmebackend.h"
 #include "keylistresult.h"
 #include "engineinfo.h"
+#include "verifyopaquejob.h"
 #include "t-support.h"
 
 #define PROGRESS_TEST_SIZE 1 * 1024 * 1024
@@ -109,7 +112,7 @@ private Q_SLOTS:
         auto decJob = new QGpgMEDecryptJob(ctx);
         QByteArray plainText;
         auto decResult = decJob->exec(cipherText, plainText);
-        QVERIFY(!result.error());
+        QVERIFY(!decResult.error());
         QVERIFY(QString::fromUtf8(plainText) == QStringLiteral("Hello World"));
         delete decJob;
     }
@@ -200,6 +203,68 @@ private Q_SLOTS:
         delete decJob;
     }
 
+    void testEncryptDecryptNowrap()
+    {
+        /* Now decrypt */
+        if (!decryptSupported()) {
+            return;
+        }
+        auto listjob = openpgp()->keyListJob(false, false, false);
+        std::vector<Key> keys;
+        auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa at example.net"),
+                                          false, keys);
+        QVERIFY(!keylistresult.error());
+        QVERIFY(keys.size() == 1);
+        delete listjob;
+
+        auto job = openpgp()->signEncryptJob(/*ASCII Armor */true, /* Textmode */ true);
+
+        auto encSignCtx = Job::context(job);
+        TestPassphraseProvider provider1;
+        encSignCtx->setPassphraseProvider(&provider1);
+        encSignCtx->setPinentryMode(Context::PinentryLoopback);
+
+        QVERIFY(job);
+        QByteArray cipherText;
+        auto result = job->exec(keys, keys, QStringLiteral("Hello World").toUtf8(), Context::AlwaysTrust, cipherText);
+        delete job;
+        QVERIFY(!result.first.error());
+        QVERIFY(!result.second.error());
+        const auto cipherString = QString::fromUtf8(cipherText);
+        QVERIFY(cipherString.startsWith("-----BEGIN PGP MESSAGE-----"));
+
+        /* Now decrypt */
+        if (!decryptSupported()) {
+            return;
+        }
+        auto ctx = Context::createForProtocol(OpenPGP);
+        TestPassphraseProvider provider;
+        ctx->setPassphraseProvider(&provider);
+        ctx->setPinentryMode(Context::PinentryLoopback);
+        ctx->setDecryptionFlags(Context::DecryptUnwrap);
+
+        auto decJob = new QGpgMEDecryptJob(ctx);
+        QByteArray plainText;
+        auto decResult = decJob->exec(cipherText, plainText);
+
+        QVERIFY(!decResult.error());
+
+        delete decJob;
+
+        // Now verify the unwrapeped data.
+        auto verifyJob = openpgp()->verifyOpaqueJob(true);
+        QByteArray verified;
+
+        auto verResult = verifyJob->exec(plainText, verified);
+        QVERIFY(!verResult.error());
+        delete verifyJob;
+
+        QVERIFY(verResult.numSignatures() == 1);
+        auto sig = verResult.signatures()[0];
+
+        QVERIFY(verified == QStringLiteral("Hello World"));
+    }
+
 private:
     /* Loopback and passphrase provider don't work for mixed encryption.
      * So this test is disabled until gnupg(?) is fixed for this. */

-- 
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