Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1278)

Unified Diff: remoting/host/security_key/gnubby_auth_handler_win_unittest.cc

Issue 2085353004: Update GnubbyAuthHandler to use the current session ID (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@host_extension
Patch Set: Fixing a non-windows build break and some additional cleanup Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/host/security_key/gnubby_auth_handler_win_unittest.cc
diff --git a/remoting/host/security_key/gnubby_auth_handler_win_unittest.cc b/remoting/host/security_key/gnubby_auth_handler_win_unittest.cc
index d844d3f8b987268a562ed201e3c9ab3dcb3633d6..eaa929dd912704371d1133f2f04acd0170f4c25c 100644
--- a/remoting/host/security_key/gnubby_auth_handler_win_unittest.cc
+++ b/remoting/host/security_key/gnubby_auth_handler_win_unittest.cc
@@ -4,6 +4,7 @@
#include "remoting/host/security_key/gnubby_auth_handler.h"
+#include <cstdint>
#include <memory>
#include <string>
@@ -45,9 +46,16 @@ class GnubbyAuthHandlerWinTest : public testing::Test {
// back when a security key request is received by it.
void SendMessageToClient(int connection_id, const std::string& data);
+ // Used as a callback given to the object under test, returns the id of the
+ // Windows session which is being remoted.
+ uint32_t GetDesktopSessionId() const;
+
// Creates a new gnubby connection on the object under test.
void CreateGnubbyConnection(const std::string& channel_name);
+ // Sets |desktop_session_id_| to the id for the current Windows session.
+ bool SetDesktopSessionId();
+
// Uses |fake_ipc_client| to connect to the initial IPC server channel, it
// then validates internal state of the object under test and closes the
// connection based on |close_connection|.
@@ -99,6 +107,10 @@ class GnubbyAuthHandlerWinTest : public testing::Test {
// communicating over the IPC channel.
int last_connection_id_received_ = -1;
+ // Used to validate that IPC connections are only allowed from a specific
+ // Windows session.
+ DWORD desktop_session_id_ = UINT32_MAX;
+
// Stores the contents of the last IPC message received for validation.
std::string last_message_received_;
@@ -108,8 +120,11 @@ class GnubbyAuthHandlerWinTest : public testing::Test {
GnubbyAuthHandlerWinTest::GnubbyAuthHandlerWinTest()
: run_loop_(new base::RunLoop()) {
- auth_handler_ = remoting::GnubbyAuthHandler::Create(base::Bind(
- &GnubbyAuthHandlerWinTest::SendMessageToClient, base::Unretained(this)));
+ auth_handler_ = remoting::GnubbyAuthHandler::Create(
+ base::Bind(&GnubbyAuthHandlerWinTest::SendMessageToClient,
+ base::Unretained(this)),
+ base::Bind(&GnubbyAuthHandlerWinTest::GetDesktopSessionId,
+ base::Unretained(this)));
}
GnubbyAuthHandlerWinTest::~GnubbyAuthHandlerWinTest() {}
@@ -130,6 +145,10 @@ void GnubbyAuthHandlerWinTest::SendMessageToClient(int connection_id,
OperationComplete();
}
+uint32_t GnubbyAuthHandlerWinTest::GetDesktopSessionId() const {
+ return desktop_session_id_;
+}
+
void GnubbyAuthHandlerWinTest::CreateGnubbyConnection(
const std::string& channel_name) {
ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest());
@@ -139,6 +158,12 @@ void GnubbyAuthHandlerWinTest::CreateGnubbyConnection(
// Create a new Gnubby IPC Server connection.
auth_handler_->CreateGnubbyConnection();
ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(channel_name));
+
+ ASSERT_TRUE(SetDesktopSessionId());
+}
+
+bool GnubbyAuthHandlerWinTest::SetDesktopSessionId() {
+ return ProcessIdToSessionId(GetCurrentProcessId(), &desktop_session_id_);
}
void GnubbyAuthHandlerWinTest::EstablishInitialIpcConnection(
@@ -489,4 +514,23 @@ TEST_F(GnubbyAuthHandlerWinTest, HandleGnubbyErrorResponse) {
/*close_connection=*/true);
}
+TEST_F(GnubbyAuthHandlerWinTest, IpcConnectionFailsFromInvalidSession) {
+ std::string channel_name(GetUniqueTestChannelName());
+ CreateGnubbyConnection(channel_name);
+
+ // Set the current session id to a 'different' session.
+ desktop_session_id_ = desktop_session_id_ + 1;
+
+ // Create a fake client and connect to the IPC server channel.
+ FakeRemoteSecurityKeyIpcClient fake_ipc_client(base::Bind(
+ &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this)));
+ ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name));
+ // Wait for the error callback to be signaled.
+ WaitForOperationComplete();
+
+ // Verify the connection was not set up.
+ ASSERT_FALSE(auth_handler_->IsValidConnectionId(kConnectionId1));
+ ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest());
+}
+
} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698