diff options
author | James Ring <sjr@jdns.org> | 2019-09-03 15:50:44 +0300 |
---|---|---|
committer | Jonathan White <support@dmapps.us> | 2019-09-22 18:19:57 +0300 |
commit | 547c246e8872d90daf2b09de58a4913bb5d66a7e (patch) | |
tree | c427ff0c9d2cbf940035f80eb75af2350d57f40b /tests/TestCli.cpp | |
parent | 344198bc2a3ac25b869b6c60cdec212c0fbef66b (diff) |
Additional database file checks in cli/Utils.unlockDatabase
Avoids prompting the user for a password if unlocking is likely to fail
due to some problem with the database file (i.e. not found, not a file,
not readable).
Add unit tests.
Diffstat (limited to 'tests/TestCli.cpp')
-rw-r--r-- | tests/TestCli.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/TestCli.cpp b/tests/TestCli.cpp index d51f90d03..0b7de14e7 100644 --- a/tests/TestCli.cpp +++ b/tests/TestCli.cpp @@ -1409,3 +1409,38 @@ void TestCli::testShow() QCOMPARE(m_stdoutFile->readAll(), QByteArray("")); QCOMPARE(m_stderrFile->readAll(), QByteArray("Entry with path /Sample Entry has no TOTP set up.\n")); } + +void TestCli::testInvalidDbFiles() +{ + Show showCmd; + QString nonExistentDbPath("/foo/bar/baz"); + QString directoryName("/"); + + qint64 pos = m_stderrFile->pos(); + showCmd.execute({"show", nonExistentDbPath, "-q", "/Sample Entry"}); + m_stderrFile->seek(pos); + QCOMPARE(QString(m_stderrFile->readAll()), + QObject::tr("Failed to open database file %1: not found").arg(nonExistentDbPath) + "\n"); + + pos = m_stderrFile->pos(); + showCmd.execute({"show", directoryName, "-q", "whatever"}); + m_stderrFile->seek(pos); + QCOMPARE(QString(m_stderrFile->readAll()), + QObject::tr("Failed to open database file %1: not a plain file").arg(directoryName) + "\n"); + + // Create a write-only file and try to open it. + // QFileInfo.isReadable returns 'true' on Windows, even after the call to + // setPermissions(WriteOwner) and with NTFS permissions enabled, so this + // check doesn't work. +#if !defined(Q_OS_WIN) + QTemporaryFile tempFile; + QVERIFY(tempFile.open()); + QString path = QFileInfo(tempFile).absoluteFilePath(); + QVERIFY(tempFile.setPermissions(QFileDevice::WriteOwner)); + pos = m_stderrFile->pos(); + showCmd.execute({"show", path, "some entry"}); + m_stderrFile->seek(pos); + QCOMPARE(QString(m_stderrFile->readAll()), + QObject::tr("Failed to open database file %1: not readable").arg(path) + "\n"); +#endif // Q_OS_WIN +} |