| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/security_key/remote_security_key_ipc_server.h" | 5 #include "remoting/host/security_key/remote_security_key_ipc_server.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 15 #include "ipc/ipc_channel.h" | 16 #include "ipc/ipc_channel.h" |
| 16 #include "remoting/host/security_key/fake_remote_security_key_ipc_client.h" | 17 #include "remoting/host/security_key/fake_remote_security_key_ipc_client.h" |
| 17 #include "remoting/host/security_key/remote_security_key_ipc_constants.h" | 18 #include "remoting/host/security_key/remote_security_key_ipc_constants.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 const int kTestConnectionId = 42; | 22 const int kTestConnectionId = 42; |
| 22 const int kInitialConnectTimeoutMs = 250; | 23 const int kInitialConnectTimeoutMs = 250; |
| 23 const int kConnectionTimeoutErrorDeltaMs = 100; | 24 const int kConnectionTimeoutErrorDeltaMs = 100; |
| 24 const int kLargeMessageSizeBytes = 256 * 1024; | 25 const int kLargeMessageSizeBytes = 256 * 1024; |
| 25 } // namespace | 26 } // namespace |
| 26 | 27 |
| 27 namespace remoting { | 28 namespace remoting { |
| 28 | 29 |
| 29 class RemoteSecurityKeyIpcServerTest : public testing::Test { | 30 class RemoteSecurityKeyIpcServerTest : public testing::Test { |
| 30 public: | 31 public: |
| 31 RemoteSecurityKeyIpcServerTest(); | 32 RemoteSecurityKeyIpcServerTest(); |
| 32 ~RemoteSecurityKeyIpcServerTest() override; | 33 ~RemoteSecurityKeyIpcServerTest() override; |
| 33 | 34 |
| 34 // Passed to the object used for testing to be called back to signal | 35 // Passed to the object used for testing to be called back to signal |
| 35 // completion of an IPC channel state change or reception of an IPC message. | 36 // completion of an IPC channel state change or reception of an IPC message. |
| 36 void OperationComplete(); | 37 void OperationComplete(); |
| 37 | 38 |
| 39 // Used as a callback to signal receipt of a security key request message. |
| 40 void SendRequestToClient(int connection_id, const std::string& data); |
| 41 |
| 38 protected: | 42 protected: |
| 39 // Returns a unique IPC channel name which prevents conflicts when running | 43 // Returns a unique IPC channel name which prevents conflicts when running |
| 40 // tests concurrently. | 44 // tests concurrently. |
| 41 std::string GetUniqueTestChannelName(); | 45 std::string GetUniqueTestChannelName(); |
| 42 | 46 |
| 43 // Waits until the current |run_loop_| instance is signaled, then resets it. | 47 // Waits until the current |run_loop_| instance is signaled, then resets it. |
| 44 void WaitForOperationComplete(); | 48 void WaitForOperationComplete(); |
| 45 | 49 |
| 46 // Used as a callback to signal receipt of a security key request message. | |
| 47 void SendRequestToClient(int connection_id, const std::string& data); | |
| 48 | |
| 49 // IPC tests require a valid MessageLoop to run. | 50 // IPC tests require a valid MessageLoop to run. |
| 50 base::MessageLoopForIO message_loop_; | 51 base::MessageLoopForIO message_loop_; |
| 51 | 52 |
| 52 // Used to allow |message_loop_| to run during tests. The instance is reset | 53 // Used to allow |message_loop_| to run during tests. The instance is reset |
| 53 // after each stage of the tests has been completed. | 54 // after each stage of the tests has been completed. |
| 54 std::unique_ptr<base::RunLoop> run_loop_; | 55 std::unique_ptr<base::RunLoop> run_loop_; |
| 55 | 56 |
| 56 // The object under test. | 57 // The object under test. |
| 57 std::unique_ptr<RemoteSecurityKeyIpcServer> remote_security_key_ipc_server_; | 58 std::unique_ptr<RemoteSecurityKeyIpcServer> remote_security_key_ipc_server_; |
| 58 | 59 |
| 59 // Used to validate the object under test uses the correct ID when | 60 // Used to validate the object under test uses the correct ID when |
| 60 // communicating over the IPC channel. | 61 // communicating over the IPC channel. |
| 61 int last_connection_id_received_ = -1; | 62 int last_connection_id_received_ = -1; |
| 62 | 63 |
| 63 // Stores the contents of the last IPC message received for validation. | 64 // Stores the contents of the last IPC message received for validation. |
| 64 std::string last_message_received_; | 65 std::string last_message_received_; |
| 65 | 66 |
| 66 private: | 67 private: |
| 67 DISALLOW_COPY_AND_ASSIGN(RemoteSecurityKeyIpcServerTest); | 68 DISALLOW_COPY_AND_ASSIGN(RemoteSecurityKeyIpcServerTest); |
| 68 }; | 69 }; |
| 69 | 70 |
| 70 RemoteSecurityKeyIpcServerTest::RemoteSecurityKeyIpcServerTest() | 71 RemoteSecurityKeyIpcServerTest::RemoteSecurityKeyIpcServerTest() |
| 71 : run_loop_(new base::RunLoop()) { | 72 : run_loop_(new base::RunLoop()) { |
| 73 uint32_t peer_session_id = UINT32_MAX; |
| 74 #if defined(OS_WIN) |
| 75 EXPECT_TRUE(ProcessIdToSessionId(GetCurrentProcessId(), |
| 76 reinterpret_cast<DWORD*>(&peer_session_id))); |
| 77 #endif // defined(OS_WIN) |
| 78 |
| 72 remote_security_key_ipc_server_ = | 79 remote_security_key_ipc_server_ = |
| 73 remoting::RemoteSecurityKeyIpcServer::Create( | 80 remoting::RemoteSecurityKeyIpcServer::Create( |
| 74 kTestConnectionId, | 81 kTestConnectionId, peer_session_id, |
| 75 base::TimeDelta::FromMilliseconds(kInitialConnectTimeoutMs), | 82 base::TimeDelta::FromMilliseconds(kInitialConnectTimeoutMs), |
| 76 base::Bind(&RemoteSecurityKeyIpcServerTest::SendRequestToClient, | 83 base::Bind(&RemoteSecurityKeyIpcServerTest::SendRequestToClient, |
| 77 base::Unretained(this)), | 84 base::Unretained(this)), |
| 78 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, | 85 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, |
| 79 base::Unretained(this))); | 86 base::Unretained(this))); |
| 80 } | 87 } |
| 81 | 88 |
| 82 RemoteSecurityKeyIpcServerTest::~RemoteSecurityKeyIpcServerTest() {} | 89 RemoteSecurityKeyIpcServerTest::~RemoteSecurityKeyIpcServerTest() {} |
| 83 | 90 |
| 84 void RemoteSecurityKeyIpcServerTest::OperationComplete() { | 91 void RemoteSecurityKeyIpcServerTest::OperationComplete() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 109 channel_name, | 116 channel_name, |
| 110 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); | 117 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); |
| 111 | 118 |
| 112 // Create a fake client and connect to the IPC server channel. | 119 // Create a fake client and connect to the IPC server channel. |
| 113 FakeRemoteSecurityKeyIpcClient fake_ipc_client( | 120 FakeRemoteSecurityKeyIpcClient fake_ipc_client( |
| 114 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, | 121 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, |
| 115 base::Unretained(this))); | 122 base::Unretained(this))); |
| 116 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); | 123 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); |
| 117 WaitForOperationComplete(); | 124 WaitForOperationComplete(); |
| 118 | 125 |
| 126 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); |
| 127 |
| 119 // Send a request from the IPC client to the IPC server. | 128 // Send a request from the IPC client to the IPC server. |
| 120 std::string request_data("Blergh!"); | 129 std::string request_data("Blergh!"); |
| 121 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); | 130 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); |
| 122 WaitForOperationComplete(); | 131 WaitForOperationComplete(); |
| 123 | 132 |
| 124 // Verify the request was received. | 133 // Verify the request was received. |
| 125 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); | 134 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); |
| 126 ASSERT_EQ(request_data, last_message_received_); | 135 ASSERT_EQ(request_data, last_message_received_); |
| 127 | 136 |
| 128 // Send a response from the IPC server to the IPC client. | 137 // Send a response from the IPC server to the IPC client. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 143 channel_name, | 152 channel_name, |
| 144 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); | 153 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); |
| 145 | 154 |
| 146 // Create a fake client and connect to the IPC server channel. | 155 // Create a fake client and connect to the IPC server channel. |
| 147 FakeRemoteSecurityKeyIpcClient fake_ipc_client( | 156 FakeRemoteSecurityKeyIpcClient fake_ipc_client( |
| 148 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, | 157 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, |
| 149 base::Unretained(this))); | 158 base::Unretained(this))); |
| 150 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); | 159 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); |
| 151 WaitForOperationComplete(); | 160 WaitForOperationComplete(); |
| 152 | 161 |
| 162 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); |
| 163 |
| 153 // Send a request from the IPC client to the IPC server. | 164 // Send a request from the IPC client to the IPC server. |
| 154 std::string request_data(kLargeMessageSizeBytes, 'Y'); | 165 std::string request_data(kLargeMessageSizeBytes, 'Y'); |
| 155 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); | 166 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); |
| 156 WaitForOperationComplete(); | 167 WaitForOperationComplete(); |
| 157 | 168 |
| 158 // Verify the request was received. | 169 // Verify the request was received. |
| 159 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); | 170 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); |
| 160 ASSERT_EQ(request_data, last_message_received_); | 171 ASSERT_EQ(request_data, last_message_received_); |
| 161 | 172 |
| 162 // Send a response from the IPC server to the IPC client. | 173 // Send a response from the IPC server to the IPC client. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 177 channel_name, | 188 channel_name, |
| 178 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); | 189 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); |
| 179 | 190 |
| 180 // Create a fake client and connect to the IPC server channel. | 191 // Create a fake client and connect to the IPC server channel. |
| 181 FakeRemoteSecurityKeyIpcClient fake_ipc_client( | 192 FakeRemoteSecurityKeyIpcClient fake_ipc_client( |
| 182 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, | 193 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, |
| 183 base::Unretained(this))); | 194 base::Unretained(this))); |
| 184 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); | 195 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); |
| 185 WaitForOperationComplete(); | 196 WaitForOperationComplete(); |
| 186 | 197 |
| 198 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); |
| 199 |
| 187 // Send a request from the IPC client to the IPC server. | 200 // Send a request from the IPC client to the IPC server. |
| 188 std::string request_data(kLargeMessageSizeBytes * 2, 'Y'); | 201 std::string request_data(kLargeMessageSizeBytes * 2, 'Y'); |
| 189 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); | 202 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); |
| 190 WaitForOperationComplete(); | 203 WaitForOperationComplete(); |
| 191 | 204 |
| 192 // Verify the request was received. | 205 // Verify the request was received. |
| 193 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); | 206 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); |
| 194 ASSERT_EQ(request_data, last_message_received_); | 207 ASSERT_EQ(request_data, last_message_received_); |
| 195 | 208 |
| 196 // Send a response from the IPC server to the IPC client. | 209 // Send a response from the IPC server to the IPC client. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 211 channel_name, | 224 channel_name, |
| 212 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); | 225 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); |
| 213 | 226 |
| 214 // Create a fake client and connect to the IPC server channel. | 227 // Create a fake client and connect to the IPC server channel. |
| 215 FakeRemoteSecurityKeyIpcClient fake_ipc_client( | 228 FakeRemoteSecurityKeyIpcClient fake_ipc_client( |
| 216 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, | 229 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, |
| 217 base::Unretained(this))); | 230 base::Unretained(this))); |
| 218 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); | 231 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); |
| 219 WaitForOperationComplete(); | 232 WaitForOperationComplete(); |
| 220 | 233 |
| 234 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); |
| 235 |
| 221 // Send a request from the IPC client to the IPC server. | 236 // Send a request from the IPC client to the IPC server. |
| 222 std::string request_data_1("Blergh!"); | 237 std::string request_data_1("Blergh!"); |
| 223 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data_1); | 238 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data_1); |
| 224 WaitForOperationComplete(); | 239 WaitForOperationComplete(); |
| 225 | 240 |
| 226 // Verify the request was received. | 241 // Verify the request was received. |
| 227 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); | 242 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); |
| 228 ASSERT_EQ(request_data_1, last_message_received_); | 243 ASSERT_EQ(request_data_1, last_message_received_); |
| 229 | 244 |
| 230 // Send a response from the IPC server to the IPC client. | 245 // Send a response from the IPC server to the IPC client. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 channel_name, | 296 channel_name, |
| 282 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); | 297 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); |
| 283 | 298 |
| 284 // Create a fake client and connect to the IPC server channel. | 299 // Create a fake client and connect to the IPC server channel. |
| 285 FakeRemoteSecurityKeyIpcClient fake_ipc_client( | 300 FakeRemoteSecurityKeyIpcClient fake_ipc_client( |
| 286 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, | 301 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, |
| 287 base::Unretained(this))); | 302 base::Unretained(this))); |
| 288 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); | 303 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); |
| 289 WaitForOperationComplete(); | 304 WaitForOperationComplete(); |
| 290 | 305 |
| 306 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); |
| 307 |
| 291 // Now that a connection has been established, we wait for the timeout. | 308 // Now that a connection has been established, we wait for the timeout. |
| 292 base::Time start_time(base::Time::NowFromSystemTime()); | 309 base::Time start_time(base::Time::NowFromSystemTime()); |
| 293 WaitForOperationComplete(); | 310 WaitForOperationComplete(); |
| 294 base::TimeDelta elapsed_time = base::Time::NowFromSystemTime() - start_time; | 311 base::TimeDelta elapsed_time = base::Time::NowFromSystemTime() - start_time; |
| 295 | 312 |
| 296 ASSERT_NEAR(elapsed_time.InMilliseconds(), kInitialConnectTimeoutMs, | 313 ASSERT_NEAR(elapsed_time.InMilliseconds(), kInitialConnectTimeoutMs, |
| 297 kConnectionTimeoutErrorDeltaMs); | 314 kConnectionTimeoutErrorDeltaMs); |
| 298 } | 315 } |
| 299 | 316 |
| 300 TEST_F(RemoteSecurityKeyIpcServerTest, GnubbyResponseTimeout) { | 317 TEST_F(RemoteSecurityKeyIpcServerTest, GnubbyResponseTimeout) { |
| 301 // Create a channel, connect to it via IPC, and issue a request, but do | 318 // Create a channel, connect to it via IPC, and issue a request, but do |
| 302 // not send a response. This simulates a client-side timeout. | 319 // not send a response. This simulates a client-side timeout. |
| 303 base::TimeDelta request_timeout(base::TimeDelta::FromMilliseconds(50)); | 320 base::TimeDelta request_timeout(base::TimeDelta::FromMilliseconds(50)); |
| 304 std::string channel_name(GetUniqueTestChannelName()); | 321 std::string channel_name(GetUniqueTestChannelName()); |
| 305 ASSERT_TRUE(remote_security_key_ipc_server_->CreateChannel(channel_name, | 322 ASSERT_TRUE(remote_security_key_ipc_server_->CreateChannel(channel_name, |
| 306 request_timeout)); | 323 request_timeout)); |
| 307 | 324 |
| 308 // Create a fake client and connect to the IPC server channel. | 325 // Create a fake client and connect to the IPC server channel. |
| 309 FakeRemoteSecurityKeyIpcClient fake_ipc_client( | 326 FakeRemoteSecurityKeyIpcClient fake_ipc_client( |
| 310 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, | 327 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, |
| 311 base::Unretained(this))); | 328 base::Unretained(this))); |
| 312 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); | 329 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); |
| 313 WaitForOperationComplete(); | 330 WaitForOperationComplete(); |
| 314 | 331 |
| 332 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); |
| 333 |
| 315 // Now that a connection has been established, we issue a request and | 334 // Now that a connection has been established, we issue a request and |
| 316 // then wait for the timeout. | 335 // then wait for the timeout. |
| 317 std::string request_data("I can haz Auth?"); | 336 std::string request_data("I can haz Auth?"); |
| 318 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); | 337 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); |
| 319 WaitForOperationComplete(); | 338 WaitForOperationComplete(); |
| 320 | 339 |
| 321 // Leave the request hanging until it times out... | 340 // Leave the request hanging until it times out... |
| 322 base::Time start_time(base::Time::NowFromSystemTime()); | 341 base::Time start_time(base::Time::NowFromSystemTime()); |
| 323 WaitForOperationComplete(); | 342 WaitForOperationComplete(); |
| 324 base::TimeDelta elapsed_time = base::Time::NowFromSystemTime() - start_time; | 343 base::TimeDelta elapsed_time = base::Time::NowFromSystemTime() - start_time; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 336 ASSERT_TRUE(remote_security_key_ipc_server_->CreateChannel( | 355 ASSERT_TRUE(remote_security_key_ipc_server_->CreateChannel( |
| 337 channel_name, request_timeout)); | 356 channel_name, request_timeout)); |
| 338 | 357 |
| 339 // Create a fake client and connect to the IPC server channel. | 358 // Create a fake client and connect to the IPC server channel. |
| 340 FakeRemoteSecurityKeyIpcClient fake_ipc_client( | 359 FakeRemoteSecurityKeyIpcClient fake_ipc_client( |
| 341 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, | 360 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, |
| 342 base::Unretained(this))); | 361 base::Unretained(this))); |
| 343 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); | 362 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); |
| 344 WaitForOperationComplete(); | 363 WaitForOperationComplete(); |
| 345 | 364 |
| 365 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); |
| 366 |
| 346 // Issue a request. | 367 // Issue a request. |
| 347 std::string request_data("Auth me yo!"); | 368 std::string request_data("Auth me yo!"); |
| 348 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); | 369 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); |
| 349 WaitForOperationComplete(); | 370 WaitForOperationComplete(); |
| 350 | 371 |
| 351 // Send a response from the IPC server to the IPC client. | 372 // Send a response from the IPC server to the IPC client. |
| 352 std::string response_data("OK, the secret code is 1-2-3-4-5"); | 373 std::string response_data("OK, the secret code is 1-2-3-4-5"); |
| 353 ASSERT_TRUE(remote_security_key_ipc_server_->SendResponse(response_data)); | 374 ASSERT_TRUE(remote_security_key_ipc_server_->SendResponse(response_data)); |
| 354 WaitForOperationComplete(); | 375 WaitForOperationComplete(); |
| 355 | 376 |
| 356 // Now wait for the timeout period for the connection to be torn down. | 377 // Now wait for the timeout period for the connection to be torn down. |
| 357 base::Time start_time(base::Time::NowFromSystemTime()); | 378 base::Time start_time(base::Time::NowFromSystemTime()); |
| 358 WaitForOperationComplete(); | 379 WaitForOperationComplete(); |
| 359 base::TimeDelta elapsed_time = base::Time::NowFromSystemTime() - start_time; | 380 base::TimeDelta elapsed_time = base::Time::NowFromSystemTime() - start_time; |
| 360 | 381 |
| 361 ASSERT_NEAR(elapsed_time.InMilliseconds(), request_timeout.InMilliseconds(), | 382 ASSERT_NEAR(elapsed_time.InMilliseconds(), request_timeout.InMilliseconds(), |
| 362 kConnectionTimeoutErrorDeltaMs); | 383 kConnectionTimeoutErrorDeltaMs); |
| 363 } | 384 } |
| 364 | 385 |
| 386 #if defined(OS_WIN) |
| 387 TEST_F(RemoteSecurityKeyIpcServerTest, IpcConnectionFailsFromInvalidSession) { |
| 388 uint32_t peer_session_id = UINT32_MAX; |
| 389 ASSERT_TRUE(ProcessIdToSessionId(GetCurrentProcessId(), |
| 390 reinterpret_cast<DWORD*>(&peer_session_id))); |
| 391 peer_session_id++; |
| 392 |
| 393 // Reinitialize the object under test. |
| 394 remote_security_key_ipc_server_ = |
| 395 remoting::RemoteSecurityKeyIpcServer::Create( |
| 396 kTestConnectionId, peer_session_id, |
| 397 base::TimeDelta::FromMilliseconds(kInitialConnectTimeoutMs), |
| 398 base::Bind(&RemoteSecurityKeyIpcServerTest::SendRequestToClient, |
| 399 base::Unretained(this)), |
| 400 base::Bind(&base::DoNothing)); |
| 401 |
| 402 base::TimeDelta request_timeout(base::TimeDelta::FromMilliseconds(500)); |
| 403 std::string channel_name(GetUniqueTestChannelName()); |
| 404 ASSERT_TRUE(remote_security_key_ipc_server_->CreateChannel(channel_name, |
| 405 request_timeout)); |
| 406 |
| 407 // Create a fake client and attempt to connect to the IPC server channel. |
| 408 FakeRemoteSecurityKeyIpcClient fake_ipc_client( |
| 409 base::Bind(&RemoteSecurityKeyIpcServerTest::OperationComplete, |
| 410 base::Unretained(this))); |
| 411 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); |
| 412 WaitForOperationComplete(); |
| 413 WaitForOperationComplete(); |
| 414 |
| 415 // Verify the connection failed. |
| 416 ASSERT_FALSE(fake_ipc_client.ipc_channel_connected()); |
| 417 } |
| 418 #endif // defined(OS_WIN) |
| 419 |
| 365 } // namespace remoting | 420 } // namespace remoting |
| OLD | NEW |