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

Add autotest for KeyParameters

GnuPG-bug-id: 5832
parent 01e7fda1
Pipeline #183558 passed with stage
in 2 minutes and 49 seconds
......@@ -29,3 +29,11 @@ ecm_add_test(
TEST_NAME stripsuffixtest
LINK_LIBRARIES KF5::I18n KF5::Libkleo Qt${QT_MAJOR_VERSION}::Test
)
ecm_add_test(
keyparameterstest.cpp
${CMAKE_SOURCE_DIR}/src/utils/keyparameters.cpp
${logging_category_srcs}
TEST_NAME keyparameterstest
LINK_LIBRARIES Gpgmepp Qt${QT_MAJOR_VERSION}::Test
)
/* -*- mode: c++; c-basic-offset:4 -*-
autotests/keyparameterstest.cpp
This file is part of Kleopatra's test suite.
SPDX-FileCopyrightText: 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "utils/keyparameters.h"
#include "utils/keyusage.h"
#include <QDate>
#include <QTest>
#include <gpgme++/key.h>
using namespace Kleo;
class KeyParametersTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void test_OpenPGP_key()
{
KeyParameters params{KeyParameters::OpenPGP};
params.setName(QStringLiteral("Ada Lovelace"));
params.setEmail(QStringLiteral("ada.lovelace@example.net"));
params.setKeyType(GpgME::Subkey::AlgoEDDSA);
params.setKeyCurve(QStringLiteral("ed25519"));
params.setKeyUsage(KeyUsage{KeyUsage::Sign | KeyUsage::Authenticate});
params.setSubkeyType(GpgME::Subkey::AlgoECDH);
params.setSubkeyCurve(QStringLiteral("cv25519"));
params.setSubkeyUsage(KeyUsage{KeyUsage::Encrypt});
params.setExpirationDate(QDate{2024, 12, 10});
QCOMPARE(params.toString(),
QStringLiteral("<GnupgKeyParms format=\"internal\">\n"
"%ask-passphrase\n"
"Key-Type:EdDSA\n"
"Key-Curve:ed25519\n"
"Key-Usage:sign auth\n"
"Subkey-Type:ECDH\n"
"Subkey-Usage:encrypt\n"
"Subkey-Curve:cv25519\n"
"Expire-Date:2024-12-10\n"
"Name-Real:Ada Lovelace\n"
"Name-Email:ada.lovelace@example.net\n"
"</GnupgKeyParms>"));
}
void test_SMIME_CSR()
{
KeyParameters params{KeyParameters::CMS};
params.setDN(QStringLiteral("CN=Ada Lovelace,L=London,C=UK"));
params.setEmail(QStringLiteral("ada.lovelace@example.net"));
params.addEmail(QStringLiteral(u"ada@t\u00E4st.example.org"));
params.setKeyType(GpgME::Subkey::AlgoRSA);
params.setKeyLength(3072);
params.setKeyUsage(KeyUsage{KeyUsage::Sign | KeyUsage::Encrypt});
params.addDomainName(QStringLiteral("ada.example.net"));
params.addDomainName(QStringLiteral(u"t\u00E4st.example.org"));
params.addURI(QStringLiteral("https://ada.example.net"));
params.addURI(QStringLiteral("https://lovelace.example.org"));
QCOMPARE(params.toString(),
QStringLiteral("<GnupgKeyParms format=\"internal\">\n"
"Key-Type:RSA\n"
"Key-Length:3072\n"
"Key-Usage:sign encrypt\n"
"Name-DN:CN=Ada Lovelace,L=London,C=UK\n"
"Name-Email:ada.lovelace@example.net\n"
"Name-Email:ada@xn--tst-qla.example.org\n"
"Name-DNS:ada.example.net\n"
"Name-DNS:xn--tst-qla.example.org\n"
"Name-URI:https://ada.example.net\n"
"Name-URI:https://lovelace.example.org\n"
"</GnupgKeyParms>"));
}
void test_SMIME_CSR_for_card_key()
{
KeyParameters params{KeyParameters::CMS};
params.setDN(QStringLiteral("CN=Ada Lovelace,L=London,C=UK"));
params.setEmail(QStringLiteral("ada@example.net"));
params.setCardKeyRef(QStringLiteral("OPENPGP.1"));
params.setKeyUsage(KeyUsage{KeyUsage::Sign});
QCOMPARE(params.toString(),
QStringLiteral("<GnupgKeyParms format=\"internal\">\n"
"Key-Type:card:OPENPGP.1\n"
"Key-Usage:sign\n"
"Name-DN:CN=Ada Lovelace,L=London,C=UK\n"
"Name-Email:ada@example.net\n"
"</GnupgKeyParms>"));
}
};
QTEST_MAIN(KeyParametersTest)
#include "keyparameterstest.moc"
Supports Markdown
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