| Index: remoting/host/security_key/security_key_ipc_server_unittest.cc
|
| diff --git a/remoting/host/security_key/remote_security_key_ipc_server_unittest.cc b/remoting/host/security_key/security_key_ipc_server_unittest.cc
|
| similarity index 71%
|
| rename from remoting/host/security_key/remote_security_key_ipc_server_unittest.cc
|
| rename to remoting/host/security_key/security_key_ipc_server_unittest.cc
|
| index cf0b4a6af1f891c54189b2f0479bcfd80eb58fe5..5cbc446555d43aa08254edebec7f5a79168b3be1 100644
|
| --- a/remoting/host/security_key/remote_security_key_ipc_server_unittest.cc
|
| +++ b/remoting/host/security_key/security_key_ipc_server_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_server.h"
|
| +#include "remoting/host/security_key/security_key_ipc_server.h"
|
|
|
| #include <memory>
|
| #include <string>
|
| @@ -14,8 +14,8 @@
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/run_loop.h"
|
| #include "ipc/ipc_channel.h"
|
| -#include "remoting/host/security_key/fake_remote_security_key_ipc_client.h"
|
| -#include "remoting/host/security_key/remote_security_key_ipc_constants.h"
|
| +#include "remoting/host/security_key/fake_security_key_ipc_client.h"
|
| +#include "remoting/host/security_key/security_key_ipc_constants.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace {
|
| @@ -27,10 +27,10 @@ const int kLargeMessageSizeBytes = 256 * 1024;
|
|
|
| namespace remoting {
|
|
|
| -class RemoteSecurityKeyIpcServerTest : public testing::Test {
|
| +class SecurityKeyIpcServerTest : public testing::Test {
|
| public:
|
| - RemoteSecurityKeyIpcServerTest();
|
| - ~RemoteSecurityKeyIpcServerTest() override;
|
| + SecurityKeyIpcServerTest();
|
| + ~SecurityKeyIpcServerTest() 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.
|
| @@ -55,7 +55,7 @@ class RemoteSecurityKeyIpcServerTest : public testing::Test {
|
| std::unique_ptr<base::RunLoop> run_loop_;
|
|
|
| // The object under test.
|
| - std::unique_ptr<RemoteSecurityKeyIpcServer> remote_security_key_ipc_server_;
|
| + std::unique_ptr<SecurityKeyIpcServer> security_key_ipc_server_;
|
|
|
| // Used to validate the object under test uses the correct ID when
|
| // communicating over the IPC channel.
|
| @@ -65,10 +65,10 @@ class RemoteSecurityKeyIpcServerTest : public testing::Test {
|
| std::string last_message_received_;
|
|
|
| private:
|
| - DISALLOW_COPY_AND_ASSIGN(RemoteSecurityKeyIpcServerTest);
|
| + DISALLOW_COPY_AND_ASSIGN(SecurityKeyIpcServerTest);
|
| };
|
|
|
| -RemoteSecurityKeyIpcServerTest::RemoteSecurityKeyIpcServerTest()
|
| +SecurityKeyIpcServerTest::SecurityKeyIpcServerTest()
|
| : run_loop_(new base::RunLoop()) {
|
| uint32_t peer_session_id = UINT32_MAX;
|
| #if defined(OS_WIN)
|
| @@ -76,50 +76,47 @@ RemoteSecurityKeyIpcServerTest::RemoteSecurityKeyIpcServerTest()
|
| reinterpret_cast<DWORD*>(&peer_session_id)));
|
| #endif // defined(OS_WIN)
|
|
|
| - remote_security_key_ipc_server_ =
|
| - remoting::RemoteSecurityKeyIpcServer::Create(
|
| - kTestConnectionId, peer_session_id,
|
| - base::TimeDelta::FromMilliseconds(kInitialConnectTimeoutMs),
|
| - base::Bind(&RemoteSecurityKeyIpcServerTest::SendRequestToClient,
|
| - base::Unretained(this)),
|
| - base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete,
|
| - base::Unretained(this)));
|
| + security_key_ipc_server_ = remoting::SecurityKeyIpcServer::Create(
|
| + kTestConnectionId, peer_session_id,
|
| + base::TimeDelta::FromMilliseconds(kInitialConnectTimeoutMs),
|
| + base::Bind(&SecurityKeyIpcServerTest::SendRequestToClient,
|
| + base::Unretained(this)),
|
| + base::Bind(&SecurityKeyIpcServerTest::OperationComplete,
|
| + base::Unretained(this)));
|
| }
|
|
|
| -RemoteSecurityKeyIpcServerTest::~RemoteSecurityKeyIpcServerTest() {}
|
| +SecurityKeyIpcServerTest::~SecurityKeyIpcServerTest() {}
|
|
|
| -void RemoteSecurityKeyIpcServerTest::OperationComplete() {
|
| +void SecurityKeyIpcServerTest::OperationComplete() {
|
| run_loop_->Quit();
|
| }
|
|
|
| -void RemoteSecurityKeyIpcServerTest::WaitForOperationComplete() {
|
| +void SecurityKeyIpcServerTest::WaitForOperationComplete() {
|
| run_loop_->Run();
|
| run_loop_.reset(new base::RunLoop());
|
| }
|
|
|
| -void RemoteSecurityKeyIpcServerTest::SendRequestToClient(
|
| - int connection_id,
|
| - const std::string& data) {
|
| +void SecurityKeyIpcServerTest::SendRequestToClient(int connection_id,
|
| + const std::string& data) {
|
| last_connection_id_received_ = connection_id;
|
| last_message_received_ = data;
|
| OperationComplete();
|
| }
|
|
|
| -std::string RemoteSecurityKeyIpcServerTest::GetUniqueTestChannelName() {
|
| +std::string SecurityKeyIpcServerTest::GetUniqueTestChannelName() {
|
| return GetChannelNamePathPrefixForTest() + "Super_Awesome_Test_Channel." +
|
| IPC::Channel::GenerateUniqueRandomChannelID();
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcServerTest, HandleSingleGnubbyRequest) {
|
| +TEST_F(SecurityKeyIpcServerTest, HandleSingleSecurityKeyRequest) {
|
| std::string channel_name(GetUniqueTestChannelName());
|
| - ASSERT_TRUE(remote_security_key_ipc_server_->CreateChannel(
|
| + ASSERT_TRUE(security_key_ipc_server_->CreateChannel(
|
| channel_name,
|
| /*request_timeout=*/base::TimeDelta::FromMilliseconds(500)));
|
|
|
| // Create a fake client and connect to the IPC server channel.
|
| - FakeRemoteSecurityKeyIpcClient fake_ipc_client(
|
| - base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete,
|
| - base::Unretained(this)));
|
| + FakeSecurityKeyIpcClient fake_ipc_client(base::Bind(
|
| + &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this)));
|
| ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name));
|
| WaitForOperationComplete();
|
|
|
| @@ -136,7 +133,7 @@ TEST_F(RemoteSecurityKeyIpcServerTest, HandleSingleGnubbyRequest) {
|
|
|
| // Send a response from the IPC server to the IPC client.
|
| std::string response_data("Blargh!");
|
| - ASSERT_TRUE(remote_security_key_ipc_server_->SendResponse(response_data));
|
| + ASSERT_TRUE(security_key_ipc_server_->SendResponse(response_data));
|
| WaitForOperationComplete();
|
|
|
| // Verify the request was received.
|
| @@ -146,16 +143,15 @@ TEST_F(RemoteSecurityKeyIpcServerTest, HandleSingleGnubbyRequest) {
|
| fake_ipc_client.CloseIpcConnection();
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcServerTest, HandleLargeGnubbyRequest) {
|
| +TEST_F(SecurityKeyIpcServerTest, HandleLargeSecurityKeyRequest) {
|
| std::string channel_name(GetUniqueTestChannelName());
|
| - ASSERT_TRUE(remote_security_key_ipc_server_->CreateChannel(
|
| + ASSERT_TRUE(security_key_ipc_server_->CreateChannel(
|
| channel_name,
|
| /*request_timeout=*/base::TimeDelta::FromMilliseconds(500)));
|
|
|
| // Create a fake client and connect to the IPC server channel.
|
| - FakeRemoteSecurityKeyIpcClient fake_ipc_client(
|
| - base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete,
|
| - base::Unretained(this)));
|
| + FakeSecurityKeyIpcClient fake_ipc_client(base::Bind(
|
| + &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this)));
|
| ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name));
|
| WaitForOperationComplete();
|
|
|
| @@ -172,7 +168,7 @@ TEST_F(RemoteSecurityKeyIpcServerTest, HandleLargeGnubbyRequest) {
|
|
|
| // Send a response from the IPC server to the IPC client.
|
| std::string response_data(kLargeMessageSizeBytes, 'Z');
|
| - ASSERT_TRUE(remote_security_key_ipc_server_->SendResponse(response_data));
|
| + ASSERT_TRUE(security_key_ipc_server_->SendResponse(response_data));
|
| WaitForOperationComplete();
|
|
|
| // Verify the request was received.
|
| @@ -182,16 +178,15 @@ TEST_F(RemoteSecurityKeyIpcServerTest, HandleLargeGnubbyRequest) {
|
| fake_ipc_client.CloseIpcConnection();
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcServerTest, HandleReallyLargeGnubbyRequest) {
|
| +TEST_F(SecurityKeyIpcServerTest, HandleReallyLargeSecurityKeyRequest) {
|
| std::string channel_name(GetUniqueTestChannelName());
|
| - ASSERT_TRUE(remote_security_key_ipc_server_->CreateChannel(
|
| + ASSERT_TRUE(security_key_ipc_server_->CreateChannel(
|
| channel_name,
|
| /*request_timeout=*/base::TimeDelta::FromMilliseconds(500)));
|
|
|
| // Create a fake client and connect to the IPC server channel.
|
| - FakeRemoteSecurityKeyIpcClient fake_ipc_client(
|
| - base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete,
|
| - base::Unretained(this)));
|
| + FakeSecurityKeyIpcClient fake_ipc_client(base::Bind(
|
| + &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this)));
|
| ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name));
|
| WaitForOperationComplete();
|
|
|
| @@ -208,7 +203,7 @@ TEST_F(RemoteSecurityKeyIpcServerTest, HandleReallyLargeGnubbyRequest) {
|
|
|
| // Send a response from the IPC server to the IPC client.
|
| std::string response_data(kLargeMessageSizeBytes * 2, 'Z');
|
| - ASSERT_TRUE(remote_security_key_ipc_server_->SendResponse(response_data));
|
| + ASSERT_TRUE(security_key_ipc_server_->SendResponse(response_data));
|
| WaitForOperationComplete();
|
|
|
| // Verify the request was received.
|
| @@ -218,16 +213,15 @@ TEST_F(RemoteSecurityKeyIpcServerTest, HandleReallyLargeGnubbyRequest) {
|
| fake_ipc_client.CloseIpcConnection();
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcServerTest, HandleMultipleGnubbyRequests) {
|
| +TEST_F(SecurityKeyIpcServerTest, HandleMultipleSecurityKeyRequests) {
|
| std::string channel_name(GetUniqueTestChannelName());
|
| - ASSERT_TRUE(remote_security_key_ipc_server_->CreateChannel(
|
| + ASSERT_TRUE(security_key_ipc_server_->CreateChannel(
|
| channel_name,
|
| /*request_timeout=*/base::TimeDelta::FromMilliseconds(500)));
|
|
|
| // Create a fake client and connect to the IPC server channel.
|
| - FakeRemoteSecurityKeyIpcClient fake_ipc_client(
|
| - base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete,
|
| - base::Unretained(this)));
|
| + FakeSecurityKeyIpcClient fake_ipc_client(base::Bind(
|
| + &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this)));
|
| ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name));
|
| WaitForOperationComplete();
|
|
|
| @@ -244,7 +238,7 @@ TEST_F(RemoteSecurityKeyIpcServerTest, HandleMultipleGnubbyRequests) {
|
|
|
| // Send a response from the IPC server to the IPC client.
|
| std::string response_data_1("Blargh!");
|
| - ASSERT_TRUE(remote_security_key_ipc_server_->SendResponse(response_data_1));
|
| + ASSERT_TRUE(security_key_ipc_server_->SendResponse(response_data_1));
|
| WaitForOperationComplete();
|
|
|
| // Verify the response was received.
|
| @@ -261,7 +255,7 @@ TEST_F(RemoteSecurityKeyIpcServerTest, HandleMultipleGnubbyRequests) {
|
|
|
| // Send a response from the IPC server to the IPC client.
|
| std::string response_data_2("Meh!");
|
| - ASSERT_TRUE(remote_security_key_ipc_server_->SendResponse(response_data_2));
|
| + ASSERT_TRUE(security_key_ipc_server_->SendResponse(response_data_2));
|
| WaitForOperationComplete();
|
|
|
| // Verify the response was received.
|
| @@ -271,12 +265,12 @@ TEST_F(RemoteSecurityKeyIpcServerTest, HandleMultipleGnubbyRequests) {
|
| fake_ipc_client.CloseIpcConnection();
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcServerTest, InitialIpcConnectionTimeout) {
|
| +TEST_F(SecurityKeyIpcServerTest, InitialIpcConnectionTimeout) {
|
| // Create a channel, then wait for the done callback to be called indicating
|
| // the connection was closed. This test simulates the IPC Server being
|
| // created but the client failing to connect to it.
|
| std::string channel_name(GetUniqueTestChannelName());
|
| - ASSERT_TRUE(remote_security_key_ipc_server_->CreateChannel(
|
| + ASSERT_TRUE(security_key_ipc_server_->CreateChannel(
|
| channel_name,
|
| /*request_timeout=*/base::TimeDelta::FromMilliseconds(500)));
|
| base::Time start_time(base::Time::NowFromSystemTime());
|
| @@ -287,19 +281,18 @@ TEST_F(RemoteSecurityKeyIpcServerTest, InitialIpcConnectionTimeout) {
|
| kConnectionTimeoutErrorDeltaMs);
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcServerTest, NoGnubbyRequestTimeout) {
|
| +TEST_F(SecurityKeyIpcServerTest, NoSecurityKeyRequestTimeout) {
|
| // Create a channel and connect to it via IPC but do not send a request.
|
| // The channel should be closed and cleaned up if the IPC client does not
|
| // issue a request within the specified timeout period.
|
| std::string channel_name(GetUniqueTestChannelName());
|
| - ASSERT_TRUE(remote_security_key_ipc_server_->CreateChannel(
|
| + ASSERT_TRUE(security_key_ipc_server_->CreateChannel(
|
| channel_name,
|
| /*request_timeout=*/base::TimeDelta::FromMilliseconds(500)));
|
|
|
| // Create a fake client and connect to the IPC server channel.
|
| - FakeRemoteSecurityKeyIpcClient fake_ipc_client(
|
| - base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete,
|
| - base::Unretained(this)));
|
| + FakeSecurityKeyIpcClient fake_ipc_client(base::Bind(
|
| + &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this)));
|
| ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name));
|
| WaitForOperationComplete();
|
|
|
| @@ -314,18 +307,17 @@ TEST_F(RemoteSecurityKeyIpcServerTest, NoGnubbyRequestTimeout) {
|
| kConnectionTimeoutErrorDeltaMs);
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcServerTest, GnubbyResponseTimeout) {
|
| +TEST_F(SecurityKeyIpcServerTest, SecurityKeyResponseTimeout) {
|
| // Create a channel, connect to it via IPC, and issue a request, but do
|
| // not send a response. This simulates a client-side timeout.
|
| base::TimeDelta request_timeout(base::TimeDelta::FromMilliseconds(50));
|
| std::string channel_name(GetUniqueTestChannelName());
|
| - ASSERT_TRUE(remote_security_key_ipc_server_->CreateChannel(channel_name,
|
| - request_timeout));
|
| + ASSERT_TRUE(
|
| + security_key_ipc_server_->CreateChannel(channel_name, request_timeout));
|
|
|
| // Create a fake client and connect to the IPC server channel.
|
| - FakeRemoteSecurityKeyIpcClient fake_ipc_client(
|
| - base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete,
|
| - base::Unretained(this)));
|
| + FakeSecurityKeyIpcClient fake_ipc_client(base::Bind(
|
| + &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this)));
|
| ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name));
|
| WaitForOperationComplete();
|
|
|
| @@ -346,19 +338,18 @@ TEST_F(RemoteSecurityKeyIpcServerTest, GnubbyResponseTimeout) {
|
| kConnectionTimeoutErrorDeltaMs);
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyIpcServerTest, SendResponseTimeout) {
|
| +TEST_F(SecurityKeyIpcServerTest, SendResponseTimeout) {
|
| // Create a channel, connect to it via IPC, issue a request, and send
|
| // a response, but do not close the channel after that. The connection
|
| // should be terminated after the initial timeout period has elapsed.
|
| base::TimeDelta request_timeout(base::TimeDelta::FromMilliseconds(500));
|
| std::string channel_name(GetUniqueTestChannelName());
|
| - ASSERT_TRUE(remote_security_key_ipc_server_->CreateChannel(
|
| - channel_name, request_timeout));
|
| + ASSERT_TRUE(
|
| + security_key_ipc_server_->CreateChannel(channel_name, request_timeout));
|
|
|
| // Create a fake client and connect to the IPC server channel.
|
| - FakeRemoteSecurityKeyIpcClient fake_ipc_client(
|
| - base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete,
|
| - base::Unretained(this)));
|
| + FakeSecurityKeyIpcClient fake_ipc_client(base::Bind(
|
| + &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this)));
|
| ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name));
|
| WaitForOperationComplete();
|
|
|
| @@ -371,7 +362,7 @@ TEST_F(RemoteSecurityKeyIpcServerTest, SendResponseTimeout) {
|
|
|
| // Send a response from the IPC server to the IPC client.
|
| std::string response_data("OK, the secret code is 1-2-3-4-5");
|
| - ASSERT_TRUE(remote_security_key_ipc_server_->SendResponse(response_data));
|
| + ASSERT_TRUE(security_key_ipc_server_->SendResponse(response_data));
|
| WaitForOperationComplete();
|
|
|
| // Now wait for the timeout period for the connection to be torn down.
|
| @@ -384,30 +375,28 @@ TEST_F(RemoteSecurityKeyIpcServerTest, SendResponseTimeout) {
|
| }
|
|
|
| #if defined(OS_WIN)
|
| -TEST_F(RemoteSecurityKeyIpcServerTest, IpcConnectionFailsFromInvalidSession) {
|
| +TEST_F(SecurityKeyIpcServerTest, IpcConnectionFailsFromInvalidSession) {
|
| uint32_t peer_session_id = UINT32_MAX;
|
| ASSERT_TRUE(ProcessIdToSessionId(GetCurrentProcessId(),
|
| reinterpret_cast<DWORD*>(&peer_session_id)));
|
| peer_session_id++;
|
|
|
| // Reinitialize the object under test.
|
| - remote_security_key_ipc_server_ =
|
| - remoting::RemoteSecurityKeyIpcServer::Create(
|
| - kTestConnectionId, peer_session_id,
|
| - base::TimeDelta::FromMilliseconds(kInitialConnectTimeoutMs),
|
| - base::Bind(&RemoteSecurityKeyIpcServerTest::SendRequestToClient,
|
| - base::Unretained(this)),
|
| - base::Bind(&base::DoNothing));
|
| + security_key_ipc_server_ = remoting::SecurityKeyIpcServer::Create(
|
| + kTestConnectionId, peer_session_id,
|
| + base::TimeDelta::FromMilliseconds(kInitialConnectTimeoutMs),
|
| + base::Bind(&SecurityKeyIpcServerTest::SendRequestToClient,
|
| + base::Unretained(this)),
|
| + base::Bind(&base::DoNothing));
|
|
|
| base::TimeDelta request_timeout(base::TimeDelta::FromMilliseconds(500));
|
| std::string channel_name(GetUniqueTestChannelName());
|
| - ASSERT_TRUE(remote_security_key_ipc_server_->CreateChannel(channel_name,
|
| - request_timeout));
|
| + ASSERT_TRUE(
|
| + security_key_ipc_server_->CreateChannel(channel_name, request_timeout));
|
|
|
| // Create a fake client and attempt to connect to the IPC server channel.
|
| - FakeRemoteSecurityKeyIpcClient fake_ipc_client(
|
| - base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete,
|
| - base::Unretained(this)));
|
| + FakeSecurityKeyIpcClient fake_ipc_client(base::Bind(
|
| + &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this)));
|
| ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name));
|
| WaitForOperationComplete();
|
| WaitForOperationComplete();
|
|
|