Enforce that group/entry uuid is set when writing a database.

This commit is contained in:
Felix Geyer 2011-12-27 15:47:06 +01:00
parent 4ebcd53801
commit bce46c5ece
5 changed files with 15 additions and 0 deletions

View File

@ -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;

View File

@ -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());

View File

@ -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>("QModelIndex");
Crypto::init();
}
void TestGroupModel::test()

View File

@ -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()

View File

@ -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);