mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-10-11 21:10:48 -04:00
add test for syntax checking
This commit is contained in:
parent
8ca444aee0
commit
a02a49a184
6 changed files with 32 additions and 28 deletions
|
@ -130,7 +130,7 @@ QStringList AutoType::windowTitles()
|
||||||
return m_plugin->windowTitles();
|
return m_plugin->windowTitles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoType::performAutoType(const Entry* entry, QWidget* hideWindow, const QString& customSequence, WId window)
|
void AutoType::_performAutoType(const Entry* entry, QWidget* hideWindow, const QString& customSequence, WId window)
|
||||||
{
|
{
|
||||||
if (m_inAutoType || !m_plugin) {
|
if (m_inAutoType || !m_plugin) {
|
||||||
return;
|
return;
|
||||||
|
@ -253,7 +253,7 @@ void AutoType::performAutoTypeFromGlobal(Entry* entry, const QString& sequence)
|
||||||
|
|
||||||
m_inAutoType = false;
|
m_inAutoType = false;
|
||||||
|
|
||||||
performAutoTypeWithSyntaxCheckingDialog(entry, nullptr, sequence, m_windowFromGlobal);
|
performAutoType(entry, nullptr, sequence, m_windowFromGlobal);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoType::resetInAutoType()
|
void AutoType::resetInAutoType()
|
||||||
|
@ -556,14 +556,6 @@ QList<AutoTypeAction*> AutoType::createActionFromTemplate(const QString& tmpl, c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//allows to insert usernames and passwords multiple times
|
|
||||||
if (!list.isEmpty()) {
|
|
||||||
for (int i = 1; i < num; i++) {
|
|
||||||
for (int j = 0; j < resolved.size(); j++) {
|
|
||||||
list.append(list.at(j)->clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -679,13 +671,13 @@ bool AutoType::windowMatchesUrl(const QString& windowTitle, const QString& resol
|
||||||
bool AutoType::checkSyntax(const QString &string)
|
bool AutoType::checkSyntax(const QString &string)
|
||||||
{
|
{
|
||||||
//checks things like {word 23}{F1 23}{~ 23}{% 23}{^}{F12}{(}{) 23}{[}{[}{]}{Delay=23}{+}{-}~+%@fixedstring
|
//checks things like {word 23}{F1 23}{~ 23}{% 23}{^}{F12}{(}{) 23}{[}{[}{]}{Delay=23}{+}{-}~+%@fixedstring
|
||||||
QString allowRepetition = "(\\s[0-9]*){0,1}";
|
QString allowRepetition = "(\\s\\d*){0,1}";
|
||||||
QString normalCommands = "[A-Z:]*" + allowRepetition; //the ":" allows custom commands
|
QString normalCommands = "[A-Z:]*" + allowRepetition; //the ":" allows custom commands
|
||||||
QString specialLiterals = "[\\^\\%\\(\\)~\\{\\}\\[\\]\\+-]" + allowRepetition;
|
QString specialLiterals = "[\\^\\%\\(\\)~\\{\\}\\[\\]\\+-]" + allowRepetition;
|
||||||
QString functionKeys = "(F[1-9]" + allowRepetition + "|F1[0-2])" + allowRepetition;
|
QString functionKeys = "(F[1-9]" + allowRepetition + "|F1[0-2])" + allowRepetition;
|
||||||
QString numpad = "NUMPAD[0-9]" + allowRepetition;
|
QString numpad = "NUMPAD\\d" + allowRepetition;
|
||||||
QString delay = "DELAY=[0-9]+";
|
QString delay = "DELAY=\\d+";
|
||||||
QString beep = "BEEP\\s[0-9]*\\s[0-9]*";
|
QString beep = "BEEP\\s\\d*\\s\\d*";
|
||||||
QString vkey = "VKEY(-[EN]X){0,1}" + allowRepetition;
|
QString vkey = "VKEY(-[EN]X){0,1}" + allowRepetition;
|
||||||
|
|
||||||
//these arent in parenthesis
|
//these arent in parenthesis
|
||||||
|
@ -703,7 +695,7 @@ bool AutoType::checkSyntax(const QString &string)
|
||||||
|
|
||||||
bool AutoType::checkHighDelay(const QString &string)
|
bool AutoType::checkHighDelay(const QString &string)
|
||||||
{
|
{
|
||||||
QRegExp highDelay(".*\\{Delay\\s[0-9]{5,}\\}.*"); //5 digit numbers(10 seconds) are too much
|
QRegExp highDelay("\\{DELAY\\s\\d{5,}\\}"); //5 digit numbers(10 seconds) are too much
|
||||||
highDelay.setCaseSensitivity(Qt::CaseInsensitive);
|
highDelay.setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
highDelay.setPatternSyntax(QRegExp::RegExp);
|
highDelay.setPatternSyntax(QRegExp::RegExp);
|
||||||
return highDelay.exactMatch(string);
|
return highDelay.exactMatch(string);
|
||||||
|
@ -711,16 +703,14 @@ bool AutoType::checkHighDelay(const QString &string)
|
||||||
|
|
||||||
bool AutoType::checkHighRepetition(const QString &string)
|
bool AutoType::checkHighRepetition(const QString &string)
|
||||||
{
|
{
|
||||||
QRegExp highRepetition(".*\\s[0-9]{3,}.*");//3 digit numbers are too much
|
QRegExp highRepetition("\\{(?!DELAY\\s)\\w*\\s\\d{3,}\\}"); //3 digit numbers are too much
|
||||||
|
highRepetition.setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
highRepetition.setPatternSyntax(QRegExp::RegExp);
|
highRepetition.setPatternSyntax(QRegExp::RegExp);
|
||||||
return highRepetition.exactMatch(string);
|
return highRepetition.exactMatch(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AutoType::performAutoTypeWithSyntaxCheckingDialog(const Entry *entry,
|
AutoType::performAutoType(const Entry *entry, QWidget *hideWindow, const QString &customSequence, WId window)
|
||||||
QWidget *hideWindow,
|
|
||||||
const QString &customSequence,
|
|
||||||
WId window)
|
|
||||||
{
|
{
|
||||||
if (!AutoType::checkSyntax(entry->effectiveAutoTypeSequence())) {
|
if (!AutoType::checkSyntax(entry->effectiveAutoTypeSequence())) {
|
||||||
QMessageBox messageBox;
|
QMessageBox messageBox;
|
||||||
|
@ -747,6 +737,6 @@ AutoType::performAutoTypeWithSyntaxCheckingDialog(const Entry *entry,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
performAutoType(entry, hideWindow, customSequence, window);
|
_performAutoType(entry, hideWindow, customSequence, window);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ class AutoType : public QObject
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QStringList windowTitles();
|
QStringList windowTitles();
|
||||||
void performAutoType(const Entry* entry, QWidget* hideWindow = nullptr,
|
void _performAutoType(const Entry* entry, QWidget* hideWindow = nullptr,
|
||||||
const QString& customSequence = QString(), WId window = 0);
|
const QString& customSequence = QString(), WId window = 0);
|
||||||
bool registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers);
|
bool registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers);
|
||||||
void unregisterGlobalShortcut();
|
void unregisterGlobalShortcut();
|
||||||
|
@ -45,10 +45,8 @@ public:
|
||||||
static bool checkSyntax(const QString &string);
|
static bool checkSyntax(const QString &string);
|
||||||
static bool checkHighRepetition(const QString &string);
|
static bool checkHighRepetition(const QString &string);
|
||||||
static bool checkHighDelay(const QString &string);
|
static bool checkHighDelay(const QString &string);
|
||||||
void performAutoTypeWithSyntaxCheckingDialog(const Entry *entry,
|
void performAutoType(const Entry *entry, QWidget *hideWindow = nullptr,
|
||||||
QWidget *hideWindow = nullptr,
|
const QString &customSequence = QString(), WId window = 0);
|
||||||
const QString &customSequence = QString(),
|
|
||||||
WId window = 0);
|
|
||||||
|
|
||||||
inline bool isAvailable() {
|
inline bool isAvailable() {
|
||||||
return m_plugin;
|
return m_plugin;
|
||||||
|
|
|
@ -584,7 +584,7 @@ void DatabaseWidget::performAutoType()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
autoType()->performAutoTypeWithSyntaxCheckingDialog(currentEntry, window());
|
autoType()->performAutoType(currentEntry, window());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWidget::openUrl()
|
void DatabaseWidget::openUrl()
|
||||||
|
|
|
@ -32,8 +32,8 @@
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <autotype/AutoType.h>
|
|
||||||
|
|
||||||
|
#include "autotype/AutoType.h"
|
||||||
#include "core/Config.h"
|
#include "core/Config.h"
|
||||||
#include "core/Database.h"
|
#include "core/Database.h"
|
||||||
#include "core/Entry.h"
|
#include "core/Entry.h"
|
||||||
|
|
|
@ -282,3 +282,18 @@ void TestAutoType::testGlobalAutoTypeRegExp()
|
||||||
QCOMPARE(m_test->actionChars(), QString("custom_attr_third"));
|
QCOMPARE(m_test->actionChars(), QString("custom_attr_third"));
|
||||||
m_test->clearActions();
|
m_test->clearActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestAutoType::testAutoTypeSyntaxChecks()
|
||||||
|
{
|
||||||
|
// Huge sequence
|
||||||
|
QCOMPARE(true, AutoType::checkSyntax("{word 23}{F1 23}{~ 23}{% 23}{^}{F12}{(}{) 23}{[}{[}{]}{Delay=23}{+}{-}~+%@fixedstring"));
|
||||||
|
// Bad sequence
|
||||||
|
QCOMPARE(false, AutoType::checkSyntax("{{{}}{}{}}{{}}"));
|
||||||
|
// High DelAY / low delay
|
||||||
|
QCOMPARE(true, AutoType::checkHighDelay("{DelAY 50000}"));
|
||||||
|
QCOMPARE(false, AutoType::checkHighDelay("{delay 50}"));
|
||||||
|
// Many repetition / few repetition / delay not repetition
|
||||||
|
QCOMPARE(true, AutoType::checkHighRepetition("{LEFT 50000000}"));
|
||||||
|
QCOMPARE(false, AutoType::checkHighRepetition("{SPACE 10}{TAB 3}{RIGHT 50}"));
|
||||||
|
QCOMPARE(false, AutoType::checkHighRepetition("{delay 5000000000}"));
|
||||||
|
}
|
|
@ -47,6 +47,7 @@ private slots:
|
||||||
void testGlobalAutoTypeUrlSubdomainMatch();
|
void testGlobalAutoTypeUrlSubdomainMatch();
|
||||||
void testGlobalAutoTypeTitleMatchDisabled();
|
void testGlobalAutoTypeTitleMatchDisabled();
|
||||||
void testGlobalAutoTypeRegExp();
|
void testGlobalAutoTypeRegExp();
|
||||||
|
void testAutoTypeSyntaxChecks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AutoTypePlatformInterface* m_platform;
|
AutoTypePlatformInterface* m_platform;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue