Skip to content

Commit

Permalink
Enforce that group/entry uuid is set when writing a database.
Browse files Browse the repository at this point in the history
  • Loading branch information
debfx committed Dec 27, 2011
1 parent 4ebcd53 commit bce46c5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/format/KeePass2XmlWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions tests/TestGroupModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions tests/TestKeePass2Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions tests/TestKeePass2XmlReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bce46c5

Please sign in to comment.