mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-26 15:59:50 -05:00
Add tests for modified, fix history for autotype
Added tests to ensure #1387 works Fixed issue detected during testing - AutoTypeAssociations were not pushed to history
This commit is contained in:
parent
045f157a63
commit
943dc6cdd6
@ -633,7 +633,7 @@ Entry* Entry::clone(CloneFlags flags) const
|
||||
entry->m_attributes->set(EntryAttributes::PasswordKey, password.toUpper(), m_attributes->isProtected(EntryAttributes::PasswordKey));
|
||||
}
|
||||
|
||||
entry->m_autoTypeAssociations->copyDataFrom(this->m_autoTypeAssociations);
|
||||
entry->m_autoTypeAssociations->copyDataFrom(m_autoTypeAssociations);
|
||||
if (flags & CloneIncludeHistory) {
|
||||
for (Entry* historyItem : m_history) {
|
||||
Entry* historyItemClone = historyItem->clone(flags & ~CloneIncludeHistory & ~CloneNewUuid);
|
||||
@ -679,6 +679,7 @@ void Entry::beginUpdate()
|
||||
m_tmpHistoryItem->m_data = m_data;
|
||||
m_tmpHistoryItem->m_attributes->copyDataFrom(m_attributes);
|
||||
m_tmpHistoryItem->m_attachments->copyDataFrom(m_attachments);
|
||||
m_tmpHistoryItem->m_autoTypeAssociations->copyDataFrom(m_autoTypeAssociations);
|
||||
|
||||
m_modifiedSinceBegin = false;
|
||||
}
|
||||
|
@ -156,9 +156,13 @@ bool EntryAttachments::operator!=(const EntryAttachments& other) const
|
||||
int EntryAttachments::attachmentsSize(const QSet<QByteArray> &ignoredAttachments) const
|
||||
{
|
||||
int size = 0;
|
||||
const QSet<QByteArray> consideredAttachments = m_attachments.values().toSet() - ignoredAttachments;
|
||||
for (const QByteArray& attachment : consideredAttachments) {
|
||||
size += attachment.size();
|
||||
|
||||
QMapIterator<QString, QByteArray> i(m_attachments);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if( ! ignoredAttachments.contains( i.value() )){
|
||||
size += i.key().toUtf8().size() + i.value().size();
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
#include <QTest>
|
||||
|
||||
#include "core/Database.h"
|
||||
#include "core/Entry.h"
|
||||
#include "core/Group.h"
|
||||
#include "crypto/Crypto.h"
|
||||
@ -48,6 +47,7 @@ void TestEntry::testHistoryItemDeletion()
|
||||
|
||||
delete entry;
|
||||
}
|
||||
|
||||
void TestEntry::testCopyDataFrom()
|
||||
{
|
||||
Entry* entry = new Entry();
|
||||
|
@ -465,5 +465,52 @@ void TestModified::testHistoryItem()
|
||||
entry3->endUpdate();
|
||||
QCOMPARE(entry3->historyItems().size(), 2);
|
||||
|
||||
Entry* entry4 = new Entry();
|
||||
entry4->setGroup(root);
|
||||
QCOMPARE(entry4->historyItems().size(), 0);
|
||||
|
||||
int reservedSize = entry4->attributes()->attributesSize();
|
||||
entry4->beginUpdate();
|
||||
entry4->attachments()->set("test1", QByteArray(17000 - 5 - reservedSize + 1, 'a'));
|
||||
entry4->endUpdate();
|
||||
QCOMPARE(entry4->historyItems().size(), 1);
|
||||
|
||||
entry4->beginUpdate();
|
||||
entry4->attachments()->remove("test1");
|
||||
entry4->endUpdate();
|
||||
QCOMPARE(entry4->historyItems().size(), 0);
|
||||
|
||||
entry4->beginUpdate();
|
||||
entry4->setTags(QByteArray(17000 - reservedSize + 1, 'a'));
|
||||
entry4->endUpdate();
|
||||
QCOMPARE(entry4->historyItems().size(), 1);
|
||||
|
||||
entry4->beginUpdate();
|
||||
entry4->setTags("");
|
||||
entry4->endUpdate();
|
||||
QCOMPARE(entry4->historyItems().size(), 0);
|
||||
|
||||
entry4->beginUpdate();
|
||||
entry4->attributes()->set("test3", QByteArray(17000 - 5 - reservedSize + 1, 'a'));
|
||||
entry4->endUpdate();
|
||||
QCOMPARE(entry4->historyItems().size(), 1);
|
||||
|
||||
entry4->beginUpdate();
|
||||
entry4->attributes()->remove("test3");
|
||||
entry4->endUpdate();
|
||||
QCOMPARE(entry4->historyItems().size(), 0);
|
||||
|
||||
entry4->beginUpdate();
|
||||
AutoTypeAssociations::Association association;
|
||||
association.window = "test3";
|
||||
association.sequence = QByteArray(17000 - 5 - reservedSize + 1, 'a');
|
||||
entry4->autoTypeAssociations()->add(association);
|
||||
entry4->endUpdate();
|
||||
QCOMPARE(entry4->historyItems().size(), 1);
|
||||
|
||||
entry4->beginUpdate();
|
||||
entry4->autoTypeAssociations()->remove(0);
|
||||
entry4->endUpdate();
|
||||
QCOMPARE(entry4->historyItems().size(), 0);
|
||||
delete db;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user