diff --git a/src/core/Database.cpp b/src/core/Database.cpp index 20fe8cbc7..6595cf83d 100644 --- a/src/core/Database.cpp +++ b/src/core/Database.cpp @@ -29,6 +29,7 @@ Database::Database() { m_metadata = new Metadata(this); setRootGroup(new Group()); + rootGroup()->setUuid(Uuid::random()); m_cipher = KeePass2::CIPHER_AES; m_compressionAlgo = CompressionGZip; diff --git a/src/format/KeePass2XmlWriter.cpp b/src/format/KeePass2XmlWriter.cpp index e7a3938c3..e95d70fa3 100644 --- a/src/format/KeePass2XmlWriter.cpp +++ b/src/format/KeePass2XmlWriter.cpp @@ -169,6 +169,8 @@ void KeePass2XmlWriter::writeRoot() void KeePass2XmlWriter::writeGroup(const Group* group) { + Q_ASSERT(!group->uuid().isNull()); + m_xml.writeStartElement("Group"); writeUuid("UUID", group->uuid()); @@ -237,6 +239,8 @@ void KeePass2XmlWriter::writeDeletedObject(const DeletedObject& delObj) void KeePass2XmlWriter::writeEntry(const Entry* entry) { + Q_ASSERT(!entry->uuid().isNull()); + m_xml.writeStartElement("Entry"); writeUuid("UUID", entry->uuid()); diff --git a/tests/TestGroupModel.cpp b/tests/TestGroupModel.cpp index 1b9a89843..70a6e4c66 100644 --- a/tests/TestGroupModel.cpp +++ b/tests/TestGroupModel.cpp @@ -23,11 +23,13 @@ #include "modeltest.h" #include "core/Database.h" #include "core/Group.h" +#include "crypto/Crypto.h" #include "gui/GroupModel.h" void TestGroupModel::initTestCase() { qRegisterMetaType("QModelIndex"); + Crypto::init(); } void TestGroupModel::test() diff --git a/tests/TestKeePass2Writer.cpp b/tests/TestKeePass2Writer.cpp index 6955ba5c4..87ea72527 100644 --- a/tests/TestKeePass2Writer.cpp +++ b/tests/TestKeePass2Writer.cpp @@ -45,6 +45,10 @@ void TestKeePass2Writer::initTestCase() entry->addAttribute("test", "protectedTest", true); QVERIFY(entry->isAttributeProtected("test")); entry->setGroup(group); + Group* groupNew = new Group(); + groupNew->setUuid(Uuid::random()); + groupNew->setName("TESTGROUP"); + groupNew->setParent(group); QBuffer buffer; buffer.open(QBuffer::ReadWrite); @@ -63,6 +67,7 @@ void TestKeePass2Writer::testBasic() { QCOMPARE(m_dbTest->metadata()->name(), m_dbOrg->metadata()->name()); QVERIFY(m_dbTest->rootGroup()); + QCOMPARE(m_dbTest->rootGroup()->children()[0]->name(), m_dbOrg->rootGroup()->children()[0]->name()); } void TestKeePass2Writer::testProtectedAttributes() diff --git a/tests/TestKeePass2XmlReader.cpp b/tests/TestKeePass2XmlReader.cpp index daf6cf390..c63f1253f 100644 --- a/tests/TestKeePass2XmlReader.cpp +++ b/tests/TestKeePass2XmlReader.cpp @@ -22,6 +22,7 @@ #include "core/Database.h" #include "core/Group.h" #include "core/Metadata.h" +#include "crypto/Crypto.h" #include "format/KeePass2XmlReader.h" #include "config-keepassx-tests.h" @@ -63,6 +64,8 @@ QDateTime TestKeePass2XmlReader::genDT(int year, int month, int day, int hour, i void TestKeePass2XmlReader::initTestCase() { + Crypto::init(); + KeePass2XmlReader* reader = new KeePass2XmlReader(); QString xmlFile = QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.xml"); m_db = reader->readDatabase(xmlFile);