void TestDeletedObjects::testDatabaseChange() { auto db = QSharedPointer<Database>::create(); Group* root = db->rootGroup(); int delObjectsSize = 0; auto db2 = QSharedPointer<Database>::create(); Group* root2 = db2->rootGroup(); int delObjectsSize2 = 0; auto* e = new Entry(); e->setGroup(root); QCOMPARE(db->deletedObjects().size(), delObjectsSize); QCOMPARE(db2->deletedObjects().size(), delObjectsSize2); e->setGroup(root2); QCOMPARE(db->deletedObjects().size(), ++delObjectsSize); QCOMPARE(db2->deletedObjects().size(), delObjectsSize2); delete e; QCOMPARE(db->deletedObjects().size(), delObjectsSize); QCOMPARE(db2->deletedObjects().size(), ++delObjectsSize2); auto* g1 = new Group(); g1->setParent(root); QUuid g1Uuid = QUuid::createUuid(); g1->setUuid(g1Uuid); auto* e1 = new Entry(); e1->setGroup(g1); QUuid e1Uuid = QUuid::createUuid(); e1->setUuid(e1Uuid); g1->setParent(root2); delObjectsSize += 2; QCOMPARE(db->deletedObjects().size(), delObjectsSize); QCOMPARE(db2->deletedObjects().size(), delObjectsSize2); QCOMPARE(db->deletedObjects().at(delObjectsSize - 2).uuid, e1Uuid); QCOMPARE(db->deletedObjects().at(delObjectsSize - 1).uuid, g1Uuid); auto* group = new Group(); auto* entry = new Entry(); entry->setGroup(group); entry->setGroup(root); QCOMPARE(db->deletedObjects().size(), delObjectsSize); QCOMPARE(db2->deletedObjects().size(), delObjectsSize2); delete group; }
void Database::createRecycleBin() { Q_ASSERT(!m_data.isReadOnly); Group* recycleBin = Group::createRecycleBin(); recycleBin->setParent(rootGroup()); m_metadata->setRecycleBin(recycleBin); }
KBookmark BookmarkManager::bookmarkForUrl(const KUrl &url) { KBookmarkGroup root = rootGroup(); if (root.isNull()) return KBookmark(); return bookmarkForUrl(root, url); }
QList<KBookmark> BookmarkManager::find(const QString &text) { QList<KBookmark> list; KBookmarkGroup root = rootGroup(); if (!root.isNull()) for (KBookmark bookmark = root.first(); !bookmark.isNull(); bookmark = root.next(bookmark)) find(&list, bookmark, text); return list; }
Database::Database() : m_metadata(new Metadata(this)) , m_data() , m_rootGroup(nullptr) , m_timer(new QTimer(this)) , m_emitModified(false) , m_uuid(QUuid::createUuid()) { setRootGroup(new Group()); rootGroup()->setUuid(QUuid::createUuid()); rootGroup()->setName(tr("Root", "Root group name")); m_timer->setSingleShot(true); s_uuidMap.insert(m_uuid, this); connect(m_metadata, SIGNAL(metadataModified()), this, SLOT(markAsModified())); connect(m_timer, SIGNAL(timeout()), SIGNAL(databaseModified())); m_modified = false; m_emitModified = true; }
Database::Database() : m_metadata(new Metadata(this)) , m_timer(new QTimer(this)) , m_cipher(KeePass2::CIPHER_AES) , m_compressionAlgo(CompressionGZip) , m_transformRounds(50000) , m_hasKey(false) , m_emitModified(false) , m_uuid(Uuid::random()) { setRootGroup(new Group()); rootGroup()->setUuid(Uuid::random()); m_timer->setSingleShot(true); m_uuidMap.insert(m_uuid, this); connect(m_metadata, SIGNAL(modified()), this, SIGNAL(modifiedImmediate())); connect(m_metadata, SIGNAL(nameTextChanged()), this, SIGNAL(nameTextChanged())); connect(this, SIGNAL(modifiedImmediate()), this, SLOT(startModifiedTimer())); connect(m_timer, SIGNAL(timeout()), SIGNAL(modified())); }
TaskGroup* AbstractGroupingStrategy::createGroup(ItemList items) { GroupPtr oldGroup; if (!items.isEmpty() && items.first()->isGrouped()) { oldGroup = items.first()->parentGroup(); } else { oldGroup = rootGroup(); } TaskGroup *newGroup = new TaskGroup(d->groupManager); ItemList oldGroupMembers = oldGroup->members(); int index = oldGroupMembers.count(); d->createdGroups.append(newGroup); //kDebug() << "added group" << d->createdGroups.count(); // NOTE: Queued is vital to make sure groups only get removed after their children, for // correct QAbstractItemModel (TasksModel) transaction semantics. connect(newGroup, SIGNAL(itemRemoved(AbstractGroupableItem*)), this, SLOT(checkGroup()), Qt::QueuedConnection); foreach (AbstractGroupableItem * item, items) { int idx = oldGroupMembers.indexOf(item); if (idx >= 0 && idx < index) { index = idx; } newGroup->add(item); }
void TestKeePass2Format::testXmlRepairUuidHistoryItem() { QString xmlFile = QString("%1/%2.xml").arg(KEEPASSX_TEST_DATA_DIR, "BrokenDifferentEntryHistoryUuid"); QVERIFY(QFile::exists(xmlFile)); bool hasError; QString errorString; auto db = readXml(xmlFile, false, hasError, errorString); if (hasError) { qWarning("Database read error: %s", qPrintable(errorString)); } QVERIFY(!hasError); QList<Entry*> entries = db->rootGroup()->entries(); QCOMPARE(entries.size(), 1); Entry* entry = entries.at(0); QList<Entry*> historyItems = entry->historyItems(); QCOMPARE(historyItems.size(), 1); Entry* historyItem = historyItems.at(0); QVERIFY(!entry->uuid().isNull()); QVERIFY(!historyItem->uuid().isNull()); QCOMPARE(historyItem->uuid(), entry->uuid()); }
//---------- void Builder::init() { PanelGroupPtr rootGroup( new Panels::Groups::Grid() ); controller.init(rootGroup); }
/** * Test for catching mapping errors with duplicate attachments. */ void TestKeePass2Format::testDuplicateAttachments() { auto db = QSharedPointer<Database>::create(); db->setKey(QSharedPointer<CompositeKey>::create()); const QByteArray attachment1("abc"); const QByteArray attachment2("def"); const QByteArray attachment3("ghi"); auto entry1 = new Entry(); entry1->setGroup(db->rootGroup()); entry1->setUuid(QUuid::fromRfc4122("aaaaaaaaaaaaaaaa")); entry1->attachments()->set("a", attachment1); auto entry2 = new Entry(); entry2->setGroup(db->rootGroup()); entry2->setUuid(QUuid::fromRfc4122("bbbbbbbbbbbbbbbb")); entry2->attachments()->set("b1", attachment1); entry2->beginUpdate(); entry2->attachments()->set("b2", attachment1); entry2->endUpdate(); entry2->beginUpdate(); entry2->attachments()->set("b3", attachment2); entry2->endUpdate(); entry2->beginUpdate(); entry2->attachments()->set("b4", attachment2); entry2->endUpdate(); auto entry3 = new Entry(); entry3->setGroup(db->rootGroup()); entry3->setUuid(QUuid::fromRfc4122("cccccccccccccccc")); entry3->attachments()->set("c1", attachment2); entry3->attachments()->set("c2", attachment2); entry3->attachments()->set("c3", attachment3); QBuffer buffer; buffer.open(QBuffer::ReadWrite); bool hasError = false; QString errorString; writeKdbx(&buffer, db.data(), hasError, errorString); if (hasError) { QFAIL(qPrintable(QString("Error while writing database: %1").arg(errorString))); } buffer.seek(0); readKdbx(&buffer, QSharedPointer<CompositeKey>::create(), db, hasError, errorString); if (hasError) { QFAIL(qPrintable(QString("Error while reading database: %1").arg(errorString))); } QCOMPARE(db->rootGroup()->entries()[0]->attachments()->value("a"), attachment1); QCOMPARE(db->rootGroup()->entries()[1]->attachments()->value("b1"), attachment1); QCOMPARE(db->rootGroup()->entries()[1]->attachments()->value("b2"), attachment1); QCOMPARE(db->rootGroup()->entries()[1]->attachments()->value("b3"), attachment2); QCOMPARE(db->rootGroup()->entries()[1]->attachments()->value("b4"), attachment2); QCOMPARE(db->rootGroup()->entries()[1]->historyItems()[0]->attachments()->value("b1"), attachment1); QCOMPARE(db->rootGroup()->entries()[1]->historyItems()[1]->attachments()->value("b1"), attachment1); QCOMPARE(db->rootGroup()->entries()[1]->historyItems()[1]->attachments()->value("b2"), attachment1); QCOMPARE(db->rootGroup()->entries()[1]->historyItems()[2]->attachments()->value("b1"), attachment1); QCOMPARE(db->rootGroup()->entries()[1]->historyItems()[2]->attachments()->value("b2"), attachment1); QCOMPARE(db->rootGroup()->entries()[1]->historyItems()[2]->attachments()->value("b3"), attachment2); QCOMPARE(db->rootGroup()->entries()[2]->attachments()->value("c1"), attachment2); QCOMPARE(db->rootGroup()->entries()[2]->attachments()->value("c2"), attachment2); QCOMPARE(db->rootGroup()->entries()[2]->attachments()->value("c3"), attachment3); }
void TestKeePass2Format::testXmlInvalidXmlChars() { QScopedPointer<Database> dbWrite(new Database()); QString strPlainInvalid = QString().append(QChar(0x02)).append(QChar(0x19)).append(QChar(0xFFFE)).append(QChar(0xFFFF)); QString strPlainValid = QString() .append(QChar(0x09)) .append(QChar(0x0A)) .append(QChar(0x20)) .append(QChar(0xD7FF)) .append(QChar(0xE000)) .append(QChar(0xFFFD)); // U+10437 in UTF-16: D801 DC37 // high low surrogate QString strSingleHighSurrogate1 = QString().append(QChar(0xD801)); QString strSingleHighSurrogate2 = QString().append(QChar(0x31)).append(QChar(0xD801)).append(QChar(0x32)); QString strHighHighSurrogate = QString().append(QChar(0xD801)).append(QChar(0xD801)); QString strSingleLowSurrogate1 = QString().append(QChar(0xDC37)); QString strSingleLowSurrogate2 = QString().append(QChar((0x31))).append(QChar(0xDC37)).append(QChar(0x32)); QString strLowLowSurrogate = QString().append(QChar(0xDC37)).append(QChar(0xDC37)); QString strSurrogateValid1 = QString().append(QChar(0xD801)).append(QChar(0xDC37)); QString strSurrogateValid2 = QString().append(QChar(0x31)).append(QChar(0xD801)).append(QChar(0xDC37)).append(QChar(0x32)); auto entry = new Entry(); entry->setUuid(QUuid::createUuid()); entry->setGroup(dbWrite->rootGroup()); entry->attributes()->set("PlainInvalid", strPlainInvalid); entry->attributes()->set("PlainValid", strPlainValid); entry->attributes()->set("SingleHighSurrogate1", strSingleHighSurrogate1); entry->attributes()->set("SingleHighSurrogate2", strSingleHighSurrogate2); entry->attributes()->set("HighHighSurrogate", strHighHighSurrogate); entry->attributes()->set("SingleLowSurrogate1", strSingleLowSurrogate1); entry->attributes()->set("SingleLowSurrogate2", strSingleLowSurrogate2); entry->attributes()->set("LowLowSurrogate", strLowLowSurrogate); entry->attributes()->set("SurrogateValid1", strSurrogateValid1); entry->attributes()->set("SurrogateValid2", strSurrogateValid2); QBuffer buffer; buffer.open(QIODevice::ReadWrite); bool hasError; QString errorString; writeXml(&buffer, dbWrite.data(), hasError, errorString); QVERIFY(!hasError); buffer.seek(0); auto dbRead = readXml(&buffer, true, hasError, errorString); if (hasError) { qWarning("Database read error: %s", qPrintable(errorString)); } QVERIFY(!hasError); QVERIFY(dbRead.data()); QCOMPARE(dbRead->rootGroup()->entries().size(), 1); Entry* entryRead = dbRead->rootGroup()->entries().at(0); EntryAttributes* attrRead = entryRead->attributes(); QCOMPARE(attrRead->value("PlainInvalid"), QString()); QCOMPARE(attrRead->value("PlainValid"), strPlainValid); QCOMPARE(attrRead->value("SingleHighSurrogate1"), QString()); QCOMPARE(attrRead->value("SingleHighSurrogate2"), QString("12")); QCOMPARE(attrRead->value("HighHighSurrogate"), QString()); QCOMPARE(attrRead->value("SingleLowSurrogate1"), QString()); QCOMPARE(attrRead->value("SingleLowSurrogate2"), QString("12")); QCOMPARE(attrRead->value("LowLowSurrogate"), QString()); QCOMPARE(attrRead->value("SurrogateValid1"), strSurrogateValid1); QCOMPARE(attrRead->value("SurrogateValid2"), strSurrogateValid2); }