From 7f089165e3ae42274e75e0e6fa1c45ca641f4023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Wed, 30 Mar 2022 12:25:53 +0200 Subject: qt: Check arguments passed to the revoke key job * lang/qt/src/qgpgmerevokekeyjob.cpp (check_arguments): New. (QGpgMERevokeKeyJob::start, QGpgMERevokeKeyJob::exec): Call check_arguments. * lang/qt/tests/t-revokekey.cpp (RevokeKeyJobTest): Add member functions testErrorHandling_nullKey, testErrorHandling_invalidReason, testErrorHandling_invalidDescription. -- Check that the key is not a null key, that the reason has a valid value, and that the description lines do not contain endline characters and are not empty. GnuPG-bug-id: 5904 --- lang/qt/tests/t-revokekey.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'lang/qt/tests/t-revokekey.cpp') diff --git a/lang/qt/tests/t-revokekey.cpp b/lang/qt/tests/t-revokekey.cpp index 6586f093..9aec5753 100644 --- a/lang/qt/tests/t-revokekey.cpp +++ b/lang/qt/tests/t-revokekey.cpp @@ -39,6 +39,7 @@ #include #include +#include #include #include @@ -196,6 +197,66 @@ private Q_SLOTS: "0000 1111 2222 3333 4444 5555 6666 7777 8888 9999."}); } + void testErrorHandling_nullKey() + { + { + auto job = std::unique_ptr{openpgp()->revokeKeyJob()}; + QTest::ignoreMessage(QtWarningMsg, "Error: Key is null key"); + const auto result = job->exec(Key{}); + QVERIFY(result.code() == GPG_ERR_INV_ARG); + } + { + auto job = std::unique_ptr{openpgp()->revokeKeyJob()}; + QTest::ignoreMessage(QtWarningMsg, "Error: Key is null key"); + const auto result = job->start(Key{}); + QVERIFY(result.code() == GPG_ERR_INV_ARG); + } + } + + void testErrorHandling_invalidReason() + { + // Get the key that shall be revoked + auto key = getTestKey("revoke-me@example.net"); + QVERIFY(!key.isNull()); + QVERIFY(!key.isRevoked()); + + { + auto job = std::unique_ptr{openpgp()->revokeKeyJob()}; + QTest::ignoreMessage(QtWarningMsg, QRegularExpression{"^Error: Invalid revocation reason"}); + const auto result = job->exec(key, static_cast(-1)); + QVERIFY(result.code() == GPG_ERR_INV_VALUE); + } + { + auto job = std::unique_ptr{openpgp()->revokeKeyJob()}; + QTest::ignoreMessage(QtWarningMsg, QRegularExpression{"^Error: Invalid revocation reason"}); + const auto result = job->start(key, static_cast(4)); + QVERIFY(result.code() == GPG_ERR_INV_VALUE); + } + } + + void testErrorHandling_invalidDescription() + { + // Get the key that shall be revoked + auto key = getTestKey("revoke-me@example.net"); + QVERIFY(!key.isNull()); + QVERIFY(!key.isRevoked()); + + { + auto job = std::unique_ptr{openpgp()->revokeKeyJob()}; + QTest::ignoreMessage(QtWarningMsg, "Error: Revocation description contains empty lines or lines with endline characters"); + const auto result = job->exec(key, RevocationReason::Unspecified, + {"line1", "", "line3"}); + QVERIFY(result.code() == GPG_ERR_INV_VALUE); + } + { + auto job = std::unique_ptr{openpgp()->revokeKeyJob()}; + QTest::ignoreMessage(QtWarningMsg, "Error: Revocation description contains empty lines or lines with endline characters"); + const auto result = job->start(key, RevocationReason::Unspecified, + {"line1\nline2"}); + QVERIFY(result.code() == GPG_ERR_INV_VALUE); + } + } + private: Key getTestKey(const char *pattern) { -- cgit v1.2.3