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:
authorJames Ring <sjr@jdns.org>2020-01-30 23:46:48 +0300
committerGitHub <noreply@github.com>2020-01-30 23:46:48 +0300
commit71a39c37eca9b080a2f06e768ad2e83fe6ff6cb8 (patch)
treeea65e56b1b6b749f00d73aa2a56dac08b8a6f3d9 /tests
parent06e0f385231df060bc3f00584670096e5fe2302f (diff)
Add --username option to Clip command. (#3947)
* make Clip accept an attribute name This allows users to copy arbitrary attributes (e.g. username, notes, URL) to the clipboard in addition to the password and TOTP values. * update Clip manpage * Add findAttributes to CLI utils * Use case-insensitive search in Show command. * Use case-insensitive search in Clip command. Co-authored-by: louib <L0U13@protonmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/TestCli.cpp44
-rw-r--r--tests/data/NewDatabase.kdbxbin15006 -> 20334 bytes
2 files changed, 43 insertions, 1 deletions
diff --git a/tests/TestCli.cpp b/tests/TestCli.cpp
index bc96de974..efaff1831 100644
--- a/tests/TestCli.cpp
+++ b/tests/TestCli.cpp
@@ -480,7 +480,7 @@ void TestCli::testClip()
QCOMPARE(clipboard->text(), QString("Password"));
m_stdoutFile->readLine(); // skip prompt line
- QCOMPARE(m_stdoutFile->readLine(), QByteArray("Entry's password copied to the clipboard!\n"));
+ QCOMPARE(m_stdoutFile->readLine(), QByteArray("Entry's \"Password\" attribute copied to the clipboard!\n"));
// Quiet option
qint64 pos = m_stdoutFile->pos();
@@ -491,6 +491,11 @@ void TestCli::testClip()
QCOMPARE(m_stdoutFile->readAll(), QByteArray(""));
QCOMPARE(clipboard->text(), QString("Password"));
+ // Username
+ Utils::Test::setNextPassword("a");
+ clipCmd.execute({"clip", m_dbFile->fileName(), "/Sample Entry", "-a", "username"});
+ QCOMPARE(clipboard->text(), QString("User Name"));
+
// TOTP
Utils::Test::setNextPassword("a");
clipCmd.execute({"clip", m_dbFile->fileName(), "/Sample Entry", "--totp"});
@@ -538,6 +543,20 @@ void TestCli::testClip()
clipCmd.execute({"clip", m_dbFile2->fileName(), "--totp", "/Sample Entry"});
m_stderrFile->seek(posErr);
QCOMPARE(m_stderrFile->readAll(), QByteArray("Entry with path /Sample Entry has no TOTP set up.\n"));
+
+ posErr = m_stderrFile->pos();
+ Utils::Test::setNextPassword("a");
+ clipCmd.execute({"clip", m_dbFile->fileName(), "-a", "TESTAttribute1", "/Sample Entry"});
+ m_stderrFile->seek(posErr);
+ QCOMPARE(
+ m_stderrFile->readAll(),
+ QByteArray("ERROR: attribute TESTAttribute1 is ambiguous, it matches TestAttribute1 and testattribute1.\n"));
+
+ posErr = m_stderrFile->pos();
+ Utils::Test::setNextPassword("a");
+ clipCmd.execute({"clip", m_dbFile2->fileName(), "--attribute", "Username", "--totp", "/Sample Entry"});
+ m_stderrFile->seek(posErr);
+ QCOMPARE(m_stderrFile->readAll(), QByteArray("ERROR: Please specify one of --attribute or --totp, not both.\n"));
}
void TestCli::testCreate()
@@ -1913,6 +1932,16 @@ void TestCli::testShow()
QByteArray("Sample Entry\n"
"http://www.somesite.com/\n"));
+ // Test case insensitivity
+ pos = m_stdoutFile->pos();
+ Utils::Test::setNextPassword("a");
+ showCmd.execute({"show", "-a", "TITLE", "-a", "URL", m_dbFile->fileName(), "/Sample Entry"});
+ m_stdoutFile->seek(pos);
+ m_stdoutFile->readLine(); // skip password prompt
+ QCOMPARE(m_stdoutFile->readAll(),
+ QByteArray("Sample Entry\n"
+ "http://www.somesite.com/\n"));
+
pos = m_stdoutFile->pos();
Utils::Test::setNextPassword("a");
showCmd.execute({"show", "-a", "DoesNotExist", m_dbFile->fileName(), "/Sample Entry"});
@@ -1946,6 +1975,19 @@ void TestCli::testShow()
m_stderrFile->seek(posErr);
QCOMPARE(m_stdoutFile->readAll(), QByteArray(""));
QCOMPARE(m_stderrFile->readAll(), QByteArray("Entry with path /Sample Entry has no TOTP set up.\n"));
+
+ // Show with ambiguous attributes
+ pos = m_stdoutFile->pos();
+ posErr = m_stderrFile->pos();
+ Utils::Test::setNextPassword("a");
+ showCmd.execute({"show", m_dbFile->fileName(), "-a", "Testattribute1", "/Sample Entry"});
+ m_stdoutFile->seek(pos);
+ m_stdoutFile->readLine(); // skip password prompt
+ m_stderrFile->seek(posErr);
+ QCOMPARE(m_stdoutFile->readAll(), QByteArray(""));
+ QCOMPARE(
+ m_stderrFile->readAll(),
+ QByteArray("ERROR: attribute Testattribute1 is ambiguous, it matches TestAttribute1 and testattribute1.\n"));
}
void TestCli::testInvalidDbFiles()
diff --git a/tests/data/NewDatabase.kdbx b/tests/data/NewDatabase.kdbx
index 3008cce7c..a6d6adb17 100644
--- a/tests/data/NewDatabase.kdbx
+++ b/tests/data/NewDatabase.kdbx
Binary files differ