2012-10-28 10:42:19 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
|
2017-06-09 17:40:36 -04:00
|
|
|
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
2012-10-28 10:42:19 -04:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "TestAutoType.h"
|
|
|
|
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QPluginLoader>
|
2021-07-11 22:10:29 -04:00
|
|
|
#include <QTest>
|
2012-10-28 10:42:19 -04:00
|
|
|
|
|
|
|
#include "autotype/AutoType.h"
|
|
|
|
#include "autotype/AutoTypePlatformPlugin.h"
|
|
|
|
#include "autotype/test/AutoTypeTestInterface.h"
|
2018-03-31 16:01:30 -04:00
|
|
|
#include "core/Config.h"
|
2021-07-11 22:10:29 -04:00
|
|
|
#include "core/Group.h"
|
2020-03-08 20:27:16 -04:00
|
|
|
#include "core/Resources.h"
|
2018-03-31 16:01:30 -04:00
|
|
|
#include "crypto/Crypto.h"
|
2014-04-07 02:54:32 -04:00
|
|
|
#include "gui/MessageBox.h"
|
2020-12-13 23:23:25 -05:00
|
|
|
#include "gui/osutils/OSUtils.h"
|
2012-10-28 10:42:19 -04:00
|
|
|
|
2014-05-16 06:32:52 -04:00
|
|
|
QTEST_GUILESS_MAIN(TestAutoType)
|
|
|
|
|
2012-10-28 10:42:19 -04:00
|
|
|
void TestAutoType::initTestCase()
|
|
|
|
{
|
2014-06-15 05:17:40 -04:00
|
|
|
QVERIFY(Crypto::init());
|
2014-05-15 12:26:01 -04:00
|
|
|
Config::createTempFileInstance();
|
2020-04-25 19:31:38 -04:00
|
|
|
config()->set(Config::AutoTypeDelay, 1);
|
|
|
|
config()->set(Config::Security_AutoTypeAsk, false);
|
2018-03-08 04:20:25 -05:00
|
|
|
AutoType::createTestInstance();
|
2012-10-28 10:42:19 -04:00
|
|
|
|
2021-02-15 17:26:23 -05:00
|
|
|
QPluginLoader loader(resources()->pluginPath("keepassxc-autotype-test"));
|
2012-10-28 10:42:19 -04:00
|
|
|
loader.setLoadHints(QLibrary::ResolveAllSymbolsHint);
|
|
|
|
QVERIFY(loader.instance());
|
|
|
|
|
|
|
|
m_platform = qobject_cast<AutoTypePlatformInterface*>(loader.instance());
|
|
|
|
QVERIFY(m_platform);
|
|
|
|
|
|
|
|
m_test = qobject_cast<AutoTypeTestInterface*>(loader.instance());
|
|
|
|
QVERIFY(m_test);
|
2012-10-28 13:13:49 -04:00
|
|
|
|
|
|
|
m_autoType = AutoType::instance();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestAutoType::init()
|
|
|
|
{
|
2020-04-25 19:31:38 -04:00
|
|
|
config()->set(Config::AutoTypeEntryTitleMatch, false);
|
2012-10-28 13:13:49 -04:00
|
|
|
m_test->clearActions();
|
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
m_db = QSharedPointer<Database>::create();
|
2014-05-15 12:26:01 -04:00
|
|
|
m_dbList.clear();
|
|
|
|
m_dbList.append(m_db);
|
2023-08-28 07:19:12 -04:00
|
|
|
m_group = m_db->rootGroup();
|
2014-05-15 12:26:01 -04:00
|
|
|
|
2015-10-10 11:36:08 -04:00
|
|
|
AutoTypeAssociations::Association association;
|
|
|
|
|
2014-05-15 12:26:01 -04:00
|
|
|
m_entry1 = new Entry();
|
|
|
|
m_entry1->setGroup(m_group);
|
|
|
|
m_entry1->setUsername("myuser");
|
|
|
|
m_entry1->setPassword("mypass");
|
|
|
|
association.window = "custom window";
|
|
|
|
association.sequence = "{username}association{password}";
|
|
|
|
m_entry1->autoTypeAssociations()->add(association);
|
|
|
|
|
|
|
|
m_entry2 = new Entry();
|
|
|
|
m_entry2->setGroup(m_group);
|
|
|
|
m_entry2->setPassword("myuser");
|
|
|
|
m_entry2->setTitle("entry title");
|
2015-10-10 11:36:08 -04:00
|
|
|
|
|
|
|
m_entry3 = new Entry();
|
|
|
|
m_entry3->setGroup(m_group);
|
|
|
|
m_entry3->setPassword("regex");
|
|
|
|
association.window = "//REGEX1//";
|
|
|
|
association.sequence = "regex1";
|
|
|
|
m_entry3->autoTypeAssociations()->add(association);
|
|
|
|
association.window = "//^REGEX2$//";
|
|
|
|
association.sequence = "regex2";
|
|
|
|
m_entry3->autoTypeAssociations()->add(association);
|
|
|
|
association.window = "//^REGEX3-([rd]\\d){2}$//";
|
|
|
|
association.sequence = "regex3";
|
|
|
|
m_entry3->autoTypeAssociations()->add(association);
|
2016-11-25 12:26:59 -05:00
|
|
|
|
|
|
|
m_entry4 = new Entry();
|
|
|
|
m_entry4->setGroup(m_group);
|
|
|
|
m_entry4->setPassword("custom_attr");
|
2018-03-31 16:01:30 -04:00
|
|
|
m_entry4->attributes()->set("CUSTOM", "Attribute", false);
|
|
|
|
m_entry4->attributes()->set("CustomAttrFirst", "AttrValueFirst", false);
|
|
|
|
m_entry4->attributes()->set("CustomAttrSecond", "AttrValueSecond", false);
|
|
|
|
m_entry4->attributes()->set("CustomAttrThird", "AttrValueThird", false);
|
2016-11-25 12:26:59 -05:00
|
|
|
association.window = "//^CustomAttr1$//";
|
2017-02-07 19:14:52 -05:00
|
|
|
association.sequence = "{PASSWORD}:{S:CUSTOM}";
|
2016-11-25 12:26:59 -05:00
|
|
|
m_entry4->autoTypeAssociations()->add(association);
|
|
|
|
association.window = "//^CustomAttr2$//";
|
2017-02-07 19:14:52 -05:00
|
|
|
association.sequence = "{S:CuStOm}";
|
2016-11-25 12:26:59 -05:00
|
|
|
m_entry4->autoTypeAssociations()->add(association);
|
|
|
|
association.window = "//^CustomAttr3$//";
|
|
|
|
association.sequence = "{PaSSworD}";
|
|
|
|
m_entry4->autoTypeAssociations()->add(association);
|
2017-10-06 12:41:04 -04:00
|
|
|
association.window = "//^{S:CustomAttrFirst}$//";
|
|
|
|
association.sequence = "custom_attr_first";
|
|
|
|
m_entry4->autoTypeAssociations()->add(association);
|
|
|
|
association.window = "//{S:CustomAttrFirst}And{S:CustomAttrSecond}//";
|
|
|
|
association.sequence = "custom_attr_first_and_second";
|
|
|
|
m_entry4->autoTypeAssociations()->add(association);
|
|
|
|
association.window = "//{S:CustomAttrThird}//";
|
|
|
|
association.sequence = "custom_attr_third";
|
|
|
|
m_entry4->autoTypeAssociations()->add(association);
|
|
|
|
|
2017-05-13 19:02:54 -04:00
|
|
|
m_entry5 = new Entry();
|
|
|
|
m_entry5->setGroup(m_group);
|
|
|
|
m_entry5->setPassword("example5");
|
|
|
|
m_entry5->setTitle("some title");
|
|
|
|
m_entry5->setUrl("http://example.org");
|
2012-10-28 10:42:19 -04:00
|
|
|
}
|
|
|
|
|
2012-11-02 10:07:44 -04:00
|
|
|
void TestAutoType::cleanup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-28 10:42:19 -04:00
|
|
|
void TestAutoType::testInternal()
|
|
|
|
{
|
|
|
|
QVERIFY(m_platform->activeWindowTitle().isEmpty());
|
|
|
|
|
|
|
|
m_test->setActiveWindowTitle("Test");
|
|
|
|
QCOMPARE(m_platform->activeWindowTitle(), QString("Test"));
|
|
|
|
}
|
|
|
|
|
2018-01-18 17:45:09 -05:00
|
|
|
void TestAutoType::testSingleAutoType()
|
2012-10-28 13:13:49 -04:00
|
|
|
{
|
2022-03-07 23:05:24 -05:00
|
|
|
m_autoType->performAutoType(m_entry1);
|
2012-10-28 13:13:49 -04:00
|
|
|
|
|
|
|
QCOMPARE(m_test->actionCount(), 14);
|
|
|
|
QCOMPARE(m_test->actionChars(),
|
2018-03-31 16:01:30 -04:00
|
|
|
QString("myuser%1mypass%2").arg(m_test->keyToString(Qt::Key_Tab)).arg(m_test->keyToString(Qt::Key_Enter)));
|
2012-10-28 13:13:49 -04:00
|
|
|
}
|
|
|
|
|
2012-11-02 10:07:44 -04:00
|
|
|
void TestAutoType::testGlobalAutoTypeWithNoMatch()
|
|
|
|
{
|
2014-05-15 12:26:01 -04:00
|
|
|
m_test->setActiveWindowTitle("nomatch");
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Ok);
|
2014-05-15 12:26:01 -04:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
2012-11-02 10:07:44 -04:00
|
|
|
|
|
|
|
QCOMPARE(m_test->actionChars(), QString());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestAutoType::testGlobalAutoTypeWithOneMatch()
|
|
|
|
{
|
|
|
|
m_test->setActiveWindowTitle("custom window");
|
2020-12-13 23:23:25 -05:00
|
|
|
emit osUtils->globalShortcutTriggered("autotype");
|
2014-05-15 12:26:01 -04:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
2012-11-02 10:07:44 -04:00
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
QCOMPARE(m_test->actionChars(), QString("%1association%2").arg(m_entry1->username()).arg(m_entry1->password()));
|
2014-05-15 12:26:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestAutoType::testGlobalAutoTypeTitleMatch()
|
|
|
|
{
|
2020-04-25 19:31:38 -04:00
|
|
|
config()->set(Config::AutoTypeEntryTitleMatch, true);
|
2014-05-15 12:26:01 -04:00
|
|
|
|
|
|
|
m_test->setActiveWindowTitle("An Entry Title!");
|
2020-12-13 23:23:25 -05:00
|
|
|
emit osUtils->globalShortcutTriggered("autotype");
|
2014-05-15 12:26:01 -04:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
QCOMPARE(m_test->actionChars(), QString("%1%2").arg(m_entry2->password(), m_test->keyToString(Qt::Key_Enter)));
|
2014-05-15 12:26:01 -04:00
|
|
|
}
|
|
|
|
|
2017-05-13 19:02:54 -04:00
|
|
|
void TestAutoType::testGlobalAutoTypeUrlMatch()
|
|
|
|
{
|
2020-04-25 19:31:38 -04:00
|
|
|
config()->set(Config::AutoTypeEntryTitleMatch, true);
|
2017-05-13 19:02:54 -04:00
|
|
|
|
|
|
|
m_test->setActiveWindowTitle("Dummy - http://example.org/ - <My Browser>");
|
2020-12-13 23:23:25 -05:00
|
|
|
emit osUtils->globalShortcutTriggered("autotype");
|
2017-05-13 19:02:54 -04:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
QCOMPARE(m_test->actionChars(), QString("%1%2").arg(m_entry5->password(), m_test->keyToString(Qt::Key_Enter)));
|
2017-05-13 19:02:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestAutoType::testGlobalAutoTypeUrlSubdomainMatch()
|
|
|
|
{
|
2020-04-25 19:31:38 -04:00
|
|
|
config()->set(Config::AutoTypeEntryTitleMatch, true);
|
2017-05-13 19:02:54 -04:00
|
|
|
|
|
|
|
m_test->setActiveWindowTitle("Dummy - http://sub.example.org/ - <My Browser>");
|
2020-12-13 23:23:25 -05:00
|
|
|
emit osUtils->globalShortcutTriggered("autotype");
|
2017-05-13 19:02:54 -04:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
QCOMPARE(m_test->actionChars(), QString("%1%2").arg(m_entry5->password(), m_test->keyToString(Qt::Key_Enter)));
|
2017-05-13 19:02:54 -04:00
|
|
|
}
|
|
|
|
|
2014-05-15 12:26:01 -04:00
|
|
|
void TestAutoType::testGlobalAutoTypeTitleMatchDisabled()
|
|
|
|
{
|
|
|
|
m_test->setActiveWindowTitle("An Entry Title!");
|
2020-12-13 23:23:25 -05:00
|
|
|
emit osUtils->globalShortcutTriggered("autotype");
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Ok);
|
2014-05-15 12:26:01 -04:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
|
|
|
|
|
|
|
QCOMPARE(m_test->actionChars(), QString());
|
2015-10-10 11:36:08 -04:00
|
|
|
}
|
2014-05-15 12:26:01 -04:00
|
|
|
|
2015-10-10 11:36:08 -04:00
|
|
|
void TestAutoType::testGlobalAutoTypeRegExp()
|
|
|
|
{
|
|
|
|
// substring matches are ok
|
|
|
|
m_test->setActiveWindowTitle("lorem REGEX1 ipsum");
|
2020-12-13 23:23:25 -05:00
|
|
|
emit osUtils->globalShortcutTriggered("autotype");
|
2015-10-10 11:36:08 -04:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
|
|
|
QCOMPARE(m_test->actionChars(), QString("regex1"));
|
|
|
|
m_test->clearActions();
|
2014-05-15 12:26:01 -04:00
|
|
|
|
2015-10-10 11:36:08 -04:00
|
|
|
// should be case-insensitive
|
|
|
|
m_test->setActiveWindowTitle("lorem regex1 ipsum");
|
2020-12-13 23:23:25 -05:00
|
|
|
emit osUtils->globalShortcutTriggered("autotype");
|
2015-10-10 11:36:08 -04:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
|
|
|
QCOMPARE(m_test->actionChars(), QString("regex1"));
|
|
|
|
m_test->clearActions();
|
|
|
|
|
|
|
|
// exact match
|
|
|
|
m_test->setActiveWindowTitle("REGEX2");
|
2020-12-13 23:23:25 -05:00
|
|
|
emit osUtils->globalShortcutTriggered("autotype");
|
2015-10-10 11:36:08 -04:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
|
|
|
QCOMPARE(m_test->actionChars(), QString("regex2"));
|
|
|
|
m_test->clearActions();
|
|
|
|
|
|
|
|
// a bit more complicated regex
|
|
|
|
m_test->setActiveWindowTitle("REGEX3-R2D2");
|
2020-12-13 23:23:25 -05:00
|
|
|
emit osUtils->globalShortcutTriggered("autotype");
|
2015-10-10 11:36:08 -04:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
|
|
|
QCOMPARE(m_test->actionChars(), QString("regex3"));
|
|
|
|
m_test->clearActions();
|
2016-11-25 12:26:59 -05:00
|
|
|
|
|
|
|
// with custom attributes
|
|
|
|
m_test->setActiveWindowTitle("CustomAttr1");
|
2020-12-13 23:23:25 -05:00
|
|
|
emit osUtils->globalShortcutTriggered("autotype");
|
2016-11-25 12:26:59 -05:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
|
|
|
QCOMPARE(m_test->actionChars(), QString("custom_attr:Attribute"));
|
|
|
|
m_test->clearActions();
|
|
|
|
|
|
|
|
// with (non uppercase) undefined custom attributes
|
|
|
|
m_test->setActiveWindowTitle("CustomAttr2");
|
2020-12-13 23:23:25 -05:00
|
|
|
emit osUtils->globalShortcutTriggered("autotype");
|
2016-11-25 12:26:59 -05:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
|
|
|
QCOMPARE(m_test->actionChars(), QString(""));
|
|
|
|
m_test->clearActions();
|
|
|
|
|
|
|
|
// with mixedcase default attributes
|
|
|
|
m_test->setActiveWindowTitle("CustomAttr3");
|
2020-12-13 23:23:25 -05:00
|
|
|
emit osUtils->globalShortcutTriggered("autotype");
|
2016-11-25 12:26:59 -05:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
|
|
|
QCOMPARE(m_test->actionChars(), QString("custom_attr"));
|
|
|
|
m_test->clearActions();
|
2017-10-06 12:41:04 -04:00
|
|
|
|
|
|
|
// with resolve placeholders in window association title
|
|
|
|
m_test->setActiveWindowTitle("AttrValueFirst");
|
2020-12-13 23:23:25 -05:00
|
|
|
emit osUtils->globalShortcutTriggered("autotype");
|
2017-10-06 12:41:04 -04:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
|
|
|
QCOMPARE(m_test->actionChars(), QString("custom_attr_first"));
|
|
|
|
m_test->clearActions();
|
|
|
|
|
|
|
|
m_test->setActiveWindowTitle("lorem AttrValueFirstAndAttrValueSecond ipsum");
|
2020-12-13 23:23:25 -05:00
|
|
|
emit osUtils->globalShortcutTriggered("autotype");
|
2017-10-06 12:41:04 -04:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
|
|
|
QCOMPARE(m_test->actionChars(), QString("custom_attr_first_and_second"));
|
|
|
|
m_test->clearActions();
|
|
|
|
|
|
|
|
m_test->setActiveWindowTitle("lorem AttrValueThird ipsum");
|
2020-12-13 23:23:25 -05:00
|
|
|
emit osUtils->globalShortcutTriggered("autotype");
|
2017-10-06 12:41:04 -04:00
|
|
|
m_autoType->performGlobalAutoType(m_dbList);
|
|
|
|
QCOMPARE(m_test->actionChars(), QString("custom_attr_third"));
|
|
|
|
m_test->clearActions();
|
2012-11-02 10:07:44 -04:00
|
|
|
}
|
2017-11-07 11:58:08 -05:00
|
|
|
|
2020-12-24 10:58:11 -05:00
|
|
|
void TestAutoType::testAutoTypeResults()
|
|
|
|
{
|
|
|
|
QScopedPointer<Entry> entry(new Entry());
|
|
|
|
entry->setUsername("Username");
|
|
|
|
entry->setPassword("Password@1");
|
|
|
|
entry->setUrl("https://example.com");
|
|
|
|
entry->attributes()->set("attr1", "value1");
|
|
|
|
entry->attributes()->set("attr2", "decode%20me");
|
|
|
|
|
|
|
|
QFETCH(QString, sequence);
|
|
|
|
QFETCH(QString, expectedResult);
|
|
|
|
|
|
|
|
m_autoType->performAutoTypeWithSequence(entry.data(), sequence);
|
|
|
|
QCOMPARE(m_test->actionChars(), expectedResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestAutoType::testAutoTypeResults_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("sequence");
|
|
|
|
QTest::addColumn<QString>("expectedResult");
|
|
|
|
|
|
|
|
// Normal Sequences
|
|
|
|
QTest::newRow("Sequence with Attributes") << QString("{USERNAME} {PASSWORD} {URL} {S:attr1}")
|
|
|
|
<< QString("Username Password@1 https://example.com value1");
|
|
|
|
QTest::newRow("Sequence with Comment") << QString("{USERNAME}{TAB}{C:Extra Tab}{TAB}{S:attr1}")
|
|
|
|
<< QString("Username[Key0x1000001][Key0x1000001]value1");
|
|
|
|
|
|
|
|
// Conversions and Replacements
|
|
|
|
QTest::newRow("T-CONV UPPER") << QString("{T-CONV:/{USERNAME}/UPPER/}") << QString("USERNAME");
|
|
|
|
QTest::newRow("T-CONV LOWER") << QString("{T-CONV:/{USERNAME}/LOWER/}") << QString("username");
|
|
|
|
QTest::newRow("T-CONV BASE64") << QString("{T-CONV:/{USERNAME}/BASE64/}") << QString("VXNlcm5hbWU=");
|
|
|
|
QTest::newRow("T-CONV HEX") << QString("{T-CONV:/{USERNAME}/HEX/}") << QString("557365726e616d65");
|
|
|
|
QTest::newRow("T-CONV URI ENCODE") << QString("{T-CONV:/{URL}/URI/}") << QString("https%3A%2F%2Fexample.com");
|
|
|
|
QTest::newRow("T-CONV URI DECODE") << QString("{T-CONV:/{S:attr2}/URI-DEC/}") << QString("decode me");
|
2021-02-15 17:26:23 -05:00
|
|
|
QTest::newRow("T-REPLACE-RX") << QString("{T-REPLACE-RX:/{USERNAME}/(User)/$1Pass/}") << QString("UserPassname");
|
2020-12-24 10:58:11 -05:00
|
|
|
}
|
|
|
|
|
2017-11-07 11:58:08 -05:00
|
|
|
void TestAutoType::testAutoTypeSyntaxChecks()
|
|
|
|
{
|
2021-02-13 22:13:10 -05:00
|
|
|
auto entry = new Entry();
|
|
|
|
QString error;
|
|
|
|
|
2017-11-07 11:58:08 -05:00
|
|
|
// Huge sequence
|
2021-02-13 22:13:10 -05:00
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax(
|
|
|
|
"{F1 23}{~ 23}{% 23}{^}{F12}{(}{) 23}{[}{[}{]}{Delay=23}{+}{SUBTRACT}~+%@fixedstring", entry, error),
|
|
|
|
error.toLatin1());
|
|
|
|
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{NUMPAD1 3}", entry, error), error.toLatin1());
|
|
|
|
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{S:SPECIALTOKEN}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{S:SPECIAL TOKEN}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{S:SPECIAL_TOKEN}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{S:SPECIAL-TOKEN}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{S:SPECIAL:TOKEN}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{S:SPECIAL_TOKEN}{ENTER}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{S:FOO}{S:HELLO WORLD}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(!AutoType::verifyAutoTypeSyntax("{S:SPECIAL_TOKEN{}}", entry, error), error.toLatin1());
|
|
|
|
|
2022-06-05 21:56:48 -04:00
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{BEEP 3 3}", entry, error), error.toLatin1());
|
2021-02-13 22:13:10 -05:00
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{BEEP 3}", entry, error), error.toLatin1());
|
|
|
|
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{VKEY 0x01}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{VKEY VK_LBUTTON}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{VKEY-EX 0x01}", entry, error), error.toLatin1());
|
2017-11-07 11:58:08 -05:00
|
|
|
// Bad sequence
|
2021-02-13 22:13:10 -05:00
|
|
|
QVERIFY2(!AutoType::verifyAutoTypeSyntax("{{{}}{}{}}{{}}", entry, error), error.toLatin1());
|
2017-12-30 08:16:18 -05:00
|
|
|
// Good sequence
|
2021-02-13 22:13:10 -05:00
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{{}{}}{}}{{}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{]}{[}{[}{]}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{)}{(}{(}{)}", entry, error), error.toLatin1());
|
|
|
|
// High delay
|
|
|
|
QVERIFY2(!AutoType::verifyAutoTypeSyntax("{DELAY 50000}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{delay 50}", entry, error), error.toLatin1());
|
2017-12-28 08:12:17 -05:00
|
|
|
// Slow typing
|
2021-02-13 22:13:10 -05:00
|
|
|
QVERIFY2(!AutoType::verifyAutoTypeSyntax("{DELAY=50000}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{delay=50}", entry, error), error.toLatin1());
|
|
|
|
// Many repetition
|
|
|
|
QVERIFY2(!AutoType::verifyAutoTypeSyntax("{LEFT 50000000}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{SPACE 10}{TAB 3}{RIGHT 50}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{delay 5000000000}", entry, error), error.toLatin1());
|
2020-12-24 10:58:11 -05:00
|
|
|
// Conversion and Regex
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{T-CONV:/{USERNAME}/base64/}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(!AutoType::verifyAutoTypeSyntax("{T-CONV:/{USERNAME}/junk/}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(!AutoType::verifyAutoTypeSyntax("{T-CONV:}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(AutoType::verifyAutoTypeSyntax("{T-REPLACE-RX:/{USERNAME}/a/b/}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(!AutoType::verifyAutoTypeSyntax("{T-REPLACE-RX:/{USERNAME}/a/}", entry, error), error.toLatin1());
|
|
|
|
QVERIFY2(!AutoType::verifyAutoTypeSyntax("{T-REPLACE-RX:}", entry, error), error.toLatin1());
|
2018-01-16 11:23:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestAutoType::testAutoTypeEffectiveSequences()
|
|
|
|
{
|
|
|
|
QString defaultSequence("{USERNAME}{TAB}{PASSWORD}{ENTER}");
|
|
|
|
QString sequenceG1("{TEST_GROUP1}");
|
|
|
|
QString sequenceG3("{TEST_GROUP3}");
|
|
|
|
QString sequenceE2("{TEST_ENTRY2}");
|
|
|
|
QString sequenceDisabled("{TEST_DISABLED}");
|
|
|
|
QString sequenceOrphan("{TEST_ORPHAN}");
|
|
|
|
|
2018-01-24 14:08:56 -05:00
|
|
|
QScopedPointer<Database> db(new Database());
|
2018-01-16 11:23:29 -05:00
|
|
|
QPointer<Group> rootGroup = db->rootGroup();
|
|
|
|
|
|
|
|
// Group with autotype enabled and custom default sequence
|
|
|
|
QPointer<Group> group1 = new Group();
|
|
|
|
group1->setParent(rootGroup);
|
|
|
|
group1->setDefaultAutoTypeSequence(sequenceG1);
|
2018-03-31 16:01:30 -04:00
|
|
|
|
2018-01-16 11:23:29 -05:00
|
|
|
// Child group with inherit
|
|
|
|
QPointer<Group> group2 = new Group();
|
|
|
|
group2->setParent(group1);
|
|
|
|
|
|
|
|
// Group with autotype disabled and custom default sequence
|
|
|
|
QPointer<Group> group3 = new Group();
|
|
|
|
group3->setParent(group1);
|
|
|
|
group3->setAutoTypeEnabled(Group::Disable);
|
|
|
|
group3->setDefaultAutoTypeSequence(sequenceG3);
|
|
|
|
|
|
|
|
QCOMPARE(rootGroup->defaultAutoTypeSequence(), QString());
|
|
|
|
QCOMPARE(rootGroup->effectiveAutoTypeSequence(), defaultSequence);
|
|
|
|
QCOMPARE(group1->defaultAutoTypeSequence(), sequenceG1);
|
|
|
|
QCOMPARE(group1->effectiveAutoTypeSequence(), sequenceG1);
|
|
|
|
QCOMPARE(group2->defaultAutoTypeSequence(), QString());
|
|
|
|
QCOMPARE(group2->effectiveAutoTypeSequence(), sequenceG1);
|
|
|
|
QCOMPARE(group3->defaultAutoTypeSequence(), sequenceG3);
|
|
|
|
QCOMPARE(group3->effectiveAutoTypeSequence(), QString());
|
|
|
|
|
|
|
|
// Entry from root group
|
|
|
|
QPointer<Entry> entry1 = new Entry();
|
|
|
|
entry1->setGroup(rootGroup);
|
|
|
|
|
|
|
|
// Entry with custom default sequence
|
|
|
|
QPointer<Entry> entry2 = new Entry();
|
|
|
|
entry2->setDefaultAutoTypeSequence(sequenceE2);
|
|
|
|
entry2->setGroup(rootGroup);
|
|
|
|
|
|
|
|
// Entry from enabled child group
|
|
|
|
QPointer<Entry> entry3 = new Entry();
|
|
|
|
entry3->setGroup(group2);
|
|
|
|
|
|
|
|
// Entry from disabled group
|
|
|
|
QPointer<Entry> entry4 = new Entry();
|
|
|
|
entry4->setDefaultAutoTypeSequence(sequenceDisabled);
|
|
|
|
entry4->setGroup(group3);
|
|
|
|
|
|
|
|
// Entry from enabled group with disabled autotype
|
|
|
|
QPointer<Entry> entry5 = new Entry();
|
|
|
|
entry5->setGroup(group2);
|
|
|
|
entry5->setDefaultAutoTypeSequence(sequenceDisabled);
|
|
|
|
entry5->setAutoTypeEnabled(false);
|
|
|
|
|
|
|
|
// Entry with no parent
|
2018-01-24 14:08:56 -05:00
|
|
|
QScopedPointer<Entry> entry6(new Entry());
|
2018-01-16 11:23:29 -05:00
|
|
|
entry6->setDefaultAutoTypeSequence(sequenceOrphan);
|
|
|
|
|
|
|
|
QCOMPARE(entry1->defaultAutoTypeSequence(), QString());
|
|
|
|
QCOMPARE(entry1->effectiveAutoTypeSequence(), defaultSequence);
|
|
|
|
QCOMPARE(entry2->defaultAutoTypeSequence(), sequenceE2);
|
|
|
|
QCOMPARE(entry2->effectiveAutoTypeSequence(), sequenceE2);
|
|
|
|
QCOMPARE(entry3->defaultAutoTypeSequence(), QString());
|
|
|
|
QCOMPARE(entry3->effectiveAutoTypeSequence(), sequenceG1);
|
|
|
|
QCOMPARE(entry4->defaultAutoTypeSequence(), sequenceDisabled);
|
|
|
|
QCOMPARE(entry4->effectiveAutoTypeSequence(), QString());
|
|
|
|
QCOMPARE(entry5->defaultAutoTypeSequence(), sequenceDisabled);
|
|
|
|
QCOMPARE(entry5->effectiveAutoTypeSequence(), QString());
|
|
|
|
QCOMPARE(entry6->defaultAutoTypeSequence(), sequenceOrphan);
|
|
|
|
QCOMPARE(entry6->effectiveAutoTypeSequence(), QString());
|
2018-12-19 23:14:11 -05:00
|
|
|
}
|