mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-06-22 05:34:40 -04:00
Compare window title with entry URLs during autotype matching. (#556)
* Compare window title with entry URLs during autotype matching. * Adapted option label to reflect that both entry title and URL are used for auto-type window matching.
This commit is contained in:
parent
03f00c5526
commit
9a59a124aa
5 changed files with 56 additions and 3 deletions
|
@ -574,8 +574,9 @@ QString AutoType::autoTypeSequence(const Entry* entry, const QString& windowTitl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!match && config()->get("AutoTypeEntryTitleMatch").toBool() && !entry->resolvePlaceholder(entry->title()).isEmpty()
|
if (!match && config()->get("AutoTypeEntryTitleMatch").toBool()
|
||||||
&& windowTitle.contains(entry->resolvePlaceholder(entry->title()), Qt::CaseInsensitive)) {
|
&& (windowMatchesTitle(windowTitle, entry->resolvePlaceholder(entry->title()))
|
||||||
|
|| windowMatchesUrl(windowTitle, entry->resolvePlaceholder(entry->url())))) {
|
||||||
sequence = entry->defaultAutoTypeSequence();
|
sequence = entry->defaultAutoTypeSequence();
|
||||||
match = true;
|
match = true;
|
||||||
}
|
}
|
||||||
|
@ -631,3 +632,22 @@ bool AutoType::windowMatches(const QString& windowTitle, const QString& windowPa
|
||||||
return WildcardMatcher(windowTitle).match(windowPattern);
|
return WildcardMatcher(windowTitle).match(windowPattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AutoType::windowMatchesTitle(const QString& windowTitle, const QString& resolvedTitle)
|
||||||
|
{
|
||||||
|
return !resolvedTitle.isEmpty() && windowTitle.contains(resolvedTitle, Qt::CaseInsensitive);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AutoType::windowMatchesUrl(const QString& windowTitle, const QString& resolvedUrl)
|
||||||
|
{
|
||||||
|
if (!resolvedUrl.isEmpty() && windowTitle.contains(resolvedUrl, Qt::CaseInsensitive)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QUrl url(resolvedUrl);
|
||||||
|
if (url.isValid() && !url.host().isEmpty()) {
|
||||||
|
return windowTitle.contains(url.host(), Qt::CaseInsensitive);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -66,6 +66,8 @@ private:
|
||||||
bool parseActions(const QString& sequence, const Entry* entry, QList<AutoTypeAction*>& actions);
|
bool parseActions(const QString& sequence, const Entry* entry, QList<AutoTypeAction*>& actions);
|
||||||
QList<AutoTypeAction*> createActionFromTemplate(const QString& tmpl, const Entry* entry);
|
QList<AutoTypeAction*> createActionFromTemplate(const QString& tmpl, const Entry* entry);
|
||||||
QString autoTypeSequence(const Entry* entry, const QString& windowTitle = QString());
|
QString autoTypeSequence(const Entry* entry, const QString& windowTitle = QString());
|
||||||
|
bool windowMatchesTitle(const QString& windowTitle, const QString& resolvedTitle);
|
||||||
|
bool windowMatchesUrl(const QString& windowTitle, const QString& resolvedUrl);
|
||||||
bool windowMatches(const QString& windowTitle, const QString& windowPattern);
|
bool windowMatches(const QString& windowTitle, const QString& windowPattern);
|
||||||
|
|
||||||
bool m_inAutoType;
|
bool m_inAutoType;
|
||||||
|
|
|
@ -303,7 +303,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="autoTypeEntryTitleMatchCheckBox">
|
<widget class="QCheckBox" name="autoTypeEntryTitleMatchCheckBox">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Use entry title to match windows for global Auto-Type</string>
|
<string>Use entry title and URL to match windows for global Auto-Type</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -104,6 +104,12 @@ void TestAutoType::init()
|
||||||
association.window = "//^CustomAttr3$//";
|
association.window = "//^CustomAttr3$//";
|
||||||
association.sequence = "{PaSSworD}";
|
association.sequence = "{PaSSworD}";
|
||||||
m_entry4->autoTypeAssociations()->add(association);
|
m_entry4->autoTypeAssociations()->add(association);
|
||||||
|
|
||||||
|
m_entry5 = new Entry();
|
||||||
|
m_entry5->setGroup(m_group);
|
||||||
|
m_entry5->setPassword("example5");
|
||||||
|
m_entry5->setTitle("some title");
|
||||||
|
m_entry5->setUrl("http://example.org");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestAutoType::cleanup()
|
void TestAutoType::cleanup()
|
||||||
|
@ -172,6 +178,28 @@ void TestAutoType::testGlobalAutoTypeTitleMatch()
|
||||||
QString("%1%2").arg(m_entry2->password(), m_test->keyToString(Qt::Key_Enter)));
|
QString("%1%2").arg(m_entry2->password(), m_test->keyToString(Qt::Key_Enter)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestAutoType::testGlobalAutoTypeUrlMatch()
|
||||||
|
{
|
||||||
|
config()->set("AutoTypeEntryTitleMatch", true);
|
||||||
|
|
||||||
|
m_test->setActiveWindowTitle("Dummy - http://example.org/ - <My Browser>");
|
||||||
|
m_autoType->performGlobalAutoType(m_dbList);
|
||||||
|
|
||||||
|
QCOMPARE(m_test->actionChars(),
|
||||||
|
QString("%1%2").arg(m_entry5->password(), m_test->keyToString(Qt::Key_Enter)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestAutoType::testGlobalAutoTypeUrlSubdomainMatch()
|
||||||
|
{
|
||||||
|
config()->set("AutoTypeEntryTitleMatch", true);
|
||||||
|
|
||||||
|
m_test->setActiveWindowTitle("Dummy - http://sub.example.org/ - <My Browser>");
|
||||||
|
m_autoType->performGlobalAutoType(m_dbList);
|
||||||
|
|
||||||
|
QCOMPARE(m_test->actionChars(),
|
||||||
|
QString("%1%2").arg(m_entry5->password(), m_test->keyToString(Qt::Key_Enter)));
|
||||||
|
}
|
||||||
|
|
||||||
void TestAutoType::testGlobalAutoTypeTitleMatchDisabled()
|
void TestAutoType::testGlobalAutoTypeTitleMatchDisabled()
|
||||||
{
|
{
|
||||||
m_test->setActiveWindowTitle("An Entry Title!");
|
m_test->setActiveWindowTitle("An Entry Title!");
|
||||||
|
|
|
@ -42,6 +42,8 @@ private slots:
|
||||||
void testGlobalAutoTypeWithNoMatch();
|
void testGlobalAutoTypeWithNoMatch();
|
||||||
void testGlobalAutoTypeWithOneMatch();
|
void testGlobalAutoTypeWithOneMatch();
|
||||||
void testGlobalAutoTypeTitleMatch();
|
void testGlobalAutoTypeTitleMatch();
|
||||||
|
void testGlobalAutoTypeUrlMatch();
|
||||||
|
void testGlobalAutoTypeUrlSubdomainMatch();
|
||||||
void testGlobalAutoTypeTitleMatchDisabled();
|
void testGlobalAutoTypeTitleMatchDisabled();
|
||||||
void testGlobalAutoTypeRegExp();
|
void testGlobalAutoTypeRegExp();
|
||||||
|
|
||||||
|
@ -56,6 +58,7 @@ private:
|
||||||
Entry* m_entry2;
|
Entry* m_entry2;
|
||||||
Entry* m_entry3;
|
Entry* m_entry3;
|
||||||
Entry* m_entry4;
|
Entry* m_entry4;
|
||||||
|
Entry* m_entry5;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEEPASSX_TESTAUTOTYPE_H
|
#endif // KEEPASSX_TESTAUTOTYPE_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue