Skip to content

Commit

Permalink
Test #287: template export/import
Browse files Browse the repository at this point in the history
Test the transport of internal name and comment during
export/import of templates.
  • Loading branch information
chris2511 committed Aug 31, 2024
1 parent 7f5bdb7 commit 14865e5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
34 changes: 33 additions & 1 deletion test/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

#include "lib/pki_multi.h"
#include "lib/db_x509.h"
#include "lib/db_temp.h"
#include "lib/pki_x509.h"
#include "lib/pki_temp.h"
#include "lib/xfile.h"
#include "lib/database_model.h"

Expand Down Expand Up @@ -96,6 +98,21 @@ void verify_file(const QString &name, QList<unsigned> hashes)
verify_key(name, hashes, false);
}

void verify_template(const QString &name)
{
pki_multi *pems = new pki_multi();
pems->probeAnything(name);
QList<pki_base *> temps = pems->pull();
QCOMPARE(temps.size(), 1);
pki_temp *temp = dynamic_cast<pki_temp*>(temps[0]);
QVERIFY(temp != nullptr);
QCOMPARE(temp->getIntName(), "My Template Internal Name");
QCOMPARE(temp->getComment(), "My XCA TEMPLATE comment");
x509name xn = temp->getSubject();
QCOMPARE(xn.getEntryByNid(NID_commonName), "CA Template");
QCOMPARE(xn.getEntryByNid(NID_pkcs9_emailAddress), "[email protected]");
}

void export_by_id(int id, const QString &name,
QModelIndexList &list, db_base *db)
{
Expand Down Expand Up @@ -135,7 +152,8 @@ void test_main::exportFormat()
pemdata["Inter CA 1 Key"] +
pemdata["Root CA"] +
pemdata["Endentity"] +
pemdata["CA CRL Test"];
pemdata["CA CRL Test"] +
pemdata["XCA Template"];

pem->fromPEMbyteArray(all.toUtf8(), QString());
QCOMPARE(pem->failed_files.count(), 0);
Expand Down Expand Up @@ -372,6 +390,20 @@ void test_main::exportFormat()
verify_key(file, QList<unsigned> { ED25519_HASH }, true);
check_pems(file, 1, QStringList{ "BEGIN ENCRYPTED PRIVATE KEY" });

// Export XCA Template and verify the internal name and comment
file = AUTOFILE(XCA_TEMPLATE)
db_base *temps = Database.model<db_temp>();
list.clear();
pki_base *temp = temps->getByName("CA Template"); // The common name
Q_ASSERT(temp != nullptr);
Q_ASSERT(temp->getComment().isEmpty());
temp->setComment("My XCA TEMPLATE comment");
temp->setIntName("My Template Internal Name");
list << temps->index(temp);
export_by_id(35, file, list, temps);
verify_template(file);
check_pems(file, 1, QStringList{ "BEGIN XCA TEMPLATE" });

} catch (...) {
QString m = QString("Exception thrown L %1").arg(l);
QVERIFY2(false, m.toUtf8().constData());
Expand Down
23 changes: 23 additions & 0 deletions test/pem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,28 @@ o5ddfKnVVLLfaf7uf1IvCsouRYr2Eo7WklH2UCOvffXoK6DwZAQ4pA9f8shI08b/
UDcS3B0AFHkYZOFWmpBL
-----END CERTIFICATE-----
)PEM"
},
{ "XCA Template", R"PEM(
-----BEGIN XCA TEMPLATE-----
AAADQgAAAAowNjEUMBIGA1UEAxMLQ0EgVGVtcGxhdGUxHjAcBgkqhkiG9w0BCQEW
D21haWxAYWRkcmVzcy50bwAAABsAAAAUAE8AQwBTAFAAcwB0AGEAcABsAGUAAAAC
ADAAAAAOAGEAZAB2AF8AZQB4AHQAAAAAAAAAFABhAHUAdABoAEkAbgBmAEEAYwBj
AAAAAAAAAA4AYQB1AHQAaABLAGUAeQAAAAIAMAAAABIAYgBhAHMAaQBjAFAAYQB0
AGgAAAAAAAAAFABiAGMAQwByAGkAdABpAGMAYQBsAAAAAgAxAAAABABjAGEAAAAC
ADEAAAAOAGMAcgBsAEQAaQBzAHQAAAAAAAAADgBlAEsAZQB5AFUAcwBl/////wAA
ABYAZQBrAHUAQwByAGkAdABpAGMAYQBsAAAAAgAwAAAAFABpAHMAcwBBAGwAdABO
AGEAbQBlAAAAAAAAAAwAawBlAHkAVQBzAGUAAAAEADkANgAAABQAawB1AEMAcgBp
AHQAaQBjAGEAbAAAAAIAMAAAACgAbgBvAFcAZQBsAGwARABlAGYAaQBuAGUAZABF
AHgAcABEAG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