Other: update gui tester to support latest changes in gRPC implementation.

This commit is contained in:
Xavier Michelon
2022-11-29 11:16:40 +01:00
parent 3408e8427d
commit 7533dc952d
15 changed files with 80 additions and 152 deletions

View File

@ -44,9 +44,7 @@ void GRPCQtProxy::connectSignals()
connect(this, &GRPCQtProxy::reportBugReceived, &settingsTab, &SettingsTab::setBugReport);
connect(this, &GRPCQtProxy::setIsStreamingReceived, &settingsTab, &SettingsTab::setIsStreaming);
connect(this, &GRPCQtProxy::setClientPlatformReceived, &settingsTab, &SettingsTab::setClientPlatform);
connect(this, &GRPCQtProxy::changePortsReceived, &settingsTab, &SettingsTab::changePorts);
connect(this, &GRPCQtProxy::setUseSSLForIMAPReceived, &settingsTab, &SettingsTab::setUseSSLForIMAP);
connect(this, &GRPCQtProxy::setUseSSLForSMTPReceived, &settingsTab, &SettingsTab::setUseSSLForSMTP);
connect(this, &GRPCQtProxy::setMailServerSettingsReceived, &settingsTab, &SettingsTab::setMailServerSettings);
connect(this, &GRPCQtProxy::setIsDoHEnabledReceived, &settingsTab, &SettingsTab::setIsDoHEnabled);
connect(this, &GRPCQtProxy::setDiskCachePathReceived, &settingsTab, &SettingsTab::setDiskCachePath);
connect(this, &GRPCQtProxy::setIsAutomaticUpdateOnReceived, &settingsTab, &SettingsTab::setIsAutomaticUpdateOn);
@ -137,30 +135,14 @@ void GRPCQtProxy::setClientPlatform(QString const &clientPlatform)
//****************************************************************************************************************************************************
/// \param[in] imapPort The IMAP port
/// \param[in] smtpPort The SMTP port
/// \param[in] imapPort The IMAP port.
/// \param[in] smtpPort The SMTP port.
/// \param[in] useSSLForIMAP The IMAP connexion mode.
/// \param[in] useSSLForSMTP The IMAP connexion mode.
//****************************************************************************************************************************************************
void GRPCQtProxy::changePorts(qint32 imapPort, qint32 smtpPort)
void GRPCQtProxy::setMailServerSettings(qint32 imapPort, qint32 smtpPort, bool useSSLForIMAP, bool userSSLForSMTP)
{
emit changePortsReceived(imapPort, smtpPort);
}
//****************************************************************************************************************************************************
/// \param[in] use Should SMTP use SSL?
//****************************************************************************************************************************************************
void GRPCQtProxy::setUseSSLForIMAP(bool use)
{
emit setUseSSLForIMAPReceived(use);
}
//****************************************************************************************************************************************************
/// \param[in] use Should SMTP use SSL?
//****************************************************************************************************************************************************
void GRPCQtProxy::setUseSSLForSMTP(bool use)
{
emit setUseSSLForSMTPReceived(use);
emit setMailServerSettingsReceived(imapPort, smtpPort, useSSLForIMAP, userSSLForSMTP);
}

View File

@ -46,10 +46,8 @@ public: // member functions.
void reportBug(QString const &osType, QString const &osVersion, QString const &emailClient, QString const &address,
QString const &description, bool includeLogs); ///< Forwards a ReportBug call via a Qt signal.
void setIsStreaming(bool isStreaming); ///< Forward a isStreaming internal messages via a Qt signal.
void setClientPlatform(QString const &clientPlatform); ///< Forward s setClientPlatform call via a Qt signal.
void changePorts(qint32 imapPort, qint32 smtpPort); ///< Forwards a ChangePorts call via a Qt signal.
void setUseSSLForIMAP(bool use); ///< Forwards a SetUseSSLForIMAP call via a Qt signal.
void setUseSSLForSMTP(bool use); ///< Forwards a SetUseSSLForSMTP call via a Qt signal.
void setClientPlatform(QString const &clientPlatform); ///< Forward a setClientPlatform call via a Qt signal.
void setMailServerSettings(qint32 imapPort, qint32 smtpPort, bool useSSLForIMAP, bool userSSLForSMTP); ///< Forwards a setMailServerSettings' call via a Qt signal.
void setIsDoHEnabled(bool enabled); ///< Forwards a setIsDoHEnabled call via a Qt signal.
void setDiskCachePath(QString const &path); ///< Forwards a setDiskCachePath call via a Qt signal.
void setIsAutomaticUpdateOn(bool on); ///< Forwards a SetIsAutomaticUpdateOn call via a Qt signal.
@ -68,9 +66,7 @@ signals:
QString const &description, bool includeLogs); ///< Signal for the ReportBug gRPC call
void setIsStreamingReceived(bool isStreaming); ///< Signal for the IsStreaming internal message.
void setClientPlatformReceived(QString const &clientPlatform); ///< Signal for the SetClientPlatform gRPC call.
void changePortsReceived(qint32 imapPort, qint32 smtpPort); ///< Signal for the ChangePorts gRPC call.
void setUseSSLForIMAPReceived(bool use); ///< Signal for the SetUseSSLForIMAP gRPC call.
void setUseSSLForSMTPReceived(bool use); ///< Signal for the SetUseSSLForSMTP gRPC call.
void setMailServerSettingsReceived(qint32 imapPort, qint32 smtpPort, bool useSSLForIMAP, bool userSSLForSMTP); ///< Signal for the SetMailServerSettings gRPC call.
void setIsDoHEnabledReceived(bool enabled); ///< Signal for the SetIsDoHEnabled gRPC call.
void setDiskCachePathReceived(QString const &path); ///< Signal for the setDiskCachePath gRPC call.
void setIsAutomaticUpdateOnReceived(bool on); ///< Signal for the SetIsAutomaticUpdateOn gRPC call.

View File

@ -62,7 +62,17 @@ void GRPCServerWorker::run()
credentials->SetAuthMetadataProcessor(processor_); // gRPC interceptors are still experimental in C++, so we use AuthMetadataProcessor
ServerBuilder builder;
int port = 0; // Port will not be known until ServerBuilder::BuildAndStart() is called
builder.AddListeningPort("127.0.0.1:0", credentials, &port);
bool const useFileSocket = useFileSocketForGRPC();
if (useFileSocket) {
QString const fileSocketPath = getAvailableFileSocketPath();
if (fileSocketPath.isEmpty())
throw Exception("Could not get an available file socket.");
builder.AddListeningPort(QString("unix://%1").arg(fileSocketPath).toStdString(), credentials);
config.fileSocketPath = fileSocketPath;
} else {
builder.AddListeningPort("127.0.0.1:0", credentials, &port);
}
builder.RegisterService(&app().grpc());
server_ = builder.BuildAndStart();

View File

@ -635,51 +635,31 @@ Status GRPCService::IsDoHEnabled(ServerContext *, Empty const *, BoolValue *resp
//****************************************************************************************************************************************************
/// \param[in] request The request.
/// \param[in] settings The IMAP/SMTP settings.
/// \return The status for the call.
//****************************************************************************************************************************************************
Status GRPCService::SetUseSslForImap(ServerContext *, BoolValue const *request, Empty *)
Status GRPCService::SetMailServerSettings(::grpc::ServerContext *context, ImapSmtpSettings const *settings, Empty *)
{
app().log().debug(__FUNCTION__);
qtProxy_.setUseSSLForIMAP(request->value());
qtProxy_.sendDelayedEvent(newUseSslForImapFinishedEvent());
qtProxy_.setMailServerSettings(settings->imapport(), settings->smtpport(), settings->usesslforimap(), settings->usesslforsmtp());
qtProxy_.sendDelayedEvent(newMailServerSettingsChanged(*settings));
qtProxy_.sendDelayedEvent(newChangeMailServerSettingsFinished());
return Status::OK;
}
//****************************************************************************************************************************************************
/// \param[out] response The response.
/// \param[out] outSettings The settings
/// \return The status for the call.
//****************************************************************************************************************************************************
Status GRPCService::UseSslForImap(ServerContext *, Empty const *, BoolValue *response)
Status GRPCService::MailServerSettings(::grpc::ServerContext *, Empty const *, ImapSmtpSettings *outSettings)
{
app().log().debug(__FUNCTION__);
response->set_value(app().mainWindow().settingsTab().useSSLForIMAP());
return Status::OK;
}
//****************************************************************************************************************************************************
/// \param[in] request The request.
/// \return The status for the call.
//****************************************************************************************************************************************************
Status GRPCService::SetUseSslForSmtp(ServerContext *, BoolValue const *request, Empty *)
{
app().log().debug(__FUNCTION__);
qtProxy_.setUseSSLForSMTP(request->value());
qtProxy_.sendDelayedEvent(newUseSslForSmtpFinishedEvent());
return Status::OK;
}
//****************************************************************************************************************************************************
/// \param[out] response The response.
/// \return The status for the call.
//****************************************************************************************************************************************************
Status GRPCService::UseSslForSmtp(ServerContext *, Empty const *, BoolValue *response)
{
app().log().debug(__FUNCTION__);
response->set_value(app().mainWindow().settingsTab().useSSLForSMTP());
SettingsTab& tab = app().mainWindow().settingsTab();
outSettings->set_imapport(tab.imapPort());
outSettings->set_smtpport(tab.smtpPort());
outSettings->set_usesslforimap(tab.useSSLForIMAP());
outSettings->set_usesslforimap(tab.useSSLForSMTP());
return Status::OK;
}
@ -696,43 +676,6 @@ Status GRPCService::Hostname(ServerContext *, Empty const *, StringValue *respon
}
//****************************************************************************************************************************************************
/// \param[out] response The response.
/// \return The status for the call.
//****************************************************************************************************************************************************
Status GRPCService::ImapPort(ServerContext *, Empty const *, Int32Value *response)
{
app().log().debug(__FUNCTION__);
response->set_value(app().mainWindow().settingsTab().imapPort());
return Status::OK;
}
//****************************************************************************************************************************************************
/// \param[out] response The response.
/// \return The status for the call.
//****************************************************************************************************************************************************
Status GRPCService::SmtpPort(ServerContext *, Empty const *, Int32Value *response)
{
app().log().debug(__FUNCTION__);
response->set_value(app().mainWindow().settingsTab().smtpPort());
return Status::OK;
}
//****************************************************************************************************************************************************
/// \param[in] request The request.
/// \return The status for the call.
//****************************************************************************************************************************************************
Status GRPCService::ChangePorts(ServerContext *, ChangePortsRequest const *request, Empty *)
{
app().log().debug(__FUNCTION__);
qtProxy_.changePorts(request->imapport(), request->smtpport());
qtProxy_.sendDelayedEvent(newChangePortsFinishedEvent());
return Status::OK;
}
//****************************************************************************************************************************************************
/// \param[in] request The request.
/// \param[out] response The response.
@ -947,5 +890,3 @@ bool GRPCService::sendEvent(SPStreamEvent const &event)
eventQueue_.push_back(event);
return isStreaming_;
}

View File

@ -80,14 +80,9 @@ public: // member functions.
grpc::Status SetDiskCachePath(::grpc::ServerContext *, ::google::protobuf::StringValue const*, ::google::protobuf::Empty *r) override;
grpc::Status SetIsDoHEnabled(::grpc::ServerContext *, ::google::protobuf::BoolValue const *request, ::google::protobuf::Empty *) override;
grpc::Status IsDoHEnabled(::grpc::ServerContext *, ::google::protobuf::Empty const*, ::google::protobuf::BoolValue *response) override;
grpc::Status SetUseSslForSmtp(::grpc::ServerContext *, ::google::protobuf::BoolValue const *request, ::google::protobuf::Empty *) override;
grpc::Status UseSslForSmtp(::grpc::ServerContext *, ::google::protobuf::Empty const*, ::google::protobuf::BoolValue *response) override;
grpc::Status SetUseSslForImap(::grpc::ServerContext *, ::google::protobuf::BoolValue const *request, ::google::protobuf::Empty *) override;
grpc::Status UseSslForImap(::grpc::ServerContext *, ::google::protobuf::Empty const*, ::google::protobuf::BoolValue *response) override;
grpc::Status SetMailServerSettings(::grpc::ServerContext *context, ::grpc::ImapSmtpSettings const *request, ::google::protobuf::Empty *response) override;
grpc::Status MailServerSettings(::grpc::ServerContext *context, ::google::protobuf::Empty const *request, ::grpc::ImapSmtpSettings *response) override;
grpc::Status Hostname(::grpc::ServerContext *, ::google::protobuf::Empty const*, ::google::protobuf::StringValue *response) override;
grpc::Status ImapPort(::grpc::ServerContext *, ::google::protobuf::Empty const*, ::google::protobuf::Int32Value *response) override;
grpc::Status SmtpPort(::grpc::ServerContext *, ::google::protobuf::Empty const*, ::google::protobuf::Int32Value *response) override;
grpc::Status ChangePorts(::grpc::ServerContext *, ::grpc::ChangePortsRequest const *request, ::google::protobuf::Empty *) override;
grpc::Status IsPortFree(::grpc::ServerContext *, ::google::protobuf::Int32Value const *request, ::google::protobuf::BoolValue *response) override;
grpc::Status AvailableKeychains(::grpc::ServerContext *, ::google::protobuf::Empty const*, ::grpc::AvailableKeychainsResponse *response) override;
grpc::Status SetCurrentKeychain(::grpc::ServerContext *, ::google::protobuf::StringValue const *request, ::google::protobuf::Empty *) override;

View File

@ -38,7 +38,7 @@ void addEntryToLogEdit(bridgepp::Log::Level level, const QString &message, QPlai
QString log = logEdit.toPlainText().trimmed();
if (!log.isEmpty())
log += "\n";
logEdit.setPlainText(log + Log::logEntryToString(level, message));
logEdit.setPlainText(log + Log::logEntryToString(level, QDateTime::currentDateTime(), message));
}

View File

@ -337,14 +337,17 @@ qint32 SettingsTab::smtpPort()
//****************************************************************************************************************************************************
/// \param[in] imapPort The IMAP port.
/// \param[in] smtpPort The SMTP port.
/// \param[in] useSSLForIMAP The IMAP connexion mode.
/// \param[in] useSSLForSMTP The IMAP connexion mode.
//****************************************************************************************************************************************************
void SettingsTab::changePorts(qint32 imapPort, qint32 smtpPort)
void SettingsTab::setMailServerSettings(qint32 imapPort, qint32 smtpPort, bool useSSLForIMAP, bool useSSLForSMTP)
{
ui_.spinPortIMAP->setValue(imapPort);
ui_.spinPortSMTP->setValue(smtpPort);
ui_.checkUseSSLForIMAP->setChecked(useSSLForIMAP);
ui_.checkUseSSLForSMTP->setChecked(useSSLForSMTP);
}
//****************************************************************************************************************************************************
/// \return The state of the 'Use SSL for SMTP' check box.
//****************************************************************************************************************************************************
@ -362,23 +365,6 @@ bool SettingsTab::useSSLForIMAP() const
}
//****************************************************************************************************************************************************
/// \param[in] use The state of the 'Use SSL for SMTP' check box.
//****************************************************************************************************************************************************
void SettingsTab::setUseSSLForSMTP(bool use)
{
ui_.checkUseSSLForSMTP->setChecked(use);
}
//****************************************************************************************************************************************************
/// \param[in] use The state of the 'Use SSL for SMTP' check box.
//****************************************************************************************************************************************************
void SettingsTab::setUseSSLForIMAP(bool use)
{
ui_.checkUseSSLForIMAP->setChecked(use);
}
//****************************************************************************************************************************************************
/// \return The state of the the 'DoH enabled' check box.
//****************************************************************************************************************************************************
@ -524,4 +510,3 @@ void SettingsTab::resetUI()
ui_.checkAutomaticUpdate->setChecked(true);
}

View File

@ -77,9 +77,7 @@ public slots:
void setColorSchemeName(QString const &name); ///< Set the value for the 'Use Dark Theme' check box.
void setBugReport(QString const &osType, QString const &osVersion, QString const &emailClient, QString const &address, QString const &description,
bool includeLogs); ///< Set the content of the bug report box.
void changePorts(qint32 imapPort, qint32 smtpPort); ///< Change the IMAP and SMTP ports.
void setUseSSLForSMTP(bool use); ///< Set the value for the 'Use SSL for SMTP' check box.
void setUseSSLForIMAP(bool use); ///< Set the value for the 'Use SSL for IMAP' check box.
void setMailServerSettings(qint32 imapPort, qint32 smtpPort, bool useSSLForIMAP, bool useSSLForSMTP); ///< Change the mail server settings.
void setIsDoHEnabled(bool enabled); ///< Set the value for the 'DoH Enabled' check box.
void setDiskCachePath(QString const &path); ///< Set the value for the 'Cache On Disk Enabled' check box.
void setIsAutomaticUpdateOn(bool on); ///< Set the value for the 'Automatic Update' check box.

View File

@ -295,7 +295,7 @@ void UsersTab::logoutUser(QString const &userID)
app().log().error(QString("%1 failed. unknown user %1").arg(__FUNCTION__, userID));
return;
}
user->setLoggedIn(false);
user->setState(UserState::SignedOut);
users_.touch(index);
app().mainWindow().sendDelayedEvent(newUserChangedEvent(userID));
}

View File

@ -19,6 +19,9 @@
#include "UserDialog.h"
using namespace bridgepp;
//****************************************************************************************************************************************************
/// \param[in] user The user.
/// \param[in] parent The parent widget of the dialog.
@ -37,7 +40,7 @@ UserDialog::UserDialog(bridgepp::SPUser &user, QWidget *parent)
ui_.editPassword->setText(user->password());
ui_.editAddresses->setPlainText(user->addresses().join("\n"));
ui_.editAvatarText->setText(user_->avatarText());
ui_.checkLoggedIn->setChecked(user_->loggedIn());
ui_.checkLoggedIn->setChecked(user_->state() == UserState::Connected);
ui_.checkSplitMode->setChecked(user_->splitMode());
ui_.checkSetupGuideSeen->setChecked(user_->setupGuideSeen());
ui_.spinUsedBytes->setValue(user->usedBytes());
@ -55,7 +58,7 @@ void UserDialog::onOK()
user_->setPassword(ui_.editPassword->text());
user_->setAddresses(ui_.editAddresses->toPlainText().split(QRegularExpression(R"(\s+)"), Qt::SkipEmptyParts));
user_->setAvatarText(ui_.editAvatarText->text());
user_->setLoggedIn(ui_.checkLoggedIn->isChecked());
user_->setState(ui_.checkLoggedIn->isChecked() ? UserState::Connected: UserState::SignedOut);
user_->setSplitMode(ui_.checkSplitMode->isChecked());
user_->setSetupGuideSeen(ui_.checkSetupGuideSeen->isChecked());
user_->setUsedBytes(float(ui_.spinUsedBytes->value()));

View File

@ -420,8 +420,6 @@ SPStreamEvent newDiskCachePathChangeFinishedEvent()
return wrapCacheEvent(cacheEvent);
}
SPStreamEvent newChangeMailServerSettingsFinished(); ///< Create a new ChangeMailServerSettingsFinished event.
//****************************************************************************************************************************************************
/// \param[in] errorType The error type.
/// \return The event.
@ -440,10 +438,10 @@ SPStreamEvent newMailServerSettingsErrorEvent(grpc::MailServerSettingsErrorType
/// \param[in] settings The settings.
/// \return The event.
//****************************************************************************************************************************************************
SPStreamEvent newMailServerSettingsChanged(grpc::ImapSmtpSettings *settings)
SPStreamEvent newMailServerSettingsChanged(grpc::ImapSmtpSettings const &settings)
{
auto event = new grpc::MailServerSettingsChangedEvent;
event->set_allocated_settings(settings);
event->set_allocated_settings(new grpc::ImapSmtpSettings(settings));
auto mailServerSettingsEvent = new grpc::MailServerSettingsEvent;
mailServerSettingsEvent->set_allocated_mailserversettingschanged(event);
return wrapMailServerSettingsEvent(mailServerSettingsEvent);

View File

@ -60,7 +60,7 @@ SPStreamEvent newDiskCachePathChangeFinishedEvent(); ///< Create a new DiskCache
// Mail settings related events
SPStreamEvent newMailServerSettingsErrorEvent(grpc::MailServerSettingsErrorType errorType); ///< Create a new MailSettingsErrorEvent event.
SPStreamEvent newMailServerSettingsChanged(grpc::ImapSmtpSettings settings); ///< Create a new ConnectionModeChanged event.
SPStreamEvent newMailServerSettingsChanged(grpc::ImapSmtpSettings const &settings); ///< Create a new ConnectionModeChanged event.
SPStreamEvent newChangeMailServerSettingsFinished(); ///< Create a new ChangeMailServerSettingsFinished event.
// keychain related events

View File

@ -40,14 +40,6 @@ qint64 const grpcConnectionWaitTimeoutMs = 60000; ///< Timeout for the connectio
qint64 const grpcConnectionRetryDelayMs = 10000; ///< Retry delay for the gRPC connection in milliseconds.
//****************************************************************************************************************************************************
/// return true if gRPC connection should use file socket instead of TCP socket.
//****************************************************************************************************************************************************
bool useFileSocket() {
return !onWindows();
}
} // anonymous namespace
@ -124,7 +116,7 @@ bool GRPCClient::connectToServer(GRPCConfig const &config, ProcessMonitor *serve
serverToken_ = config.token.toStdString();
QString address;
grpc::ChannelArguments chanArgs;
if (useFileSocket())
if (useFileSocketForGRPC())
{
address = QString("unix://" + config.fileSocketPath);
chanArgs.SetSslTargetNameOverride("127.0.0.1"); // for file socket, we skip name verification to avoid a confusion localhost/127.0.0.1

View File

@ -69,6 +69,14 @@ QString serverKeyFilename()
}
} // anonymous namespace
//****************************************************************************************************************************************************
/// return true if gRPC connection should use file socket instead of TCP socket.
//****************************************************************************************************************************************************
bool useFileSocketForGRPC() {
return !onWindows();
}
@ -278,4 +286,22 @@ void userToGRPC(User const &user, grpc::User &outGRPCUser)
}
//****************************************************************************************************************************************************
/// \return The path to a file that can be used for a gRPC file socket.
/// \return A null string if no path could be found.
//****************************************************************************************************************************************************
QString getAvailableFileSocketPath()
{
QDir const tempDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
for (qint32 i = 0; i < 10000; i++) {
QString const path = tempDir.absoluteFilePath(QString("bridge_%1.sock").arg(qint32(i), 4, 10, QChar('0')));
QFile f(path);
if ((!f.exists()) || f.remove())
return path;
}
return QString();
}
} // namespace bridgepp

View File

@ -46,6 +46,8 @@ grpc::UserState userStateToGRPC(UserState state); ///< Convert a bridgepp::UserS
UserState userStateFromGRPC(grpc::UserState state); ///< Convert a grpc::UserState to a bridgepp::UserState.
void userToGRPC(User const &user, grpc::User &outGRPCUser); ///< Convert a bridgepp::User to a grpc::User.
SPUser userFromGRPC(grpc::User const &grpcUser); ///< Create a bridgepp::User from a grpc::User.
bool useFileSocketForGRPC(); ///< Check whether the Bridge gRPC service should use file sockets instead of TCP sockets.
QString getAvailableFileSocketPath(); ///< Return the path of a new available socket, or a null string if none could be found.
}