From 79dc8584460ada0c26faca207f31cd0fd82d0206 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Fri, 14 Feb 2025 23:37:15 -0500 Subject: [PATCH] chore: modify client trying to connect dialog to inform user the new client needs to be put in the layout when both tls is enabled and peer key checking is enabled , otherwise show the old dialog asking to allow the client to connect --- src/lib/gui/core/ServerConnection.cpp | 7 ++-- src/lib/gui/core/ServerConnection.h | 3 +- src/lib/gui/messages.cpp | 34 ++++++++++++------- src/lib/gui/messages.h | 2 +- .../gui/core/ServerConnectionTests.cpp | 15 ++++---- 5 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/lib/gui/core/ServerConnection.cpp b/src/lib/gui/core/ServerConnection.cpp index 819450d98..fe13a7b3a 100644 --- a/src/lib/gui/core/ServerConnection.cpp +++ b/src/lib/gui/core/ServerConnection.cpp @@ -20,9 +20,9 @@ namespace deskflow::gui { // messages::NewClientPromptResult -ServerConnection::Deps::showNewClientPrompt(QWidget *parent, const QString &clientName) const +ServerConnection::Deps::showNewClientPrompt(QWidget *parent, const QString &clientName, bool previouslyAccepted) const { - return messages::showNewClientPrompt(parent, clientName); + return messages::showNewClientPrompt(parent, clientName, previouslyAccepted); } // @@ -93,7 +93,8 @@ void ServerConnection::handleNewClient(const QString &clientName) Q_EMIT messageShowing(); m_messageShowing = true; - const auto result = m_pDeps->showNewClientPrompt(m_pParent, clientName); + const auto result = + m_pDeps->showNewClientPrompt(m_pParent, clientName, m_appConfig.tlsEnabled() && m_appConfig.requireClientCerts()); m_messageShowing = false; if (result == Add) { diff --git a/src/lib/gui/core/ServerConnection.h b/src/lib/gui/core/ServerConnection.h index 23c60800c..1891c0ed8 100644 --- a/src/lib/gui/core/ServerConnection.h +++ b/src/lib/gui/core/ServerConnection.h @@ -25,7 +25,8 @@ public: struct Deps { virtual ~Deps() = default; - virtual messages::NewClientPromptResult showNewClientPrompt(QWidget *parent, const QString &clientName) const; + virtual messages::NewClientPromptResult + showNewClientPrompt(QWidget *parent, const QString &clientName, bool previouslyAccepted = false) const; }; explicit ServerConnection( diff --git a/src/lib/gui/messages.cpp b/src/lib/gui/messages.cpp index 017b6faa3..60cc3a599 100644 --- a/src/lib/gui/messages.cpp +++ b/src/lib/gui/messages.cpp @@ -205,23 +205,33 @@ void showClientConnectError(QWidget *parent, ClientError error, const QString &a dialog.exec(); } -NewClientPromptResult showNewClientPrompt(QWidget *parent, const QString &clientName) +NewClientPromptResult showNewClientPrompt(QWidget *parent, const QString &clientName, bool tlsAcceptedClient) { using enum NewClientPromptResult; - QMessageBox message(parent); - const QPushButton *ignore = message.addButton("Ignore", QMessageBox::RejectRole); - const QPushButton *add = message.addButton("Add client", QMessageBox::AcceptRole); - message.setText(QString("A new client called '%1' wants to connect").arg(clientName)); - message.exec(); - - if (message.clickedButton() == add) { + if (tlsAcceptedClient) { + // When peer checking is enabled you will be prompted to allow the connection before seeing this dialog. + // This is why we do not show a dialog with an option to ignore the new client + QMessageBox::information( + parent, QString("New Client"), + QString("A new client called '%1' has been accepted. You'll need to add it to your server's screen layout.") + .arg(clientName) + ); return Add; - } else if (message.clickedButton() == ignore) { - return Ignore; } else { - qFatal("no expected dialog button was clicked"); - abort(); + QMessageBox message(parent); + const QPushButton *ignore = message.addButton("Ignore", QMessageBox::RejectRole); + const QPushButton *add = message.addButton("Add client", QMessageBox::AcceptRole); + message.setText(QString("A new client called '%1' wants to connect").arg(clientName)); + message.exec(); + if (message.clickedButton() == add) { + return Add; + } else if (message.clickedButton() == ignore) { + return Ignore; + } else { + qFatal("no expected dialog button was clicked"); + abort(); + } } } diff --git a/src/lib/gui/messages.h b/src/lib/gui/messages.h index 0174c0b53..ffce2c596 100644 --- a/src/lib/gui/messages.h +++ b/src/lib/gui/messages.h @@ -38,7 +38,7 @@ void showCloseReminder(QWidget *parent); void showClientConnectError(QWidget *parent, ClientError error, const QString &address); -NewClientPromptResult showNewClientPrompt(QWidget *parent, const QString &clientName); +NewClientPromptResult showNewClientPrompt(QWidget *parent, const QString &clientName, bool tlsAcceptedClient = false); bool showClearSettings(QWidget *parent); diff --git a/src/test/unittests/gui/core/ServerConnectionTests.cpp b/src/test/unittests/gui/core/ServerConnectionTests.cpp index 8c33d07a9..d39c68390 100644 --- a/src/test/unittests/gui/core/ServerConnectionTests.cpp +++ b/src/test/unittests/gui/core/ServerConnectionTests.cpp @@ -25,8 +25,8 @@ namespace { struct DepsMock : public ServerConnection::Deps { MOCK_METHOD( - messages::NewClientPromptResult, showNewClientPrompt, (QWidget * parent, const QString &clientName), - (const, override) + messages::NewClientPromptResult, showNewClientPrompt, + (QWidget * parent, const QString &clientName, bool previousyAccepted), (const, override) ); }; @@ -46,7 +46,7 @@ TEST_F(ServerConnectionTests, handleLogLine_newClient_shouldShowPrompt) ServerConnection serverConnection(nullptr, m_appConfig, m_serverConfig, m_serverConfigDialogState, m_pDeps); QString clientName = "test client"; - EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, clientName)); + EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, clientName, false)); serverConnection.handleLogLine(R"(unrecognised client name "test client")"); } @@ -54,10 +54,11 @@ TEST_F(ServerConnectionTests, handleLogLine_newClient_shouldShowPrompt) TEST_F(ServerConnectionTests, handleLogLine_ignoredClient_shouldNotShowPrompt) { ServerConnection serverConnection(nullptr, m_appConfig, m_serverConfig, m_serverConfigDialogState, m_pDeps); - ON_CALL(*m_pDeps, showNewClientPrompt(_, _)).WillByDefault(testing::Return(messages::NewClientPromptResult::Ignore)); + ON_CALL(*m_pDeps, showNewClientPrompt(_, _, false)) + .WillByDefault(testing::Return(messages::NewClientPromptResult::Ignore)); serverConnection.handleLogLine(R"(unrecognised client name "stub")"); - EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, _)).Times(0); + EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, _, false)).Times(0); serverConnection.handleLogLine(R"(unrecognised client name "stub")"); } @@ -67,7 +68,7 @@ TEST_F(ServerConnectionTests, handleLogLine_serverConfigFull_shouldNotShowPrompt ServerConnection serverConnection(nullptr, m_appConfig, m_serverConfig, m_serverConfigDialogState, m_pDeps); ON_CALL(m_serverConfig, isFull()).WillByDefault(testing::Return(true)); - EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, _)).Times(0); + EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, _, false)).Times(0); serverConnection.handleLogLine(R"(unrecognised client name "test client")"); } @@ -77,7 +78,7 @@ TEST_F(ServerConnectionTests, handleLogLine_screenExists_shouldNotShowPrompt) ServerConnection serverConnection(nullptr, m_appConfig, m_serverConfig, m_serverConfigDialogState, m_pDeps); ON_CALL(m_serverConfig, screenExists(_)).WillByDefault(testing::Return(true)); - EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, _)).Times(0); + EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, _, false)).Times(0); serverConnection.handleLogLine(R"(unrecognised client name "test client")"); }