Skip to content

Commit

Permalink
Add test for searching Entries via UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
piegamesde committed May 20, 2020
1 parent 2a6b418 commit 1d22018
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/TestBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,55 @@ void TestBrowser::testSearchEntries()
QCOMPARE(result[3]->url(), QString("github.com/login"));
}

void TestBrowser::testSearchEntriesByUUID()
{
auto db = QSharedPointer<Database>::create();
auto* root = db->rootGroup();

/* The URLs don't really matter for this test, we just need some entries */
QStringList urls = {"https://github.com/login_page",
"https://github.com/login",
"https://github.com/",
"github.com/login",
"http://github.com",
"https://github.com/login",
"github.com",
"github.com/login",
"https://github",
"github.com",
"",
"not an URL"};
auto entries = createEntries(urls, root);

for (Entry* entry : entries) {
QString testUrl = "keepassxc://by-uuid/" + entry->uuidToHex();
/* Look for an entry with that UUID. First using handleEntry, then through the search */
QCOMPARE(m_browserService->handleEntry(entry, testUrl, ""), true);
auto result = m_browserService->searchEntries(db, testUrl, "");
QCOMPARE(result.length(), 1);
QCOMPARE(result[0], entry);
}

/* Test for entries that don't exist */
QStringList uuids = {"00000000000000000000000000000000",
"00000000000000000000000000000001",
"00000000000000000000000000000002/",
"invalid uuid",
"000000000000000000000000000000000000000"
"00000000000000000000000"};

for (QString uuid : uuids) {
QString testUrl = "keepassxc://by-uuid/" + uuid;

for (Entry* entry : entries) {
QCOMPARE(m_browserService->handleEntry(entry, testUrl, ""), false);
}

auto result = m_browserService->searchEntries(db, testUrl, "");
QCOMPARE(result.length(), 0);
}
}

void TestBrowser::testSearchEntriesWithPort()
{
auto db = QSharedPointer<Database>::create();
Expand Down Expand Up @@ -404,6 +453,7 @@ QList<Entry*> TestBrowser::createEntries(QStringList& urls, Group* root) const
entry->beginUpdate();
entry->setUrl(urls[i]);
entry->setUsername(QString("User %1").arg(i));
entry->setUuid(QUuid::createUuid());
entry->endUpdate();
entries.push_back(entry);
}
Expand Down
1 change: 1 addition & 0 deletions tests/TestBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private slots:
void testBaseDomain();
void testSortPriority();
void testSearchEntries();
void testSearchEntriesByUUID();
void testSearchEntriesWithPort();
void testSearchEntriesWithAdditionalURLs();
void testInvalidEntries();
Expand Down

0 comments on commit 1d22018

Please sign in to comment.