Falkon Develop
Cross-platform Qt-based web browser
databaseencryptedpasswordbackendtest.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2013-2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
19#include "aesinterface.h"
20
21#include <QtTest/QtTest>
22#include <QSqlDatabase>
23#include <QSqlQuery>
24
26{
27 delete m_backend;
28 auto* backend = new DatabaseEncryptedPasswordBackend;
29
30 if (m_testMasterPassword.isEmpty()) {
31 m_testMasterPassword = AesInterface::passwordToHash(QString::fromUtf8(AesInterface::createRandomData(8)));
32 backend->updateSampleData(m_testMasterPassword);
33 }
34
35 // a trick for setting masterPassword without gui interactions
36 backend->isPasswordVerified(m_testMasterPassword);
37 backend->setAskMasterPasswordState(false);
38
39 m_backend = backend;
40}
41
43{
44 QSqlDatabase db = QSqlDatabase::database();
45 if (!db.isValid()) {
46 db = QSqlDatabase::addDatabase(QSL("QSQLITE"));
47 db.setDatabaseName(QSL(":memory:"));
48 }
49 db.open();
50}
51
53{
54 QSqlDatabase::removeDatabase(QSqlDatabase::database().databaseName());
55}
56
static QByteArray createRandomData(int length)
static QByteArray passwordToHash(const QString &masterPassword)
PasswordBackend * m_backend
#define QSL(x)
Definition: qzcommon.h:40