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

This commit is contained in:
sithlord48 2025-02-14 23:37:15 -05:00 committed by Nick Bolton
parent 0667f5de73
commit 79dc858446
5 changed files with 37 additions and 24 deletions

View file

@ -20,9 +20,9 @@ namespace deskflow::gui {
// //
messages::NewClientPromptResult 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(); Q_EMIT messageShowing();
m_messageShowing = true; 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; m_messageShowing = false;
if (result == Add) { if (result == Add) {

View file

@ -25,7 +25,8 @@ public:
struct Deps struct Deps
{ {
virtual ~Deps() = default; 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( explicit ServerConnection(

View file

@ -205,23 +205,33 @@ void showClientConnectError(QWidget *parent, ClientError error, const QString &a
dialog.exec(); dialog.exec();
} }
NewClientPromptResult showNewClientPrompt(QWidget *parent, const QString &clientName) NewClientPromptResult showNewClientPrompt(QWidget *parent, const QString &clientName, bool tlsAcceptedClient)
{ {
using enum NewClientPromptResult; using enum NewClientPromptResult;
QMessageBox message(parent); if (tlsAcceptedClient) {
const QPushButton *ignore = message.addButton("Ignore", QMessageBox::RejectRole); // When peer checking is enabled you will be prompted to allow the connection before seeing this dialog.
const QPushButton *add = message.addButton("Add client", QMessageBox::AcceptRole); // This is why we do not show a dialog with an option to ignore the new client
message.setText(QString("A new client called '%1' wants to connect").arg(clientName)); QMessageBox::information(
message.exec(); 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.")
if (message.clickedButton() == add) { .arg(clientName)
);
return Add; return Add;
} else if (message.clickedButton() == ignore) {
return Ignore;
} else { } else {
qFatal("no expected dialog button was clicked"); QMessageBox message(parent);
abort(); 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();
}
} }
} }

View file

@ -38,7 +38,7 @@ void showCloseReminder(QWidget *parent);
void showClientConnectError(QWidget *parent, ClientError error, const QString &address); 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); bool showClearSettings(QWidget *parent);

View file

@ -25,8 +25,8 @@ namespace {
struct DepsMock : public ServerConnection::Deps struct DepsMock : public ServerConnection::Deps
{ {
MOCK_METHOD( MOCK_METHOD(
messages::NewClientPromptResult, showNewClientPrompt, (QWidget * parent, const QString &clientName), messages::NewClientPromptResult, showNewClientPrompt,
(const, override) (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); ServerConnection serverConnection(nullptr, m_appConfig, m_serverConfig, m_serverConfigDialogState, m_pDeps);
QString clientName = "test client"; 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")"); serverConnection.handleLogLine(R"(unrecognised client name "test client")");
} }
@ -54,10 +54,11 @@ TEST_F(ServerConnectionTests, handleLogLine_newClient_shouldShowPrompt)
TEST_F(ServerConnectionTests, handleLogLine_ignoredClient_shouldNotShowPrompt) TEST_F(ServerConnectionTests, handleLogLine_ignoredClient_shouldNotShowPrompt)
{ {
ServerConnection serverConnection(nullptr, m_appConfig, m_serverConfig, m_serverConfigDialogState, m_pDeps); 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")"); 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")"); 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); ServerConnection serverConnection(nullptr, m_appConfig, m_serverConfig, m_serverConfigDialogState, m_pDeps);
ON_CALL(m_serverConfig, isFull()).WillByDefault(testing::Return(true)); 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")"); 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); ServerConnection serverConnection(nullptr, m_appConfig, m_serverConfig, m_serverConfigDialogState, m_pDeps);
ON_CALL(m_serverConfig, screenExists(_)).WillByDefault(testing::Return(true)); 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")"); serverConnection.handleLogLine(R"(unrecognised client name "test client")");
} }