From 43160a39f27f6c3507447620666c85af00b3499c Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Thu, 2 Feb 2017 17:16:27 +0100 Subject: [PATCH] qt: Add test for tofu conflict * lang/qt/tests/t-tofuinfo.cpp (TofuInfoTest::testTofuConflict): New. --- lang/qt/tests/t-tofuinfo.cpp | 133 +++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/lang/qt/tests/t-tofuinfo.cpp b/lang/qt/tests/t-tofuinfo.cpp index d88861cf..e16b1fde 100644 --- a/lang/qt/tests/t-tofuinfo.cpp +++ b/lang/qt/tests/t-tofuinfo.cpp @@ -35,12 +35,16 @@ #include #include #include +#include + #include "protocol.h" #include "tofuinfo.h" #include "tofupolicyjob.h" #include "verifyopaquejob.h" #include "verificationresult.h" #include "signingresult.h" +#include "importjob.h" +#include "importresult.h" #include "keylistjob.h" #include "keylistresult.h" #include "qgpgmesignjob.h" @@ -61,10 +65,57 @@ static const char testMsg1[] = "=Crq6\n" "-----END PGP MESSAGE-----\n"; +static const char conflictKey1[] = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +"\n" +"mDMEWG+w/hYJKwYBBAHaRw8BAQdAiq1oStvDYg8ZfFs5DgisYJo8dJxD+C/AA21O\n" +"K/aif0O0GXRvZnVfY29uZmxpY3RAZXhhbXBsZS5jb22IlgQTFggAPhYhBHoJBLaV\n" +"DamYAgoa1L5BwMOl/x88BQJYb7D+AhsDBQkDwmcABQsJCAcCBhUICQoLAgQWAgMB\n" +"Ah4BAheAAAoJEL5BwMOl/x88GvwA/0SxkbLyAcshGm2PRrPsFQsSVAfwaSYFVmS2\n" +"cMVIw1PfAQDclRH1Z4MpufK07ju4qI33o4s0UFpVRBuSxt7A4P2ZD7g4BFhvsP4S\n" +"CisGAQQBl1UBBQEBB0AmVrgaDNJ7K2BSalsRo2EkRJjHGqnp5bBB0tapnF81CQMB\n" +"CAeIeAQYFggAIBYhBHoJBLaVDamYAgoa1L5BwMOl/x88BQJYb7D+AhsMAAoJEL5B\n" +"wMOl/x88OR0BAMq4/vmJUORRTmzjHcv/DDrQB030DSq666rlckGIKTShAPoDXM9N\n" +"0gZK+YzvrinSKZXHmn0aSwmC1/hyPybJPEljBw==\n" +"=p2Oj\n" +"-----END PGP PUBLIC KEY BLOCK-----\n"; + +static const char conflictKey2[] = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +"\n" +"mDMEWG+xShYJKwYBBAHaRw8BAQdA567gPEPJRpqKnZjlFJMRNUqruRviYMyygfF6\n" +"6Ok+ygu0GXRvZnVfY29uZmxpY3RAZXhhbXBsZS5jb22IlgQTFggAPhYhBJ5kRh7E\n" +"I98w8kgUcmkAfYFvqqHsBQJYb7FKAhsDBQkDwmcABQsJCAcCBhUICQoLAgQWAgMB\n" +"Ah4BAheAAAoJEGkAfYFvqqHsYR0BAOz8JjYB4VvGkt6noLS3F5TLfsedGwQkBCw5\n" +"znw/vGZsAQD9DSX+ekwdrN56mNO8ISt5uVS7B1ZQtouNBF+nzcwbDbg4BFhvsUoS\n" +"CisGAQQBl1UBBQEBB0BFupW8+Xc1ikab8TJqANjQhvFVh6uLsgcK4g9lZgbGXAMB\n" +"CAeIeAQYFggAIBYhBJ5kRh7EI98w8kgUcmkAfYFvqqHsBQJYb7FKAhsMAAoJEGkA\n" +"fYFvqqHs15ABALdN3uiV/07cJ3RkNb3WPcijGsto+lECDS11dKEwTMFeAQDx+V36\n" +"ocbYC/xEuwi3w45oNqGieazzcD/GBbt8OBk3BA==\n" +"=45IR\n" +"-----END PGP PUBLIC KEY BLOCK-----\n"; + +static const char conflictMsg1[] = "-----BEGIN PGP MESSAGE-----\n" +"\n" +"owGbwMvMwCG2z/HA4aX/5W0YT3MlMUTkb2xPSizi6ihlYRDjYJAVU2Sp4mTZNpV3\n" +"5QwmLqkrMLWsTCCFDFycAjCR1vcMf4U0Qrs6qzqfHJ9puGOFduLN2nVmhsumxjBE\n" +"mdw4lr1ehIWR4QdLuNBpe86PGx1PtNXfVAzm/hu+vfjCp5BVNjPTM9L0eAA=\n" +"=MfBD\n" +"-----END PGP MESSAGE-----\n"; + +static const char conflictMsg2[] = "-----BEGIN PGP MESSAGE-----\n" +"\n" +"owGbwMvMwCGWyVDbmL9q4RvG01xJDBH5GyvS8vO5OkpZGMQ4GGTFFFnmpbjJHVG+\n" +"b/DJQ6QIppaVCaSQgYtTACaySZHhr/SOPrdFJ89KrcwKY5i1XnflXYf2PK76SafK\n" +"tkxXuXzvJAvDX4kCybuqFk3HXCexz2+IrnZ+5X5EqOnuo3ens2cte+uzlhMA\n" +"=BIAi\n" +"-----END PGP MESSAGE-----\n"; + class TofuInfoTest: public QGpgMETest { Q_OBJECT +Q_SIGNALS: + void asyncDone(); +private: bool testSupported() { return !(GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.16"); @@ -349,6 +400,88 @@ private Q_SLOTS: delete job; } + void testTofuConflict() + { + if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.19") { + return; + } + + // Import key 1 + auto importjob = openpgp()->importJob(); + connect(importjob, &ImportJob::result, this, + [this](ImportResult result, QString, Error) + { + QVERIFY(!result.error()); + QVERIFY(!result.imports().empty()); + QVERIFY(result.numImported()); + Q_EMIT asyncDone(); + }); + importjob->start(QByteArray(conflictKey1)); + QSignalSpy spy (this, SIGNAL(asyncDone())); + QVERIFY(spy.wait()); + + // Verify Message 1 + const QByteArray signedData(conflictMsg1); + auto verifyJob = openpgp()->verifyOpaqueJob(true); + QByteArray verified; + auto result = verifyJob->exec(signedData, verified); + delete verifyJob; + + QVERIFY(!result.isNull()); + QVERIFY(!result.error()); + + QVERIFY(result.numSignatures() == 1); + auto sig = result.signatures()[0]; + QVERIFY(sig.validity() == Signature::Marginal); + + auto stats = sig.key().userID(0).tofuInfo(); + QVERIFY(!stats.isNull()); + QVERIFY(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint())); + QVERIFY(stats.signFirst() == stats.signLast()); + QVERIFY(stats.signCount() == 1); + QVERIFY(stats.policy() == TofuInfo::PolicyAuto); + QVERIFY(stats.validity() == TofuInfo::LittleHistory); + + // Import key 2 + importjob = openpgp()->importJob(); + connect(importjob, &ImportJob::result, this, + [this](ImportResult result, QString, Error) + { + QVERIFY(!result.error()); + QVERIFY(!result.imports().empty()); + QVERIFY(result.numImported()); + Q_EMIT asyncDone(); + }); + importjob->start(QByteArray(conflictKey2)); + QSignalSpy spy2 (this, SIGNAL(asyncDone())); + QVERIFY(spy2.wait()); + + // Verify Message 2 + const QByteArray signedData2(conflictMsg2); + QByteArray verified2; + verifyJob = openpgp()->verifyOpaqueJob(true); + result = verifyJob->exec(signedData2, verified2); + delete verifyJob; + + QVERIFY(!result.isNull()); + QVERIFY(!result.error()); + + QVERIFY(result.numSignatures() == 1); + sig = result.signatures()[0]; + QVERIFY(sig.validity() == Signature::Unknown); + // TODO activate when implemented + // QVERIFY(sig.summary() == Signature::TofuConflict); + + stats = sig.key().userID(0).tofuInfo(); + QVERIFY(!stats.isNull()); + QVERIFY(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint())); + QVERIFY(stats.signFirst() == stats.signLast()); + QVERIFY(stats.signCount() == 1); + QVERIFY(stats.policy() == TofuInfo::PolicyAsk); + QVERIFY(stats.validity() == TofuInfo::Conflict); + } + + void initTestCase() { QGpgMETest::initTestCase();