Fix db history when adding new db (#9022)

Fixes https://github.com/keepassxreboot/keepassxc/issues/8375
This commit is contained in:
Dmytro 2023-01-29 06:24:10 -08:00 committed by GitHub
parent 93831f64a3
commit 8846880015
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 1 deletions

View file

@ -99,6 +99,34 @@ void TestDatabase::testSave()
QVERIFY(!QFile::exists(backupFilePath));
}
void TestDatabase::testSaveAs()
{
TemporaryFile tempFile;
QVERIFY(tempFile.copyFromFile(dbFileName));
auto db = QSharedPointer<Database>::create();
auto key = QSharedPointer<CompositeKey>::create();
key->addKey(QSharedPointer<PasswordKey>::create("a"));
QString error;
QVERIFY(db->open(tempFile.fileName(), key, &error));
// Happy path case when try to save as new DB.
QSignalSpy spyFilePathChanged(db.data(), SIGNAL(filePathChanged(const QString&, const QString&)));
QString newDbFileName = QStringLiteral(KEEPASSX_TEST_DATA_DIR).append("/SaveAsNewDatabase.kdbx");
QVERIFY2(db->saveAs(newDbFileName, Database::Atomic, QString(), &error), error.toLatin1());
QVERIFY(!db->isModified());
QCOMPARE(spyFilePathChanged.count(), 1);
QVERIFY(QFile::exists(newDbFileName));
QFile::remove(newDbFileName);
QVERIFY(!QFile::exists(newDbFileName));
// Negative case when try to save not initialized DB.
db->releaseData();
QVERIFY2(!db->saveAs(newDbFileName, Database::Atomic, QString(), &error), error.toLatin1());
QCOMPARE(error, QString("Could not save, database has not been initialized!"));
}
void TestDatabase::testSignals()
{
TemporaryFile tempFile;

View file

@ -29,6 +29,7 @@ private slots:
void initTestCase();
void testOpen();
void testSave();
void testSaveAs();
void testSignals();
void testEmptyRecycleBinOnDisabled();
void testEmptyRecycleBinOnNotCreated();