diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index db82da163..06fea2107 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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}) diff --git a/tests/TestEntry.cpp b/tests/TestEntry.cpp index 07519d94b..ffdf6cb51 100644 --- a/tests/TestEntry.cpp +++ b/tests/TestEntry.cpp @@ -19,6 +19,8 @@ #include #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 historyEntry = new Entry(); + historyEntry->setPassword("oldpassword"); + m_clock->advanceSecond(500); + QScopedPointer entry(new Entry()); + entry->setPassword("newpassword"); + entry->addHistoryItem(historyEntry); + m_clock->advanceSecond(100); + + QCOMPARE(entry->getPasswordAge(), 100); + + QPointer historyEntry2 = new Entry(); + historyEntry2->setPassword("oldpassword"); + m_clock->advanceSecond(500); + QScopedPointer 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(new Entry()); diff --git a/tests/TestEntry.h b/tests/TestEntry.h index 3bfd8f52d..fa00fd508 100644 --- a/tests/TestEntry.h +++ b/tests/TestEntry.h @@ -29,6 +29,7 @@ class TestEntry : public QObject private slots: void initTestCase(); void testHistoryItemDeletion(); + void testGetPasswordAge(); void testCopyDataFrom(); void testClone(); void testResolveUrl();