diff options
author | Wizz <wizzk42@gmail.com> | 2019-12-21 17:46:01 +0300 |
---|---|---|
committer | Jonathan White <support@dmapps.us> | 2019-12-22 01:39:50 +0300 |
commit | 0654ffc1173da78d26a417459178f761f01ecfd7 (patch) | |
tree | be7c540e18a31e5979953248310dce469ac6af5c /tests/TestCli.cpp | |
parent | c0796d8fb1d7b840a1f019de4c5a0e577d18f88b (diff) |
CLI: Fix keyfile from/to parameter collision in merge command
Rename 'k' to 'f' because 'k' is already used to specify the key for the target database of the merge
* Remove short -f option from keepassxc-cli.1
* Remove -f option from keepassxc-cli merge
* Add test cases covering cli options for merge
* Add functional test for merge with keys
Diffstat (limited to 'tests/TestCli.cpp')
-rw-r--r-- | tests/TestCli.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/TestCli.cpp b/tests/TestCli.cpp index 9a2756eac..076f7f74e 100644 --- a/tests/TestCli.cpp +++ b/tests/TestCli.cpp @@ -1422,6 +1422,107 @@ void TestCli::testMerge() QCOMPARE(m_stdoutFile->readAll(), QByteArray("")); } +void TestCli::testMergeWithKeys() +{ + Create createCmd; + QVERIFY(!createCmd.name.isEmpty()); + QVERIFY(createCmd.getDescriptionLine().contains(createCmd.name)); + + Merge mergeCmd; + QVERIFY(!mergeCmd.name.isEmpty()); + QVERIFY(mergeCmd.getDescriptionLine().contains(mergeCmd.name)); + + Kdbx4Writer writer; + Kdbx4Reader reader; + + QScopedPointer<QTemporaryDir> testDir(new QTemporaryDir()); + + QString sourceDatabaseFilename = testDir->path() + "/testSourceDatabase.kdbx"; + QString sourceKeyfilePath = testDir->path() + "/testSourceKeyfile.txt"; + + QString targetDatabaseFilename = testDir->path() + "/testTargetDatabase.kdbx"; + QString targetKeyfilePath = testDir->path() + "/testTargetKeyfile.txt"; + + qint64 pos = m_stdoutFile->pos(); + + Utils::Test::setNextPassword("a"); + createCmd.execute({"create", sourceDatabaseFilename, "-k", sourceKeyfilePath}); + + Utils::Test::setNextPassword("b"); + createCmd.execute({"create", targetDatabaseFilename, "-k", targetKeyfilePath}); + + Utils::Test::setNextPassword("a"); + auto sourceDatabase = QSharedPointer<Database>( + Utils::unlockDatabase(sourceDatabaseFilename, true, sourceKeyfilePath, "", Utils::STDOUT)); + QVERIFY(sourceDatabase); + + Utils::Test::setNextPassword("b"); + auto targetDatabase = QSharedPointer<Database>( + Utils::unlockDatabase(targetDatabaseFilename, true, targetKeyfilePath, "", Utils::STDOUT)); + QVERIFY(targetDatabase); + + auto* rootGroup = new Group(); + rootGroup->setName("root"); + rootGroup->setUuid(QUuid::createUuid()); + auto* group = new Group(); + group->setUuid(QUuid::createUuid()); + group->setParent(rootGroup); + group->setName("Internet"); + + auto* entry = new Entry(); + entry->setUuid(QUuid::createUuid()); + entry->setTitle("Some Website"); + entry->setPassword("secretsecretsecret"); + group->addEntry(entry); + + sourceDatabase->setRootGroup(rootGroup); + + auto* otherRootGroup = new Group(); + otherRootGroup->setName("root"); + otherRootGroup->setUuid(QUuid::createUuid()); + auto* otherGroup = new Group(); + otherGroup->setUuid(QUuid::createUuid()); + otherGroup->setParent(otherRootGroup); + otherGroup->setName("Internet"); + + auto* otherEntry = new Entry(); + otherEntry->setUuid(QUuid::createUuid()); + otherEntry->setTitle("Some Website 2"); + otherEntry->setPassword("secretsecretsecret 2"); + otherGroup->addEntry(otherEntry); + + targetDatabase->setRootGroup(otherRootGroup); + + QFile sourceDatabaseFile(sourceDatabaseFilename); + sourceDatabaseFile.open(QIODevice::WriteOnly); + QVERIFY(writer.writeDatabase(&sourceDatabaseFile, sourceDatabase.data())); + sourceDatabaseFile.flush(); + sourceDatabaseFile.close(); + + QFile targetDatabaseFile(targetDatabaseFilename); + targetDatabaseFile.open(QIODevice::WriteOnly); + QVERIFY(writer.writeDatabase(&targetDatabaseFile, targetDatabase.data())); + targetDatabaseFile.flush(); + targetDatabaseFile.close(); + + pos = m_stdoutFile->pos(); + Utils::Test::setNextPassword("b"); + Utils::Test::setNextPassword("a"); + mergeCmd.execute({"merge", + "-k", + targetKeyfilePath, + "--key-file-from", + sourceKeyfilePath, + targetDatabaseFile.fileName(), + sourceDatabaseFile.fileName()}); + + m_stdoutFile->seek(pos); + QList<QByteArray> lines = m_stdoutFile->readAll().split('\n'); + QVERIFY(lines.contains(QString("Successfully merged %1 into %2.") + .arg(sourceDatabaseFile.fileName(), targetDatabaseFile.fileName()) + .toUtf8())); +} + void TestCli::testMove() { Move moveCmd; |