LCOV - code coverage report
Current view: top level - lang/qt/tests - t-verify.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 18 100.0 %
Date: 2018-11-14 16:53:58 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /* t-verifiy.cpp
       2             : 
       3             :     This file is part of qgpgme, the Qt API binding for gpgme
       4             :     Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
       5             :     Software engineering by Intevation GmbH
       6             : 
       7             :     QGpgME is free software; you can redistribute it and/or
       8             :     modify it under the terms of the GNU General Public License as
       9             :     published by the Free Software Foundation; either version 2 of the
      10             :     License, or (at your option) any later version.
      11             : 
      12             :     QGpgME is distributed in the hope that it will be useful,
      13             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :     General Public License for more details.
      16             : 
      17             :     You should have received a copy of the GNU General Public License
      18             :     along with this program; if not, write to the Free Software
      19             :     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      20             : 
      21             :     In addition, as a special exception, the copyright holders give
      22             :     permission to link the code of this program with any edition of
      23             :     the Qt library by Trolltech AS, Norway (or with modified versions
      24             :     of Qt that use the same license as Qt), and distribute linked
      25             :     combinations including the two.  You must obey the GNU General
      26             :     Public License in all respects for all of the code used other than
      27             :     Qt.  If you modify this file, you may extend this exception to
      28             :     your version of the file, but you are not obligated to do so.  If
      29             :     you do not wish to do so, delete this exception statement from
      30             :     your version.
      31             : */
      32             : #ifdef HAVE_CONFIG_H
      33             :  #include "config.h"
      34             : #endif
      35             : 
      36             : #include <QDebug>
      37             : #include <QTest>
      38             : 
      39             : 
      40             : #include "protocol.h"
      41             : 
      42             : #include "verifyopaquejob.h"
      43             : #include "verificationresult.h"
      44             : #include "key.h"
      45             : #include "t-support.h"
      46             : 
      47             : using namespace QGpgME;
      48             : using namespace GpgME;
      49             : 
      50             : static const char testMsg1[] =
      51             : "-----BEGIN PGP MESSAGE-----\n"
      52             : "\n"
      53             : "owGbwMvMwCSoW1RzPCOz3IRxjXQSR0lqcYleSUWJTZOvjVdpcYmCu1+oQmaJIleH\n"
      54             : "GwuDIBMDGysTSIqBi1MApi+nlGGuwDeHao53HBr+FoVGP3xX+kvuu9fCMJvl6IOf\n"
      55             : "y1kvP4y+8D5a11ang0udywsA\n"
      56             : "=Crq6\n"
      57             : "-----END PGP MESSAGE-----\n";
      58             : 
      59             : 
      60           2 : class VerifyTest: public QGpgMETest
      61             : {
      62             :     Q_OBJECT
      63             : 
      64             : private Q_SLOTS:
      65             : 
      66             :     /* Check that a signature always has a key. */
      67           1 :     void testSignatureKey()
      68             :     {
      69           2 :         const QByteArray signedData(testMsg1);
      70           1 :         auto verifyJob = openpgp()->verifyOpaqueJob(true);
      71           2 :         QByteArray verified;
      72             : 
      73           2 :         auto result = verifyJob->exec(signedData, verified);
      74           1 :         QVERIFY(!result.error());
      75           1 :         delete verifyJob;
      76             : 
      77           1 :         QVERIFY(result.numSignatures() == 1);
      78           2 :         auto sig = result.signatures()[0];
      79             : 
      80           2 :         const auto key = sig.key(true, false);
      81           1 :         QVERIFY(!key.isNull());
      82             : 
      83           1 :         bool found = false;
      84           3 :         for (const auto subkey: key.subkeys()) {
      85           2 :             if (!strcmp (subkey.fingerprint(), sig.fingerprint())) {
      86           1 :                 found = true;
      87             :             }
      88             :         }
      89           1 :         QVERIFY(found);
      90             :     }
      91             : };
      92             : 
      93           1 : QTEST_MAIN(VerifyTest)
      94             : #include "t-verify.moc"

Generated by: LCOV version 1.13