From 2abf37ed375581452f8262c81f4c6f9fae594b8d Mon Sep 17 00:00:00 2001 From: "S. Razi Alavizadeh" Date: Sat, 8 Jun 2013 18:37:21 +0430 Subject: [PATCH] [DatabaseEncryptedPasswordBackend] Added tests. --- tests/autotests/main.cpp | 1 + tests/autotests/passwordbackendtest.cpp | 33 +++++++++++++++++++++++++ tests/autotests/passwordbackendtest.h | 15 +++++++++++ 3 files changed, 49 insertions(+) diff --git a/tests/autotests/main.cpp b/tests/autotests/main.cpp index fd0b15ac0..8ff39a08a 100644 --- a/tests/autotests/main.cpp +++ b/tests/autotests/main.cpp @@ -48,6 +48,7 @@ int main(int argc, char *argv[]) RUN_TEST(PacTest) RUN_TEST(DatabasePasswordBackendTest) + RUN_TEST(DatabaseEncryptedPasswordBackendTest) RUN_TEST(KWalletPasswordBackendTest) RUN_TEST(GnomeKeyringPasswordBackendTest) diff --git a/tests/autotests/passwordbackendtest.cpp b/tests/autotests/passwordbackendtest.cpp index 640e18589..2bfcf31e2 100644 --- a/tests/autotests/passwordbackendtest.cpp +++ b/tests/autotests/passwordbackendtest.cpp @@ -16,6 +16,7 @@ * along with this program. If not, see . * ============================================================ */ #include "passwordbackendtest.h" +#include "aesinterface.h" #include #include @@ -225,6 +226,38 @@ void DatabasePasswordBackendTest::cleanup() QSqlDatabase::removeDatabase(QSqlDatabase::database().databaseName()); } +// DatabaseEncryptedPasswordBackendTest +void DatabaseEncryptedPasswordBackendTest::reloadBackend() +{ + delete m_backend; + DatabaseEncryptedPasswordBackend* backend = new DatabaseEncryptedPasswordBackend; + + if (m_testMasterPassword.isEmpty()) { + m_testMasterPassword = AesInterface::passwordToHash(QString::fromUtf8(AesInterface::createRandomData(8))); + backend->updateSampleData(m_testMasterPassword); + } + + // a trick for setting masterPassword without gui interactions + backend->isPasswordVerified(m_testMasterPassword); + backend->setAskMasterPasswordState(false); + + m_backend = backend; +} + +void DatabaseEncryptedPasswordBackendTest::init() +{ + QSqlDatabase db = QSqlDatabase::database(); + if (!db.isValid()) { + db = QSqlDatabase::addDatabase("QSQLITE"); + db.setDatabaseName(":memory:"); + } + db.open(); +} + +void DatabaseEncryptedPasswordBackendTest::cleanup() +{ + QSqlDatabase::removeDatabase(QSqlDatabase::database().databaseName()); +} // KWalletPassswordBackendTest void KWalletPasswordBackendTest::reloadBackend() diff --git a/tests/autotests/passwordbackendtest.h b/tests/autotests/passwordbackendtest.h index a818f9de9..d88ed05fd 100644 --- a/tests/autotests/passwordbackendtest.h +++ b/tests/autotests/passwordbackendtest.h @@ -60,6 +60,21 @@ protected: void cleanup(); }; +#include "passwordbackends/databaseencryptedpasswordbackend.h" + +class DatabaseEncryptedPasswordBackendTest : public PasswordBackendTest +{ + Q_OBJECT + +private: + QByteArray m_testMasterPassword; + +protected: + void reloadBackend(); + void init(); + void cleanup(); +}; + #include "../../src/plugins/KWalletPasswords/kwalletpasswordbackend.h" class KWalletPasswordBackendTest : public PasswordBackendTest