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