From 676f64f7b27e93b2bca7979751705a11f2dc2da3 Mon Sep 17 00:00:00 2001 From: mattesony <49170923+mattesony@users.noreply.github.com> Date: Mon, 30 Jan 2023 14:06:20 -0800 Subject: [PATCH] Rename Entry::getPasswordAge() to Entry::passwordAgeSeconds() --- src/core/Entry.cpp | 2 +- src/core/Entry.h | 2 +- src/core/PasswordHealth.cpp | 2 +- tests/TestEntry.cpp | 30 +++++++++++++++--------------- tests/TestEntry.h | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 81702fd7a..48fd6a769 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -231,7 +231,7 @@ const QSharedPointer Entry::passwordHealth() const return m_data.passwordHealth; } -int Entry::getPasswordAge() const +int Entry::passwordAgeSeconds() const { QListIterator i(m_history); i.toBack(); diff --git a/src/core/Entry.h b/src/core/Entry.h index 1ac7c5763..3b3dabd29 100644 --- a/src/core/Entry.h +++ b/src/core/Entry.h @@ -116,7 +116,7 @@ public: QString path() const; const QSharedPointer passwordHealth(); const QSharedPointer passwordHealth() const; - int getPasswordAge() const; + int passwordAgeSeconds() const; bool excludeFromReports() const; void setExcludeFromReports(bool state); diff --git a/src/core/PasswordHealth.cpp b/src/core/PasswordHealth.cpp index c7d00f761..5d085df4b 100644 --- a/src/core/PasswordHealth.cpp +++ b/src/core/PasswordHealth.cpp @@ -200,7 +200,7 @@ QSharedPointer HealthChecker::evaluate(const Entry* entry) const } // Fourth, add note if password is two or more years old. - int ageInSeconds = entry->getPasswordAge(); + int ageInSeconds = entry->passwordAgeSeconds(); // Unfortunately, Qt doesn't seem to have a utility for seconds->year. // (365 days)(24 hours/day)(3600 s/hr) is approximately a year and gets compiled away. if (ageInSeconds / (365 * 24 * 3600) > 1) { diff --git a/tests/TestEntry.cpp b/tests/TestEntry.cpp index b0c88bcc9..70daff4d2 100644 --- a/tests/TestEntry.cpp +++ b/tests/TestEntry.cpp @@ -49,54 +49,54 @@ void TestEntry::testHistoryItemDeletion() QVERIFY(historyEntry.isNull()); } -void TestEntry::testGetPasswordAge() +void TestEntry::testPasswordAgeSeconds() { - MockClock* m_clock = new MockClock(2022, 2, 4, 17, 00, 00); - MockClock::setup(m_clock); + MockClock* mockClock = new MockClock(2022, 2, 4, 17, 00, 00); + MockClock::setup(mockClock); // Old password updated 100 seconds ago QPointer historyEntry = new Entry(); historyEntry->setPassword("oldpassword"); - m_clock->advanceSecond(500); + mockClock->advanceSecond(500); QScopedPointer entry(new Entry()); entry->setPassword("newpassword"); entry->addHistoryItem(historyEntry); - m_clock->advanceSecond(100); + mockClock->advanceSecond(100); - QCOMPARE(entry->getPasswordAge(), 100); + QCOMPARE(entry->passwordAgeSeconds(), 100); QPointer historyEntry2 = new Entry(); historyEntry2->setPassword("oldpassword"); - m_clock->advanceSecond(500); + mockClock->advanceSecond(500); QScopedPointer entry2(new Entry()); entry2->setPassword("oldpassword"); // No history, password just created - QCOMPARE(entry2->getPasswordAge(), 0); - m_clock->advanceSecond(100); + QCOMPARE(entry2->passwordAgeSeconds(), 0); + mockClock->advanceSecond(100); // 100 seconds pass since creation - QCOMPARE(entry2->getPasswordAge(), 100); + QCOMPARE(entry2->passwordAgeSeconds(), 100); entry2->addHistoryItem(historyEntry2); // History entry shows password is actually // 500 seconds older than the creation time - QCOMPARE(entry2->getPasswordAge(), 600); + QCOMPARE(entry2->passwordAgeSeconds(), 600); // Bury password change in history entry2->setPassword("newpassword"); QPointer historyEntry3 = new Entry(); historyEntry3->setPassword("newpassword"); entry->addHistoryItem(historyEntry3); - m_clock->advanceSecond(400); + mockClock->advanceSecond(400); QPointer historyEntry4 = new Entry(); historyEntry4->setPassword("newpassword"); entry->addHistoryItem(historyEntry4); - m_clock->advanceSecond(400); - QCOMPARE(entry2->getPasswordAge(), 800); + mockClock->advanceSecond(400); + QCOMPARE(entry2->passwordAgeSeconds(), 800); // Second test where current password is the latest entry2->setPassword("newerpassword"); - QCOMPARE(entry2->getPasswordAge(), 0); + QCOMPARE(entry2->passwordAgeSeconds(), 0); MockClock::teardown(); } diff --git a/tests/TestEntry.h b/tests/TestEntry.h index fa00fd508..ec0bd5e19 100644 --- a/tests/TestEntry.h +++ b/tests/TestEntry.h @@ -29,7 +29,7 @@ class TestEntry : public QObject private slots: void initTestCase(); void testHistoryItemDeletion(); - void testGetPasswordAge(); + void testPasswordAgeSeconds(); void testCopyDataFrom(); void testClone(); void testResolveUrl();