mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-11 15:29:51 -05:00
Enforce that group/entry uuid is set when writing a database.
This commit is contained in:
parent
4ebcd53801
commit
bce46c5ece
@ -29,6 +29,7 @@ Database::Database()
|
|||||||
{
|
{
|
||||||
m_metadata = new Metadata(this);
|
m_metadata = new Metadata(this);
|
||||||
setRootGroup(new Group());
|
setRootGroup(new Group());
|
||||||
|
rootGroup()->setUuid(Uuid::random());
|
||||||
|
|
||||||
m_cipher = KeePass2::CIPHER_AES;
|
m_cipher = KeePass2::CIPHER_AES;
|
||||||
m_compressionAlgo = CompressionGZip;
|
m_compressionAlgo = CompressionGZip;
|
||||||
|
@ -169,6 +169,8 @@ void KeePass2XmlWriter::writeRoot()
|
|||||||
|
|
||||||
void KeePass2XmlWriter::writeGroup(const Group* group)
|
void KeePass2XmlWriter::writeGroup(const Group* group)
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(!group->uuid().isNull());
|
||||||
|
|
||||||
m_xml.writeStartElement("Group");
|
m_xml.writeStartElement("Group");
|
||||||
|
|
||||||
writeUuid("UUID", group->uuid());
|
writeUuid("UUID", group->uuid());
|
||||||
@ -237,6 +239,8 @@ void KeePass2XmlWriter::writeDeletedObject(const DeletedObject& delObj)
|
|||||||
|
|
||||||
void KeePass2XmlWriter::writeEntry(const Entry* entry)
|
void KeePass2XmlWriter::writeEntry(const Entry* entry)
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(!entry->uuid().isNull());
|
||||||
|
|
||||||
m_xml.writeStartElement("Entry");
|
m_xml.writeStartElement("Entry");
|
||||||
|
|
||||||
writeUuid("UUID", entry->uuid());
|
writeUuid("UUID", entry->uuid());
|
||||||
|
@ -23,11 +23,13 @@
|
|||||||
#include "modeltest.h"
|
#include "modeltest.h"
|
||||||
#include "core/Database.h"
|
#include "core/Database.h"
|
||||||
#include "core/Group.h"
|
#include "core/Group.h"
|
||||||
|
#include "crypto/Crypto.h"
|
||||||
#include "gui/GroupModel.h"
|
#include "gui/GroupModel.h"
|
||||||
|
|
||||||
void TestGroupModel::initTestCase()
|
void TestGroupModel::initTestCase()
|
||||||
{
|
{
|
||||||
qRegisterMetaType<QModelIndex>("QModelIndex");
|
qRegisterMetaType<QModelIndex>("QModelIndex");
|
||||||
|
Crypto::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestGroupModel::test()
|
void TestGroupModel::test()
|
||||||
|
@ -45,6 +45,10 @@ void TestKeePass2Writer::initTestCase()
|
|||||||
entry->addAttribute("test", "protectedTest", true);
|
entry->addAttribute("test", "protectedTest", true);
|
||||||
QVERIFY(entry->isAttributeProtected("test"));
|
QVERIFY(entry->isAttributeProtected("test"));
|
||||||
entry->setGroup(group);
|
entry->setGroup(group);
|
||||||
|
Group* groupNew = new Group();
|
||||||
|
groupNew->setUuid(Uuid::random());
|
||||||
|
groupNew->setName("TESTGROUP");
|
||||||
|
groupNew->setParent(group);
|
||||||
|
|
||||||
QBuffer buffer;
|
QBuffer buffer;
|
||||||
buffer.open(QBuffer::ReadWrite);
|
buffer.open(QBuffer::ReadWrite);
|
||||||
@ -63,6 +67,7 @@ void TestKeePass2Writer::testBasic()
|
|||||||
{
|
{
|
||||||
QCOMPARE(m_dbTest->metadata()->name(), m_dbOrg->metadata()->name());
|
QCOMPARE(m_dbTest->metadata()->name(), m_dbOrg->metadata()->name());
|
||||||
QVERIFY(m_dbTest->rootGroup());
|
QVERIFY(m_dbTest->rootGroup());
|
||||||
|
QCOMPARE(m_dbTest->rootGroup()->children()[0]->name(), m_dbOrg->rootGroup()->children()[0]->name());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestKeePass2Writer::testProtectedAttributes()
|
void TestKeePass2Writer::testProtectedAttributes()
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "core/Database.h"
|
#include "core/Database.h"
|
||||||
#include "core/Group.h"
|
#include "core/Group.h"
|
||||||
#include "core/Metadata.h"
|
#include "core/Metadata.h"
|
||||||
|
#include "crypto/Crypto.h"
|
||||||
#include "format/KeePass2XmlReader.h"
|
#include "format/KeePass2XmlReader.h"
|
||||||
#include "config-keepassx-tests.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()
|
void TestKeePass2XmlReader::initTestCase()
|
||||||
{
|
{
|
||||||
|
Crypto::init();
|
||||||
|
|
||||||
KeePass2XmlReader* reader = new KeePass2XmlReader();
|
KeePass2XmlReader* reader = new KeePass2XmlReader();
|
||||||
QString xmlFile = QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.xml");
|
QString xmlFile = QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.xml");
|
||||||
m_db = reader->readDatabase(xmlFile);
|
m_db = reader->readDatabase(xmlFile);
|
||||||
|
Loading…
Reference in New Issue
Block a user