Commit 1b3ecd9a authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Fix overriding of the sender's encryption keys

... by making sure that the sender's address is added to the list of
recipients.

GnuPG-bug-id: 5283
parent 15ec596d
Pipeline #55363 passed with stage
in 10 minutes and 59 seconds
......@@ -30,7 +30,6 @@ private Q_SLOTS:
{
mGnupgHome = QTest::qExtractTestData("/fixtures/keyresolvertest");
qputenv("GNUPGHOME", mGnupgHome->path().toLocal8Bit());
qDebug() << "Using GNUPGHOME" << qgetenv("GNUPGHOME");
// hold a reference to the key cache to avoid rebuilding while the test is running
mKeyCache = KeyCache::instance();
......@@ -139,6 +138,39 @@ private Q_SLOTS:
testKey("sender-mixed@example.net", CMS).primaryFingerprint());
}
void test_override_sender_openpgp()
{
const QString override = testKey("prefer-openpgp@example.net", OpenPGP).primaryFingerprint();
KeyResolver resolver(/*encrypt=*/ true, /*sign=*/ true);
resolver.setSender(QStringLiteral("sender-mixed@example.net"));
resolver.setOverrideKeys({{OpenPGP, {{QStringLiteral("sender-mixed@example.net"), {override}}}}});
spyOnKeysResolvedSignal(&resolver);
resolver.start(/*showApproval=*/ false);
verifyKeysResolvedSignalEmittedWith(/*success=*/ true, /*sendUnencrypted=*/ false);
QCOMPARE(resolver.encryptionKeys().value(OpenPGP).size(), 1);
QCOMPARE(resolver.encryptionKeys().value(OpenPGP).value("sender-mixed@example.net").size(), 1);
QCOMPARE(resolver.encryptionKeys().value(OpenPGP).value("sender-mixed@example.net")[0].primaryFingerprint(), override);
}
void test_override_sender_smime()
{
const QString override = testKey("prefer-smime@example.net", CMS).primaryFingerprint();
KeyResolver resolver(/*encrypt=*/ true, /*sign=*/ true);
resolver.setPreferredProtocol(CMS);
resolver.setSender(QStringLiteral("sender-mixed@example.net"));
resolver.setOverrideKeys({{CMS, {{QStringLiteral("sender-mixed@example.net"), {override}}}}});
spyOnKeysResolvedSignal(&resolver);
resolver.start(/*showApproval=*/ false);
verifyKeysResolvedSignalEmittedWith(/*success=*/ true, /*sendUnencrypted=*/ false);
QCOMPARE(resolver.encryptionKeys().value(CMS).size(), 1);
QCOMPARE(resolver.encryptionKeys().value(CMS).value("sender-mixed@example.net").size(), 1);
QCOMPARE(resolver.encryptionKeys().value(CMS).value("sender-mixed@example.net")[0].primaryFingerprint(), override);
}
Key testKey(const char *email, Protocol protocol = UnknownProtocol)
{
const std::vector<Key> keys = KeyCache::instance()->findByEMailAddress(email);
......
......@@ -544,14 +544,7 @@ void KeyResolver::setSender(const QString &address)
if (d->mSign) {
d->mSender = normStr;
}
if (d->mEncrypt) {
if (!d->mUnresolvedCMS.contains(normStr)) {
d->mUnresolvedCMS << normStr;
}
if (!d->mUnresolvedPGP.contains(normStr)) {
d->mUnresolvedPGP << normStr;
}
}
d->addRecpients({address});
}
void KeyResolver::setOverrideKeys(const QMap<Protocol, QMap<QString, QStringList> > &overrides)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment