File indexing completed on 2024-04-28 08:47:47
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2013-2018 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "databaseencryptedpasswordbackendtest.h" 0019 #include "aesinterface.h" 0020 0021 #include <QtTest/QtTest> 0022 #include <QSqlDatabase> 0023 #include <QSqlQuery> 0024 0025 void DatabaseEncryptedPasswordBackendTest::reloadBackend() 0026 { 0027 delete m_backend; 0028 auto* backend = new DatabaseEncryptedPasswordBackend; 0029 0030 if (m_testMasterPassword.isEmpty()) { 0031 m_testMasterPassword = AesInterface::passwordToHash(QString::fromUtf8(AesInterface::createRandomData(8))); 0032 backend->updateSampleData(m_testMasterPassword); 0033 } 0034 0035 // a trick for setting masterPassword without gui interactions 0036 backend->isPasswordVerified(m_testMasterPassword); 0037 backend->setAskMasterPasswordState(false); 0038 0039 m_backend = backend; 0040 } 0041 0042 void DatabaseEncryptedPasswordBackendTest::init() 0043 { 0044 QSqlDatabase db = QSqlDatabase::database(); 0045 if (!db.isValid()) { 0046 db = QSqlDatabase::addDatabase(QSL("QSQLITE")); 0047 db.setDatabaseName(QSL(":memory:")); 0048 } 0049 db.open(); 0050 } 0051 0052 void DatabaseEncryptedPasswordBackendTest::cleanup() 0053 { 0054 QSqlDatabase::removeDatabase(QSqlDatabase::database().databaseName()); 0055 } 0056 0057 QTEST_GUILESS_MAIN(DatabaseEncryptedPasswordBackendTest)