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:
authorJonathan White <support@dmapps.us>2019-10-14 16:31:23 +0300
committerJonathan White <support@dmapps.us>2019-10-21 01:56:41 +0300
commit744b4abce801440ff4e143fb2bb416b3d7a91e07 (patch)
tree6d0f520feb41501f173536dc32a1b5d7ab0d494a /tests
parent6b746913e4cd96dc6d539486c539de86a39f5d28 (diff)
Move FileWatcher into Database class
* Fix #3506 * Fix #2389 * Fix #2536 * Fix #2230 Every database that has been opened now watch's it's own file. This allows the database class to manage file changes and detect fail conditions during saving. Additionally, all stakeholders of the database can listen for the database file changed notification and respond accordingly. Performed significant cleanup of the autoreload code within DatabaseWidget. Fixed several issues with handling changes due to merging, not merging, and other scenarios while reloading. Prevent database saves to the same file if there are changes on disk that have not been merged with the open database.
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/TestDatabase.cpp57
-rw-r--r--tests/TestDatabase.h2
3 files changed, 59 insertions, 2 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index c4df1d8e6..288f64470 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -224,7 +224,7 @@ if(WITH_XC_KEESHARE)
endif()
add_unit_test(NAME testdatabase SOURCES TestDatabase.cpp
- LIBS ${TEST_LIBRARIES})
+ LIBS testsupport ${TEST_LIBRARIES})
add_unit_test(NAME testtools SOURCES TestTools.cpp
LIBS ${TEST_LIBRARIES})
diff --git a/tests/TestDatabase.cpp b/tests/TestDatabase.cpp
index 94e3c8ba7..960578872 100644
--- a/tests/TestDatabase.cpp
+++ b/tests/TestDatabase.cpp
@@ -20,13 +20,14 @@
#include "TestGlobal.h"
#include <QSignalSpy>
-#include <QTemporaryFile>
#include "config-keepassx-tests.h"
#include "core/Metadata.h"
+#include "core/Tools.h"
#include "crypto/Crypto.h"
#include "format/KeePass2Writer.h"
#include "keys/PasswordKey.h"
+#include "util/TemporaryFile.h"
QTEST_GUILESS_MAIN(TestDatabase)
@@ -35,6 +36,60 @@ void TestDatabase::initTestCase()
QVERIFY(Crypto::init());
}
+void TestDatabase::testOpen()
+{
+ auto db = QSharedPointer<Database>::create();
+ QVERIFY(!db->isInitialized());
+ QVERIFY(!db->isModified());
+
+ auto key = QSharedPointer<CompositeKey>::create();
+ key->addKey(QSharedPointer<PasswordKey>::create("a"));
+
+ bool ok = db->open(QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.kdbx"), key);
+ QVERIFY(ok);
+
+ QVERIFY(db->isInitialized());
+ QVERIFY(!db->isModified());
+
+ db->metadata()->setName("test");
+ QVERIFY(db->isModified());
+}
+
+void TestDatabase::testSave()
+{
+ QByteArray data;
+ QFile sourceDbFile(QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.kdbx"));
+ QVERIFY(sourceDbFile.open(QIODevice::ReadOnly));
+ QVERIFY(Tools::readAllFromDevice(&sourceDbFile, data));
+ sourceDbFile.close();
+
+ TemporaryFile tempFile;
+ QVERIFY(tempFile.open());
+ QCOMPARE(tempFile.write(data), static_cast<qint64>((data.size())));
+ tempFile.close();
+
+ auto db = QSharedPointer<Database>::create();
+ auto key = QSharedPointer<CompositeKey>::create();
+ key->addKey(QSharedPointer<PasswordKey>::create("a"));
+
+ QString error;
+ bool ok = db->open(tempFile.fileName(), key, &error);
+ QVERIFY(ok);
+
+ // Test safe saves
+ db->metadata()->setName("test");
+ QVERIFY(db->isModified());
+
+ // Test unsafe saves
+ QVERIFY2(db->save(&error, false, false), error.toLatin1());
+
+ QVERIFY2(db->save(&error), error.toLatin1());
+ QVERIFY(!db->isModified());
+
+ // Test save backups
+ QVERIFY2(db->save(&error, true, true), error.toLatin1());
+}
+
void TestDatabase::testEmptyRecycleBinOnDisabled()
{
QString filename = QString(KEEPASSX_TEST_DATA_DIR).append("/RecycleBinDisabled.kdbx");
diff --git a/tests/TestDatabase.h b/tests/TestDatabase.h
index 46deb58aa..b5df8690f 100644
--- a/tests/TestDatabase.h
+++ b/tests/TestDatabase.h
@@ -27,6 +27,8 @@ class TestDatabase : public QObject
private slots:
void initTestCase();
+ void testOpen();
+ void testSave();
void testEmptyRecycleBinOnDisabled();
void testEmptyRecycleBinOnNotCreated();
void testEmptyRecycleBinOnEmpty();