aboutsummaryrefslogtreecommitdiffstats
path: root/lang/qt/tests
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2023-08-23 10:00:26 +0000
committerIngo Klöcker <[email protected]>2023-08-23 10:00:26 +0000
commit3f297387bf401475385c458e4d1d95b3eefaf3d8 (patch)
tree84c417987274d7a78a3579e6bf8e46b6bdbb0c46 /lang/qt/tests
parentqt,tests: Fix build in source directory, part 2 (diff)
downloadgpgme-3f297387bf401475385c458e4d1d95b3eefaf3d8.tar.gz
gpgme-3f297387bf401475385c458e4d1d95b3eefaf3d8.zip
qt: Allow specifying user IDs to use when refreshing keys via WKD
* lang/qt/src/wkdrefreshjob.h, lang/qt/src/wkdrefreshjob.cpp (WKDRefreshJob::start): New overload. * lang/qt/src/wkdrefreshjob_p.h (WKDRefreshJobPrivate): Add field m_userIds. * lang/qt/src/qgpgmewkdrefreshjob.cpp (toEmailAddresses): New. (locate_external_keys): Change return type and arguments. (refresh_keys): Remove. (QGpgMEWKDRefreshJobPrivate::startIt): Get emails from keys or user IDs. Remove duplicates. Call locate_external_keys instead of refresh_keys. * lang/qt/tests/run-wkdrefreshjob.cpp (CommandLineOptions, parseCommandLine): New. (main): Support new option --all-userids. -- The new start() overload allows to specify the user IDs to use for the WKD lookup explicitly. This allows updating user IDs via WKD which were originally not retrieved via WKD. GnuPG-bug-id: 6672
Diffstat (limited to 'lang/qt/tests')
-rw-r--r--lang/qt/tests/run-wkdrefreshjob.cpp52
1 files changed, 42 insertions, 10 deletions
diff --git a/lang/qt/tests/run-wkdrefreshjob.cpp b/lang/qt/tests/run-wkdrefreshjob.cpp
index 757ee899..c75718e6 100644
--- a/lang/qt/tests/run-wkdrefreshjob.cpp
+++ b/lang/qt/tests/run-wkdrefreshjob.cpp
@@ -38,6 +38,7 @@
#include <protocol.h>
#include <wkdrefreshjob.h>
+#include <QCommandLineParser>
#include <QCoreApplication>
#include <QDebug>
@@ -53,6 +54,36 @@ std::ostream &operator<<(std::ostream &os, const QString &s)
return os << s.toLocal8Bit().constData();
}
+struct CommandLineOptions {
+ bool allUserIds;
+ QString keyId;
+};
+
+CommandLineOptions parseCommandLine(const QStringList &arguments)
+{
+ CommandLineOptions options;
+
+ QCommandLineParser parser;
+ parser.setApplicationDescription("Test program for WKDRefreshJob");
+ parser.addHelpOption();
+ parser.addOptions({
+ {"all-userids", "Query WKD for all user IDs."},
+ });
+ parser.addPositionalArgument("key ID", "Key to refresh");
+
+ parser.process(arguments);
+
+ const auto args = parser.positionalArguments();
+ if (args.size() != 1) {
+ parser.showHelp(1);
+ }
+
+ options.allUserIds = parser.isSet("all-userids");
+ options.keyId = args[0];
+
+ return options;
+}
+
Key getOpenPGPKey(const QString &keyId, Error &err)
{
Key key;
@@ -74,22 +105,19 @@ int main(int argc, char **argv)
{
GpgME::initializeLibrary();
- if (argc != 2) {
- std::cerr << "Usage: " << argv[0] << " KEYID" << std::endl;
- return 1;
- }
-
QCoreApplication app{argc, argv};
- const auto keyId = qApp->arguments().last();
+ app.setApplicationName("run-wkdrefreshjob");
+
+ const auto options = parseCommandLine(app.arguments());
Error err;
- const auto key = getOpenPGPKey(keyId, err);
+ const auto key = getOpenPGPKey(options.keyId, err);
if (err.code() == GPG_ERR_AMBIGUOUS_NAME) {
- std::cerr << "Error: Multiple OpenPGP keys matching '" << keyId << "' found" << std::endl;
+ std::cerr << "Error: Multiple OpenPGP keys matching '" << options.keyId << "' found" << std::endl;
return 1;
}
if (key.isNull()) {
- std::cerr << "Error: No OpenPGP key matching '" << keyId << "' found" << std::endl;
+ std::cerr << "Error: No OpenPGP key matching '" << options.keyId << "' found" << std::endl;
return 1;
}
if (err) {
@@ -111,7 +139,11 @@ int main(int argc, char **argv)
}
qApp->quit();
});
- err = job->start({key});
+ if (options.allUserIds) {
+ err = job->start(key.userIDs());
+ } else {
+ err = job->start({key});
+ }
if (err) {
std::cerr << "Error: " << err.asString() << std::endl;
return 1;