mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-05-15 04:52:30 -04:00
Fixed tests and improved age logic
This commit is contained in:
parent
28f1cd398d
commit
c14725cf97
2 changed files with 31 additions and 17 deletions
|
@ -235,27 +235,25 @@ int Entry::getPasswordAge() const
|
||||||
{
|
{
|
||||||
QListIterator<Entry*> i(m_history);
|
QListIterator<Entry*> i(m_history);
|
||||||
i.toBack();
|
i.toBack();
|
||||||
Entry* compare = nullptr;
|
const Entry* curr = nullptr;
|
||||||
Entry* curr = nullptr;
|
const Entry* previous = this;
|
||||||
|
|
||||||
while (i.hasPrevious()) {
|
while (i.hasPrevious()) {
|
||||||
curr = i.previous();
|
curr = previous;
|
||||||
if (!compare) {
|
previous = i.previous();
|
||||||
compare = curr;
|
if (previous->password() != curr->password()) {
|
||||||
continue;
|
// Found last change in history
|
||||||
|
return curr->timeInfo().lastModificationTime().secsTo(Clock::currentDateTime());
|
||||||
}
|
}
|
||||||
if (*curr->attributes() != *compare->attributes()) {
|
|
||||||
if (curr->password() != compare->password()) {
|
|
||||||
// Found most recent password change; break out.
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
if (previous!=this) {
|
||||||
|
// If no change in history, password is from oldest history entry.
|
||||||
|
// Not using creation time here because that changes when an entry is cloned
|
||||||
|
return previous->timeInfo().lastModificationTime().secsTo(Clock::currentDateTime());
|
||||||
}
|
}
|
||||||
}
|
// If no history, creation time is when the password appeared
|
||||||
if (!curr) {
|
return this->timeInfo().creationTime().secsTo(Clock::currentDateTime());
|
||||||
// If no change in history, password is from creation time
|
|
||||||
return this->timeInfo().creationTime().secsTo(QDateTime::currentDateTime());
|
|
||||||
}
|
|
||||||
return curr->timeInfo().lastModificationTime().secsTo(QDateTime::currentDateTime());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Entry::excludeFromReports() const
|
bool Entry::excludeFromReports() const
|
||||||
|
|
|
@ -79,9 +79,25 @@ void TestEntry::testGetPasswordAge()
|
||||||
|
|
||||||
entry2->addHistoryItem(historyEntry2);
|
entry2->addHistoryItem(historyEntry2);
|
||||||
// History entry shows password is actually
|
// History entry shows password is actually
|
||||||
// 500 seconds older than the most recent update
|
// 500 seconds older than the creation time
|
||||||
QCOMPARE(entry2->getPasswordAge(), 600);
|
QCOMPARE(entry2->getPasswordAge(), 600);
|
||||||
|
|
||||||
|
// Bury password change in history
|
||||||
|
entry2->setPassword("newpassword");
|
||||||
|
QPointer<Entry> historyEntry3 = new Entry();
|
||||||
|
historyEntry3->setPassword("newpassword");
|
||||||
|
entry->addHistoryItem(historyEntry3);
|
||||||
|
m_clock->advanceSecond(400);
|
||||||
|
QPointer<Entry> historyEntry4 = new Entry();
|
||||||
|
historyEntry4->setPassword("newpassword");
|
||||||
|
entry->addHistoryItem(historyEntry4);
|
||||||
|
m_clock->advanceSecond(400);
|
||||||
|
QCOMPARE(entry2->getPasswordAge(), 800);
|
||||||
|
|
||||||
|
// Second test where current password is the latest
|
||||||
|
entry2->setPassword("newerpassword");
|
||||||
|
QCOMPARE(entry2->getPasswordAge(), 0);
|
||||||
|
|
||||||
MockClock::teardown();
|
MockClock::teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue