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