mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-04-27 19:06:19 -04:00
getPasswordAge unit tests.
Tests fail because QDateTime::currentDateTime() is not using the MockClock instance. The time is correct, but as it changes every time it makes the test non-deterministic.
This commit is contained in:
parent
d85f3a2b82
commit
28f1cd398d
@ -168,7 +168,7 @@ if(WITH_XC_SSHAGENT)
|
||||
endif()
|
||||
|
||||
add_unit_test(NAME testentry SOURCES TestEntry.cpp
|
||||
LIBS ${TEST_LIBRARIES})
|
||||
LIBS testsupport ${TEST_LIBRARIES})
|
||||
|
||||
add_unit_test(NAME testmerge SOURCES TestMerge.cpp
|
||||
LIBS testsupport ${TEST_LIBRARIES})
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include <QTest>
|
||||
|
||||
#include "TestEntry.h"
|
||||
#include "mock/MockClock.h"
|
||||
|
||||
#include "core/Clock.h"
|
||||
#include "core/Group.h"
|
||||
#include "core/Metadata.h"
|
||||
@ -47,6 +49,42 @@ void TestEntry::testHistoryItemDeletion()
|
||||
QVERIFY(historyEntry.isNull());
|
||||
}
|
||||
|
||||
void TestEntry::testGetPasswordAge()
|
||||
{
|
||||
MockClock* m_clock = new MockClock(2022, 2, 4, 17, 00, 00);
|
||||
MockClock::setup(m_clock);
|
||||
|
||||
// Old password updated 100 seconds ago
|
||||
QPointer<Entry> historyEntry = new Entry();
|
||||
historyEntry->setPassword("oldpassword");
|
||||
m_clock->advanceSecond(500);
|
||||
QScopedPointer<Entry> entry(new Entry());
|
||||
entry->setPassword("newpassword");
|
||||
entry->addHistoryItem(historyEntry);
|
||||
m_clock->advanceSecond(100);
|
||||
|
||||
QCOMPARE(entry->getPasswordAge(), 100);
|
||||
|
||||
QPointer<Entry> historyEntry2 = new Entry();
|
||||
historyEntry2->setPassword("oldpassword");
|
||||
m_clock->advanceSecond(500);
|
||||
QScopedPointer<Entry> entry2(new Entry());
|
||||
entry2->setPassword("oldpassword");
|
||||
|
||||
// No history, password just created
|
||||
QCOMPARE(entry2->getPasswordAge(), 0);
|
||||
m_clock->advanceSecond(100);
|
||||
// 100 seconds pass since creation
|
||||
QCOMPARE(entry2->getPasswordAge(), 100);
|
||||
|
||||
entry2->addHistoryItem(historyEntry2);
|
||||
// History entry shows password is actually
|
||||
// 500 seconds older than the most recent update
|
||||
QCOMPARE(entry2->getPasswordAge(), 600);
|
||||
|
||||
MockClock::teardown();
|
||||
}
|
||||
|
||||
void TestEntry::testCopyDataFrom()
|
||||
{
|
||||
QScopedPointer<Entry> entry(new Entry());
|
||||
|
@ -29,6 +29,7 @@ class TestEntry : public QObject
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void testHistoryItemDeletion();
|
||||
void testGetPasswordAge();
|
||||
void testCopyDataFrom();
|
||||
void testClone();
|
||||
void testResolveUrl();
|
||||
|
Loading…
x
Reference in New Issue
Block a user