Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F35336821
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
63 KB
Subscribers
None
View Options
diff --git a/lang/qt/tests/t-encrypt.cpp b/lang/qt/tests/t-encrypt.cpp
index 4d65dc7f..57b586d5 100644
--- a/lang/qt/tests/t-encrypt.cpp
+++ b/lang/qt/tests/t-encrypt.cpp
@@ -1,284 +1,284 @@
/* t-encrypt.cpp
This file is part of qgpgme, the Qt API binding for gpgme
Copyright (c) 2016 Intevation GmbH
QGpgME is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
QGpgME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <QDebug>
#include <QTest>
#include <QTemporaryDir>
#include <QSignalSpy>
#include <QBuffer>
#include "keylistjob.h"
#include "encryptjob.h"
#include "qgpgmeencryptjob.h"
#include "encryptionresult.h"
#include "decryptionresult.h"
#include "qgpgmedecryptjob.h"
#include "qgpgmebackend.h"
#include "keylistresult.h"
#include "engineinfo.h"
#include "t-support.h"
#define PROGRESS_TEST_SIZE 1 * 1024 * 1024
using namespace QGpgME;
using namespace GpgME;
static bool decryptSupported()
{
/* With GnuPG 2.0.x (at least 2.0.26 by default on jessie)
* the passphrase_cb does not work. So the test popped up
* a pinentry. So tests requiring decryption don't work. */
static auto version = GpgME::engineInfo(GpgME::GpgEngine).engineVersion();
if (version < "2.0.0") {
/* With 1.4 it just works */
return true;
}
if (version < "2.1.0") {
/* With 2.1 it works with loopback mode */
return false;
}
return true;
}
class EncryptionTest : public QGpgMETest
{
Q_OBJECT
Q_SIGNALS:
void asyncDone();
private Q_SLOTS:
void testSimpleEncryptDecrypt()
{
auto listjob = openpgp()->keyListJob(false, false, false);
std::vector<Key> keys;
auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
- Q_ASSERT(!keylistresult.error());
- Q_ASSERT(keys.size() == 1);
+ QVERIFY(!keylistresult.error());
+ QVERIFY(keys.size() == 1);
delete listjob;
auto job = openpgp()->encryptJob(/*ASCII Armor */true, /* Textmode */ true);
- Q_ASSERT(job);
+ QVERIFY(job);
QByteArray cipherText;
auto result = job->exec(keys, QStringLiteral("Hello World").toUtf8(), Context::AlwaysTrust, cipherText);
delete job;
- Q_ASSERT(!result.error());
+ QVERIFY(!result.error());
const auto cipherString = QString::fromUtf8(cipherText);
- Q_ASSERT(cipherString.startsWith("-----BEGIN PGP MESSAGE-----"));
+ QVERIFY(cipherString.startsWith("-----BEGIN PGP MESSAGE-----"));
/* Now decrypt */
if (!decryptSupported()) {
return;
}
auto ctx = Context::createForProtocol(OpenPGP);
TestPassphraseProvider provider;
ctx->setPassphraseProvider(&provider);
ctx->setPinentryMode(Context::PinentryLoopback);
auto decJob = new QGpgMEDecryptJob(ctx);
QByteArray plainText;
auto decResult = decJob->exec(cipherText, plainText);
- Q_ASSERT(!result.error());
- Q_ASSERT(QString::fromUtf8(plainText) == QStringLiteral("Hello World"));
+ QVERIFY(!result.error());
+ QVERIFY(QString::fromUtf8(plainText) == QStringLiteral("Hello World"));
delete decJob;
}
void testProgress()
{
if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.15") {
// We can only test the progress with 2.1.15 as this started to
// have total progress for memory callbacks
return;
}
auto listjob = openpgp()->keyListJob(false, false, false);
std::vector<Key> keys;
auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
- Q_ASSERT(!keylistresult.error());
- Q_ASSERT(keys.size() == 1);
+ QVERIFY(!keylistresult.error());
+ QVERIFY(keys.size() == 1);
delete listjob;
auto job = openpgp()->encryptJob(/*ASCII Armor */false, /* Textmode */ false);
- Q_ASSERT(job);
+ QVERIFY(job);
QByteArray plainBa;
plainBa.fill('X', PROGRESS_TEST_SIZE);
QByteArray cipherText;
bool initSeen = false;
bool finishSeen = false;
connect(job, &Job::progress, this, [this, &initSeen, &finishSeen] (const QString&, int current, int total) {
// We only check for progress 0 and max progress as the other progress
// lines depend on the system speed and are as such unreliable to test.
- Q_ASSERT(total == PROGRESS_TEST_SIZE);
+ QVERIFY(total == PROGRESS_TEST_SIZE);
if (current == 0) {
initSeen = true;
}
if (current == total) {
finishSeen = true;
}
- Q_ASSERT(current >= 0 && current <= total);
+ QVERIFY(current >= 0 && current <= total);
});
connect(job, &EncryptJob::result, this, [this, &initSeen, &finishSeen] (const GpgME::EncryptionResult &,
const QByteArray &,
const QString,
const GpgME::Error) {
- Q_ASSERT(initSeen);
- Q_ASSERT(finishSeen);
+ QVERIFY(initSeen);
+ QVERIFY(finishSeen);
Q_EMIT asyncDone();
});
auto inptr = std::shared_ptr<QIODevice>(new QBuffer(&plainBa));
inptr->open(QIODevice::ReadOnly);
auto outptr = std::shared_ptr<QIODevice>(new QBuffer(&cipherText));
outptr->open(QIODevice::WriteOnly);
job->start(keys, inptr, outptr, Context::AlwaysTrust);
QSignalSpy spy (this, SIGNAL(asyncDone()));
- Q_ASSERT(spy.wait());
+ QVERIFY(spy.wait());
}
void testSymmetricEncryptDecrypt()
{
if (!decryptSupported()) {
return;
}
auto ctx = Context::createForProtocol(OpenPGP);
TestPassphraseProvider provider;
ctx->setPassphraseProvider(&provider);
ctx->setPinentryMode(Context::PinentryLoopback);
ctx->setArmor(true);
ctx->setTextMode(true);
auto job = new QGpgMEEncryptJob(ctx);
QByteArray cipherText;
auto result = job->exec(std::vector<Key>(), QStringLiteral("Hello symmetric World").toUtf8(), Context::AlwaysTrust, cipherText);
delete job;
- Q_ASSERT(!result.error());
+ QVERIFY(!result.error());
const auto cipherString = QString::fromUtf8(cipherText);
- Q_ASSERT(cipherString.startsWith("-----BEGIN PGP MESSAGE-----"));
+ QVERIFY(cipherString.startsWith("-----BEGIN PGP MESSAGE-----"));
killAgent(mDir.path());
auto ctx2 = Context::createForProtocol(OpenPGP);
ctx2->setPassphraseProvider(&provider);
ctx2->setPinentryMode(Context::PinentryLoopback);
auto decJob = new QGpgMEDecryptJob(ctx2);
QByteArray plainText;
auto decResult = decJob->exec(cipherText, plainText);
- Q_ASSERT(!result.error());
- Q_ASSERT(QString::fromUtf8(plainText) == QStringLiteral("Hello symmetric World"));
+ QVERIFY(!result.error());
+ QVERIFY(QString::fromUtf8(plainText) == QStringLiteral("Hello symmetric World"));
delete decJob;
}
private:
/* Loopback and passphrase provider don't work for mixed encryption.
* So this test is disabled until gnupg(?) is fixed for this. */
void testMixedEncryptDecrypt()
{
if (!decryptSupported()) {
return;
}
auto listjob = openpgp()->keyListJob(false, false, false);
std::vector<Key> keys;
auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
- Q_ASSERT(!keylistresult.error());
- Q_ASSERT(keys.size() == 1);
+ QVERIFY(!keylistresult.error());
+ QVERIFY(keys.size() == 1);
delete listjob;
auto ctx = Context::createForProtocol(OpenPGP);
ctx->setPassphraseProvider(new TestPassphraseProvider);
ctx->setPinentryMode(Context::PinentryLoopback);
ctx->setArmor(true);
ctx->setTextMode(true);
auto job = new QGpgMEEncryptJob(ctx);
QByteArray cipherText;
printf("Before exec, flags: %x\n", Context::Symmetric | Context::AlwaysTrust);
auto result = job->exec(keys, QStringLiteral("Hello symmetric World").toUtf8(),
static_cast<Context::EncryptionFlags>(Context::Symmetric | Context::AlwaysTrust),
cipherText);
printf("After exec\n");
delete job;
- Q_ASSERT(!result.error());
+ QVERIFY(!result.error());
printf("Cipher:\n%s\n", cipherText.constData());
const auto cipherString = QString::fromUtf8(cipherText);
- Q_ASSERT(cipherString.startsWith("-----BEGIN PGP MESSAGE-----"));
+ QVERIFY(cipherString.startsWith("-----BEGIN PGP MESSAGE-----"));
killAgent(mDir.path());
/* Now create a new homedir which with we test symetric decrypt. */
QTemporaryDir tmp;
qputenv("GNUPGHOME", tmp.path().toUtf8());
QFile agentConf(tmp.path() + QStringLiteral("/gpg-agent.conf"));
- Q_ASSERT(agentConf.open(QIODevice::WriteOnly));
+ QVERIFY(agentConf.open(QIODevice::WriteOnly));
agentConf.write("allow-loopback-pinentry");
agentConf.close();
auto ctx2 = Context::createForProtocol(OpenPGP);
ctx2->setPassphraseProvider(new TestPassphraseProvider);
ctx2->setPinentryMode(Context::PinentryLoopback);
ctx2->setTextMode(true);
auto decJob = new QGpgMEDecryptJob(ctx2);
QByteArray plainText;
auto decResult = decJob->exec(cipherText, plainText);
- Q_ASSERT(!decResult.error());
+ QVERIFY(!decResult.error());
qDebug() << "Plain: " << plainText;
- Q_ASSERT(QString::fromUtf8(plainText) == QStringLiteral("Hello symmetric World"));
+ QVERIFY(QString::fromUtf8(plainText) == QStringLiteral("Hello symmetric World"));
delete decJob;
killAgent(tmp.path());
qputenv("GNUPGHOME", mDir.path().toUtf8());
}
public Q_SLOT:
void initTestCase()
{
QGpgMETest::initTestCase();
const QString gpgHome = qgetenv("GNUPGHOME");
qputenv("GNUPGHOME", mDir.path().toUtf8());
- Q_ASSERT(mDir.isValid());
+ QVERIFY(mDir.isValid());
QFile agentConf(mDir.path() + QStringLiteral("/gpg-agent.conf"));
- Q_ASSERT(agentConf.open(QIODevice::WriteOnly));
+ QVERIFY(agentConf.open(QIODevice::WriteOnly));
agentConf.write("allow-loopback-pinentry");
agentConf.close();
- Q_ASSERT(copyKeyrings(gpgHome, mDir.path()));
+ QVERIFY(copyKeyrings(gpgHome, mDir.path()));
}
private:
QTemporaryDir mDir;
};
QTEST_MAIN(EncryptionTest)
#include "t-encrypt.moc"
diff --git a/lang/qt/tests/t-keylist.cpp b/lang/qt/tests/t-keylist.cpp
index 2578576d..5e88a5ea 100644
--- a/lang/qt/tests/t-keylist.cpp
+++ b/lang/qt/tests/t-keylist.cpp
@@ -1,111 +1,111 @@
/* t-keylist.cpp
This file is part of qgpgme, the Qt API binding for gpgme
Copyright (c) 2016 Intevation GmbH
QGpgME is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
QGpgME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <QDebug>
#include <QTest>
#include <QSignalSpy>
#include <QMap>
#include "keylistjob.h"
#include "qgpgmebackend.h"
#include "keylistresult.h"
#include "t-support.h"
using namespace QGpgME;
using namespace GpgME;
class KeyListTest : public QGpgMETest
{
Q_OBJECT
Q_SIGNALS:
void asyncDone();
private Q_SLOTS:
void testSingleKeyListSync()
{
KeyListJob *job = openpgp()->keyListJob(false, false, false);
std::vector<GpgME::Key> keys;
GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
delete job;
- Q_ASSERT (!result.error());
- Q_ASSERT (keys.size() == 1);
+ QVERIFY (!result.error());
+ QVERIFY (keys.size() == 1);
const QString kId = QLatin1String(keys.front().keyID());
- Q_ASSERT (kId == QStringLiteral("2D727CC768697734"));
+ QVERIFY (kId == QStringLiteral("2D727CC768697734"));
- Q_ASSERT (keys[0].subkeys().size() == 2);
- Q_ASSERT (keys[0].subkeys()[0].publicKeyAlgorithm() == Subkey::AlgoDSA);
- Q_ASSERT (keys[0].subkeys()[1].publicKeyAlgorithm() == Subkey::AlgoELG_E);
+ QVERIFY (keys[0].subkeys().size() == 2);
+ QVERIFY (keys[0].subkeys()[0].publicKeyAlgorithm() == Subkey::AlgoDSA);
+ QVERIFY (keys[0].subkeys()[1].publicKeyAlgorithm() == Subkey::AlgoELG_E);
}
void testPubkeyAlgoAsString()
{
static const QMap<Subkey::PubkeyAlgo, QString> expected {
{ Subkey::AlgoRSA, QStringLiteral("RSA") },
{ Subkey::AlgoRSA_E, QStringLiteral("RSA-E") },
{ Subkey::AlgoRSA_S, QStringLiteral("RSA-S") },
{ Subkey::AlgoELG_E, QStringLiteral("ELG-E") },
{ Subkey::AlgoDSA, QStringLiteral("DSA") },
{ Subkey::AlgoECC, QStringLiteral("ECC") },
{ Subkey::AlgoELG, QStringLiteral("ELG") },
{ Subkey::AlgoECDSA, QStringLiteral("ECDSA") },
{ Subkey::AlgoECDH, QStringLiteral("ECDH") },
{ Subkey::AlgoEDDSA, QStringLiteral("EdDSA") },
{ Subkey::AlgoUnknown, QString() }
};
Q_FOREACH (Subkey::PubkeyAlgo algo, expected.keys()) {
- Q_ASSERT(QString::fromUtf8(Subkey::publicKeyAlgorithmAsString(algo)) ==
+ QVERIFY(QString::fromUtf8(Subkey::publicKeyAlgorithmAsString(algo)) ==
expected.value(algo));
}
}
void testKeyListAsync()
{
KeyListJob *job = openpgp()->keyListJob();
connect(job, &KeyListJob::result, job, [this, job](KeyListResult, std::vector<Key> keys, QString, Error)
{
- Q_ASSERT(keys.size() == 1);
+ QVERIFY(keys.size() == 1);
Q_EMIT asyncDone();
});
job->start(QStringList() << "alfa@example.net");
QSignalSpy spy (this, SIGNAL(asyncDone()));
- Q_ASSERT(spy.wait());
+ QVERIFY(spy.wait());
}
};
QTEST_MAIN(KeyListTest)
#include "t-keylist.moc"
diff --git a/lang/qt/tests/t-keylocate.cpp b/lang/qt/tests/t-keylocate.cpp
index 63cb8367..550305c9 100644
--- a/lang/qt/tests/t-keylocate.cpp
+++ b/lang/qt/tests/t-keylocate.cpp
@@ -1,134 +1,134 @@
/* t-keylocate.cpp
This file is part of qgpgme, the Qt API binding for gpgme
Copyright (c) 2016 Intevation GmbH
QGpgME is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
QGpgME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <QDebug>
#include <QTest>
#include <QSignalSpy>
#include <QTemporaryDir>
#include "keylistjob.h"
#include "protocol.h"
#include "keylistresult.h"
#include "engineinfo.h"
#include "t-support.h"
using namespace QGpgME;
using namespace GpgME;
class KeyLocateTest : public QGpgMETest
{
Q_OBJECT
Q_SIGNALS:
void asyncDone();
private Q_SLOTS:
#ifdef DO_ONLINE_TESTS
void testDaneKeyLocate()
{
QTemporaryDir dir;
const QString oldHome = qgetenv("GNUPGHOME");
qputenv("GNUPGHOME", dir.path().toUtf8());
/* Could do this with gpgconf but this is not a gpgconf test ;-) */
QFile conf(dir.path() + QStringLiteral("/gpg.conf"));
- Q_ASSERT(conf.open(QIODevice::WriteOnly));
+ QVERIFY(conf.open(QIODevice::WriteOnly));
conf.write("auto-key-locate dane");
conf.close();
auto *job = openpgp()->locateKeysJob();
mTestpattern = QStringLiteral("wk@gnupg.org");
connect(job, &KeyListJob::result, job, [this, job](KeyListResult result, std::vector<Key> keys, QString, Error)
{
- Q_ASSERT(!result.error());
- Q_ASSERT(keys.size() == 1);
+ QVERIFY(!result.error());
+ QVERIFY(keys.size() == 1);
Key k = keys.front();
- Q_ASSERT(k.numUserIDs());
+ QVERIFY(k.numUserIDs());
bool found = false;
Q_FOREACH (const UserID uid, k.userIDs()) {
const QString mailBox = QString::fromUtf8(uid.email());
if (mTestpattern.toLower() == mailBox.toLower()) {
found = true;
}
}
- Q_ASSERT(found);
+ QVERIFY(found);
Q_EMIT asyncDone();
});
job->start(QStringList() << mTestpattern);
QSignalSpy spy (this, SIGNAL(asyncDone()));
- Q_ASSERT(spy.wait());
+ QVERIFY(spy.wait());
qputenv("GNUPGHOME", oldHome.toUtf8());
}
#endif
void testKeyLocateSingle()
{
if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.0.10") {
return;
}
auto *job = openpgp()->locateKeysJob();
mTestpattern = QStringLiteral("alfa@example.net");
connect(job, &KeyListJob::result, job, [this, job](KeyListResult result, std::vector<Key> keys, QString, Error)
{
- Q_ASSERT(!result.isNull());
- Q_ASSERT(!result.isTruncated());
- Q_ASSERT(!result.error());
- Q_ASSERT(keys.size() == 1);
+ QVERIFY(!result.isNull());
+ QVERIFY(!result.isTruncated());
+ QVERIFY(!result.error());
+ QVERIFY(keys.size() == 1);
Key k = keys.front();
- Q_ASSERT(k.numUserIDs());
+ QVERIFY(k.numUserIDs());
bool found = false;
Q_FOREACH (const UserID uid, k.userIDs()) {
const QString mailBox = QString::fromUtf8(uid.email());
if (mTestpattern.toLower() == mailBox.toLower()) {
found = true;
}
}
- Q_ASSERT(found);
+ QVERIFY(found);
Q_EMIT asyncDone();
});
job->start(QStringList() << mTestpattern);
QSignalSpy spy (this, SIGNAL(asyncDone()));
- Q_ASSERT(spy.wait());
+ QVERIFY(spy.wait());
}
private:
QString mTestpattern;
};
QTEST_MAIN(KeyLocateTest)
#include "t-keylocate.moc"
diff --git a/lang/qt/tests/t-ownertrust.cpp b/lang/qt/tests/t-ownertrust.cpp
index db863b23..f2fa3c8e 100644
--- a/lang/qt/tests/t-ownertrust.cpp
+++ b/lang/qt/tests/t-ownertrust.cpp
@@ -1,111 +1,111 @@
/* t-ownertrust.cpp
This file is part of qgpgme, the Qt API binding for gpgme
Copyright (c) 2016 Intevation GmbH
QGpgME is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
QGpgME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <QDebug>
#include <QTest>
#include <QSignalSpy>
#include "keylistjob.h"
#include "protocol.h"
#include "keylistresult.h"
#include "changeownertrustjob.h"
#include "t-support.h"
using namespace QGpgME;
using namespace GpgME;
class ChangeOwnerTrustTest: public QGpgMETest
{
Q_OBJECT
Q_SIGNALS:
void asyncDone();
private Q_SLOTS:
void testChangeOwnerTrust()
{
KeyListJob *job = openpgp()->keyListJob(false, true, true);
std::vector<GpgME::Key> keys;
GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
delete job;
- Q_ASSERT (!result.error());
- Q_ASSERT (keys.size() == 1);
+ QVERIFY (!result.error());
+ QVERIFY (keys.size() == 1);
Key key = keys.front();
- Q_ASSERT (key.ownerTrust() == Key::Unknown);
+ QVERIFY (key.ownerTrust() == Key::Unknown);
ChangeOwnerTrustJob *job2 = openpgp()->changeOwnerTrustJob();
connect(job2, &ChangeOwnerTrustJob::result, this, [this](Error e)
{
if (e) {
qDebug() << "Error in result: " << e.asString();
}
- Q_ASSERT(!e);
+ QVERIFY(!e);
Q_EMIT asyncDone();
});
job2->start(key, Key::Ultimate);
QSignalSpy spy (this, SIGNAL(asyncDone()));
- Q_ASSERT(spy.wait());
+ QVERIFY(spy.wait());
job = openpgp()->keyListJob(false, true, true);
result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
delete job;
key = keys.front();
- Q_ASSERT (key.ownerTrust() == Key::Ultimate);
+ QVERIFY (key.ownerTrust() == Key::Ultimate);
ChangeOwnerTrustJob *job3 = openpgp()->changeOwnerTrustJob();
connect(job3, &ChangeOwnerTrustJob::result, this, [this](Error e)
{
- Q_ASSERT(!e);
+ QVERIFY(!e);
Q_EMIT asyncDone();
});
job3->start(key, Key::Unknown);
- Q_ASSERT(spy.wait());
+ QVERIFY(spy.wait());
job = openpgp()->keyListJob(false, true, true);
result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
delete job;
key = keys.front();
- Q_ASSERT (key.ownerTrust() == Key::Unknown);
+ QVERIFY (key.ownerTrust() == Key::Unknown);
}
};
QTEST_MAIN(ChangeOwnerTrustTest)
#include "t-ownertrust.moc"
diff --git a/lang/qt/tests/t-tofuinfo.cpp b/lang/qt/tests/t-tofuinfo.cpp
index f89e1c27..d88861cf 100644
--- a/lang/qt/tests/t-tofuinfo.cpp
+++ b/lang/qt/tests/t-tofuinfo.cpp
@@ -1,375 +1,375 @@
/* t-tofuinfo.cpp
This file is part of qgpgme, the Qt API binding for gpgme
Copyright (c) 2016 Intevation GmbH
QGpgME is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
QGpgME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <QDebug>
#include <QTest>
#include <QTemporaryDir>
#include "protocol.h"
#include "tofuinfo.h"
#include "tofupolicyjob.h"
#include "verifyopaquejob.h"
#include "verificationresult.h"
#include "signingresult.h"
#include "keylistjob.h"
#include "keylistresult.h"
#include "qgpgmesignjob.h"
#include "key.h"
#include "t-support.h"
#include "engineinfo.h"
#include <iostream>
using namespace QGpgME;
using namespace GpgME;
static const char testMsg1[] =
"-----BEGIN PGP MESSAGE-----\n"
"\n"
"owGbwMvMwCSoW1RzPCOz3IRxjXQSR0lqcYleSUWJTZOvjVdpcYmCu1+oQmaJIleH\n"
"GwuDIBMDGysTSIqBi1MApi+nlGGuwDeHao53HBr+FoVGP3xX+kvuu9fCMJvl6IOf\n"
"y1kvP4y+8D5a11ang0udywsA\n"
"=Crq6\n"
"-----END PGP MESSAGE-----\n";
class TofuInfoTest: public QGpgMETest
{
Q_OBJECT
bool testSupported()
{
return !(GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.16");
}
void testTofuCopy(TofuInfo other, const TofuInfo &orig)
{
- Q_ASSERT(!orig.isNull());
- Q_ASSERT(!other.isNull());
- Q_ASSERT(orig.signLast() == other.signLast());
- Q_ASSERT(orig.signCount() == other.signCount());
- Q_ASSERT(orig.validity() == other.validity());
- Q_ASSERT(orig.policy() == other.policy());
+ QVERIFY(!orig.isNull());
+ QVERIFY(!other.isNull());
+ QVERIFY(orig.signLast() == other.signLast());
+ QVERIFY(orig.signCount() == other.signCount());
+ QVERIFY(orig.validity() == other.validity());
+ QVERIFY(orig.policy() == other.policy());
}
void signAndVerify(const QString &what, const GpgME::Key &key, int expected)
{
Context *ctx = Context::createForProtocol(OpenPGP);
TestPassphraseProvider provider;
ctx->setPassphraseProvider(&provider);
ctx->setPinentryMode(Context::PinentryLoopback);
auto *job = new QGpgMESignJob(ctx);
std::vector<Key> keys;
keys.push_back(key);
QByteArray signedData;
auto sigResult = job->exec(keys, what.toUtf8(), NormalSignatureMode, signedData);
delete job;
- Q_ASSERT(!sigResult.error());
+ QVERIFY(!sigResult.error());
foreach (const auto uid, keys[0].userIDs()) {
auto info = uid.tofuInfo();
- Q_ASSERT(info.signCount() == expected - 1);
+ QVERIFY(info.signCount() == expected - 1);
}
auto verifyJob = openpgp()->verifyOpaqueJob();
QByteArray verified;
auto result = verifyJob->exec(signedData, verified);
delete verifyJob;
- Q_ASSERT(!result.error());
- Q_ASSERT(verified == what.toUtf8());
+ QVERIFY(!result.error());
+ QVERIFY(verified == what.toUtf8());
- Q_ASSERT(result.numSignatures() == 1);
+ QVERIFY(result.numSignatures() == 1);
auto sig = result.signatures()[0];
auto key2 = sig.key();
- Q_ASSERT(!key.isNull());
- Q_ASSERT(!strcmp (key2.primaryFingerprint(), key.primaryFingerprint()));
- Q_ASSERT(!strcmp (key.primaryFingerprint(), sig.fingerprint()));
+ QVERIFY(!key.isNull());
+ QVERIFY(!strcmp (key2.primaryFingerprint(), key.primaryFingerprint()));
+ QVERIFY(!strcmp (key.primaryFingerprint(), sig.fingerprint()));
auto stats = key2.userID(0).tofuInfo();
- Q_ASSERT(!stats.isNull());
+ QVERIFY(!stats.isNull());
if (stats.signCount() != expected) {
std::cout << "################ Key before verify: "
<< key
<< "################ Key after verify: "
<< key2;
}
- Q_ASSERT(stats.signCount() == expected);
+ QVERIFY(stats.signCount() == expected);
}
private Q_SLOTS:
void testTofuNull()
{
if (!testSupported()) {
return;
}
TofuInfo tofu;
- Q_ASSERT(tofu.isNull());
- Q_ASSERT(!tofu.description());
- Q_ASSERT(!tofu.signCount());
- Q_ASSERT(!tofu.signLast());
- Q_ASSERT(!tofu.signFirst());
- Q_ASSERT(tofu.validity() == TofuInfo::ValidityUnknown);
- Q_ASSERT(tofu.policy() == TofuInfo::PolicyUnknown);
+ QVERIFY(tofu.isNull());
+ QVERIFY(!tofu.description());
+ QVERIFY(!tofu.signCount());
+ QVERIFY(!tofu.signLast());
+ QVERIFY(!tofu.signFirst());
+ QVERIFY(tofu.validity() == TofuInfo::ValidityUnknown);
+ QVERIFY(tofu.policy() == TofuInfo::PolicyUnknown);
}
void testTofuInfo()
{
if (!testSupported()) {
return;
}
auto *job = openpgp()->verifyOpaqueJob(true);
const QByteArray data1(testMsg1);
QByteArray plaintext;
auto ctx = Job::context(job);
- Q_ASSERT(ctx);
+ QVERIFY(ctx);
ctx->setSender("alfa@example.net");
auto result = job->exec(data1, plaintext);
delete job;
- Q_ASSERT(!result.isNull());
- Q_ASSERT(!result.error());
- Q_ASSERT(!strcmp(plaintext.constData(), "Just GNU it!\n"));
+ QVERIFY(!result.isNull());
+ QVERIFY(!result.error());
+ QVERIFY(!strcmp(plaintext.constData(), "Just GNU it!\n"));
- Q_ASSERT(result.numSignatures() == 1);
+ QVERIFY(result.numSignatures() == 1);
Signature sig = result.signatures()[0];
/* TOFU is always marginal */
- Q_ASSERT(sig.validity() == Signature::Marginal);
+ QVERIFY(sig.validity() == Signature::Marginal);
auto stats = sig.key().userID(0).tofuInfo();
- Q_ASSERT(!stats.isNull());
- Q_ASSERT(sig.key().primaryFingerprint());
- Q_ASSERT(sig.fingerprint());
- Q_ASSERT(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint()));
- Q_ASSERT(stats.signFirst() == stats.signLast());
- Q_ASSERT(stats.signCount() == 1);
- Q_ASSERT(stats.policy() == TofuInfo::PolicyAuto);
- Q_ASSERT(stats.validity() == TofuInfo::LittleHistory);
+ QVERIFY(!stats.isNull());
+ QVERIFY(sig.key().primaryFingerprint());
+ QVERIFY(sig.fingerprint());
+ QVERIFY(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint()));
+ QVERIFY(stats.signFirst() == stats.signLast());
+ QVERIFY(stats.signCount() == 1);
+ QVERIFY(stats.policy() == TofuInfo::PolicyAuto);
+ QVERIFY(stats.validity() == TofuInfo::LittleHistory);
testTofuCopy(stats, stats);
/* Another verify */
job = openpgp()->verifyOpaqueJob(true);
result = job->exec(data1, plaintext);
delete job;
- Q_ASSERT(!result.isNull());
- Q_ASSERT(!result.error());
+ QVERIFY(!result.isNull());
+ QVERIFY(!result.error());
- Q_ASSERT(result.numSignatures() == 1);
+ QVERIFY(result.numSignatures() == 1);
sig = result.signatures()[0];
/* TOFU is always marginal */
- Q_ASSERT(sig.validity() == Signature::Marginal);
+ QVERIFY(sig.validity() == Signature::Marginal);
stats = sig.key().userID(0).tofuInfo();
- Q_ASSERT(!stats.isNull());
- Q_ASSERT(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint()));
- Q_ASSERT(stats.signFirst() == stats.signLast());
- Q_ASSERT(stats.signCount() == 1);
- Q_ASSERT(stats.policy() == TofuInfo::PolicyAuto);
- Q_ASSERT(stats.validity() == TofuInfo::LittleHistory);
+ QVERIFY(!stats.isNull());
+ QVERIFY(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint()));
+ QVERIFY(stats.signFirst() == stats.signLast());
+ QVERIFY(stats.signCount() == 1);
+ QVERIFY(stats.policy() == TofuInfo::PolicyAuto);
+ QVERIFY(stats.validity() == TofuInfo::LittleHistory);
/* Verify that another call yields the same result */
job = openpgp()->verifyOpaqueJob(true);
result = job->exec(data1, plaintext);
delete job;
- Q_ASSERT(!result.isNull());
- Q_ASSERT(!result.error());
+ QVERIFY(!result.isNull());
+ QVERIFY(!result.error());
- Q_ASSERT(result.numSignatures() == 1);
+ QVERIFY(result.numSignatures() == 1);
sig = result.signatures()[0];
/* TOFU is always marginal */
- Q_ASSERT(sig.validity() == Signature::Marginal);
+ QVERIFY(sig.validity() == Signature::Marginal);
stats = sig.key().userID(0).tofuInfo();
- Q_ASSERT(!stats.isNull());
- Q_ASSERT(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint()));
- Q_ASSERT(stats.signFirst() == stats.signLast());
- Q_ASSERT(stats.signCount() == 1);
- Q_ASSERT(stats.policy() == TofuInfo::PolicyAuto);
- Q_ASSERT(stats.validity() == TofuInfo::LittleHistory);
+ QVERIFY(!stats.isNull());
+ QVERIFY(!strcmp(sig.key().primaryFingerprint(), sig.fingerprint()));
+ QVERIFY(stats.signFirst() == stats.signLast());
+ QVERIFY(stats.signCount() == 1);
+ QVERIFY(stats.policy() == TofuInfo::PolicyAuto);
+ QVERIFY(stats.validity() == TofuInfo::LittleHistory);
}
void testTofuSignCount()
{
if (!testSupported()) {
return;
}
auto *job = openpgp()->keyListJob(false, false, false);
job->addMode(GpgME::WithTofu);
std::vector<GpgME::Key> keys;
GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("zulu@example.net"),
true, keys);
delete job;
- Q_ASSERT(!keys.empty());
+ QVERIFY(!keys.empty());
Key key = keys[0];
- Q_ASSERT(!key.isNull());
+ QVERIFY(!key.isNull());
/* As we sign & verify quickly here we need different
* messages to avoid having them treated as the same
* message if they were created within the same second.
* Alternatively we could use the same message and wait
* a second between each call. But this would slow down
* the testsuite. */
signAndVerify(QStringLiteral("Hello"), key, 1);
key.update();
signAndVerify(QStringLiteral("Hello2"), key, 2);
key.update();
signAndVerify(QStringLiteral("Hello3"), key, 3);
key.update();
signAndVerify(QStringLiteral("Hello4"), key, 4);
}
void testTofuKeyList()
{
if (!testSupported()) {
return;
}
/* First check that the key has no tofu info. */
auto *job = openpgp()->keyListJob(false, false, false);
std::vector<GpgME::Key> keys;
auto result = job->exec(QStringList() << QStringLiteral("zulu@example.net"),
true, keys);
delete job;
- Q_ASSERT(!keys.empty());
+ QVERIFY(!keys.empty());
auto key = keys[0];
- Q_ASSERT(!key.isNull());
- Q_ASSERT(key.userID(0).tofuInfo().isNull());
+ QVERIFY(!key.isNull());
+ QVERIFY(key.userID(0).tofuInfo().isNull());
auto keyCopy = key;
keyCopy.update();
auto sigCnt = keyCopy.userID(0).tofuInfo().signCount();
signAndVerify(QStringLiteral("Hello5"), keyCopy,
sigCnt + 1);
keyCopy.update();
signAndVerify(QStringLiteral("Hello6"), keyCopy,
sigCnt + 2);
/* Now another one but with tofu */
job = openpgp()->keyListJob(false, false, false);
job->addMode(GpgME::WithTofu);
result = job->exec(QStringList() << QStringLiteral("zulu@example.net"),
true, keys);
delete job;
- Q_ASSERT(!result.error());
- Q_ASSERT(!keys.empty());
+ QVERIFY(!result.error());
+ QVERIFY(!keys.empty());
auto key2 = keys[0];
- Q_ASSERT(!key2.isNull());
+ QVERIFY(!key2.isNull());
auto info = key2.userID(0).tofuInfo();
- Q_ASSERT(!info.isNull());
- Q_ASSERT(info.signCount());
+ QVERIFY(!info.isNull());
+ QVERIFY(info.signCount());
}
void testTofuPolicy()
{
if (!testSupported()) {
return;
}
/* First check that the key has no tofu info. */
auto *job = openpgp()->keyListJob(false, false, false);
std::vector<GpgME::Key> keys;
job->addMode(GpgME::WithTofu);
auto result = job->exec(QStringList() << QStringLiteral("bravo@example.net"),
false, keys);
if (keys.empty()) {
qDebug() << "bravo@example.net not found";
qDebug() << "Error: " << result.error().asString();
const auto homedir = QString::fromLocal8Bit(qgetenv("GNUPGHOME"));
qDebug() << "Homedir is: " << homedir;
QFileInfo fi(homedir + "/pubring.gpg");
qDebug () << "pubring exists: " << fi.exists() << " readable? "
<< fi.isReadable() << " size: " << fi.size();
QFileInfo fi2(homedir + "/pubring.kbx");
qDebug () << "keybox exists: " << fi2.exists() << " readable? "
<< fi2.isReadable() << " size: " << fi2.size();
result = job->exec(QStringList(), false, keys);
foreach (const auto key, keys) {
qDebug() << "Key: " << key.userID(0).name() << " <"
<< key.userID(0).email()
<< ">\n fpr: " << key.primaryFingerprint();
}
}
- Q_ASSERT(!result.error());
- Q_ASSERT(!keys.empty());
+ QVERIFY(!result.error());
+ QVERIFY(!keys.empty());
auto key = keys[0];
- Q_ASSERT(!key.isNull());
- Q_ASSERT(key.userID(0).tofuInfo().policy() != TofuInfo::PolicyBad);
+ QVERIFY(!key.isNull());
+ QVERIFY(key.userID(0).tofuInfo().policy() != TofuInfo::PolicyBad);
auto *tofuJob = openpgp()->tofuPolicyJob();
auto err = tofuJob->exec(key, TofuInfo::PolicyBad);
- Q_ASSERT(!err);
+ QVERIFY(!err);
result = job->exec(QStringList() << QStringLiteral("bravo@example.net"),
false, keys);
- Q_ASSERT(!keys.empty());
+ QVERIFY(!keys.empty());
key = keys[0];
- Q_ASSERT(key.userID(0).tofuInfo().policy() == TofuInfo::PolicyBad);
+ QVERIFY(key.userID(0).tofuInfo().policy() == TofuInfo::PolicyBad);
err = tofuJob->exec(key, TofuInfo::PolicyGood);
result = job->exec(QStringList() << QStringLiteral("bravo@example.net"),
false, keys);
key = keys[0];
- Q_ASSERT(key.userID(0).tofuInfo().policy() == TofuInfo::PolicyGood);
+ QVERIFY(key.userID(0).tofuInfo().policy() == TofuInfo::PolicyGood);
delete tofuJob;
delete job;
}
void initTestCase()
{
QGpgMETest::initTestCase();
const QString gpgHome = qgetenv("GNUPGHOME");
qputenv("GNUPGHOME", mDir.path().toUtf8());
- Q_ASSERT(mDir.isValid());
+ QVERIFY(mDir.isValid());
QFile conf(mDir.path() + QStringLiteral("/gpg.conf"));
- Q_ASSERT(conf.open(QIODevice::WriteOnly));
+ QVERIFY(conf.open(QIODevice::WriteOnly));
conf.write("trust-model tofu+pgp");
conf.close();
QFile agentConf(mDir.path() + QStringLiteral("/gpg-agent.conf"));
- Q_ASSERT(agentConf.open(QIODevice::WriteOnly));
+ QVERIFY(agentConf.open(QIODevice::WriteOnly));
agentConf.write("allow-loopback-pinentry");
agentConf.close();
- Q_ASSERT(copyKeyrings(gpgHome, mDir.path()));
+ QVERIFY(copyKeyrings(gpgHome, mDir.path()));
}
private:
QTemporaryDir mDir;
};
QTEST_MAIN(TofuInfoTest)
#include "t-tofuinfo.moc"
diff --git a/lang/qt/tests/t-various.cpp b/lang/qt/tests/t-various.cpp
index 330e62d8..aa45b622 100644
--- a/lang/qt/tests/t-various.cpp
+++ b/lang/qt/tests/t-various.cpp
@@ -1,126 +1,126 @@
/* t-various.cpp
This file is part of qgpgme, the Qt API binding for gpgme
Copyright (c) 2017 Intevation GmbH
QGpgME is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
QGpgME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <QDebug>
#include <QTest>
#include <QSignalSpy>
#include "keylistjob.h"
#include "protocol.h"
#include "keylistresult.h"
#include "context.h"
#include "engineinfo.h"
#include "t-support.h"
using namespace QGpgME;
using namespace GpgME;
class TestVarious: public QGpgMETest
{
Q_OBJECT
Q_SIGNALS:
void asyncDone();
private Q_SLOTS:
void testQuickUid()
{
if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.13") {
return;
}
KeyListJob *job = openpgp()->keyListJob(false, true, true);
std::vector<GpgME::Key> keys;
GpgME::KeyListResult result = job->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
delete job;
- Q_ASSERT (!result.error());
- Q_ASSERT (keys.size() == 1);
+ QVERIFY (!result.error());
+ QVERIFY (keys.size() == 1);
Key key = keys.front();
QVERIFY (key.numUserIDs() == 3);
const char uid[] = "Foo Bar (with comment) <foo@bar.baz>";
auto ctx = Context::createForProtocol(key.protocol());
- Q_ASSERT (ctx);
+ QVERIFY (ctx);
TestPassphraseProvider provider;
ctx->setPassphraseProvider(&provider);
ctx->setPinentryMode(Context::PinentryLoopback);
QVERIFY(!ctx->addUid(key, uid));
delete ctx;
key.update();
QVERIFY (key.numUserIDs() == 4);
bool id_found = false;;
for (const auto &u: key.userIDs()) {
if (!strcmp (u.id(), uid)) {
QVERIFY (!u.isRevoked());
id_found = true;
break;
}
}
QVERIFY (id_found);
ctx = Context::createForProtocol(key.protocol());
QVERIFY (!ctx->revUid(key, uid));
delete ctx;
key.update();
bool id_revoked = false;;
for (const auto &u: key.userIDs()) {
if (!strcmp (u.id(), uid)) {
id_revoked = true;
break;
}
}
- Q_ASSERT(id_revoked);
+ QVERIFY(id_revoked);
}
void initTestCase()
{
QGpgMETest::initTestCase();
const QString gpgHome = qgetenv("GNUPGHOME");
- Q_ASSERT(copyKeyrings(gpgHome, mDir.path()));
+ QVERIFY(copyKeyrings(gpgHome, mDir.path()));
qputenv("GNUPGHOME", mDir.path().toUtf8());
}
private:
QTemporaryDir mDir;
};
QTEST_MAIN(TestVarious)
#include "t-various.moc"
diff --git a/lang/qt/tests/t-verify.cpp b/lang/qt/tests/t-verify.cpp
index aedfc19a..7caed28f 100644
--- a/lang/qt/tests/t-verify.cpp
+++ b/lang/qt/tests/t-verify.cpp
@@ -1,93 +1,93 @@
/* t-verifiy.cpp
This file is part of qgpgme, the Qt API binding for gpgme
Copyright (c) 2016 Intevation GmbH
QGpgME is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
QGpgME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <QDebug>
#include <QTest>
#include "protocol.h"
#include "verifyopaquejob.h"
#include "verificationresult.h"
#include "key.h"
#include "t-support.h"
using namespace QGpgME;
using namespace GpgME;
static const char testMsg1[] =
"-----BEGIN PGP MESSAGE-----\n"
"\n"
"owGbwMvMwCSoW1RzPCOz3IRxjXQSR0lqcYleSUWJTZOvjVdpcYmCu1+oQmaJIleH\n"
"GwuDIBMDGysTSIqBi1MApi+nlGGuwDeHao53HBr+FoVGP3xX+kvuu9fCMJvl6IOf\n"
"y1kvP4y+8D5a11ang0udywsA\n"
"=Crq6\n"
"-----END PGP MESSAGE-----\n";
class VerifyTest: public QGpgMETest
{
Q_OBJECT
private Q_SLOTS:
/* Check that a signature always has a key. */
void testSignatureKey()
{
const QByteArray signedData(testMsg1);
auto verifyJob = openpgp()->verifyOpaqueJob(true);
QByteArray verified;
auto result = verifyJob->exec(signedData, verified);
- Q_ASSERT(!result.error());
+ QVERIFY(!result.error());
delete verifyJob;
- Q_ASSERT(result.numSignatures() == 1);
+ QVERIFY(result.numSignatures() == 1);
auto sig = result.signatures()[0];
const auto key = sig.key(true, false);
- Q_ASSERT(!key.isNull());
+ QVERIFY(!key.isNull());
bool found = false;
for (const auto subkey: key.subkeys()) {
if (!strcmp (subkey.fingerprint(), sig.fingerprint())) {
found = true;
}
}
- Q_ASSERT(found);
+ QVERIFY(found);
}
};
QTEST_MAIN(VerifyTest)
#include "t-verify.moc"
diff --git a/lang/qt/tests/t-wkspublish.cpp b/lang/qt/tests/t-wkspublish.cpp
index 326ecaa7..64f101ee 100644
--- a/lang/qt/tests/t-wkspublish.cpp
+++ b/lang/qt/tests/t-wkspublish.cpp
@@ -1,282 +1,282 @@
/* t-wkspublish.cpp
This file is part of qgpgme, the Qt API binding for gpgme
Copyright (c) 2016 Intevation GmbH
QGpgME is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
QGpgME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <QDebug>
#include <QTest>
#include <QSignalSpy>
#include <QTemporaryDir>
#include "wkspublishjob.h"
#include "keygenerationjob.h"
#include "keygenerationresult.h"
#include "importjob.h"
#include "importresult.h"
#include "protocol.h"
#include "engineinfo.h"
#include "t-support.h"
using namespace QGpgME;
using namespace GpgME;
//#define DO_ONLINE_TESTS
#define TEST_ADDRESS "testuser2@test.gnupg.org"
static const char *testSecKey =
"-----BEGIN PGP PRIVATE KEY BLOCK-----\n"
"\n"
"lHgEV77hVhMJKyQDAwIIAQEHAgMEN3qKqBr9EecnfUnpw8RS8DHAjJqhwm2HAoEE\n"
"3yfQQ9w8uB/bKm5dqW4HML3JWRH8YoJaKSVrJY2D1FZUY+vHlgABAKDwEAB0HND8\n"
"5kbxiJmqKIuuNqCJ2jHgs9G0xk4GdKvZEdq0JlRlc3QgVXNlciAyIDx0ZXN0dXNl\n"
"cjJAdGVzdC5nbnVwZy5vcmc+iHkEExMIACEFAle+4VYCGwMFCwkIBwIGFQgJCgsC\n"
"BBYCAwECHgECF4AACgkQRVRoUEJO+6zgFQD7BF3pnS3w3A7J9y+Y3kyGfmscXFWJ\n"
"Kme1PAsAlVSm1y4A+weReMvWFYHJH257v94yhStmV8egGoybsNDttNAW53cbnHwE\n"
"V77hVhIJKyQDAwIIAQEHAgMEX+6cF0HEn4g3ztFvwHyr7uwXMVYUGL3lE3mjhnV3\n"
"SbY6Dmy3OeFVnEVkawHqSv+HobpQTeEqNoQHAoIiXFCRlgMBCAcAAP9FykiyDspm\n"
"T33XWRPD+LAOmaIU7CIhfv9+lVkeExlU1w+qiGEEGBMIAAkFAle+4VYCGwwACgkQ\n"
"RVRoUEJO+6xjhgD/ZJ/MwYZJPk/xPYhTP8+wF+tErVNA8w3pP9D69dgUPdcA/izZ\n"
"Pji6YetVhgsyaHc4PrKynsk5G6nM3KkAOehUQsX8\n"
"=S/Wa\n"
"-----END PGP PRIVATE KEY BLOCK-----\n";
static const char *testResponse =
"From key-submission@test.gnupg.org Thu Aug 25 12:15:54 2016\n"
"Return-Path: <webkey@g10code.com>\n"
"From: key-submission@test.gnupg.org\n"
"To: testuser2@test.gnupg.org\n"
"Subject: Confirm your key publication\n"
"X-Wks-Loop: webkey.g10code.com\n"
"MIME-Version: 1.0\n"
"Content-Type: multipart/encrypted; protocol=\"application/pgp-encrypted\";\n"
" boundary=\"=-=01-wbu5fr9nu6fix5tcojjo=-=\"\n"
"Date: Thu, 25 Aug 2016 12:15:54 +0000\n"
"Message-Id: <E1bctZa-0004LE-Fr@kerckhoffs.g10code.com>\n"
"Sender: <webkey@g10code.com>\n"
"X-Kolab-Scheduling-Message: FALSE\n"
"\n"
" \n"
"\n"
"--=-=01-wbu5fr9nu6fix5tcojjo=-=\n"
"Content-Type: application/pgp-encrypted\n"
"\n"
"Version: 1\n"
"\n"
"--=-=01-wbu5fr9nu6fix5tcojjo=-=\n"
"Content-Type: application/octet-stream\n"
"\n"
"-----BEGIN PGP MESSAGE-----\n"
"Version: GnuPG v2\n"
"\n"
"hH4D8pSp7hUsFUASAgMEg0w39E6d0TkFYxLbT6n3YcoKTT+Ur/c7Sn1ECyL7Rnuk\n"
"cmPO0adt3JxueK7Oz5COlk32SECFODdF3cQuDhkGxzC6Sfc4SfisdILmNhaT/MeW\n"
"8a+yE4skSK70absif4kw5XkvxXNxHeIHfAteP50jPJLSwEsBTEceb9cRMoP7s8w0\n"
"lYyi+RWQ7UKlKKywtcRCL4ow2H7spjx+a+3FzNOAoy7K0/thhLVRk8z+iuPi0/4n\n"
"Z2Ql60USLLUlfV2ZIpXdCd+5GjTJsnGhDos1pas5TZcOOAxO12Cg5TcqHISOaqa8\n"
"6BqxcKCU3NypIynOKHj375KArSs0WsEH8HWHyBBHB+NYtNpnTAuHNKxM+JtNxf+U\n"
"NfD2zptS6kyiHLw+4zjL5pEV7RHS2PBwWBDS6vhnyybNwckleya96U04iYiGRYGE\n"
"lUUR6Fl8H6x04dItFH1/jJA6Ppcu4FoYou04HADWCqJXPTgztjiW1/9QoCeXl5lm\n"
"CcOCcuw7lXp+qTejuns=\n"
"=SsWX\n"
"-----END PGP MESSAGE-----\n"
"\n"
"--=-=01-wbu5fr9nu6fix5tcojjo=-=--\n";
class WKSPublishTest : public QGpgMETest
{
Q_OBJECT
Q_SIGNALS:
void asyncDone();
private Q_SLOTS:
void testUnsupported()
{
// First check if it is supported
auto job = openpgp()->wksPublishJob();
connect(job, &WKSPublishJob::result, this,
[this] (Error err, QByteArray, QByteArray, QString, Error) {
- Q_ASSERT(err);
+ QVERIFY(err);
Q_EMIT asyncDone();
});
job->startCheck ("testuser1@localhost");
QSignalSpy spy (this, SIGNAL(asyncDone()));
- Q_ASSERT(spy.wait());
+ QVERIFY(spy.wait());
}
#ifdef DO_ONLINE_TESTS
private Q_SLOTS:
#else
private:
#endif
void testWSKPublishSupport()
{
// First check if it is supported
auto job = openpgp()->wksPublishJob();
connect(job, &WKSPublishJob::result, this,
[this] (Error err, QByteArray, QByteArray, QString, Error) {
if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.0.16") {
std::cout << err;
- Q_ASSERT(err);
+ QVERIFY(err);
} else {
- Q_ASSERT(!err);
+ QVERIFY(!err);
}
Q_EMIT asyncDone();
});
job->startCheck ("testuser1@test.gnupg.org");
QSignalSpy spy (this, SIGNAL(asyncDone()));
- Q_ASSERT(spy.wait());
+ QVERIFY(spy.wait());
}
void testWKSPublishErrors() {
if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.0.16") {
/* Not supported */
return;
}
auto job = openpgp()->wksPublishJob();
connect(job, &WKSPublishJob::result, this,
[this] (Error err, QByteArray, QByteArray, QString, Error) {
- Q_ASSERT(err);
+ QVERIFY(err);
Q_EMIT asyncDone();
});
job->startCreate("AB874F24E98EBB8487EE7B170F8E3D97FE7011B7",
QStringLiteral("Foo@bar.baz"));
QSignalSpy spy (this, SIGNAL(asyncDone()));
- Q_ASSERT(spy.wait());
+ QVERIFY(spy.wait());
}
void testWKSPublishCreate() {
if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.0.16") {
/* Not supported */
return;
}
/* First generate a test key */
const QString args = QStringLiteral("<GnupgKeyParms format=\"internal\">\n"
"%no-protection\n"
"%transient-key\n"
"key-type: ECDSA\n"
"key-curve: brainpoolP256r1\n"
"key-usage: sign\n"
"subkey-type: ECDH\n"
"subkey-curve: brainpoolP256r1\n"
"subkey-usage: encrypt\n"
"name-email: %1\n"
"name-real: Test User\n"
"</GnupgKeyParms>").arg(TEST_ADDRESS);
auto keygenjob = openpgp()->keyGenerationJob();
QByteArray fpr;
connect(keygenjob, &KeyGenerationJob::result, this,
[this, &fpr](KeyGenerationResult result, QByteArray, QString, Error)
{
- Q_ASSERT(!result.error());
+ QVERIFY(!result.error());
fpr = QByteArray(result.fingerprint());
- Q_ASSERT(!fpr.isEmpty());
+ QVERIFY(!fpr.isEmpty());
Q_EMIT asyncDone();
});
keygenjob->start(args);
QSignalSpy spy (this, SIGNAL(asyncDone()));
- Q_ASSERT(spy.wait());
+ QVERIFY(spy.wait());
/* Then try to create a request. */
auto job = openpgp()->wksPublishJob();
connect(job, &WKSPublishJob::result, this,
[this] (Error err, QByteArray out, QByteArray, QString, Error) {
- Q_ASSERT(!err);
+ QVERIFY(!err);
Q_EMIT asyncDone();
const QString outstr = QString(out);
- Q_ASSERT(outstr.contains(
+ QVERIFY(outstr.contains(
QStringLiteral("-----BEGIN PGP PUBLIC KEY BLOCK-----")));
- Q_ASSERT(outstr.contains(
+ QVERIFY(outstr.contains(
QStringLiteral("Content-Type: application/pgp-keys")));
- Q_ASSERT(outstr.contains(
+ QVERIFY(outstr.contains(
QStringLiteral("From: " TEST_ADDRESS)));
});
job->startCreate(fpr.constData(), QLatin1String(TEST_ADDRESS));
- Q_ASSERT(spy.wait());
+ QVERIFY(spy.wait());
}
void testWKSPublishReceive() {
if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.0.16") {
/* Not supported */
return;
}
auto importjob = openpgp()->importJob();
connect(importjob, &ImportJob::result, this,
[this](ImportResult result, QString, Error)
{
- Q_ASSERT(!result.error());
- Q_ASSERT(!result.imports().empty());
- Q_ASSERT(result.numSecretKeysImported());
+ QVERIFY(!result.error());
+ QVERIFY(!result.imports().empty());
+ QVERIFY(result.numSecretKeysImported());
Q_EMIT asyncDone();
});
importjob->start(QByteArray(testSecKey));
QSignalSpy spy (this, SIGNAL(asyncDone()));
- Q_ASSERT(spy.wait());
+ QVERIFY(spy.wait());
/* Get a response. */
auto job = openpgp()->wksPublishJob();
connect(job, &WKSPublishJob::result, this,
[this] (Error err, QByteArray out, QByteArray, QString, Error) {
- Q_ASSERT(!err);
+ QVERIFY(!err);
Q_EMIT asyncDone();
const QString outstr = QString(out);
- Q_ASSERT(outstr.contains(
+ QVERIFY(outstr.contains(
QStringLiteral("-----BEGIN PGP MESSAGE-----")));
- Q_ASSERT(outstr.contains(
+ QVERIFY(outstr.contains(
QStringLiteral("Content-Type: multipart/encrypted;")));
- Q_ASSERT(outstr.contains(
+ QVERIFY(outstr.contains(
QStringLiteral("From: " TEST_ADDRESS)));
});
job->startReceive(QByteArray(testResponse));
- Q_ASSERT(spy.wait());
+ QVERIFY(spy.wait());
}
void initTestCase()
{
QGpgMETest::initTestCase();
const QString gpgHome = qgetenv("GNUPGHOME");
qputenv("GNUPGHOME", mDir.path().toUtf8());
- Q_ASSERT(mDir.isValid());
+ QVERIFY(mDir.isValid());
QFile agentConf(mDir.path() + QStringLiteral("/gpg-agent.conf"));
- Q_ASSERT(agentConf.open(QIODevice::WriteOnly));
+ QVERIFY(agentConf.open(QIODevice::WriteOnly));
agentConf.write("allow-loopback-pinentry");
agentConf.close();
}
private:
QTemporaryDir mDir;
};
QTEST_MAIN(WKSPublishTest)
#include "t-wkspublish.moc"
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Feb 6, 8:09 AM (4 h, 45 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
4d/05/cdd610d06c6b5a27f7c25bdd329c
Attached To
rM GPGME
Event Timeline
Log In to Comment