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

Side by Side Diff: remoting/host/security_key/security_key_ipc_server_unittest.cc

Issue 2468523003: Pass the desktop session ID to the remoting network process. (Closed)
Patch Set: rebase Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « remoting/host/security_key/security_key_ipc_server_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "ipc/ipc_channel.h" 16 #include "ipc/ipc_channel.h"
17 #include "remoting/host/client_session_details.h"
17 #include "remoting/host/security_key/fake_security_key_ipc_client.h" 18 #include "remoting/host/security_key/fake_security_key_ipc_client.h"
18 #include "remoting/host/security_key/security_key_ipc_constants.h" 19 #include "remoting/host/security_key/security_key_ipc_constants.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace { 22 namespace {
22 const int kTestConnectionId = 42; 23 const int kTestConnectionId = 42;
23 const int kInitialConnectTimeoutMs = 250; 24 const int kInitialConnectTimeoutMs = 250;
24 const int kConnectionTimeoutErrorDeltaMs = 100; 25 const int kConnectionTimeoutErrorDeltaMs = 100;
25 const int kLargeMessageSizeBytes = 256 * 1024; 26 const int kLargeMessageSizeBytes = 256 * 1024;
26 } // namespace 27 } // namespace
27 28
28 namespace remoting { 29 namespace remoting {
29 30
30 class SecurityKeyIpcServerTest : public testing::Test { 31 class SecurityKeyIpcServerTest : public testing::Test,
32 public ClientSessionDetails {
31 public: 33 public:
32 SecurityKeyIpcServerTest(); 34 SecurityKeyIpcServerTest();
33 ~SecurityKeyIpcServerTest() override; 35 ~SecurityKeyIpcServerTest() override;
34 36
35 // Passed to the object used for testing to be called back to signal 37 // Passed to the object used for testing to be called back to signal
36 // completion of an IPC channel state change or reception of an IPC message. 38 // completion of an IPC channel state change or reception of an IPC message.
37 void OperationComplete(); 39 void OperationComplete();
38 40
39 // Used as a callback to signal receipt of a security key request message. 41 // Used as a callback to signal receipt of a security key request message.
40 void SendRequestToClient(int connection_id, const std::string& data); 42 void SendRequestToClient(int connection_id, const std::string& data);
41 43
42 protected: 44 protected:
43 // Returns a unique IPC channel name which prevents conflicts when running 45 // Returns a unique IPC channel name which prevents conflicts when running
44 // tests concurrently. 46 // tests concurrently.
45 std::string GetUniqueTestChannelName(); 47 std::string GetUniqueTestChannelName();
46 48
47 // Waits until the current |run_loop_| instance is signaled, then resets it. 49 // Waits until the current |run_loop_| instance is signaled, then resets it.
48 void WaitForOperationComplete(); 50 void WaitForOperationComplete();
49 51
52 // ClientSessionControl overrides:
53 ClientSessionControl* session_control() override { return nullptr; }
54 uint32_t desktop_session_id() const override { return peer_session_id_; }
55
50 // IPC tests require a valid MessageLoop to run. 56 // IPC tests require a valid MessageLoop to run.
51 base::MessageLoopForIO message_loop_; 57 base::MessageLoopForIO message_loop_;
52 58
53 // Used to allow |message_loop_| to run during tests. The instance is reset 59 // Used to allow |message_loop_| to run during tests. The instance is reset
54 // after each stage of the tests has been completed. 60 // after each stage of the tests has been completed.
55 std::unique_ptr<base::RunLoop> run_loop_; 61 std::unique_ptr<base::RunLoop> run_loop_;
56 62
57 // The object under test. 63 // The object under test.
58 std::unique_ptr<SecurityKeyIpcServer> security_key_ipc_server_; 64 std::unique_ptr<SecurityKeyIpcServer> security_key_ipc_server_;
59 65
60 // Used to validate the object under test uses the correct ID when 66 // Used to validate the object under test uses the correct ID when
61 // communicating over the IPC channel. 67 // communicating over the IPC channel.
62 int last_connection_id_received_ = -1; 68 int last_connection_id_received_ = -1;
63 69
64 // Stores the contents of the last IPC message received for validation. 70 // Stores the contents of the last IPC message received for validation.
65 std::string last_message_received_; 71 std::string last_message_received_;
66 72
73 uint32_t peer_session_id_ = UINT32_MAX;
74
67 private: 75 private:
68 DISALLOW_COPY_AND_ASSIGN(SecurityKeyIpcServerTest); 76 DISALLOW_COPY_AND_ASSIGN(SecurityKeyIpcServerTest);
69 }; 77 };
70 78
71 SecurityKeyIpcServerTest::SecurityKeyIpcServerTest() 79 SecurityKeyIpcServerTest::SecurityKeyIpcServerTest()
72 : run_loop_(new base::RunLoop()) { 80 : run_loop_(new base::RunLoop()) {
73 uint32_t peer_session_id = UINT32_MAX;
74 #if defined(OS_WIN) 81 #if defined(OS_WIN)
75 EXPECT_TRUE(ProcessIdToSessionId(GetCurrentProcessId(), 82 EXPECT_TRUE(ProcessIdToSessionId(
76 reinterpret_cast<DWORD*>(&peer_session_id))); 83 GetCurrentProcessId(), reinterpret_cast<DWORD*>(&peer_session_id_)));
77 #endif // defined(OS_WIN) 84 #endif // defined(OS_WIN)
78 85
79 security_key_ipc_server_ = remoting::SecurityKeyIpcServer::Create( 86 security_key_ipc_server_ = remoting::SecurityKeyIpcServer::Create(
80 kTestConnectionId, peer_session_id, 87 kTestConnectionId, this,
81 base::TimeDelta::FromMilliseconds(kInitialConnectTimeoutMs), 88 base::TimeDelta::FromMilliseconds(kInitialConnectTimeoutMs),
82 base::Bind(&SecurityKeyIpcServerTest::SendRequestToClient, 89 base::Bind(&SecurityKeyIpcServerTest::SendRequestToClient,
83 base::Unretained(this)), 90 base::Unretained(this)),
84 base::Bind(&SecurityKeyIpcServerTest::OperationComplete, 91 base::Bind(&SecurityKeyIpcServerTest::OperationComplete,
85 base::Unretained(this))); 92 base::Unretained(this)));
86 } 93 }
87 94
88 SecurityKeyIpcServerTest::~SecurityKeyIpcServerTest() {} 95 SecurityKeyIpcServerTest::~SecurityKeyIpcServerTest() {}
89 96
90 void SecurityKeyIpcServerTest::OperationComplete() { 97 void SecurityKeyIpcServerTest::OperationComplete() {
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 base::Time start_time(base::Time::NowFromSystemTime()); 376 base::Time start_time(base::Time::NowFromSystemTime());
370 WaitForOperationComplete(); 377 WaitForOperationComplete();
371 base::TimeDelta elapsed_time = base::Time::NowFromSystemTime() - start_time; 378 base::TimeDelta elapsed_time = base::Time::NowFromSystemTime() - start_time;
372 379
373 ASSERT_NEAR(elapsed_time.InMilliseconds(), request_timeout.InMilliseconds(), 380 ASSERT_NEAR(elapsed_time.InMilliseconds(), request_timeout.InMilliseconds(),
374 kConnectionTimeoutErrorDeltaMs); 381 kConnectionTimeoutErrorDeltaMs);
375 } 382 }
376 383
377 #if defined(OS_WIN) 384 #if defined(OS_WIN)
378 TEST_F(SecurityKeyIpcServerTest, IpcConnectionFailsFromInvalidSession) { 385 TEST_F(SecurityKeyIpcServerTest, IpcConnectionFailsFromInvalidSession) {
379 uint32_t peer_session_id = UINT32_MAX; 386 // Change the expected session ID to not match the current session.
380 ASSERT_TRUE(ProcessIdToSessionId(GetCurrentProcessId(), 387 peer_session_id_++;
381 reinterpret_cast<DWORD*>(&peer_session_id)));
382 peer_session_id++;
383
384 // Reinitialize the object under test.
385 security_key_ipc_server_ = remoting::SecurityKeyIpcServer::Create(
386 kTestConnectionId, peer_session_id,
387 base::TimeDelta::FromMilliseconds(kInitialConnectTimeoutMs),
388 base::Bind(&SecurityKeyIpcServerTest::SendRequestToClient,
389 base::Unretained(this)),
390 base::Bind(&base::DoNothing));
391 388
392 base::TimeDelta request_timeout(base::TimeDelta::FromMilliseconds(500)); 389 base::TimeDelta request_timeout(base::TimeDelta::FromMilliseconds(500));
393 std::string channel_name(GetUniqueTestChannelName()); 390 std::string channel_name(GetUniqueTestChannelName());
394 ASSERT_TRUE( 391 ASSERT_TRUE(
395 security_key_ipc_server_->CreateChannel(channel_name, request_timeout)); 392 security_key_ipc_server_->CreateChannel(channel_name, request_timeout));
396 393
397 // Create a fake client and attempt to connect to the IPC server channel. 394 // Create a fake client and attempt to connect to the IPC server channel.
398 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind( 395 FakeSecurityKeyIpcClient fake_ipc_client(base::Bind(
399 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this))); 396 &SecurityKeyIpcServerTest::OperationComplete, base::Unretained(this)));
400 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); 397 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name));
401 WaitForOperationComplete(); 398 WaitForOperationComplete();
402 WaitForOperationComplete(); 399 WaitForOperationComplete();
400 WaitForOperationComplete();
403 401
404 // Verify the connection failed. 402 // Verify the connection failed.
405 ASSERT_FALSE(fake_ipc_client.ipc_channel_connected()); 403 ASSERT_FALSE(fake_ipc_client.ipc_channel_connected());
406 } 404 }
407 #endif // defined(OS_WIN) 405 #endif // defined(OS_WIN)
408 406
409 } // namespace remoting 407 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/security_key/security_key_ipc_server_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698