qt: Add unittest for decrypt unwrap
* lang/qt/tests/t-encrypt.cpp (EncryptTest::testEncryptDecryptNowrap): New.
This commit is contained in:
parent
8ad37ecc29
commit
5493164f86
@ -39,6 +39,8 @@
|
|||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include "keylistjob.h"
|
#include "keylistjob.h"
|
||||||
#include "encryptjob.h"
|
#include "encryptjob.h"
|
||||||
|
#include "signencryptjob.h"
|
||||||
|
#include "signingresult.h"
|
||||||
#include "qgpgmeencryptjob.h"
|
#include "qgpgmeencryptjob.h"
|
||||||
#include "encryptionresult.h"
|
#include "encryptionresult.h"
|
||||||
#include "decryptionresult.h"
|
#include "decryptionresult.h"
|
||||||
@ -46,6 +48,7 @@
|
|||||||
#include "qgpgmebackend.h"
|
#include "qgpgmebackend.h"
|
||||||
#include "keylistresult.h"
|
#include "keylistresult.h"
|
||||||
#include "engineinfo.h"
|
#include "engineinfo.h"
|
||||||
|
#include "verifyopaquejob.h"
|
||||||
#include "t-support.h"
|
#include "t-support.h"
|
||||||
|
|
||||||
#define PROGRESS_TEST_SIZE 1 * 1024 * 1024
|
#define PROGRESS_TEST_SIZE 1 * 1024 * 1024
|
||||||
@ -109,7 +112,7 @@ private Q_SLOTS:
|
|||||||
auto decJob = new QGpgMEDecryptJob(ctx);
|
auto decJob = new QGpgMEDecryptJob(ctx);
|
||||||
QByteArray plainText;
|
QByteArray plainText;
|
||||||
auto decResult = decJob->exec(cipherText, plainText);
|
auto decResult = decJob->exec(cipherText, plainText);
|
||||||
QVERIFY(!result.error());
|
QVERIFY(!decResult.error());
|
||||||
QVERIFY(QString::fromUtf8(plainText) == QStringLiteral("Hello World"));
|
QVERIFY(QString::fromUtf8(plainText) == QStringLiteral("Hello World"));
|
||||||
delete decJob;
|
delete decJob;
|
||||||
}
|
}
|
||||||
@ -200,6 +203,68 @@ private Q_SLOTS:
|
|||||||
delete decJob;
|
delete decJob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testEncryptDecryptNowrap()
|
||||||
|
{
|
||||||
|
/* Now decrypt */
|
||||||
|
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);
|
||||||
|
QVERIFY(!keylistresult.error());
|
||||||
|
QVERIFY(keys.size() == 1);
|
||||||
|
delete listjob;
|
||||||
|
|
||||||
|
auto job = openpgp()->signEncryptJob(/*ASCII Armor */true, /* Textmode */ true);
|
||||||
|
|
||||||
|
auto encSignCtx = Job::context(job);
|
||||||
|
TestPassphraseProvider provider1;
|
||||||
|
encSignCtx->setPassphraseProvider(&provider1);
|
||||||
|
encSignCtx->setPinentryMode(Context::PinentryLoopback);
|
||||||
|
|
||||||
|
QVERIFY(job);
|
||||||
|
QByteArray cipherText;
|
||||||
|
auto result = job->exec(keys, keys, QStringLiteral("Hello World").toUtf8(), Context::AlwaysTrust, cipherText);
|
||||||
|
delete job;
|
||||||
|
QVERIFY(!result.first.error());
|
||||||
|
QVERIFY(!result.second.error());
|
||||||
|
const auto cipherString = QString::fromUtf8(cipherText);
|
||||||
|
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);
|
||||||
|
ctx->setDecryptionFlags(Context::DecryptUnwrap);
|
||||||
|
|
||||||
|
auto decJob = new QGpgMEDecryptJob(ctx);
|
||||||
|
QByteArray plainText;
|
||||||
|
auto decResult = decJob->exec(cipherText, plainText);
|
||||||
|
|
||||||
|
QVERIFY(!decResult.error());
|
||||||
|
|
||||||
|
delete decJob;
|
||||||
|
|
||||||
|
// Now verify the unwrapeped data.
|
||||||
|
auto verifyJob = openpgp()->verifyOpaqueJob(true);
|
||||||
|
QByteArray verified;
|
||||||
|
|
||||||
|
auto verResult = verifyJob->exec(plainText, verified);
|
||||||
|
QVERIFY(!verResult.error());
|
||||||
|
delete verifyJob;
|
||||||
|
|
||||||
|
QVERIFY(verResult.numSignatures() == 1);
|
||||||
|
auto sig = verResult.signatures()[0];
|
||||||
|
|
||||||
|
QVERIFY(verified == QStringLiteral("Hello World"));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* Loopback and passphrase provider don't work for mixed encryption.
|
/* Loopback and passphrase provider don't work for mixed encryption.
|
||||||
* So this test is disabled until gnupg(?) is fixed for this. */
|
* So this test is disabled until gnupg(?) is fixed for this. */
|
||||||
|
Loading…
Reference in New Issue
Block a user