diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index d30adeeca..951c2184b 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -218,31 +218,29 @@ QString Entry::defaultAutoTypeSequence() const return m_data.defaultAutoTypeSequence; } +/** + * Determine the effective sequence that will be injected + * This function return an empty string if a parent group has autotype disabled or if the entry has no parent + */ QString Entry::effectiveAutoTypeSequence() const { + if (autoTypeEnabled() == false) { + return QString(); + } + + const Group* parent = group(); + if (!parent) { + return QString(); + } + + QString sequence = parent->effectiveAutoTypeSequence(); + if (sequence.isEmpty()) { + return QString(); + } + if (!m_data.defaultAutoTypeSequence.isEmpty()) { return m_data.defaultAutoTypeSequence; } - QString sequence; - - const Group* grp = group(); - if(grp) { - sequence = grp->effectiveAutoTypeSequence(); - } else { - return QString(); - } - - if (sequence.isEmpty() && (!username().isEmpty() || !password().isEmpty())) { - if (username().isEmpty()) { - sequence = "{PASSWORD}{ENTER}"; - } - else if (password().isEmpty()) { - sequence = "{USERNAME}{ENTER}"; - } - else { - sequence = "{USERNAME}{TAB}{PASSWORD}{ENTER}"; - } - } return sequence; } diff --git a/src/core/Group.cpp b/src/core/Group.cpp index bdcfeff73..e75f45268 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -192,6 +192,10 @@ QString Group::defaultAutoTypeSequence() const return m_data.defaultAutoTypeSequence; } +/** + * Determine the effective sequence that will be injected + * This function return an empty string if the current group or any parent has autotype disabled + */ QString Group::effectiveAutoTypeSequence() const { QString sequence; diff --git a/tests/TestAutoType.cpp b/tests/TestAutoType.cpp index 9d2f063e8..7d26a6afe 100644 --- a/tests/TestAutoType.cpp +++ b/tests/TestAutoType.cpp @@ -310,4 +310,84 @@ void TestAutoType::testAutoTypeSyntaxChecks() QCOMPARE(true, AutoType::checkHighRepetition("{LEFT 50000000}")); QCOMPARE(false, AutoType::checkHighRepetition("{SPACE 10}{TAB 3}{RIGHT 50}")); QCOMPARE(false, AutoType::checkHighRepetition("{delay 5000000000}")); +} + +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}"); + + Database* db = new Database(); + QPointer rootGroup = db->rootGroup(); + + // Group with autotype enabled and custom default sequence + QPointer group1 = new Group(); + group1->setParent(rootGroup); + group1->setDefaultAutoTypeSequence(sequenceG1); + + // Child group with inherit + QPointer group2 = new Group(); + group2->setParent(group1); + + // Group with autotype disabled and custom default sequence + QPointer 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 entry1 = new Entry(); + entry1->setGroup(rootGroup); + + // Entry with custom default sequence + QPointer entry2 = new Entry(); + entry2->setDefaultAutoTypeSequence(sequenceE2); + entry2->setGroup(rootGroup); + + // Entry from enabled child group + QPointer entry3 = new Entry(); + entry3->setGroup(group2); + + // Entry from disabled group + QPointer entry4 = new Entry(); + entry4->setDefaultAutoTypeSequence(sequenceDisabled); + entry4->setGroup(group3); + + // Entry from enabled group with disabled autotype + QPointer entry5 = new Entry(); + entry5->setGroup(group2); + entry5->setDefaultAutoTypeSequence(sequenceDisabled); + entry5->setAutoTypeEnabled(false); + + // Entry with no parent + QPointer entry6 = new Entry(); + 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()); + + delete db; } \ No newline at end of file diff --git a/tests/TestAutoType.h b/tests/TestAutoType.h index b7c33823b..516481282 100644 --- a/tests/TestAutoType.h +++ b/tests/TestAutoType.h @@ -48,6 +48,7 @@ private slots: void testGlobalAutoTypeTitleMatchDisabled(); void testGlobalAutoTypeRegExp(); void testAutoTypeSyntaxChecks(); + void testAutoTypeEffectiveSequences(); private: AutoTypePlatformInterface* m_platform;