2010-08-13 12:08:06 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-11-21 17:06:30 -05:00
|
|
|
#include "TestKeePass2XmlReader.h"
|
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
#include <QtTest/QTest>
|
|
|
|
|
2012-01-01 16:04:27 -05:00
|
|
|
#include "tests.h"
|
2010-08-13 12:08:06 -04:00
|
|
|
#include "core/Database.h"
|
2011-07-08 07:57:02 -04:00
|
|
|
#include "core/Group.h"
|
2010-08-13 12:08:06 -04:00
|
|
|
#include "core/Metadata.h"
|
2011-12-27 09:47:06 -05:00
|
|
|
#include "crypto/Crypto.h"
|
2010-08-31 08:39:35 -04:00
|
|
|
#include "format/KeePass2XmlReader.h"
|
2010-08-13 12:08:06 -04:00
|
|
|
#include "config-keepassx-tests.h"
|
|
|
|
|
2010-08-25 15:14:41 -04:00
|
|
|
namespace QTest {
|
|
|
|
template<>
|
2012-05-15 11:48:48 -04:00
|
|
|
char* toString(const Uuid& uuid)
|
2010-08-25 15:14:41 -04:00
|
|
|
{
|
|
|
|
QByteArray ba = "Uuid(";
|
2012-04-21 18:55:52 -04:00
|
|
|
ba += uuid.toBase64().toAscii().constData();
|
2010-08-25 15:14:41 -04:00
|
|
|
ba += ")";
|
2012-05-15 11:48:48 -04:00
|
|
|
return qstrdup(ba.constData());
|
2010-08-25 15:14:41 -04:00
|
|
|
}
|
2011-07-07 06:45:14 -04:00
|
|
|
|
|
|
|
template<>
|
2012-05-15 11:48:48 -04:00
|
|
|
char* toString(const Group::TriState& triState)
|
2011-07-07 06:45:14 -04:00
|
|
|
{
|
|
|
|
QString value;
|
|
|
|
|
|
|
|
if (triState == Group::Inherit) {
|
|
|
|
value = "null";
|
|
|
|
}
|
|
|
|
else if (triState == Group::Enable) {
|
|
|
|
value = "true";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
value = "false";
|
|
|
|
}
|
|
|
|
|
|
|
|
return qstrdup(value.toLocal8Bit().constData());
|
|
|
|
}
|
2010-08-25 15:14:41 -04:00
|
|
|
}
|
|
|
|
|
2010-09-19 18:15:32 -04:00
|
|
|
QDateTime TestKeePass2XmlReader::genDT(int year, int month, int day, int hour, int min, int second)
|
2010-08-13 12:08:06 -04:00
|
|
|
{
|
|
|
|
QDate date(year, month, day);
|
|
|
|
QTime time(hour, min, second);
|
|
|
|
return QDateTime(date, time, Qt::UTC);
|
|
|
|
}
|
|
|
|
|
2010-09-19 18:15:32 -04:00
|
|
|
void TestKeePass2XmlReader::initTestCase()
|
2010-08-13 12:08:06 -04:00
|
|
|
{
|
2011-12-27 09:47:06 -05:00
|
|
|
Crypto::init();
|
|
|
|
|
2012-04-22 17:09:52 -04:00
|
|
|
KeePass2XmlReader reader;
|
2011-11-20 05:10:01 -05:00
|
|
|
QString xmlFile = QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.xml");
|
2012-04-22 17:09:52 -04:00
|
|
|
m_db = reader.readDatabase(xmlFile);
|
2010-09-19 18:15:32 -04:00
|
|
|
QVERIFY(m_db);
|
2012-04-22 17:09:52 -04:00
|
|
|
QVERIFY(!reader.hasError());
|
2010-08-13 12:08:06 -04:00
|
|
|
}
|
|
|
|
|
2010-09-19 18:15:32 -04:00
|
|
|
void TestKeePass2XmlReader::testMetadata()
|
2010-08-13 12:08:06 -04:00
|
|
|
{
|
2010-08-18 05:05:46 -04:00
|
|
|
QCOMPARE(m_db->metadata()->generator(), QString("KeePass"));
|
|
|
|
QCOMPARE(m_db->metadata()->name(), QString("ANAME"));
|
2010-08-13 12:08:06 -04:00
|
|
|
QCOMPARE(m_db->metadata()->nameChanged(), genDT(2010, 8, 8, 17, 24, 53));
|
2010-08-18 05:05:46 -04:00
|
|
|
QCOMPARE(m_db->metadata()->description(), QString("ADESC"));
|
2010-08-13 12:08:06 -04:00
|
|
|
QCOMPARE(m_db->metadata()->descriptionChanged(), genDT(2010, 8, 8, 17, 27, 12));
|
2010-08-18 05:05:46 -04:00
|
|
|
QCOMPARE(m_db->metadata()->defaultUserName(), QString("DEFUSERNAME"));
|
2010-08-13 12:08:06 -04:00
|
|
|
QCOMPARE(m_db->metadata()->defaultUserNameChanged(), genDT(2010, 8, 8, 17, 27, 45));
|
|
|
|
QCOMPARE(m_db->metadata()->maintenanceHistoryDays(), 127);
|
2012-04-21 10:45:46 -04:00
|
|
|
QCOMPARE(m_db->metadata()->color(), QColor(0xff, 0xef, 0x00));
|
|
|
|
QCOMPARE(m_db->metadata()->masterKeyChanged(), genDT(2012, 4, 5, 17, 9, 34));
|
|
|
|
QCOMPARE(m_db->metadata()->masterKeyChangeRec(), 101);
|
|
|
|
QCOMPARE(m_db->metadata()->masterKeyChangeForce(), -1);
|
2010-08-13 12:08:06 -04:00
|
|
|
QCOMPARE(m_db->metadata()->protectTitle(), false);
|
|
|
|
QCOMPARE(m_db->metadata()->protectUsername(), true);
|
|
|
|
QCOMPARE(m_db->metadata()->protectPassword(), false);
|
|
|
|
QCOMPARE(m_db->metadata()->protectUrl(), true);
|
|
|
|
QCOMPARE(m_db->metadata()->protectNotes(), false);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBinEnabled(), true);
|
2012-06-29 08:15:16 -04:00
|
|
|
QVERIFY(m_db->metadata()->recycleBin() != Q_NULLPTR);
|
2010-08-18 05:05:46 -04:00
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->name(), QString("Recycle Bin"));
|
2010-08-25 15:14:41 -04:00
|
|
|
QCOMPARE(m_db->metadata()->recycleBinChanged(), genDT(2010, 8, 25, 16, 12, 57));
|
2012-06-29 08:15:16 -04:00
|
|
|
QVERIFY(m_db->metadata()->entryTemplatesGroup() == Q_NULLPTR);
|
2010-08-13 12:08:06 -04:00
|
|
|
QCOMPARE(m_db->metadata()->entryTemplatesGroupChanged(), genDT(2010, 8, 8, 17, 24, 19));
|
2012-06-29 08:15:16 -04:00
|
|
|
QVERIFY(m_db->metadata()->lastSelectedGroup() != Q_NULLPTR);
|
2010-08-18 05:05:46 -04:00
|
|
|
QCOMPARE(m_db->metadata()->lastSelectedGroup()->name(), QString("NewDatabase"));
|
2010-08-14 08:26:25 -04:00
|
|
|
QVERIFY(m_db->metadata()->lastTopVisibleGroup() == m_db->metadata()->lastSelectedGroup());
|
2012-04-21 10:45:46 -04:00
|
|
|
QCOMPARE(m_db->metadata()->historyMaxItems(), -1);
|
|
|
|
QCOMPARE(m_db->metadata()->historyMaxSize(), 5242880);
|
2010-08-13 12:08:06 -04:00
|
|
|
}
|
|
|
|
|
2010-09-19 18:15:32 -04:00
|
|
|
void TestKeePass2XmlReader::testCustomIcons()
|
2010-08-25 15:14:41 -04:00
|
|
|
{
|
|
|
|
QCOMPARE(m_db->metadata()->customIcons().size(), 1);
|
|
|
|
Uuid uuid = Uuid::fromBase64("++vyI+daLk6omox4a6kQGA==");
|
|
|
|
QVERIFY(m_db->metadata()->customIcons().contains(uuid));
|
2012-01-01 15:52:54 -05:00
|
|
|
QImage icon = m_db->metadata()->customIcon(uuid);
|
|
|
|
QCOMPARE(icon.width(), 16);
|
|
|
|
QCOMPARE(icon.height(), 16);
|
|
|
|
|
2012-04-18 16:08:22 -04:00
|
|
|
for (int x = 0; x < 16; x++) {
|
|
|
|
for (int y = 0; y < 16; y++) {
|
2012-01-01 15:52:54 -05:00
|
|
|
QRgb rgb = icon.pixel(x, y);
|
2010-08-25 15:14:41 -04:00
|
|
|
QCOMPARE(qRed(rgb), 128);
|
|
|
|
QCOMPARE(qGreen(rgb), 0);
|
|
|
|
QCOMPARE(qBlue(rgb), 128);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-19 18:15:32 -04:00
|
|
|
void TestKeePass2XmlReader::testCustomData()
|
2010-08-25 18:31:07 -04:00
|
|
|
{
|
|
|
|
QHash<QString, QString> customFields = m_db->metadata()->customFields();
|
|
|
|
|
|
|
|
QCOMPARE(customFields.size(), 2);
|
|
|
|
QCOMPARE(customFields.value("A Sample Test Key"), QString("valu"));
|
|
|
|
QCOMPARE(customFields.value("custom key"), QString("blub"));
|
|
|
|
}
|
|
|
|
|
2010-09-19 18:15:32 -04:00
|
|
|
void TestKeePass2XmlReader::testGroupRoot()
|
2010-08-13 12:08:06 -04:00
|
|
|
{
|
2010-08-25 15:14:41 -04:00
|
|
|
const Group* group = m_db->rootGroup();
|
|
|
|
QVERIFY(group);
|
|
|
|
QCOMPARE(group->uuid().toBase64(), QString("lmU+9n0aeESKZvcEze+bRg=="));
|
|
|
|
QCOMPARE(group->name(), QString("NewDatabase"));
|
|
|
|
QCOMPARE(group->notes(), QString(""));
|
|
|
|
QCOMPARE(group->iconNumber(), 49);
|
|
|
|
QCOMPARE(group->iconUuid(), Uuid());
|
|
|
|
QVERIFY(group->isExpanded());
|
|
|
|
TimeInfo ti = group->timeInfo();
|
2010-08-18 05:05:46 -04:00
|
|
|
QCOMPARE(ti.lastModificationTime(), genDT(2010, 8, 8, 17, 24, 27));
|
|
|
|
QCOMPARE(ti.creationTime(), genDT(2010, 8, 7, 17, 24, 27));
|
|
|
|
QCOMPARE(ti.lastAccessTime(), genDT(2010, 8, 9, 9, 9, 44));
|
|
|
|
QCOMPARE(ti.expiryTime(), genDT(2010, 8, 8, 17, 24, 17));
|
|
|
|
QVERIFY(!ti.expires());
|
2010-08-25 15:14:41 -04:00
|
|
|
QCOMPARE(ti.usageCount(), 52);
|
2010-08-18 05:05:46 -04:00
|
|
|
QCOMPARE(ti.locationChanged(), genDT(2010, 8, 8, 17, 24, 27));
|
2010-08-25 15:14:41 -04:00
|
|
|
QCOMPARE(group->defaultAutoTypeSequence(), QString(""));
|
2011-07-07 06:45:14 -04:00
|
|
|
QCOMPARE(group->autoTypeEnabled(), Group::Inherit);
|
2012-05-13 07:33:55 -04:00
|
|
|
QCOMPARE(group->searchingEnabled(), Group::Inherit);
|
2010-08-25 15:14:41 -04:00
|
|
|
QCOMPARE(group->lastTopVisibleEntry()->uuid().toBase64(), QString("+wSUOv6qf0OzW8/ZHAs2sA=="));
|
2010-08-14 08:26:25 -04:00
|
|
|
|
2010-08-25 15:14:41 -04:00
|
|
|
QCOMPARE(group->children().size(), 3);
|
2010-08-14 08:26:25 -04:00
|
|
|
QVERIFY(m_db->metadata()->recycleBin() == m_db->rootGroup()->children().at(2));
|
2010-08-25 15:14:41 -04:00
|
|
|
|
|
|
|
QCOMPARE(group->entries().size(), 2);
|
|
|
|
}
|
|
|
|
|
2010-09-19 18:15:32 -04:00
|
|
|
void TestKeePass2XmlReader::testGroup1()
|
2010-08-25 15:14:41 -04:00
|
|
|
{
|
|
|
|
const Group* group = m_db->rootGroup()->children().at(0);
|
|
|
|
|
|
|
|
QCOMPARE(group->uuid().toBase64(), QString("AaUYVdXsI02h4T1RiAlgtg=="));
|
|
|
|
QCOMPARE(group->name(), QString("General"));
|
|
|
|
QCOMPARE(group->notes(), QString("Group Notez"));
|
|
|
|
QCOMPARE(group->iconNumber(), 48);
|
|
|
|
QCOMPARE(group->iconUuid(), Uuid());
|
|
|
|
QCOMPARE(group->isExpanded(), true);
|
|
|
|
QCOMPARE(group->defaultAutoTypeSequence(), QString("{Password}{ENTER}"));
|
2011-07-07 06:45:14 -04:00
|
|
|
QCOMPARE(group->autoTypeEnabled(), Group::Enable);
|
2012-05-13 07:33:55 -04:00
|
|
|
QCOMPARE(group->searchingEnabled(), Group::Disable);
|
2010-08-25 15:14:41 -04:00
|
|
|
QVERIFY(!group->lastTopVisibleEntry());
|
|
|
|
}
|
|
|
|
|
2010-09-19 18:15:32 -04:00
|
|
|
void TestKeePass2XmlReader::testGroup2()
|
2010-08-25 15:14:41 -04:00
|
|
|
{
|
|
|
|
const Group* group = m_db->rootGroup()->children().at(1);
|
|
|
|
|
|
|
|
QCOMPARE(group->uuid().toBase64(), QString("1h4NtL5DK0yVyvaEnN//4A=="));
|
|
|
|
QCOMPARE(group->name(), QString("Windows"));
|
|
|
|
QCOMPARE(group->isExpanded(), false);
|
|
|
|
|
|
|
|
QCOMPARE(group->children().size(), 1);
|
|
|
|
const Group* child = group->children().first();
|
|
|
|
|
|
|
|
QCOMPARE(child->uuid().toBase64(), QString("HoYE/BjLfUSW257pCHJ/eA=="));
|
|
|
|
QCOMPARE(child->name(), QString("Subsub"));
|
|
|
|
QCOMPARE(child->entries().size(), 1);
|
|
|
|
|
|
|
|
const Entry* entry = child->entries().first();
|
|
|
|
QCOMPARE(entry->uuid().toBase64(), QString("GZpdQvGXOU2kaKRL/IVAGg=="));
|
|
|
|
QCOMPARE(entry->title(), QString("Subsub Entry"));
|
|
|
|
}
|
|
|
|
|
2010-09-19 18:15:32 -04:00
|
|
|
void TestKeePass2XmlReader::testEntry1()
|
2010-08-25 15:14:41 -04:00
|
|
|
{
|
|
|
|
const Entry* entry = m_db->rootGroup()->entries().at(0);
|
|
|
|
|
|
|
|
QCOMPARE(entry->uuid().toBase64(), QString("+wSUOv6qf0OzW8/ZHAs2sA=="));
|
2012-04-21 10:45:46 -04:00
|
|
|
QCOMPARE(entry->historyItems().size(), 2);
|
2010-08-25 15:14:41 -04:00
|
|
|
QCOMPARE(entry->iconNumber(), 0);
|
|
|
|
QCOMPARE(entry->iconUuid(), Uuid());
|
|
|
|
QVERIFY(!entry->foregroundColor().isValid());
|
|
|
|
QVERIFY(!entry->backgroundColor().isValid());
|
|
|
|
QCOMPARE(entry->overrideUrl(), QString(""));
|
2012-04-21 10:45:46 -04:00
|
|
|
QCOMPARE(entry->tags(), QString("a b c"));
|
2010-08-25 15:14:41 -04:00
|
|
|
|
|
|
|
const TimeInfo ti = entry->timeInfo();
|
|
|
|
QCOMPARE(ti.lastModificationTime(), genDT(2010, 8, 25, 16, 19, 25));
|
|
|
|
QCOMPARE(ti.creationTime(), genDT(2010, 8, 25, 16, 13, 54));
|
|
|
|
QCOMPARE(ti.lastAccessTime(), genDT(2010, 8, 25, 16, 19, 25));
|
|
|
|
QCOMPARE(ti.expiryTime(), genDT(2010, 8, 25, 16, 12, 57));
|
|
|
|
QVERIFY(!ti.expires());
|
|
|
|
QCOMPARE(ti.usageCount(), 8);
|
|
|
|
QCOMPARE(ti.locationChanged(), genDT(2010, 8, 25, 16, 13, 54));
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
QList<QString> attrs = entry->attributes()->keys();
|
|
|
|
QCOMPARE(entry->attributes()->value("Notes"), QString("Notes"));
|
2012-04-21 10:45:46 -04:00
|
|
|
QVERIFY(!entry->attributes()->isProtected("Notes"));
|
2012-04-06 13:33:29 -04:00
|
|
|
QVERIFY(attrs.removeOne("Notes"));
|
2012-04-14 09:38:20 -04:00
|
|
|
QCOMPARE(entry->attributes()->value("Password"), QString("Password"));
|
2012-04-21 10:45:46 -04:00
|
|
|
QVERIFY(!entry->attributes()->isProtected("Password"));
|
2012-04-06 13:33:29 -04:00
|
|
|
QVERIFY(attrs.removeOne("Password"));
|
2012-04-14 09:38:20 -04:00
|
|
|
QCOMPARE(entry->attributes()->value("Title"), QString("Sample Entry 1"));
|
2012-04-21 10:45:46 -04:00
|
|
|
QVERIFY(!entry->attributes()->isProtected("Title"));
|
2012-04-06 13:33:29 -04:00
|
|
|
QVERIFY(attrs.removeOne("Title"));
|
2012-04-14 09:38:20 -04:00
|
|
|
QCOMPARE(entry->attributes()->value("URL"), QString(""));
|
2012-04-21 10:45:46 -04:00
|
|
|
QVERIFY(entry->attributes()->isProtected("URL"));
|
2012-04-06 13:33:29 -04:00
|
|
|
QVERIFY(attrs.removeOne("URL"));
|
2012-04-14 09:38:20 -04:00
|
|
|
QCOMPARE(entry->attributes()->value("UserName"), QString("User Name"));
|
2012-04-21 10:45:46 -04:00
|
|
|
QVERIFY(entry->attributes()->isProtected("UserName"));
|
2012-04-06 13:33:29 -04:00
|
|
|
QVERIFY(attrs.removeOne("UserName"));
|
2010-08-25 15:14:41 -04:00
|
|
|
QVERIFY(attrs.isEmpty());
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
QCOMPARE(entry->title(), entry->attributes()->value("Title"));
|
|
|
|
QCOMPARE(entry->url(), entry->attributes()->value("URL"));
|
|
|
|
QCOMPARE(entry->username(), entry->attributes()->value("UserName"));
|
|
|
|
QCOMPARE(entry->password(), entry->attributes()->value("Password"));
|
|
|
|
QCOMPARE(entry->notes(), entry->attributes()->value("Notes"));
|
2010-08-25 15:14:41 -04:00
|
|
|
|
2012-04-21 10:45:46 -04:00
|
|
|
QCOMPARE(entry->attachments()->keys().size(), 1);
|
|
|
|
QCOMPARE(entry->attachments()->value("myattach.txt"), QByteArray("abcdefghijk"));
|
|
|
|
QCOMPARE(entry->historyItems().at(0)->attachments()->keys().size(), 1);
|
|
|
|
QCOMPARE(entry->historyItems().at(0)->attachments()->value("myattach.txt"), QByteArray("0123456789"));
|
|
|
|
QCOMPARE(entry->historyItems().at(1)->attachments()->keys().size(), 1);
|
|
|
|
QCOMPARE(entry->historyItems().at(1)->attachments()->value("myattach.txt"), QByteArray("abcdefghijk"));
|
|
|
|
|
2010-08-25 15:14:41 -04:00
|
|
|
QCOMPARE(entry->autoTypeEnabled(), false);
|
|
|
|
QCOMPARE(entry->autoTypeObfuscation(), 0);
|
|
|
|
QCOMPARE(entry->defaultAutoTypeSequence(), QString(""));
|
2012-07-16 03:54:04 -04:00
|
|
|
QCOMPARE(entry->autoTypeAssociations()->size(), 1);
|
|
|
|
const AutoTypeAssociations::Association assoc1 = entry->autoTypeAssociations()->get(0);
|
2010-08-25 15:14:41 -04:00
|
|
|
QCOMPARE(assoc1.window, QString("Target Window"));
|
|
|
|
QCOMPARE(assoc1.sequence, QString(""));
|
|
|
|
}
|
|
|
|
|
2010-09-19 18:15:32 -04:00
|
|
|
void TestKeePass2XmlReader::testEntry2()
|
2010-08-25 15:14:41 -04:00
|
|
|
{
|
|
|
|
const Entry* entry = m_db->rootGroup()->entries().at(1);
|
|
|
|
|
|
|
|
QCOMPARE(entry->uuid().toBase64(), QString("4jbADG37hkiLh2O0qUdaOQ=="));
|
|
|
|
QCOMPARE(entry->iconNumber(), 0);
|
|
|
|
QCOMPARE(entry->iconUuid().toBase64(), QString("++vyI+daLk6omox4a6kQGA=="));
|
2012-05-11 06:39:06 -04:00
|
|
|
// TODO: test entry->icon()
|
2010-08-25 15:14:41 -04:00
|
|
|
QCOMPARE(entry->foregroundColor(), QColor(255, 0, 0));
|
|
|
|
QCOMPARE(entry->backgroundColor(), QColor(255, 255, 0));
|
|
|
|
QCOMPARE(entry->overrideUrl(), QString("http://override.net/"));
|
2012-04-21 10:45:46 -04:00
|
|
|
QCOMPARE(entry->tags(), QString(""));
|
2010-08-25 15:14:41 -04:00
|
|
|
|
|
|
|
const TimeInfo ti = entry->timeInfo();
|
|
|
|
QCOMPARE(ti.usageCount(), 7);
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
QList<QString> attrs = entry->attributes()->keys();
|
|
|
|
QCOMPARE(entry->attributes()->value("CustomString"), QString("isavalue"));
|
2012-04-06 13:33:29 -04:00
|
|
|
QVERIFY(attrs.removeOne("CustomString"));
|
2012-04-14 09:38:20 -04:00
|
|
|
QCOMPARE(entry->attributes()->value("Notes"), QString(""));
|
2012-04-06 13:33:29 -04:00
|
|
|
QVERIFY(attrs.removeOne("Notes"));
|
2012-04-14 09:38:20 -04:00
|
|
|
QCOMPARE(entry->attributes()->value("Password"), QString("Jer60Hz8o9XHvxBGcRqT"));
|
2012-04-06 13:33:29 -04:00
|
|
|
QVERIFY(attrs.removeOne("Password"));
|
2012-05-11 06:39:06 -04:00
|
|
|
QCOMPARE(entry->attributes()->value("Protected String"), QString("y")); // TODO: should have a protection attribute
|
2012-04-06 13:33:29 -04:00
|
|
|
QVERIFY(attrs.removeOne("Protected String"));
|
2012-04-14 09:38:20 -04:00
|
|
|
QCOMPARE(entry->attributes()->value("Title"), QString("Sample Entry 2"));
|
2012-04-06 13:33:29 -04:00
|
|
|
QVERIFY(attrs.removeOne("Title"));
|
2012-04-14 09:38:20 -04:00
|
|
|
QCOMPARE(entry->attributes()->value("URL"), QString("http://www.keepassx.org/"));
|
2012-04-06 13:33:29 -04:00
|
|
|
QVERIFY(attrs.removeOne("URL"));
|
2012-04-14 09:38:20 -04:00
|
|
|
QCOMPARE(entry->attributes()->value("UserName"), QString("notDEFUSERNAME"));
|
2012-04-06 13:33:29 -04:00
|
|
|
QVERIFY(attrs.removeOne("UserName"));
|
2010-08-25 15:14:41 -04:00
|
|
|
QVERIFY(attrs.isEmpty());
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
QCOMPARE(entry->attachments()->keys().size(), 1);
|
2012-06-24 12:23:27 -04:00
|
|
|
QCOMPARE(QString::fromAscii(entry->attachments()->value("myattach.txt")), QString("abcdefghijk"));
|
2010-08-25 15:14:41 -04:00
|
|
|
|
|
|
|
QCOMPARE(entry->autoTypeEnabled(), true);
|
|
|
|
QCOMPARE(entry->autoTypeObfuscation(), 1);
|
|
|
|
QCOMPARE(entry->defaultAutoTypeSequence(), QString("{USERNAME}{TAB}{PASSWORD}{ENTER}"));
|
2012-07-16 03:54:04 -04:00
|
|
|
QCOMPARE(entry->autoTypeAssociations()->size(), 2);
|
|
|
|
const AutoTypeAssociations::Association assoc1 = entry->autoTypeAssociations()->get(0);
|
2010-08-25 15:14:41 -04:00
|
|
|
QCOMPARE(assoc1.window, QString("Target Window"));
|
|
|
|
QCOMPARE(assoc1.sequence, QString("{Title}{UserName}"));
|
2012-07-16 03:54:04 -04:00
|
|
|
const AutoTypeAssociations::Association assoc2 = entry->autoTypeAssociations()->get(1);
|
2010-08-25 15:14:41 -04:00
|
|
|
QCOMPARE(assoc2.window, QString("Target Window 2"));
|
|
|
|
QCOMPARE(assoc2.sequence, QString("{Title}{UserName} test"));
|
|
|
|
}
|
|
|
|
|
2010-09-19 18:15:32 -04:00
|
|
|
void TestKeePass2XmlReader::testEntryHistory()
|
2010-08-25 15:14:41 -04:00
|
|
|
{
|
|
|
|
const Entry* entryMain = m_db->rootGroup()->entries().first();
|
|
|
|
QCOMPARE(entryMain->historyItems().size(), 2);
|
|
|
|
|
|
|
|
{
|
|
|
|
const Entry* entry = entryMain->historyItems().at(0);
|
|
|
|
QCOMPARE(entry->uuid(), entryMain->uuid());
|
|
|
|
QVERIFY(!entry->parent());
|
|
|
|
QCOMPARE(entry->timeInfo().lastModificationTime(), genDT(2010, 8, 25, 16, 13, 54));
|
|
|
|
QCOMPARE(entry->timeInfo().usageCount(), 3);
|
|
|
|
QCOMPARE(entry->title(), QString("Sample Entry"));
|
|
|
|
QCOMPARE(entry->url(), QString("http://www.somesite.com/"));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const Entry* entry = entryMain->historyItems().at(1);
|
|
|
|
QCOMPARE(entry->uuid(), entryMain->uuid());
|
|
|
|
QVERIFY(!entry->parent());
|
|
|
|
QCOMPARE(entry->timeInfo().lastModificationTime(), genDT(2010, 8, 25, 16, 15, 43));
|
|
|
|
QCOMPARE(entry->timeInfo().usageCount(), 7);
|
|
|
|
QCOMPARE(entry->title(), QString("Sample Entry 1"));
|
|
|
|
QCOMPARE(entry->url(), QString("http://www.somesite.com/"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-19 18:15:32 -04:00
|
|
|
void TestKeePass2XmlReader::testDeletedObjects()
|
2010-08-25 15:14:41 -04:00
|
|
|
{
|
|
|
|
QList<DeletedObject> objList = m_db->deletedObjects();
|
|
|
|
DeletedObject delObj;
|
|
|
|
|
|
|
|
delObj = objList.takeFirst();
|
|
|
|
QCOMPARE(delObj.uuid.toBase64(), QString("5K/bzWCSmkCv5OZxYl4N/w=="));
|
|
|
|
QCOMPARE(delObj.deletionTime, genDT(2010, 8, 25, 16, 14, 12));
|
|
|
|
|
|
|
|
delObj = objList.takeFirst();
|
|
|
|
QCOMPARE(delObj.uuid.toBase64(), QString("80h8uSNWgkKhKCp1TgXF7g=="));
|
|
|
|
QCOMPARE(delObj.deletionTime, genDT(2010, 8, 25, 16, 14, 14));
|
|
|
|
|
|
|
|
QVERIFY(objList.isEmpty());
|
2010-08-13 12:08:06 -04:00
|
|
|
}
|
|
|
|
|
2012-04-22 17:09:52 -04:00
|
|
|
void TestKeePass2XmlReader::cleanupTestCase()
|
|
|
|
{
|
|
|
|
delete m_db;
|
|
|
|
}
|
|
|
|
|
2012-07-23 18:07:28 -04:00
|
|
|
QTEST_GUILESS_MAIN(TestKeePass2XmlReader)
|