Line data Source code
1 : /* t-keylist.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 :
32 : #ifdef HAVE_CONFIG_H
33 : #include "config.h"
34 : #endif
35 :
36 : #include <QDebug>
37 : #include <QTest>
38 : #include <QSignalSpy>
39 : #include <QMap>
40 : #include "keylistjob.h"
41 : #include "qgpgmebackend.h"
42 : #include "keylistresult.h"
43 :
44 : #include "t-support.h"
45 :
46 : using namespace QGpgME;
47 : using namespace GpgME;
48 :
49 0 : class KeyListTest : public QGpgMETest
50 : {
51 : Q_OBJECT
52 :
53 : Q_SIGNALS:
54 : void asyncDone();
55 :
56 : private Q_SLOTS:
57 0 : void testSingleKeyListSync()
58 : {
59 0 : KeyListJob *job = openpgp()->keyListJob(false, false, false);
60 0 : std::vector<GpgME::Key> keys;
61 0 : GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
62 0 : false, keys);
63 0 : delete job;
64 0 : Q_ASSERT (!result.error());
65 0 : Q_ASSERT (keys.size() == 1);
66 0 : const QString kId = QLatin1String(keys.front().keyID());
67 0 : Q_ASSERT (kId == QStringLiteral("2D727CC768697734"));
68 :
69 0 : Q_ASSERT (keys[0].subkeys().size() == 2);
70 0 : Q_ASSERT (keys[0].subkeys()[0].publicKeyAlgorithm() == Subkey::AlgoDSA);
71 0 : Q_ASSERT (keys[0].subkeys()[1].publicKeyAlgorithm() == Subkey::AlgoELG_E);
72 0 : }
73 :
74 0 : void testPubkeyAlgoAsString()
75 : {
76 : static const QMap<Subkey::PubkeyAlgo, QString> expected {
77 0 : { Subkey::AlgoRSA, QStringLiteral("RSA") },
78 0 : { Subkey::AlgoRSA_E, QStringLiteral("RSA-E") },
79 0 : { Subkey::AlgoRSA_S, QStringLiteral("RSA-S") },
80 0 : { Subkey::AlgoELG_E, QStringLiteral("ELG-E") },
81 0 : { Subkey::AlgoDSA, QStringLiteral("DSA") },
82 0 : { Subkey::AlgoECC, QStringLiteral("ECC") },
83 0 : { Subkey::AlgoELG, QStringLiteral("ELG") },
84 0 : { Subkey::AlgoECDSA, QStringLiteral("ECDSA") },
85 0 : { Subkey::AlgoECDH, QStringLiteral("ECDH") },
86 0 : { Subkey::AlgoEDDSA, QStringLiteral("EdDSA") },
87 0 : { Subkey::AlgoUnknown, QString() }
88 0 : };
89 0 : Q_FOREACH (Subkey::PubkeyAlgo algo, expected.keys()) {
90 0 : Q_ASSERT(QString::fromUtf8(Subkey::publicKeyAlgorithmAsString(algo)) ==
91 0 : expected.value(algo));
92 : }
93 0 : }
94 :
95 0 : void testKeyListAsync()
96 : {
97 0 : KeyListJob *job = openpgp()->keyListJob();
98 0 : connect(job, &KeyListJob::result, job, [this, job](KeyListResult, std::vector<Key> keys, QString, Error)
99 0 : {
100 0 : Q_ASSERT(keys.size() == 1);
101 0 : Q_EMIT asyncDone();
102 0 : });
103 0 : job->start(QStringList() << "alfa@example.net");
104 0 : QSignalSpy spy (this, SIGNAL(asyncDone()));
105 0 : Q_ASSERT(spy.wait());
106 0 : }
107 : };
108 :
109 0 : QTEST_MAIN(KeyListTest)
110 :
111 : #include "t-keylist.moc"
|