From e87db5b2ab49131ebf92924195a35b0c29463cd3 Mon Sep 17 00:00:00 2001 From: Xavier Michelon Date: Thu, 1 Dec 2022 15:39:20 +0100 Subject: [PATCH] Other: updated GUI tester for new gRPC calls. --- .../bridge-gui-tester/GRPCQtProxy.cpp | 10 +++++ .../bridge-gui-tester/GRPCQtProxy.h | 2 + .../bridge-gui-tester/GRPCService.cpp | 15 +++++++ .../bridge-gui-tester/GRPCService.h | 1 + .../bridge-gui-tester/Tabs/SettingsTab.cpp | 29 +++++++++++++ .../bridge-gui-tester/Tabs/SettingsTab.h | 3 ++ .../bridge-gui-tester/Tabs/SettingsTab.ui | 42 +++++++++++++++++++ .../qml/Notifications/Notifications.qml | 2 +- .../bridgepp/bridgepp/GRPC/EventFactory.cpp | 24 +++++++++++ .../bridgepp/bridgepp/GRPC/EventFactory.h | 2 + 10 files changed, 129 insertions(+), 1 deletion(-) diff --git a/internal/frontend/bridge-gui/bridge-gui-tester/GRPCQtProxy.cpp b/internal/frontend/bridge-gui/bridge-gui-tester/GRPCQtProxy.cpp index 0e466b7b..a3c8625e 100644 --- a/internal/frontend/bridge-gui/bridge-gui-tester/GRPCQtProxy.cpp +++ b/internal/frontend/bridge-gui/bridge-gui-tester/GRPCQtProxy.cpp @@ -42,6 +42,7 @@ void GRPCQtProxy::connectSignals() connect(this, &GRPCQtProxy::setIsAllMailVisibleReceived, &settingsTab, &SettingsTab::setIsAllMailVisible); connect(this, &GRPCQtProxy::setColorSchemeNameReceived, &settingsTab, &SettingsTab::setColorSchemeName); connect(this, &GRPCQtProxy::reportBugReceived, &settingsTab, &SettingsTab::setBugReport); + connect(this, &GRPCQtProxy::exportTLSCertificatesReceived, &settingsTab, &SettingsTab::exportTLSCertificates); connect(this, &GRPCQtProxy::setIsStreamingReceived, &settingsTab, &SettingsTab::setIsStreaming); connect(this, &GRPCQtProxy::setClientPlatformReceived, &settingsTab, &SettingsTab::setClientPlatform); connect(this, &GRPCQtProxy::setMailServerSettingsReceived, &settingsTab, &SettingsTab::setMailServerSettings); @@ -116,6 +117,15 @@ void GRPCQtProxy::reportBug(QString const &osType, QString const &osVersion, QSt } +//**************************************************************************************************************************************************** +/// \param[in] folderPath The folder path. +//**************************************************************************************************************************************************** +void GRPCQtProxy::exportTLSCertificates(QString const &folderPath) +{ + emit exportTLSCertificatesReceived(folderPath); +} + + //**************************************************************************************************************************************************** /// \param[in] isStreaming Is the gRPC server streaming. //**************************************************************************************************************************************************** diff --git a/internal/frontend/bridge-gui/bridge-gui-tester/GRPCQtProxy.h b/internal/frontend/bridge-gui/bridge-gui-tester/GRPCQtProxy.h index 9609f0b6..d8be210e 100644 --- a/internal/frontend/bridge-gui/bridge-gui-tester/GRPCQtProxy.h +++ b/internal/frontend/bridge-gui/bridge-gui-tester/GRPCQtProxy.h @@ -45,6 +45,7 @@ public: // member functions. void setColorSchemeName(QString const &name); ///< Forward a SetColorSchemeName call via a Qt Signal 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 exportTLSCertificates(QString const &folderPath); //< Forward an 'ExportTLSCertificates' call via a Qt signal. void setIsStreaming(bool isStreaming); ///< Forward a isStreaming internal messages 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. @@ -64,6 +65,7 @@ signals: void setColorSchemeNameReceived(QString const &name); ///< Forward a SetColorScheme call via a Qt Signal void reportBugReceived(QString const &osType, QString const &osVersion, QString const &emailClient, QString const &address, QString const &description, bool includeLogs); ///< Signal for the ReportBug gRPC call + void exportTLSCertificatesReceived(QString const &folderPath); ///< Signal for the ExportTLSCertificates gRPC call. void setIsStreamingReceived(bool isStreaming); ///< Signal for the IsStreaming internal message. void setClientPlatformReceived(QString const &clientPlatform); ///< Signal for the SetClientPlatform gRPC call. void setMailServerSettingsReceived(qint32 imapPort, qint32 smtpPort, bool useSSLForIMAP, bool userSSLForSMTP); ///< Signal for the SetMailServerSettings gRPC call. diff --git a/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.cpp b/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.cpp index 785e91f5..90fb36d3 100644 --- a/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.cpp +++ b/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.cpp @@ -404,6 +404,21 @@ Status GRPCService::ReportBug(ServerContext *, ReportBugRequest const *request, } +//**************************************************************************************************************************************************** +/// \param[in] request The request +//**************************************************************************************************************************************************** +Status GRPCService::ExportTLSCertificates(ServerContext *, StringValue const *request, Empty *response) +{ + SettingsTab &tab = app().mainWindow().settingsTab(); + if (!tab.nextTLSCertExportWillSucceed()) + qtProxy_.sendDelayedEvent(newGenericErrorEvent(grpc::TLS_CERT_EXPORT_ERROR)); + if (!tab.nextTLSKeyExportWillSucceed()) + qtProxy_.sendDelayedEvent(newGenericErrorEvent(grpc::TLS_KEY_EXPORT_ERROR)); + qtProxy_.exportTLSCertificates(QString::fromStdString(request->value())); + return Status::OK; +} + + //**************************************************************************************************************************************************** /// \param[in] request The request. /// \return The status for the call. diff --git a/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.h b/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.h index fd72954d..dabb89f1 100644 --- a/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.h +++ b/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.h @@ -66,6 +66,7 @@ public: // member functions. grpc::Status ColorSchemeName(::grpc::ServerContext *, ::google::protobuf::Empty const*, ::google::protobuf::StringValue *response) override; grpc::Status CurrentEmailClient(::grpc::ServerContext *, ::google::protobuf::Empty const*, ::google::protobuf::StringValue *response) override; grpc::Status ReportBug(::grpc::ServerContext *, ::grpc::ReportBugRequest const *request, ::google::protobuf::Empty *) override; + grpc::Status ExportTLSCertificates(::grpc::ServerContext *context, ::google::protobuf::StringValue const *request, ::google::protobuf::Empty *response) override; grpc::Status ForceLauncher(::grpc::ServerContext *, ::google::protobuf::StringValue const *request, ::google::protobuf::Empty *) override; grpc::Status SetMainExecutable(::grpc::ServerContext *, ::google::protobuf::StringValue const *request, ::google::protobuf::Empty *) override; grpc::Status Login(::grpc::ServerContext *, ::grpc::LoginRequest const *request, ::google::protobuf::Empty *) override; diff --git a/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.cpp b/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.cpp index 1ad14903..263b3f9d 100644 --- a/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.cpp +++ b/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.cpp @@ -298,6 +298,17 @@ void SettingsTab::setBugReport(QString const &osType, QString const &osVersion, } +//**************************************************************************************************************************************************** +/// \param[in] folderPath The folder path. +//**************************************************************************************************************************************************** +void SettingsTab::exportTLSCertificates(QString const &folderPath) +{ + ui_.labeLastTLSCertsExport->setText(QString("%1 Export to %2") + .arg(QDateTime::currentDateTime().toString(Qt::ISODateWithMs)) + .arg(folderPath)); +} + + //**************************************************************************************************************************************************** /// \return The state of the check box. //**************************************************************************************************************************************************** @@ -307,6 +318,24 @@ bool SettingsTab::nextBugReportWillSucceed() const } +//**************************************************************************************************************************************************** +/// \return true if the 'Next TLS key export will succeed' check box is checked +//**************************************************************************************************************************************************** +bool SettingsTab::nextTLSCertExportWillSucceed() const +{ + return ui_.checkTLSCertExportWillSucceed->isChecked(); +} + + +//**************************************************************************************************************************************************** +/// \return true if the 'Next TLS key export will succeed' check box is checked +//**************************************************************************************************************************************************** +bool SettingsTab::nextTLSKeyExportWillSucceed() const +{ + return ui_.checkTLSKeyExportWillSucceed->isChecked(); +} + + //**************************************************************************************************************************************************** /// \return The value of the 'Hostname' edit. //**************************************************************************************************************************************************** diff --git a/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.h b/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.h index 08d9a464..0d414ec5 100644 --- a/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.h +++ b/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.h @@ -55,6 +55,8 @@ public: // member functions. QString dependencyLicenseLink() const; ///< Get the content of the 'Dependency License Link' edit. QString landingPageLink() const; ///< Get the content of the 'Landing Page Link' edit. bool nextBugReportWillSucceed() const; ///< Get the status of the 'Next Bug Report Will Fail' check box. + bool nextTLSCertExportWillSucceed() const; ///< Get the status of the 'Next TLS Cert export will succeed' check box. + bool nextTLSKeyExportWillSucceed() const; ///< Get the status of the 'Next TLS Key export will succeed' check box. QString hostname() const; ///< Get the value of the 'Hostname' edit. qint32 imapPort(); ///< Get the value of the IMAP port spin. qint32 smtpPort(); ///< Get the value of the SMTP port spin. @@ -77,6 +79,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 exportTLSCertificates(QString const& folderPath); ///< Export the TLS certificates. 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. diff --git a/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.ui b/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.ui index cb19f55d..352b0b6c 100644 --- a/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.ui +++ b/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.ui @@ -372,6 +372,48 @@ + + + + + 0 + 0 + + + + TLS Certficates + + + + + + Last Export: Never + + + + + + + TLS certificate export will succeed + + + true + + + + + + + TLS private key export will succeed + + + true + + + + + + diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/Notifications/Notifications.qml b/internal/frontend/bridge-gui/bridge-gui/qml/Notifications/Notifications.qml index 1b75cae1..32e0954d 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/Notifications/Notifications.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/Notifications/Notifications.qml @@ -1106,7 +1106,7 @@ QtObject { description: "#PlaceholderText#" icon: "./icons/ic-exclamation-circle-filled.svg" type: Notification.NotificationType.Danger - group: Notification.Groups.Connection + group: Notifications.Group.Dialogs Connections { target: Backend function onGenericError(title, description) { diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.cpp b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.cpp index 813b83e6..b0c5a75e 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.cpp +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.cpp @@ -132,6 +132,18 @@ bridgepp::SPStreamEvent wrapUserEvent(grpc::UserEvent *userEvent) } +//**************************************************************************************************************************************************** +/// \param[in] genericErrorEvent The generic error event. +/// \return The stream event. +//**************************************************************************************************************************************************** +bridgepp::SPStreamEvent wrapGenericErrorEvent(grpc::GenericErrorEvent *genericErrorEvent) +{ + auto event = newStreamEvent(); + event->set_allocated_genericerror(genericErrorEvent); + return event; +} + + } // namespace //**************************************************************************************************************************************************** @@ -592,4 +604,16 @@ SPStreamEvent newUserChangedEvent(QString const &userID) } +//**************************************************************************************************************************************************** +/// \param[in] errorCode The error errorCode. +/// \return The event. +//**************************************************************************************************************************************************** +SPStreamEvent newGenericErrorEvent(grpc::ErrorCode errorCode) +{ + auto event = new grpc::GenericErrorEvent; + event->set_code(errorCode); + return wrapGenericErrorEvent(event); +} + + } // namespace bridgepp diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.h b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.h index 8a9fdae9..a37190d8 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.h +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.h @@ -79,6 +79,8 @@ SPStreamEvent newToggleSplitModeFinishedEvent(QString const &userID); ///< Creat SPStreamEvent newUserDisconnectedEvent(QString const &username); ///< Create a new UserDisconnectedEvent event. SPStreamEvent newUserChangedEvent(QString const &userID); ///< Create a new UserChangedEvent event. +// Generic error event +SPStreamEvent newGenericErrorEvent(grpc::ErrorCode errorCode); ///< Create a new GenericErrrorEvent event. } // namespace bridgepp