mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-24 06:49:46 -05:00
Add tests for broken databases.
Make sure we detect the error and don't crash.
This commit is contained in:
parent
e16720d06d
commit
f1bebe904a
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include "TestKeePass2XmlReader.h"
|
#include "TestKeePass2XmlReader.h"
|
||||||
|
|
||||||
|
#include <QtCore/QFile>
|
||||||
#include <QtTest/QTest>
|
#include <QtTest/QTest>
|
||||||
|
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
@ -351,6 +352,26 @@ void TestKeePass2XmlReader::testDeletedObjects()
|
|||||||
QVERIFY(objList.isEmpty());
|
QVERIFY(objList.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestKeePass2XmlReader::testBroken()
|
||||||
|
{
|
||||||
|
QFETCH(QString, baseName);
|
||||||
|
|
||||||
|
KeePass2XmlReader reader;
|
||||||
|
QString xmlFile = QString("%1/%2.xml").arg(KEEPASSX_TEST_DATA_DIR, baseName);
|
||||||
|
QVERIFY(QFile::exists(xmlFile));
|
||||||
|
QScopedPointer<Database> db(reader.readDatabase(xmlFile));
|
||||||
|
QVERIFY(reader.hasError());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestKeePass2XmlReader::testBroken_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QString>("baseName");
|
||||||
|
|
||||||
|
QTest::newRow("BrokenNoGroupUuid") << "BrokenNoGroupUuid";
|
||||||
|
QTest::newRow("BrokenNoEntryUuid") << "BrokenNoEntryUuid";
|
||||||
|
QTest::newRow("BrokenNoRootGroup") << "BrokenNoRootGroup";
|
||||||
|
}
|
||||||
|
|
||||||
void TestKeePass2XmlReader::cleanupTestCase()
|
void TestKeePass2XmlReader::cleanupTestCase()
|
||||||
{
|
{
|
||||||
delete m_db;
|
delete m_db;
|
||||||
|
@ -39,6 +39,8 @@ private Q_SLOTS:
|
|||||||
void testEntry2();
|
void testEntry2();
|
||||||
void testEntryHistory();
|
void testEntryHistory();
|
||||||
void testDeletedObjects();
|
void testDeletedObjects();
|
||||||
|
void testBroken();
|
||||||
|
void testBroken_data();
|
||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
14
tests/data/BrokenNoEntryUuid.xml
Normal file
14
tests/data/BrokenNoEntryUuid.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||||
|
<KeePassFile>
|
||||||
|
<Root>
|
||||||
|
<Group>
|
||||||
|
<UUID>lmU+9n0aeESKZvcEze+bRg==</UUID>
|
||||||
|
<Name>Test</Name>
|
||||||
|
<Entry>
|
||||||
|
<String>
|
||||||
|
<Key>Title</Key>
|
||||||
|
<Value>Sample Entry 1</Value>
|
||||||
|
</String>
|
||||||
|
</Group>
|
||||||
|
</Root>
|
||||||
|
</KeePassFile>
|
8
tests/data/BrokenNoGroupUuid.xml
Normal file
8
tests/data/BrokenNoGroupUuid.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||||
|
<KeePassFile>
|
||||||
|
<Root>
|
||||||
|
<Group>
|
||||||
|
<Name>Test</Name>
|
||||||
|
</Group>
|
||||||
|
</Root>
|
||||||
|
</KeePassFile>
|
5
tests/data/BrokenNoRootGroup.xml
Normal file
5
tests/data/BrokenNoRootGroup.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||||
|
<KeePassFile>
|
||||||
|
<Root>
|
||||||
|
</Root>
|
||||||
|
</KeePassFile>
|
Loading…
Reference in New Issue
Block a user