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

Use S/MIME if S/MIME only is possible and S/MIME is preferred

Previously, OpenPGP was used if OpenPGP only and S/MIME only were both
possible regardless of the preferred protocol.

GnuPG-bug-id: 5283
parent c5f0aa65
......@@ -87,7 +87,7 @@ private Q_SLOTS:
}
}
void test_openpgp_is_preferred_if_openpgp_only_and_smime_only_are_both_possible()
void test_openpgp_is_used_if_openpgp_only_and_smime_only_are_both_possible()
{
KeyResolver resolver(/*encrypt=*/ true, /*sign=*/ true);
resolver.setSender(QStringLiteral("sender-mixed@example.net"));
......@@ -103,6 +103,40 @@ private Q_SLOTS:
QCOMPARE(resolver.encryptionKeys().value(CMS).size(), 0);
}
void test_openpgp_is_used_if_openpgp_only_and_smime_only_are_both_possible_with_preference_for_openpgp()
{
KeyResolver resolver(/*encrypt=*/ true, /*sign=*/ true);
resolver.setPreferredProtocol(OpenPGP);
resolver.setSender(QStringLiteral("sender-mixed@example.net"));
spyOnKeysResolvedSignal(&resolver);
resolver.start(/*showApproval=*/ false);
verifyKeysResolvedSignalEmittedWith(/*success=*/ true, /*sendUnencrypted=*/ false);
QCOMPARE(resolver.signingKeys().value(OpenPGP).size(), 1);
QCOMPARE(resolver.signingKeys().value(CMS).size(), 0);
QCOMPARE(resolver.encryptionKeys().value(OpenPGP).size(), 1);
QCOMPARE(resolver.encryptionKeys().value(OpenPGP).value("sender-mixed@example.net").size(), 1);
QCOMPARE(resolver.encryptionKeys().value(CMS).size(), 0);
}
void test_smime_is_used_if_openpgp_only_and_smime_only_are_both_possible_with_preference_for_smime()
{
KeyResolver resolver(/*encrypt=*/ true, /*sign=*/ true);
resolver.setPreferredProtocol(CMS);
resolver.setSender(QStringLiteral("sender-mixed@example.net"));
spyOnKeysResolvedSignal(&resolver);
resolver.start(/*showApproval=*/ false);
verifyKeysResolvedSignalEmittedWith(/*success=*/ true, /*sendUnencrypted=*/ false);
QCOMPARE(resolver.signingKeys().value(OpenPGP).size(), 0);
QCOMPARE(resolver.signingKeys().value(CMS).size(), 1);
QCOMPARE(resolver.encryptionKeys().value(OpenPGP).size(), 0);
QCOMPARE(resolver.encryptionKeys().value(CMS).size(), 1);
QCOMPARE(resolver.encryptionKeys().value(CMS).value("sender-mixed@example.net").size(), 1);
}
void spyOnKeysResolvedSignal(KeyResolver *resolver)
{
mKeysResolvedSpy = std::make_unique<QSignalSpy>(resolver, &KeyResolver::keysResolved);
......
......@@ -493,7 +493,15 @@ void KeyResolver::start(bool showApproval, QWidget *parentWidget)
}
if (!needsUser && !showApproval) {
if (pgpOnly) {
if (pgpOnly && cmsOnly) {
if (d->mPreferredProtocol == CMS) {
d->mSigKeys.remove(OpenPGP);
d->mEncKeys.remove(OpenPGP);
} else {
d->mSigKeys.remove(CMS);
d->mEncKeys.remove(CMS);
}
} else if (pgpOnly) {
d->mSigKeys.remove(CMS);
d->mEncKeys.remove(CMS);
} else if (cmsOnly) {
......
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