mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-24 23:09:44 -05:00
Fix support for referenced URL fields
This commit is contained in:
parent
c112ffc3fc
commit
c1720c3711
@ -814,7 +814,7 @@ QList<Entry*> BrowserService::sortEntries(QList<Entry*>& entries, const QString&
|
|||||||
// Build map of prioritized entries
|
// Build map of prioritized entries
|
||||||
QMultiMap<int, Entry*> priorities;
|
QMultiMap<int, Entry*> priorities;
|
||||||
for (auto* entry : entries) {
|
for (auto* entry : entries) {
|
||||||
priorities.insert(sortPriority(getEntryURLs(entry), siteUrl, formUrl), entry);
|
priorities.insert(sortPriority(entry->getAllUrls(), siteUrl, formUrl), entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto keys = priorities.uniqueKeys();
|
auto keys = priorities.uniqueKeys();
|
||||||
@ -1214,21 +1214,6 @@ QSharedPointer<Database> BrowserService::selectedDatabase()
|
|||||||
return getDatabase();
|
return getDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList BrowserService::getEntryURLs(const Entry* entry)
|
|
||||||
{
|
|
||||||
QStringList urlList;
|
|
||||||
urlList << entry->url();
|
|
||||||
|
|
||||||
// Handle additional URL's
|
|
||||||
for (const auto& key : entry->attributes()->keys()) {
|
|
||||||
if (key.startsWith(ADDITIONAL_URL)) {
|
|
||||||
urlList << entry->attributes()->value(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return urlList;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BrowserService::hideWindow() const
|
void BrowserService::hideWindow() const
|
||||||
{
|
{
|
||||||
if (m_prevWindowState == WindowState::Minimized) {
|
if (m_prevWindowState == WindowState::Minimized) {
|
||||||
|
@ -159,7 +159,7 @@ private:
|
|||||||
QSharedPointer<Database> selectedDatabase();
|
QSharedPointer<Database> selectedDatabase();
|
||||||
QString getDatabaseRootUuid();
|
QString getDatabaseRootUuid();
|
||||||
QString getDatabaseRecycleBinUuid();
|
QString getDatabaseRecycleBinUuid();
|
||||||
QStringList getEntryURLs(const Entry* entry);
|
bool checkLegacySettings(QSharedPointer<Database> db);
|
||||||
void hideWindow() const;
|
void hideWindow() const;
|
||||||
void raiseWindow(const bool force = false);
|
void raiseWindow(const bool force = false);
|
||||||
void updateWindowState();
|
void updateWindowState();
|
||||||
|
@ -372,16 +372,18 @@ QString Entry::url() const
|
|||||||
QStringList Entry::getAllUrls() const
|
QStringList Entry::getAllUrls() const
|
||||||
{
|
{
|
||||||
QStringList urlList;
|
QStringList urlList;
|
||||||
|
auto entryUrl = url();
|
||||||
|
|
||||||
if (!url().isEmpty()) {
|
if (!entryUrl.isEmpty()) {
|
||||||
urlList << url();
|
urlList << (EntryAttributes::matchReference(entryUrl).hasMatch() ? resolveMultiplePlaceholders(entryUrl)
|
||||||
|
: entryUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& key : m_attributes->keys()) {
|
for (const auto& key : m_attributes->keys()) {
|
||||||
if (key.startsWith("KP2A_URL")) {
|
if (key.startsWith("KP2A_URL")) {
|
||||||
auto additionalUrl = m_attributes->value(key);
|
auto additionalUrl = m_attributes->value(key);
|
||||||
if (!additionalUrl.isEmpty()) {
|
if (!additionalUrl.isEmpty()) {
|
||||||
urlList << additionalUrl;
|
urlList << resolveMultiplePlaceholders(additionalUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,8 +202,7 @@ void TestBrowser::testSortPriority()
|
|||||||
QScopedPointer<Entry> entry(new Entry());
|
QScopedPointer<Entry> entry(new Entry());
|
||||||
entry->setUrl(entryUrl);
|
entry->setUrl(entryUrl);
|
||||||
|
|
||||||
QCOMPARE(m_browserService->sortPriority(m_browserService->getEntryURLs(entry.data()), siteUrl, formUrl),
|
QCOMPARE(m_browserService->sortPriority(entry->getAllUrls(), siteUrl, formUrl), expectedScore);
|
||||||
expectedScore);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestBrowser::testSortPriority_data()
|
void TestBrowser::testSortPriority_data()
|
||||||
@ -344,7 +343,7 @@ void TestBrowser::testSearchEntriesByUUID()
|
|||||||
|
|
||||||
for (Entry* entry : entries) {
|
for (Entry* entry : entries) {
|
||||||
QString testUrl = "keepassxc://by-uuid/" + entry->uuidToHex();
|
QString testUrl = "keepassxc://by-uuid/" + entry->uuidToHex();
|
||||||
/* Look for an entry with that UUID. First using handleEntry, then through the search */
|
/* Look for an entry with that UUID. First using shouldIncludeEntry, then through the search */
|
||||||
QCOMPARE(m_browserService->shouldIncludeEntry(entry, testUrl, ""), true);
|
QCOMPARE(m_browserService->shouldIncludeEntry(entry, testUrl, ""), true);
|
||||||
auto result = m_browserService->searchEntries(db, testUrl, "");
|
auto result = m_browserService->searchEntries(db, testUrl, "");
|
||||||
QCOMPARE(result.length(), 1);
|
QCOMPARE(result.length(), 1);
|
||||||
@ -371,6 +370,46 @@ void TestBrowser::testSearchEntriesByUUID()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestBrowser::testSearchEntriesByReference()
|
||||||
|
{
|
||||||
|
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://subdomain.example.com",
|
||||||
|
"example.com", // Only includes a partial URL for references
|
||||||
|
"https://another.domain.com", // Additional URL as full reference
|
||||||
|
"https://subdomain.somesite.com", // Additional URL as partial reference
|
||||||
|
"", // Full reference will be added to https://subdomain.example.com
|
||||||
|
"" // Partial reference will be added to https://subdomain.example.com
|
||||||
|
"https://www.notincluded.com"}; // Should not show in search
|
||||||
|
auto entries = createEntries(urls, root);
|
||||||
|
|
||||||
|
auto firstEntryUuid = entries.first()->uuidToHex();
|
||||||
|
auto secondEntryUuid = entries[1]->uuidToHex();
|
||||||
|
auto fullReference = QString("{REF:A@I:%1}").arg(firstEntryUuid);
|
||||||
|
auto partialReference = QString("https://subdomain.{REF:A@I:%1}").arg(secondEntryUuid);
|
||||||
|
entries[2]->attributes()->set(BrowserService::ADDITIONAL_URL, fullReference);
|
||||||
|
entries[3]->attributes()->set(BrowserService::ADDITIONAL_URL, partialReference);
|
||||||
|
entries[4]->setUrl(fullReference);
|
||||||
|
entries[5]->setUrl(partialReference);
|
||||||
|
|
||||||
|
auto result = m_browserService->searchEntries(db, "https://subdomain.example.com", "");
|
||||||
|
QCOMPARE(result.length(), 6);
|
||||||
|
QCOMPARE(result[0]->url(), urls[0]);
|
||||||
|
QCOMPARE(result[1]->url(), urls[1]);
|
||||||
|
QCOMPARE(result[2]->url(), urls[2]);
|
||||||
|
QCOMPARE(result[2]->resolveMultiplePlaceholders(result[2]->attributes()->value(BrowserService::ADDITIONAL_URL)),
|
||||||
|
urls[0]);
|
||||||
|
QCOMPARE(result[3]->url(), urls[3]);
|
||||||
|
QCOMPARE(result[3]->resolveMultiplePlaceholders(result[3]->attributes()->value(BrowserService::ADDITIONAL_URL)),
|
||||||
|
urls[0]);
|
||||||
|
QCOMPARE(result[4]->url(), fullReference);
|
||||||
|
QCOMPARE(result[4]->resolveMultiplePlaceholders(result[4]->url()), urls[0]); // Should be resolved to the main entry
|
||||||
|
QCOMPARE(result[5]->url(), partialReference);
|
||||||
|
QCOMPARE(result[5]->resolveMultiplePlaceholders(result[5]->url()), urls[0]); // Should be resolved to the main entry
|
||||||
|
}
|
||||||
|
|
||||||
void TestBrowser::testSearchEntriesWithPort()
|
void TestBrowser::testSearchEntriesWithPort()
|
||||||
{
|
{
|
||||||
auto db = QSharedPointer<Database>::create();
|
auto db = QSharedPointer<Database>::create();
|
||||||
|
@ -44,6 +44,7 @@ private slots:
|
|||||||
void testSearchEntries();
|
void testSearchEntries();
|
||||||
void testSearchEntriesByPath();
|
void testSearchEntriesByPath();
|
||||||
void testSearchEntriesByUUID();
|
void testSearchEntriesByUUID();
|
||||||
|
void testSearchEntriesByReference();
|
||||||
void testSearchEntriesWithPort();
|
void testSearchEntriesWithPort();
|
||||||
void testSearchEntriesWithAdditionalURLs();
|
void testSearchEntriesWithAdditionalURLs();
|
||||||
void testInvalidEntries();
|
void testInvalidEntries();
|
||||||
|
Loading…
Reference in New Issue
Block a user