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