| 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/security_key_ipc_server.h" | 5 #include "remoting/host/security_key/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" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 ASSERT_TRUE(security_key_ipc_server_->CreateChannel( | 127 ASSERT_TRUE(security_key_ipc_server_->CreateChannel( |
| 128 channel_handle, | 128 channel_handle, |
| 129 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); | 129 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); |
| 130 | 130 |
| 131 // Create a fake client and connect to the IPC server channel. | 131 // Create a fake client and connect to the IPC server channel. |
| 132 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( | 132 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( |
| 133 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); | 133 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); |
| 134 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); | 134 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); |
| 135 WaitForOperationComplete(); | 135 WaitForOperationComplete(); |
| 136 | 136 |
| 137 ASSERT_FALSE(fake_ipc_client.invalid_session_error()); |
| 138 ASSERT_TRUE(fake_ipc_client.connection_ready()); |
| 137 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); | 139 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); |
| 138 | 140 |
| 139 // Send a request from the IPC client to the IPC server. | 141 // Send a request from the IPC client to the IPC server. |
| 140 std::string request_data("Blergh!"); | 142 std::string request_data("Blergh!"); |
| 141 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); | 143 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); |
| 142 WaitForOperationComplete(); | 144 WaitForOperationComplete(); |
| 143 | 145 |
| 144 // Verify the request was received. | 146 // Verify the request was received. |
| 145 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); | 147 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); |
| 146 ASSERT_EQ(request_data, last_message_received_); | 148 ASSERT_EQ(request_data, last_message_received_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 162 ASSERT_TRUE(security_key_ipc_server_->CreateChannel( | 164 ASSERT_TRUE(security_key_ipc_server_->CreateChannel( |
| 163 channel_handle, | 165 channel_handle, |
| 164 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); | 166 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); |
| 165 | 167 |
| 166 // Create a fake client and connect to the IPC server channel. | 168 // Create a fake client and connect to the IPC server channel. |
| 167 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( | 169 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( |
| 168 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); | 170 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); |
| 169 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); | 171 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); |
| 170 WaitForOperationComplete(); | 172 WaitForOperationComplete(); |
| 171 | 173 |
| 174 ASSERT_FALSE(fake_ipc_client.invalid_session_error()); |
| 175 ASSERT_TRUE(fake_ipc_client.connection_ready()); |
| 172 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); | 176 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); |
| 173 | 177 |
| 174 // Send a request from the IPC client to the IPC server. | 178 // Send a request from the IPC client to the IPC server. |
| 175 std::string request_data(kLargeMessageSizeBytes, 'Y'); | 179 std::string request_data(kLargeMessageSizeBytes, 'Y'); |
| 176 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); | 180 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); |
| 177 WaitForOperationComplete(); | 181 WaitForOperationComplete(); |
| 178 | 182 |
| 179 // Verify the request was received. | 183 // Verify the request was received. |
| 180 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); | 184 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); |
| 181 ASSERT_EQ(request_data, last_message_received_); | 185 ASSERT_EQ(request_data, last_message_received_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 197 ASSERT_TRUE(security_key_ipc_server_->CreateChannel( | 201 ASSERT_TRUE(security_key_ipc_server_->CreateChannel( |
| 198 channel_handle, | 202 channel_handle, |
| 199 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); | 203 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); |
| 200 | 204 |
| 201 // Create a fake client and connect to the IPC server channel. | 205 // Create a fake client and connect to the IPC server channel. |
| 202 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( | 206 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( |
| 203 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); | 207 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); |
| 204 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); | 208 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); |
| 205 WaitForOperationComplete(); | 209 WaitForOperationComplete(); |
| 206 | 210 |
| 211 ASSERT_FALSE(fake_ipc_client.invalid_session_error()); |
| 212 ASSERT_TRUE(fake_ipc_client.connection_ready()); |
| 207 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); | 213 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); |
| 208 | 214 |
| 209 // Send a request from the IPC client to the IPC server. | 215 // Send a request from the IPC client to the IPC server. |
| 210 std::string request_data(kLargeMessageSizeBytes * 2, 'Y'); | 216 std::string request_data(kLargeMessageSizeBytes * 2, 'Y'); |
| 211 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); | 217 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); |
| 212 WaitForOperationComplete(); | 218 WaitForOperationComplete(); |
| 213 | 219 |
| 214 // Verify the request was received. | 220 // Verify the request was received. |
| 215 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); | 221 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); |
| 216 ASSERT_EQ(request_data, last_message_received_); | 222 ASSERT_EQ(request_data, last_message_received_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 232 ASSERT_TRUE(security_key_ipc_server_->CreateChannel( | 238 ASSERT_TRUE(security_key_ipc_server_->CreateChannel( |
| 233 channel_handle, | 239 channel_handle, |
| 234 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); | 240 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); |
| 235 | 241 |
| 236 // Create a fake client and connect to the IPC server channel. | 242 // Create a fake client and connect to the IPC server channel. |
| 237 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( | 243 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( |
| 238 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); | 244 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); |
| 239 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); | 245 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); |
| 240 WaitForOperationComplete(); | 246 WaitForOperationComplete(); |
| 241 | 247 |
| 248 ASSERT_FALSE(fake_ipc_client.invalid_session_error()); |
| 249 ASSERT_TRUE(fake_ipc_client.connection_ready()); |
| 242 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); | 250 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); |
| 243 | 251 |
| 244 // Send a request from the IPC client to the IPC server. | 252 // Send a request from the IPC client to the IPC server. |
| 245 std::string request_data_1("Blergh!"); | 253 std::string request_data_1("Blergh!"); |
| 246 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data_1); | 254 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data_1); |
| 247 WaitForOperationComplete(); | 255 WaitForOperationComplete(); |
| 248 | 256 |
| 249 // Verify the request was received. | 257 // Verify the request was received. |
| 250 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); | 258 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); |
| 251 ASSERT_EQ(request_data_1, last_message_received_); | 259 ASSERT_EQ(request_data_1, last_message_received_); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 ASSERT_TRUE(security_key_ipc_server_->CreateChannel( | 334 ASSERT_TRUE(security_key_ipc_server_->CreateChannel( |
| 327 channel_handle, | 335 channel_handle, |
| 328 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); | 336 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); |
| 329 | 337 |
| 330 // Create a fake client and connect to the IPC server channel. | 338 // Create a fake client and connect to the IPC server channel. |
| 331 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( | 339 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( |
| 332 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); | 340 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); |
| 333 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); | 341 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); |
| 334 WaitForOperationComplete(); | 342 WaitForOperationComplete(); |
| 335 | 343 |
| 344 ASSERT_FALSE(fake_ipc_client.invalid_session_error()); |
| 345 ASSERT_TRUE(fake_ipc_client.connection_ready()); |
| 336 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); | 346 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); |
| 337 | 347 |
| 338 // Now that a connection has been established, we wait for the timeout. | 348 // Now that a connection has been established, we wait for the timeout. |
| 339 base::Time start_time(base::Time::NowFromSystemTime()); | 349 base::Time start_time(base::Time::NowFromSystemTime()); |
| 340 WaitForOperationComplete(); | 350 WaitForOperationComplete(); |
| 341 base::TimeDelta elapsed_time = base::Time::NowFromSystemTime() - start_time; | 351 base::TimeDelta elapsed_time = base::Time::NowFromSystemTime() - start_time; |
| 342 | 352 |
| 343 ASSERT_NEAR(elapsed_time.InMilliseconds(), kInitialConnectTimeoutMs, | 353 ASSERT_NEAR(elapsed_time.InMilliseconds(), kInitialConnectTimeoutMs, |
| 344 kConnectionTimeoutErrorDeltaMs); | 354 kConnectionTimeoutErrorDeltaMs); |
| 345 } | 355 } |
| 346 | 356 |
| 347 TEST_F(SecurityKeyIpcServerTest, SecurityKeyResponseTimeout) { | 357 TEST_F(SecurityKeyIpcServerTest, SecurityKeyResponseTimeout) { |
| 348 // Create a channel, connect to it via IPC, and issue a request, but do | 358 // Create a channel, connect to it via IPC, and issue a request, but do |
| 349 // not send a response. This simulates a client-side timeout. | 359 // not send a response. This simulates a client-side timeout. |
| 350 base::TimeDelta request_timeout(base::TimeDelta::FromMilliseconds(50)); | 360 base::TimeDelta request_timeout(base::TimeDelta::FromMilliseconds(50)); |
| 351 mojo::edk::NamedPlatformHandle channel_handle(GetUniqueTestChannelName()); | 361 mojo::edk::NamedPlatformHandle channel_handle(GetUniqueTestChannelName()); |
| 352 ASSERT_TRUE( | 362 ASSERT_TRUE( |
| 353 security_key_ipc_server_->CreateChannel(channel_handle, request_timeout)); | 363 security_key_ipc_server_->CreateChannel(channel_handle, request_timeout)); |
| 354 | 364 |
| 355 // Create a fake client and connect to the IPC server channel. | 365 // Create a fake client and connect to the IPC server channel. |
| 356 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( | 366 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( |
| 357 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); | 367 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); |
| 358 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); | 368 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); |
| 359 WaitForOperationComplete(); | 369 WaitForOperationComplete(); |
| 360 | 370 |
| 371 ASSERT_FALSE(fake_ipc_client.invalid_session_error()); |
| 372 ASSERT_TRUE(fake_ipc_client.connection_ready()); |
| 361 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); | 373 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); |
| 362 | 374 |
| 363 // Now that a connection has been established, we issue a request and | 375 // Now that a connection has been established, we issue a request and |
| 364 // then wait for the timeout. | 376 // then wait for the timeout. |
| 365 std::string request_data("I can haz Auth?"); | 377 std::string request_data("I can haz Auth?"); |
| 366 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); | 378 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); |
| 367 WaitForOperationComplete(); | 379 WaitForOperationComplete(); |
| 368 | 380 |
| 369 // Leave the request hanging until it times out... | 381 // Leave the request hanging until it times out... |
| 370 base::Time start_time(base::Time::NowFromSystemTime()); | 382 base::Time start_time(base::Time::NowFromSystemTime()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 383 mojo::edk::NamedPlatformHandle channel_handle(GetUniqueTestChannelName()); | 395 mojo::edk::NamedPlatformHandle channel_handle(GetUniqueTestChannelName()); |
| 384 ASSERT_TRUE( | 396 ASSERT_TRUE( |
| 385 security_key_ipc_server_->CreateChannel(channel_handle, request_timeout)); | 397 security_key_ipc_server_->CreateChannel(channel_handle, request_timeout)); |
| 386 | 398 |
| 387 // Create a fake client and connect to the IPC server channel. | 399 // Create a fake client and connect to the IPC server channel. |
| 388 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( | 400 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( |
| 389 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); | 401 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); |
| 390 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); | 402 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); |
| 391 WaitForOperationComplete(); | 403 WaitForOperationComplete(); |
| 392 | 404 |
| 405 ASSERT_FALSE(fake_ipc_client.invalid_session_error()); |
| 406 ASSERT_TRUE(fake_ipc_client.connection_ready()); |
| 393 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); | 407 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); |
| 394 | 408 |
| 395 // Issue a request. | 409 // Issue a request. |
| 396 std::string request_data("Auth me yo!"); | 410 std::string request_data("Auth me yo!"); |
| 397 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); | 411 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); |
| 398 WaitForOperationComplete(); | 412 WaitForOperationComplete(); |
| 399 | 413 |
| 400 // Send a response from the IPC server to the IPC client. | 414 // Send a response from the IPC server to the IPC client. |
| 401 std::string response_data("OK, the secret code is 1-2-3-4-5"); | 415 std::string response_data("OK, the secret code is 1-2-3-4-5"); |
| 402 ASSERT_TRUE(security_key_ipc_server_->SendResponse(response_data)); | 416 ASSERT_TRUE(security_key_ipc_server_->SendResponse(response_data)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 431 } | 445 } |
| 432 // The mojo system posts tasks as part of its cleanup, so run them all. | 446 // The mojo system posts tasks as part of its cleanup, so run them all. |
| 433 base::RunLoop().RunUntilIdle(); | 447 base::RunLoop().RunUntilIdle(); |
| 434 | 448 |
| 435 // Create a fake client and connect to the IPC server channel. | 449 // Create a fake client and connect to the IPC server channel. |
| 436 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( | 450 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( |
| 437 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); | 451 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); |
| 438 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); | 452 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); |
| 439 WaitForOperationComplete(); | 453 WaitForOperationComplete(); |
| 440 | 454 |
| 455 ASSERT_FALSE(fake_ipc_client.invalid_session_error()); |
| 456 ASSERT_TRUE(fake_ipc_client.connection_ready()); |
| 441 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); | 457 ASSERT_TRUE(fake_ipc_client.ipc_channel_connected()); |
| 442 | 458 |
| 443 // Send a request from the IPC client to the IPC server. | 459 // Send a request from the IPC client to the IPC server. |
| 444 std::string request_data("Blergh!"); | 460 std::string request_data("Blergh!"); |
| 445 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); | 461 fake_ipc_client.SendSecurityKeyRequestViaIpc(request_data); |
| 446 WaitForOperationComplete(); | 462 WaitForOperationComplete(); |
| 447 | 463 |
| 448 // Verify the request was received. | 464 // Verify the request was received. |
| 449 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); | 465 ASSERT_EQ(kTestConnectionId, last_connection_id_received_); |
| 450 ASSERT_EQ(request_data, last_message_received_); | 466 ASSERT_EQ(request_data, last_message_received_); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 473 | 489 |
| 474 // Create a fake client and attempt to connect to the IPC server channel. | 490 // Create a fake client and attempt to connect to the IPC server channel. |
| 475 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( | 491 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( |
| 476 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); | 492 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); |
| 477 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); | 493 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_handle)); |
| 478 WaitForOperationComplete(); | 494 WaitForOperationComplete(); |
| 479 WaitForOperationComplete(); | 495 WaitForOperationComplete(); |
| 480 WaitForOperationComplete(); | 496 WaitForOperationComplete(); |
| 481 | 497 |
| 482 // Verify the connection failed. | 498 // Verify the connection failed. |
| 499 ASSERT_TRUE(fake_ipc_client.invalid_session_error()); |
| 500 ASSERT_FALSE(fake_ipc_client.connection_ready()); |
| 483 ASSERT_FALSE(fake_ipc_client.ipc_channel_connected()); | 501 ASSERT_FALSE(fake_ipc_client.ipc_channel_connected()); |
| 484 } | 502 } |
| 485 #endif // defined(OS_WIN) | 503 #endif // defined(OS_WIN) |
| 486 | 504 |
| 487 } // namespace remoting | 505 } // namespace remoting |
| OLD | NEW |