Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorlouib <L0U13@protonmail.com>2020-01-27 07:44:31 +0300
committerJonathan White <support@dmapps.us>2020-01-27 07:44:31 +0300
commitb78ca924fdf2b6d5937d87bab65104cba629382f (patch)
tree2eea94caa125f66f50e7c37451fb5f0364d54a1b /tests
parent04be724614460d5d0e60a741f93a99c15dec4ee3 (diff)
Adding db-info CLI command. (#4231)
This adds a basic db-show CLI command, to display the information related to a database.
Diffstat (limited to 'tests')
-rw-r--r--tests/TestCli.cpp58
-rw-r--r--tests/TestCli.h1
2 files changed, 49 insertions, 10 deletions
diff --git a/tests/TestCli.cpp b/tests/TestCli.cpp
index 076f7f74e..d73cdeddd 100644
--- a/tests/TestCli.cpp
+++ b/tests/TestCli.cpp
@@ -44,6 +44,7 @@
#include "cli/Generate.h"
#include "cli/Help.h"
#include "cli/Import.h"
+#include "cli/Info.h"
#include "cli/List.h"
#include "cli/Locate.h"
#include "cli/Merge.h"
@@ -192,7 +193,8 @@ void TestCli::testBatchCommands()
QVERIFY(Commands::getCommand("analyze"));
QVERIFY(Commands::getCommand("clip"));
QVERIFY(Commands::getCommand("close"));
- QVERIFY(Commands::getCommand("create"));
+ QVERIFY(Commands::getCommand("db-create"));
+ QVERIFY(Commands::getCommand("db-info"));
QVERIFY(Commands::getCommand("diceware"));
QVERIFY(Commands::getCommand("edit"));
QVERIFY(Commands::getCommand("estimate"));
@@ -210,7 +212,7 @@ void TestCli::testBatchCommands()
QVERIFY(Commands::getCommand("rmdir"));
QVERIFY(Commands::getCommand("show"));
QVERIFY(!Commands::getCommand("doesnotexist"));
- QCOMPARE(Commands::getCommands().size(), 21);
+ QCOMPARE(Commands::getCommands().size(), 22);
}
void TestCli::testInteractiveCommands()
@@ -220,7 +222,8 @@ void TestCli::testInteractiveCommands()
QVERIFY(Commands::getCommand("analyze"));
QVERIFY(Commands::getCommand("clip"));
QVERIFY(Commands::getCommand("close"));
- QVERIFY(Commands::getCommand("create"));
+ QVERIFY(Commands::getCommand("db-create"));
+ QVERIFY(Commands::getCommand("db-info"));
QVERIFY(Commands::getCommand("diceware"));
QVERIFY(Commands::getCommand("edit"));
QVERIFY(Commands::getCommand("estimate"));
@@ -238,7 +241,7 @@ void TestCli::testInteractiveCommands()
QVERIFY(Commands::getCommand("rmdir"));
QVERIFY(Commands::getCommand("show"));
QVERIFY(!Commands::getCommand("doesnotexist"));
- QCOMPARE(Commands::getCommands().size(), 21);
+ QCOMPARE(Commands::getCommands().size(), 22);
}
void TestCli::testAdd()
@@ -548,7 +551,7 @@ void TestCli::testCreate()
QString databaseFilename = testDir->path() + "/testCreate1.kdbx";
// Password
Utils::Test::setNextPassword("a");
- createCmd.execute({"create", databaseFilename});
+ createCmd.execute({"db-create", databaseFilename});
m_stderrFile->reset();
m_stdoutFile->reset();
@@ -563,7 +566,7 @@ void TestCli::testCreate()
// Should refuse to create the database if it already exists.
qint64 pos = m_stdoutFile->pos();
qint64 errPos = m_stderrFile->pos();
- createCmd.execute({"create", databaseFilename});
+ createCmd.execute({"db-create", databaseFilename});
m_stdoutFile->seek(pos);
m_stderrFile->seek(errPos);
// Output should be empty when there is an error.
@@ -577,7 +580,7 @@ void TestCli::testCreate()
pos = m_stdoutFile->pos();
errPos = m_stderrFile->pos();
Utils::Test::setNextPassword("a");
- createCmd.execute({"create", databaseFilename2, "-k", keyfilePath});
+ createCmd.execute({"db-create", databaseFilename2, "-k", keyfilePath});
m_stdoutFile->seek(pos);
m_stderrFile->seek(errPos);
@@ -594,7 +597,7 @@ void TestCli::testCreate()
pos = m_stdoutFile->pos();
errPos = m_stderrFile->pos();
Utils::Test::setNextPassword("a");
- createCmd.execute({"create", databaseFilename3, "-k", keyfilePath});
+ createCmd.execute({"db-create", databaseFilename3, "-k", keyfilePath});
m_stdoutFile->seek(pos);
m_stderrFile->seek(errPos);
@@ -607,6 +610,41 @@ void TestCli::testCreate()
QVERIFY(db3);
}
+void TestCli::testInfo()
+{
+ Info infoCmd;
+ QVERIFY(!infoCmd.name.isEmpty());
+ QVERIFY(infoCmd.getDescriptionLine().contains(infoCmd.name));
+
+ Utils::Test::setNextPassword("a");
+ infoCmd.execute({"db-info", m_dbFile->fileName()});
+ m_stdoutFile->reset();
+ m_stderrFile->reset();
+ m_stdoutFile->readLine(); // skip prompt line
+ QCOMPARE(m_stderrFile->readAll(), QByteArray(""));
+ QVERIFY(m_stdoutFile->readLine().contains(QByteArray("UUID: ")));
+ QCOMPARE(m_stdoutFile->readLine(), QByteArray("Name: \n"));
+ QCOMPARE(m_stdoutFile->readLine(), QByteArray("Description: \n"));
+ QCOMPARE(m_stdoutFile->readLine(), QByteArray("Cipher: AES 256-bit\n"));
+ QCOMPARE(m_stdoutFile->readLine(), QByteArray("KDF: AES (6000 rounds)\n"));
+ QCOMPARE(m_stdoutFile->readLine(), QByteArray("Recycle bin is enabled.\n"));
+
+ // Test with quiet option.
+ qint64 pos = m_stdoutFile->pos();
+ qint64 errPos = m_stderrFile->pos();
+ Utils::Test::setNextPassword("a");
+ infoCmd.execute({"db-info", "-q", m_dbFile->fileName()});
+ m_stdoutFile->seek(pos);
+ m_stderrFile->seek(errPos);
+ QCOMPARE(m_stderrFile->readAll(), QByteArray(""));
+ QVERIFY(m_stdoutFile->readLine().contains(QByteArray("UUID: ")));
+ QCOMPARE(m_stdoutFile->readLine(), QByteArray("Name: \n"));
+ QCOMPARE(m_stdoutFile->readLine(), QByteArray("Description: \n"));
+ QCOMPARE(m_stdoutFile->readLine(), QByteArray("Cipher: AES 256-bit\n"));
+ QCOMPARE(m_stdoutFile->readLine(), QByteArray("KDF: AES (6000 rounds)\n"));
+ QCOMPARE(m_stdoutFile->readLine(), QByteArray("Recycle bin is enabled.\n"));
+}
+
void TestCli::testDiceware()
{
Diceware dicewareCmd;
@@ -1446,10 +1484,10 @@ void TestCli::testMergeWithKeys()
qint64 pos = m_stdoutFile->pos();
Utils::Test::setNextPassword("a");
- createCmd.execute({"create", sourceDatabaseFilename, "-k", sourceKeyfilePath});
+ createCmd.execute({"db-create", sourceDatabaseFilename, "-k", sourceKeyfilePath});
Utils::Test::setNextPassword("b");
- createCmd.execute({"create", targetDatabaseFilename, "-k", targetKeyfilePath});
+ createCmd.execute({"db-create", targetDatabaseFilename, "-k", targetKeyfilePath});
Utils::Test::setNextPassword("a");
auto sourceDatabase = QSharedPointer<Database>(
diff --git a/tests/TestCli.h b/tests/TestCli.h
index 4947ee472..44420d580 100644
--- a/tests/TestCli.h
+++ b/tests/TestCli.h
@@ -59,6 +59,7 @@ private slots:
void testGenerate_data();
void testGenerate();
void testImport();
+ void testInfo();
void testKeyFileOption();
void testNoPasswordOption();
void testHelp();