| Index: remoting/host/security_key/security_key_ipc_client_unittest.cc
|
| diff --git a/remoting/host/security_key/remote_security_key_ipc_client_unittest.cc b/remoting/host/security_key/security_key_ipc_client_unittest.cc
|
| similarity index 60%
|
| rename from remoting/host/security_key/remote_security_key_ipc_client_unittest.cc
|
| rename to remoting/host/security_key/security_key_ipc_client_unittest.cc
|
| index dd0a09a3bcfde79d7f19fa94f0490947d269c31e..0f86f0626468598a502cb294c8d92ec3909ffe7c 100644
|
| --- a/remoting/host/security_key/remote_security_key_ipc_client_unittest.cc
|
| +++ b/remoting/host/security_key/security_key_ipc_client_unittest.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "remoting/host/security_key/remote_security_key_ipc_client.h"
|
| +#include "remoting/host/security_key/security_key_ipc_client.h"
|
|
|
| #include <memory>
|
| #include <string>
|
| @@ -12,25 +12,24 @@
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/run_loop.h"
|
| #include "ipc/ipc_channel.h"
|
| -#include "remoting/host/security_key/fake_ipc_gnubby_auth_handler.h"
|
| -#include "remoting/host/security_key/fake_remote_security_key_ipc_server.h"
|
| -#include "remoting/host/security_key/remote_security_key_ipc_constants.h"
|
| +#include "remoting/host/security_key/fake_ipc_security_key_auth_handler.h"
|
| +#include "remoting/host/security_key/fake_security_key_ipc_server.h"
|
| +#include "remoting/host/security_key/security_key_ipc_constants.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace {
|
| const int kTestConnectionId = 1;
|
| const char kNonexistentIpcChannelName[] = "Nonexistent_IPC_Channel";
|
| -const char kValidIpcChannelName[] =
|
| - "Remote_Security_Key_Ipc_Client_Test_Channel.";
|
| +const char kValidIpcChannelName[] = "Security_Key_Ipc_Client_Test_Channel.";
|
| const int kLargeMessageSizeBytes = 256 * 1024;
|
| } // namespace
|
|
|
| namespace remoting {
|
|
|
| -class RemoteSecurityKeyIpcClientTest : public testing::Test {
|
| +class SecurityKeyIpcClientTest : public testing::Test {
|
| public:
|
| - RemoteSecurityKeyIpcClientTest();
|
| - ~RemoteSecurityKeyIpcClientTest() override;
|
| + SecurityKeyIpcClientTest();
|
| + ~SecurityKeyIpcClientTest() override;
|
|
|
| // Passed to the object used for testing to be called back to signal
|
| // completion of an IPC channel state change or reception of an IPC message.
|
| @@ -51,12 +50,12 @@ class RemoteSecurityKeyIpcClientTest : public testing::Test {
|
| // Waits until the current |run_loop_| instance is signaled, then resets it.
|
| void WaitForOperationComplete();
|
|
|
| - // Sets up an active IPC connection between |remote_security_key_ipc_client_|
|
| + // Sets up an active IPC connection between |security_key_ipc_client_|
|
| // and |fake_ipc_server_|. |expect_success| defines whether the operation
|
| // is expected to succeed or fail.
|
| void EstablishConnection(bool expect_success);
|
|
|
| - // Sends a security key request from |remote_security_key_ipc_client_| and
|
| + // Sends a security key request from |security_key_ipc_client_| and
|
| // a response from |fake_ipc_server_| and verifies the payloads for both.
|
| void SendRequestAndResponse(const std::string& request_data,
|
| const std::string& response_data);
|
| @@ -72,14 +71,14 @@ class RemoteSecurityKeyIpcClientTest : public testing::Test {
|
| std::unique_ptr<base::RunLoop> run_loop_;
|
|
|
| // The object under test.
|
| - RemoteSecurityKeyIpcClient remote_security_key_ipc_client_;
|
| + SecurityKeyIpcClient security_key_ipc_client_;
|
|
|
| - // Provides a connection details message to |remote_security_key_ipc_client_|
|
| + // Provides a connection details message to |security_key_ipc_client_|
|
| // for testing.
|
| - FakeIpcGnubbyAuthHandler fake_gnubby_auth_handler_;
|
| + FakeIpcSecurityKeyAuthHandler fake_security_key_auth_handler_;
|
|
|
| // Used to send/receive security key IPC messages for testing.
|
| - FakeRemoteSecurityKeyIpcServer fake_ipc_server_;
|
| + FakeSecurityKeyIpcServer fake_ipc_server_;
|
|
|
| // Stores the current session ID on supported platforms.
|
| uint32_t session_id_ = 0;
|
| @@ -95,108 +94,103 @@ class RemoteSecurityKeyIpcClientTest : public testing::Test {
|
| std::string last_message_received_;
|
|
|
| private:
|
| - DISALLOW_COPY_AND_ASSIGN(RemoteSecurityKeyIpcClientTest);
|
| + DISALLOW_COPY_AND_ASSIGN(SecurityKeyIpcClientTest);
|
| };
|
|
|
| -RemoteSecurityKeyIpcClientTest::RemoteSecurityKeyIpcClientTest()
|
| +SecurityKeyIpcClientTest::SecurityKeyIpcClientTest()
|
| : run_loop_(new base::RunLoop()),
|
| fake_ipc_server_(
|
| kTestConnectionId,
|
| /*peer_session_id=*/UINT32_MAX,
|
| /*initial_connect_timeout=*/base::TimeDelta::FromMilliseconds(500),
|
| - base::Bind(&RemoteSecurityKeyIpcClientTest::SendMessageToClient,
|
| + base::Bind(&SecurityKeyIpcClientTest::SendMessageToClient,
|
| base::Unretained(this)),
|
| - base::Bind(&RemoteSecurityKeyIpcClientTest::OperationComplete,
|
| + base::Bind(&SecurityKeyIpcClientTest::OperationComplete,
|
| base::Unretained(this),
|
| /*failed=*/false)) {}
|
|
|
| -RemoteSecurityKeyIpcClientTest::~RemoteSecurityKeyIpcClientTest() {}
|
| +SecurityKeyIpcClientTest::~SecurityKeyIpcClientTest() {}
|
|
|
| -void RemoteSecurityKeyIpcClientTest::SetUp() {
|
| +void SecurityKeyIpcClientTest::SetUp() {
|
| #if defined(OS_WIN)
|
| DWORD session_id = 0;
|
| // If we are on Windows, then we need to set the correct session ID or the
|
| // IPC connection will not be created successfully.
|
| ASSERT_TRUE(ProcessIdToSessionId(GetCurrentProcessId(), &session_id));
|
| session_id_ = session_id;
|
| - remote_security_key_ipc_client_.SetExpectedIpcServerSessionIdForTest(
|
| - session_id_);
|
| + security_key_ipc_client_.SetExpectedIpcServerSessionIdForTest(session_id_);
|
| #endif // defined(OS_WIN)
|
| }
|
|
|
| -void RemoteSecurityKeyIpcClientTest::OperationComplete(bool failed) {
|
| +void SecurityKeyIpcClientTest::OperationComplete(bool failed) {
|
| operation_failed_ |= failed;
|
| run_loop_->Quit();
|
| }
|
|
|
| -void RemoteSecurityKeyIpcClientTest::WaitForOperationComplete() {
|
| +void SecurityKeyIpcClientTest::WaitForOperationComplete() {
|
| run_loop_->Run();
|
| run_loop_.reset(new base::RunLoop());
|
| }
|
|
|
| -void RemoteSecurityKeyIpcClientTest::SendMessageToClient(
|
| - int connection_id,
|
| - const std::string& data) {
|
| +void SecurityKeyIpcClientTest::SendMessageToClient(int connection_id,
|
| + const std::string& data) {
|
| last_connection_id_received_ = connection_id;
|
| last_message_received_ = data;
|
| OperationComplete(/*failed=*/false);
|
| }
|
|
|
| -void RemoteSecurityKeyIpcClientTest::ClientMessageReceived(
|
| +void SecurityKeyIpcClientTest::ClientMessageReceived(
|
| const std::string& response_payload) {
|
| last_message_received_ = response_payload;
|
| OperationComplete(/*failed=*/false);
|
| }
|
|
|
| -std::string RemoteSecurityKeyIpcClientTest::GenerateUniqueTestChannelName() {
|
| +std::string SecurityKeyIpcClientTest::GenerateUniqueTestChannelName() {
|
| return GetChannelNamePathPrefixForTest() + kValidIpcChannelName +
|
| IPC::Channel::GenerateUniqueRandomChannelID();
|
| }
|
|
|
| -void RemoteSecurityKeyIpcClientTest::EstablishConnection(bool expect_success) {
|
| +void SecurityKeyIpcClientTest::EstablishConnection(bool expect_success) {
|
| // Start up the security key forwarding session IPC channel first, that way
|
| - // we can provide the channel using the fake GnubbyAuthHandler later on.
|
| + // we can provide the channel using the fake SecurityKeyAuthHandler later on.
|
| std::string ipc_session_channel_name = GenerateUniqueTestChannelName();
|
| ASSERT_TRUE(fake_ipc_server_.CreateChannel(
|
| ipc_session_channel_name,
|
| /*request_timeout=*/base::TimeDelta::FromMilliseconds(500)));
|
| ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(ipc_session_channel_name));
|
| - fake_gnubby_auth_handler_.set_ipc_security_key_channel_name(
|
| + fake_security_key_auth_handler_.set_ipc_security_key_channel_name(
|
| ipc_session_channel_name);
|
|
|
| // Set up the channel name for the initial IPC channel.
|
| std::string ipc_server_channel_name = GenerateUniqueTestChannelName();
|
| - fake_gnubby_auth_handler_.set_ipc_server_channel_name(
|
| + fake_security_key_auth_handler_.set_ipc_server_channel_name(
|
| ipc_server_channel_name);
|
| - remote_security_key_ipc_client_.SetInitialIpcChannelNameForTest(
|
| + security_key_ipc_client_.SetInitialIpcChannelNameForTest(
|
| ipc_server_channel_name);
|
|
|
| // Create the initial IPC channel and verify it was set up correctly.
|
| - ASSERT_FALSE(
|
| - remote_security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel());
|
| - fake_gnubby_auth_handler_.CreateGnubbyConnection();
|
| + ASSERT_FALSE(security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel());
|
| + fake_security_key_auth_handler_.CreateSecurityKeyConnection();
|
| ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(ipc_server_channel_name));
|
| - ASSERT_TRUE(
|
| - remote_security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel());
|
| + ASSERT_TRUE(security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel());
|
|
|
| // Establish the IPC channel so we can begin sending and receiving security
|
| // key messages.
|
| - remote_security_key_ipc_client_.EstablishIpcConnection(
|
| - base::Bind(&RemoteSecurityKeyIpcClientTest::OperationComplete,
|
| + security_key_ipc_client_.EstablishIpcConnection(
|
| + base::Bind(&SecurityKeyIpcClientTest::OperationComplete,
|
| base::Unretained(this), /*failed=*/false),
|
| - base::Bind(&RemoteSecurityKeyIpcClientTest::OperationComplete,
|
| + base::Bind(&SecurityKeyIpcClientTest::OperationComplete,
|
| base::Unretained(this), /*failed=*/true));
|
| WaitForOperationComplete();
|
| ASSERT_NE(operation_failed_, expect_success);
|
| }
|
|
|
| -void RemoteSecurityKeyIpcClientTest::SendRequestAndResponse(
|
| +void SecurityKeyIpcClientTest::SendRequestAndResponse(
|
| const std::string& request_data,
|
| const std::string& response_data) {
|
| - ASSERT_TRUE(remote_security_key_ipc_client_.SendSecurityKeyRequest(
|
| - request_data,
|
| - base::Bind(&RemoteSecurityKeyIpcClientTest::ClientMessageReceived,
|
| - base::Unretained(this))));
|
| + ASSERT_TRUE(security_key_ipc_client_.SendSecurityKeyRequest(
|
| + request_data, base::Bind(&SecurityKeyIpcClientTest::ClientMessageReceived,
|
| + base::Unretained(this))));
|
| WaitForOperationComplete();
|
| ASSERT_FALSE(operation_failed_);
|
| ASSERT_EQ(last_connection_id_received_, kTestConnectionId);
|
| @@ -208,73 +202,72 @@ void RemoteSecurityKeyIpcClientTest::SendRequestAndResponse(
|
| ASSERT_EQ(last_message_received_, response_data);
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcClientTest, GenerateSingleGnubbyRequest) {
|
| +TEST_F(SecurityKeyIpcClientTest, GenerateSingleSecurityKeyRequest) {
|
| EstablishConnection(/*expect_success=*/true);
|
|
|
| SendRequestAndResponse("Auth me!", "You've been authed!");
|
|
|
| - remote_security_key_ipc_client_.CloseIpcConnection();
|
| + security_key_ipc_client_.CloseIpcConnection();
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcClientTest, GenerateLargeGnubbyRequest) {
|
| +TEST_F(SecurityKeyIpcClientTest, GenerateLargeSecurityKeyRequest) {
|
| EstablishConnection(/*expect_success=*/true);
|
|
|
| SendRequestAndResponse(std::string(kLargeMessageSizeBytes, 'Y'),
|
| std::string(kLargeMessageSizeBytes, 'Z'));
|
|
|
| - remote_security_key_ipc_client_.CloseIpcConnection();
|
| + security_key_ipc_client_.CloseIpcConnection();
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcClientTest, GenerateReallyLargeGnubbyRequest) {
|
| +TEST_F(SecurityKeyIpcClientTest, GenerateReallyLargeSecurityKeyRequest) {
|
| EstablishConnection(/*expect_success=*/true);
|
|
|
| SendRequestAndResponse(std::string(kLargeMessageSizeBytes * 2, 'Y'),
|
| std::string(kLargeMessageSizeBytes * 2, 'Z'));
|
|
|
| - remote_security_key_ipc_client_.CloseIpcConnection();
|
| + security_key_ipc_client_.CloseIpcConnection();
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcClientTest, GenerateMultipleGnubbyRequest) {
|
| +TEST_F(SecurityKeyIpcClientTest, GenerateMultipleSecurityKeyRequest) {
|
| EstablishConnection(/*expect_success=*/true);
|
|
|
| SendRequestAndResponse("Auth me 1!", "You've been authed once!");
|
| SendRequestAndResponse("Auth me 2!", "You've been authed twice!");
|
| SendRequestAndResponse("Auth me 3!", "You've been authed thrice!");
|
|
|
| - remote_security_key_ipc_client_.CloseIpcConnection();
|
| + security_key_ipc_client_.CloseIpcConnection();
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcClientTest,
|
| - ServerClosesConnectionAfterRequestTimeout) {
|
| +TEST_F(SecurityKeyIpcClientTest, ServerClosesConnectionAfterRequestTimeout) {
|
| EstablishConnection(/*expect_success=*/true);
|
| fake_ipc_server_.CloseChannel();
|
| WaitForOperationComplete();
|
| ASSERT_FALSE(operation_failed_);
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcClientTest,
|
| - SecondGnubbyRequestBeforeFirstResponseReceived) {
|
| +TEST_F(SecurityKeyIpcClientTest,
|
| + SecondSecurityKeyRequestBeforeFirstResponseReceived) {
|
| EstablishConnection(/*expect_success=*/true);
|
|
|
| - ASSERT_TRUE(remote_security_key_ipc_client_.SendSecurityKeyRequest(
|
| + ASSERT_TRUE(security_key_ipc_client_.SendSecurityKeyRequest(
|
| "First Request",
|
| - base::Bind(&RemoteSecurityKeyIpcClientTest::ClientMessageReceived,
|
| + base::Bind(&SecurityKeyIpcClientTest::ClientMessageReceived,
|
| base::Unretained(this))));
|
| WaitForOperationComplete();
|
| ASSERT_FALSE(operation_failed_);
|
|
|
| - ASSERT_FALSE(remote_security_key_ipc_client_.SendSecurityKeyRequest(
|
| + ASSERT_FALSE(security_key_ipc_client_.SendSecurityKeyRequest(
|
| "Second Request",
|
| - base::Bind(&RemoteSecurityKeyIpcClientTest::ClientMessageReceived,
|
| + base::Bind(&SecurityKeyIpcClientTest::ClientMessageReceived,
|
| base::Unretained(this))));
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcClientTest, ReceiveGnubbyResponseWithEmptyPayload) {
|
| +TEST_F(SecurityKeyIpcClientTest, ReceiveSecurityKeyResponseWithEmptyPayload) {
|
| EstablishConnection(/*expect_success=*/true);
|
|
|
| - ASSERT_TRUE(remote_security_key_ipc_client_.SendSecurityKeyRequest(
|
| + ASSERT_TRUE(security_key_ipc_client_.SendSecurityKeyRequest(
|
| "Valid request",
|
| - base::Bind(&RemoteSecurityKeyIpcClientTest::ClientMessageReceived,
|
| + base::Bind(&SecurityKeyIpcClientTest::ClientMessageReceived,
|
| base::Unretained(this))));
|
| WaitForOperationComplete();
|
| ASSERT_FALSE(operation_failed_);
|
| @@ -284,67 +277,63 @@ TEST_F(RemoteSecurityKeyIpcClientTest, ReceiveGnubbyResponseWithEmptyPayload) {
|
| ASSERT_TRUE(operation_failed_);
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcClientTest,
|
| - SendRequestBeforeEstablishingConnection) {
|
| +TEST_F(SecurityKeyIpcClientTest, SendRequestBeforeEstablishingConnection) {
|
| // Sending a request will fail since the IPC connection has not been
|
| // established.
|
| - ASSERT_FALSE(remote_security_key_ipc_client_.SendSecurityKeyRequest(
|
| - "Too soon!!",
|
| - base::Bind(&RemoteSecurityKeyIpcClientTest::ClientMessageReceived,
|
| - base::Unretained(this))));
|
| + ASSERT_FALSE(security_key_ipc_client_.SendSecurityKeyRequest(
|
| + "Too soon!!", base::Bind(&SecurityKeyIpcClientTest::ClientMessageReceived,
|
| + base::Unretained(this))));
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcClientTest, NonExistentMainIpcServerChannel) {
|
| +TEST_F(SecurityKeyIpcClientTest, NonExistentMainIpcServerChannel) {
|
| std::string ipc_server_channel_name(kNonexistentIpcChannelName);
|
| - remote_security_key_ipc_client_.SetInitialIpcChannelNameForTest(
|
| + security_key_ipc_client_.SetInitialIpcChannelNameForTest(
|
| ipc_server_channel_name);
|
|
|
| // Attempt to establish the conection (should fail since the IPC channel does
|
| // not exist).
|
| - remote_security_key_ipc_client_.EstablishIpcConnection(
|
| - base::Bind(&RemoteSecurityKeyIpcClientTest::OperationComplete,
|
| + security_key_ipc_client_.EstablishIpcConnection(
|
| + base::Bind(&SecurityKeyIpcClientTest::OperationComplete,
|
| base::Unretained(this), /*failed=*/false),
|
| - base::Bind(&RemoteSecurityKeyIpcClientTest::OperationComplete,
|
| + base::Bind(&SecurityKeyIpcClientTest::OperationComplete,
|
| base::Unretained(this), /*failed=*/true));
|
| WaitForOperationComplete();
|
| ASSERT_TRUE(operation_failed_);
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcClientTest, NonExistentIpcSessionChannel) {
|
| - fake_gnubby_auth_handler_.set_ipc_security_key_channel_name(
|
| +TEST_F(SecurityKeyIpcClientTest, NonExistentIpcSessionChannel) {
|
| + fake_security_key_auth_handler_.set_ipc_security_key_channel_name(
|
| kNonexistentIpcChannelName);
|
|
|
| // Set up the channel name for the initial IPC channel.
|
| std::string ipc_server_channel_name = GenerateUniqueTestChannelName();
|
| - fake_gnubby_auth_handler_.set_ipc_server_channel_name(
|
| + fake_security_key_auth_handler_.set_ipc_server_channel_name(
|
| ipc_server_channel_name);
|
| - remote_security_key_ipc_client_.SetInitialIpcChannelNameForTest(
|
| + security_key_ipc_client_.SetInitialIpcChannelNameForTest(
|
| ipc_server_channel_name);
|
|
|
| // Create the initial IPC channel and verify it was set up correctly.
|
| - ASSERT_FALSE(
|
| - remote_security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel());
|
| - fake_gnubby_auth_handler_.CreateGnubbyConnection();
|
| + ASSERT_FALSE(security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel());
|
| + fake_security_key_auth_handler_.CreateSecurityKeyConnection();
|
| ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(ipc_server_channel_name));
|
| - ASSERT_TRUE(
|
| - remote_security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel());
|
| + ASSERT_TRUE(security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel());
|
|
|
| // Attempt to establish the conection (should fail since the IPC channel does
|
| // not exist).
|
| - remote_security_key_ipc_client_.EstablishIpcConnection(
|
| - base::Bind(&RemoteSecurityKeyIpcClientTest::OperationComplete,
|
| + security_key_ipc_client_.EstablishIpcConnection(
|
| + base::Bind(&SecurityKeyIpcClientTest::OperationComplete,
|
| base::Unretained(this), /*failed=*/false),
|
| - base::Bind(&RemoteSecurityKeyIpcClientTest::OperationComplete,
|
| + base::Bind(&SecurityKeyIpcClientTest::OperationComplete,
|
| base::Unretained(this), /*failed=*/true));
|
| WaitForOperationComplete();
|
| ASSERT_TRUE(operation_failed_);
|
| }
|
|
|
| #if defined(OS_WIN)
|
| -TEST_F(RemoteSecurityKeyIpcClientTest, GnubbyIpcServerRunningInWrongSession) {
|
| +TEST_F(SecurityKeyIpcClientTest, SecurityKeyIpcServerRunningInWrongSession) {
|
| // Set the expected session Id to a different session than we are running in.
|
| - remote_security_key_ipc_client_.SetExpectedIpcServerSessionIdForTest(
|
| - session_id_ + 1);
|
| + security_key_ipc_client_.SetExpectedIpcServerSessionIdForTest(session_id_ +
|
| + 1);
|
|
|
| // Attempting to establish a connection should fail here since the IPC Server
|
| // is 'running' in a different session than expected.
|
|
|