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

Support additional/unknown keyserver flags

This preserves keyserver flags that are not known or not handled by
KeyserverConfig, e.g. the legacy "ldaps" flag.

GnuPG-bug-id: 5465
parent 4d26770b
......@@ -255,6 +255,22 @@ private Q_SLOTS:
QVERIFY(!createdUrl.hasQuery());
QVERIFY(!createdUrl.hasFragment());
}
void test_ldap_keyserver_with_additional_flags()
{
const QUrl url{QStringLiteral("ldap://ldap.example.net#flag1,StartTLS, Flag2 ,NTDS,flag 3")};
auto config = KeyserverConfig::fromUrl(url);
QCOMPARE(config.authentication(), KeyserverAuthentication::ActiveDirectory);
QCOMPARE(config.connection(), KeyserverConnection::UseSTARTTLS);
const QStringList expectedFlags{"flag1", "flag2", "flag 3"};
QCOMPARE(config.additionalFlags(), expectedFlags);
const auto createdUrl = config.toUrl();
const auto expectedUrl = QUrl{QStringLiteral("ldap://ldap.example.net#starttls,ntds,flag1,flag2,flag 3")};
QCOMPARE(createdUrl, expectedUrl);
QVERIFY(!createdUrl.hasQuery());
QVERIFY(createdUrl.hasFragment());
}
};
QTEST_MAIN(KeyserverConfigTest)
......
......@@ -29,6 +29,7 @@ public:
QString password;
KeyserverConnection connection = KeyserverConnection::Default;
QString baseDn;
QStringList additionalFlags;
};
KeyserverConfig::Private::Private()
......@@ -80,6 +81,8 @@ KeyserverConfig KeyserverConfig::fromUrl(const QUrl &url)
config.d->connection = KeyserverConnection::Plain;
} else if (flag == QLatin1String{"ntds"}) {
config.d->authentication = KeyserverAuthentication::ActiveDirectory;
} else {
config.d->additionalFlags.push_back(flag);
}
}
}
......@@ -127,6 +130,7 @@ QUrl KeyserverConfig::toUrl() const
if (d->authentication == KeyserverAuthentication::ActiveDirectory) {
flags.push_back(QStringLiteral("ntds"));
}
std::copy(std::cbegin(d->additionalFlags), std::cend(d->additionalFlags), std::back_inserter(flags));
if (!flags.isEmpty()) {
url.setFragment(flags.join(QLatin1Char{','}));
}
......@@ -203,3 +207,13 @@ void KeyserverConfig::setLdapBaseDn(const QString &baseDn)
{
d->baseDn = baseDn;
}
QStringList KeyserverConfig::additionalFlags() const
{
return d->additionalFlags;
}
void KeyserverConfig::setAdditionalFlags(const QStringList &flags)
{
d->additionalFlags = flags;
}
......@@ -15,6 +15,7 @@
#include <memory>
class QString;
class QStringList;
class QUrl;
namespace Kleo
......@@ -69,6 +70,9 @@ public:
QString ldapBaseDn() const;
void setLdapBaseDn(const QString &baseDn);
QStringList additionalFlags() const;
void setAdditionalFlags(const QStringList &flags);
private:
class Private;
std::unique_ptr<Private> d;
......
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