76 lines
2.7 KiB
C++
76 lines
2.7 KiB
C++
#include <QString>
|
|||
|
|
#include <QDebug>
|
||
|
|
#include <QCoreApplication>
|
||
|
|
#include "src/db/databasemanager.h"
|
||
|
|
#include "src/db/dao/accountdao.h"
|
||
|
|
#include "src/core/models/account.h"
|
||
|
|
|
||
|
|
int main(int argc, char *argv[]) {
|
||
|
|
QCoreApplication app(argc, argv);
|
||
|
|
// Initialize database (will open/create wino-mail.sqlite in current dir)
|
||
|
|
if (!DatabaseManager::instance().initialize()) {
|
||
|
|
qCritical() << "Failed to initialize database";
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
qInfo() << "Database initialized";
|
||
|
|
|
||
|
|
// Prepare test account
|
||
|
|
Account acc;
|
||
|
|
acc.setEmail("test@example.com");
|
||
|
|
acc.setDisplayName("Test User");
|
||
|
|
acc.setType(AccountType::IMAP);
|
||
|
|
Account::ConnectionSettings settings;
|
||
|
|
settings.type = "imap";
|
||
|
|
settings.incomingHost = "imap.example.com";
|
||
|
|
settings.incomingPort = 993;
|
||
|
|
settings.incomingSsl = true;
|
||
|
|
settings.outgoingHost = "smtp.example.com";
|
||
|
|
settings.outgoingPort = 465;
|
||
|
|
settings.outgoingSsl = true;
|
||
|
|
settings.username = "test@example.com";
|
||
|
|
settings.password = "SuperSecret123!";
|
||
|
|
settings.authMethod = "plain";
|
||
|
|
acc.setConnectionSettings(settings);
|
||
|
|
|
||
|
|
// Insert
|
||
|
|
bool inserted = AccountDao::insert(acc);
|
||
|
|
if (!inserted) {
|
||
|
|
qCritical() << "Failed to insert account";
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
qInfo() << "Account inserted with ID:" << acc.id();
|
||
|
|
|
||
|
|
// Retrieve by email
|
||
|
|
Account* retrieved = AccountDao::findByEmail("test@example.com");
|
||
|
|
if (!retrieved) {
|
||
|
|
qCritical() << "Failed to retrieve account by email";
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
qInfo() << "Retrieved account ID:" << retrieved->id();
|
||
|
|
qInfo() << "Email:" << retrieved->email();
|
||
|
|
qInfo() << "DisplayName:" << retrieved->displayName();
|
||
|
|
qInfo() << "Type:" << static_cast<int>(retrieved->type());
|
||
|
|
const auto& rs = retrieved->connectionSettings();
|
||
|
|
qInfo() << "Incoming host:" << rs.incomingHost;
|
||
|
|
qInfo() << "Incoming port:" << rs.incomingPort;
|
||
|
|
qInfo() << "Incoming SSL:" << rs.incomingSsl;
|
||
|
|
qInfo() << "Username:" << rs.username;
|
||
|
|
qInfo() << "Password (encrypted stored):" << // we need to get raw from DB? we can't directly.
|
||
|
|
"[encrypted]"; // we will decrypt
|
||
|
|
QString decryptedPass = Account::decryptPassword(rs.password);
|
||
|
|
qInfo() << "Decrypted password:" << decryptedPass;
|
||
|
|
bool ok = (decryptedPass == settings.password);
|
||
|
|
if (ok) {
|
||
|
|
qInfo() << "SUCCESS: password matches after decrypt";
|
||
|
|
} else {
|
||
|
|
qCritical: Also check that the stored password in DB is encrypted (not plain). We could query directly but we trust encrypt function.
|
||
|
|
// Cleanup: remove the account
|
||
|
|
if (!AccountDao::remove(retrieved->id())) {
|
||
|
|
qWarning() << "Failed to remove test account";
|
||
|
|
} else {
|
||
|
|
qInfo() << "Test account removed";
|
||
|
|
}
|
||
|
|
delete retrieved;
|
||
|
|
return ok ? 0 : 2;
|
||
|
|
}
|