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

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

Issue 2162083003: Renaming Gnubby and RemoteSecurityKey files/classes/members (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing a GYP build error Created 4 years, 5 months 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
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/remote_security_key_ipc_client.h" 5 #include "remoting/host/security_key/security_key_ipc_client.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/macros.h" 11 #include "base/macros.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "ipc/ipc_channel.h" 14 #include "ipc/ipc_channel.h"
15 #include "remoting/host/security_key/fake_ipc_gnubby_auth_handler.h" 15 #include "remoting/host/security_key/fake_ipc_security_key_auth_handler.h"
16 #include "remoting/host/security_key/fake_remote_security_key_ipc_server.h" 16 #include "remoting/host/security_key/fake_security_key_ipc_server.h"
17 #include "remoting/host/security_key/remote_security_key_ipc_constants.h" 17 #include "remoting/host/security_key/security_key_ipc_constants.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 namespace { 20 namespace {
21 const int kTestConnectionId = 1; 21 const int kTestConnectionId = 1;
22 const char kNonexistentIpcChannelName[] = "Nonexistent_IPC_Channel"; 22 const char kNonexistentIpcChannelName[] = "Nonexistent_IPC_Channel";
23 const char kValidIpcChannelName[] = 23 const char kValidIpcChannelName[] = "Security_Key_Ipc_Client_Test_Channel.";
24 "Remote_Security_Key_Ipc_Client_Test_Channel.";
25 const int kLargeMessageSizeBytes = 256 * 1024; 24 const int kLargeMessageSizeBytes = 256 * 1024;
26 } // namespace 25 } // namespace
27 26
28 namespace remoting { 27 namespace remoting {
29 28
30 class RemoteSecurityKeyIpcClientTest : public testing::Test { 29 class SecurityKeyIpcClientTest : public testing::Test {
31 public: 30 public:
32 RemoteSecurityKeyIpcClientTest(); 31 SecurityKeyIpcClientTest();
33 ~RemoteSecurityKeyIpcClientTest() override; 32 ~SecurityKeyIpcClientTest() override;
34 33
35 // Passed to the object used for testing to be called back to signal 34 // 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. 35 // completion of an IPC channel state change or reception of an IPC message.
37 void OperationComplete(bool failed); 36 void OperationComplete(bool failed);
38 37
39 // Used as a callback given to the object under test, expected to be called 38 // Used as a callback given to the object under test, expected to be called
40 // back when a security key request is received by it. 39 // back when a security key request is received by it.
41 void SendMessageToClient(int connection_id, const std::string& data); 40 void SendMessageToClient(int connection_id, const std::string& data);
42 41
43 // Used as a callback given to the object under test, expected to be called 42 // Used as a callback given to the object under test, expected to be called
44 // back when a security key response is sent. 43 // back when a security key response is sent.
45 void ClientMessageReceived(const std::string& response_payload); 44 void ClientMessageReceived(const std::string& response_payload);
46 45
47 protected: 46 protected:
48 // testing::Test interface. 47 // testing::Test interface.
49 void SetUp() override; 48 void SetUp() override;
50 49
51 // Waits until the current |run_loop_| instance is signaled, then resets it. 50 // Waits until the current |run_loop_| instance is signaled, then resets it.
52 void WaitForOperationComplete(); 51 void WaitForOperationComplete();
53 52
54 // Sets up an active IPC connection between |remote_security_key_ipc_client_| 53 // Sets up an active IPC connection between |security_key_ipc_client_|
55 // and |fake_ipc_server_|. |expect_success| defines whether the operation 54 // and |fake_ipc_server_|. |expect_success| defines whether the operation
56 // is expected to succeed or fail. 55 // is expected to succeed or fail.
57 void EstablishConnection(bool expect_success); 56 void EstablishConnection(bool expect_success);
58 57
59 // Sends a security key request from |remote_security_key_ipc_client_| and 58 // Sends a security key request from |security_key_ipc_client_| and
60 // a response from |fake_ipc_server_| and verifies the payloads for both. 59 // a response from |fake_ipc_server_| and verifies the payloads for both.
61 void SendRequestAndResponse(const std::string& request_data, 60 void SendRequestAndResponse(const std::string& request_data,
62 const std::string& response_data); 61 const std::string& response_data);
63 62
64 // Creates a unique IPC channel name to use for testing. 63 // Creates a unique IPC channel name to use for testing.
65 std::string GenerateUniqueTestChannelName(); 64 std::string GenerateUniqueTestChannelName();
66 65
67 // IPC tests require a valid MessageLoop to run. 66 // IPC tests require a valid MessageLoop to run.
68 base::MessageLoopForIO message_loop_; 67 base::MessageLoopForIO message_loop_;
69 68
70 // Used to allow |message_loop_| to run during tests. The instance is reset 69 // Used to allow |message_loop_| to run during tests. The instance is reset
71 // after each stage of the tests has been completed. 70 // after each stage of the tests has been completed.
72 std::unique_ptr<base::RunLoop> run_loop_; 71 std::unique_ptr<base::RunLoop> run_loop_;
73 72
74 // The object under test. 73 // The object under test.
75 RemoteSecurityKeyIpcClient remote_security_key_ipc_client_; 74 SecurityKeyIpcClient security_key_ipc_client_;
76 75
77 // Provides a connection details message to |remote_security_key_ipc_client_| 76 // Provides a connection details message to |security_key_ipc_client_|
78 // for testing. 77 // for testing.
79 FakeIpcGnubbyAuthHandler fake_gnubby_auth_handler_; 78 FakeIpcSecurityKeyAuthHandler fake_security_key_auth_handler_;
80 79
81 // Used to send/receive security key IPC messages for testing. 80 // Used to send/receive security key IPC messages for testing.
82 FakeRemoteSecurityKeyIpcServer fake_ipc_server_; 81 FakeSecurityKeyIpcServer fake_ipc_server_;
83 82
84 // Stores the current session ID on supported platforms. 83 // Stores the current session ID on supported platforms.
85 uint32_t session_id_ = 0; 84 uint32_t session_id_ = 0;
86 85
87 // Tracks the success/failure of the last async operation. 86 // Tracks the success/failure of the last async operation.
88 bool operation_failed_ = false; 87 bool operation_failed_ = false;
89 88
90 // Used to validate the object under test uses the correct ID when 89 // Used to validate the object under test uses the correct ID when
91 // communicating over the IPC channel. 90 // communicating over the IPC channel.
92 int last_connection_id_received_ = -1; 91 int last_connection_id_received_ = -1;
93 92
94 // Stores the contents of the last IPC message received for validation. 93 // Stores the contents of the last IPC message received for validation.
95 std::string last_message_received_; 94 std::string last_message_received_;
96 95
97 private: 96 private:
98 DISALLOW_COPY_AND_ASSIGN(RemoteSecurityKeyIpcClientTest); 97 DISALLOW_COPY_AND_ASSIGN(SecurityKeyIpcClientTest);
99 }; 98 };
100 99
101 RemoteSecurityKeyIpcClientTest::RemoteSecurityKeyIpcClientTest() 100 SecurityKeyIpcClientTest::SecurityKeyIpcClientTest()
102 : run_loop_(new base::RunLoop()), 101 : run_loop_(new base::RunLoop()),
103 fake_ipc_server_( 102 fake_ipc_server_(
104 kTestConnectionId, 103 kTestConnectionId,
105 /*peer_session_id=*/UINT32_MAX, 104 /*peer_session_id=*/UINT32_MAX,
106 /*initial_connect_timeout=*/base::TimeDelta::FromMilliseconds(500), 105 /*initial_connect_timeout=*/base::TimeDelta::FromMilliseconds(500),
107 base::Bind(&RemoteSecurityKeyIpcClientTest::SendMessageToClient, 106 base::Bind(&SecurityKeyIpcClientTest::SendMessageToClient,
108 base::Unretained(this)), 107 base::Unretained(this)),
109 base::Bind(&RemoteSecurityKeyIpcClientTest::OperationComplete, 108 base::Bind(&SecurityKeyIpcClientTest::OperationComplete,
110 base::Unretained(this), 109 base::Unretained(this),
111 /*failed=*/false)) {} 110 /*failed=*/false)) {}
112 111
113 RemoteSecurityKeyIpcClientTest::~RemoteSecurityKeyIpcClientTest() {} 112 SecurityKeyIpcClientTest::~SecurityKeyIpcClientTest() {}
114 113
115 void RemoteSecurityKeyIpcClientTest::SetUp() { 114 void SecurityKeyIpcClientTest::SetUp() {
116 #if defined(OS_WIN) 115 #if defined(OS_WIN)
117 DWORD session_id = 0; 116 DWORD session_id = 0;
118 // If we are on Windows, then we need to set the correct session ID or the 117 // If we are on Windows, then we need to set the correct session ID or the
119 // IPC connection will not be created successfully. 118 // IPC connection will not be created successfully.
120 ASSERT_TRUE(ProcessIdToSessionId(GetCurrentProcessId(), &session_id)); 119 ASSERT_TRUE(ProcessIdToSessionId(GetCurrentProcessId(), &session_id));
121 session_id_ = session_id; 120 session_id_ = session_id;
122 remote_security_key_ipc_client_.SetExpectedIpcServerSessionIdForTest( 121 security_key_ipc_client_.SetExpectedIpcServerSessionIdForTest(session_id_);
123 session_id_);
124 #endif // defined(OS_WIN) 122 #endif // defined(OS_WIN)
125 } 123 }
126 124
127 void RemoteSecurityKeyIpcClientTest::OperationComplete(bool failed) { 125 void SecurityKeyIpcClientTest::OperationComplete(bool failed) {
128 operation_failed_ |= failed; 126 operation_failed_ |= failed;
129 run_loop_->Quit(); 127 run_loop_->Quit();
130 } 128 }
131 129
132 void RemoteSecurityKeyIpcClientTest::WaitForOperationComplete() { 130 void SecurityKeyIpcClientTest::WaitForOperationComplete() {
133 run_loop_->Run(); 131 run_loop_->Run();
134 run_loop_.reset(new base::RunLoop()); 132 run_loop_.reset(new base::RunLoop());
135 } 133 }
136 134
137 void RemoteSecurityKeyIpcClientTest::SendMessageToClient( 135 void SecurityKeyIpcClientTest::SendMessageToClient(int connection_id,
138 int connection_id, 136 const std::string& data) {
139 const std::string& data) {
140 last_connection_id_received_ = connection_id; 137 last_connection_id_received_ = connection_id;
141 last_message_received_ = data; 138 last_message_received_ = data;
142 OperationComplete(/*failed=*/false); 139 OperationComplete(/*failed=*/false);
143 } 140 }
144 141
145 void RemoteSecurityKeyIpcClientTest::ClientMessageReceived( 142 void SecurityKeyIpcClientTest::ClientMessageReceived(
146 const std::string& response_payload) { 143 const std::string& response_payload) {
147 last_message_received_ = response_payload; 144 last_message_received_ = response_payload;
148 OperationComplete(/*failed=*/false); 145 OperationComplete(/*failed=*/false);
149 } 146 }
150 147
151 std::string RemoteSecurityKeyIpcClientTest::GenerateUniqueTestChannelName() { 148 std::string SecurityKeyIpcClientTest::GenerateUniqueTestChannelName() {
152 return GetChannelNamePathPrefixForTest() + kValidIpcChannelName + 149 return GetChannelNamePathPrefixForTest() + kValidIpcChannelName +
153 IPC::Channel::GenerateUniqueRandomChannelID(); 150 IPC::Channel::GenerateUniqueRandomChannelID();
154 } 151 }
155 152
156 void RemoteSecurityKeyIpcClientTest::EstablishConnection(bool expect_success) { 153 void SecurityKeyIpcClientTest::EstablishConnection(bool expect_success) {
157 // Start up the security key forwarding session IPC channel first, that way 154 // Start up the security key forwarding session IPC channel first, that way
158 // we can provide the channel using the fake GnubbyAuthHandler later on. 155 // we can provide the channel using the fake SecurityKeyAuthHandler later on.
159 std::string ipc_session_channel_name = GenerateUniqueTestChannelName(); 156 std::string ipc_session_channel_name = GenerateUniqueTestChannelName();
160 ASSERT_TRUE(fake_ipc_server_.CreateChannel( 157 ASSERT_TRUE(fake_ipc_server_.CreateChannel(
161 ipc_session_channel_name, 158 ipc_session_channel_name,
162 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500))); 159 /*request_timeout=*/base::TimeDelta::FromMilliseconds(500)));
163 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(ipc_session_channel_name)); 160 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(ipc_session_channel_name));
164 fake_gnubby_auth_handler_.set_ipc_security_key_channel_name( 161 fake_security_key_auth_handler_.set_ipc_security_key_channel_name(
165 ipc_session_channel_name); 162 ipc_session_channel_name);
166 163
167 // Set up the channel name for the initial IPC channel. 164 // Set up the channel name for the initial IPC channel.
168 std::string ipc_server_channel_name = GenerateUniqueTestChannelName(); 165 std::string ipc_server_channel_name = GenerateUniqueTestChannelName();
169 fake_gnubby_auth_handler_.set_ipc_server_channel_name( 166 fake_security_key_auth_handler_.set_ipc_server_channel_name(
170 ipc_server_channel_name); 167 ipc_server_channel_name);
171 remote_security_key_ipc_client_.SetInitialIpcChannelNameForTest( 168 security_key_ipc_client_.SetInitialIpcChannelNameForTest(
172 ipc_server_channel_name); 169 ipc_server_channel_name);
173 170
174 // Create the initial IPC channel and verify it was set up correctly. 171 // Create the initial IPC channel and verify it was set up correctly.
175 ASSERT_FALSE( 172 ASSERT_FALSE(security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel());
176 remote_security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel()); 173 fake_security_key_auth_handler_.CreateSecurityKeyConnection();
177 fake_gnubby_auth_handler_.CreateGnubbyConnection();
178 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(ipc_server_channel_name)); 174 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(ipc_server_channel_name));
179 ASSERT_TRUE( 175 ASSERT_TRUE(security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel());
180 remote_security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel());
181 176
182 // Establish the IPC channel so we can begin sending and receiving security 177 // Establish the IPC channel so we can begin sending and receiving security
183 // key messages. 178 // key messages.
184 remote_security_key_ipc_client_.EstablishIpcConnection( 179 security_key_ipc_client_.EstablishIpcConnection(
185 base::Bind(&RemoteSecurityKeyIpcClientTest::OperationComplete, 180 base::Bind(&SecurityKeyIpcClientTest::OperationComplete,
186 base::Unretained(this), /*failed=*/false), 181 base::Unretained(this), /*failed=*/false),
187 base::Bind(&RemoteSecurityKeyIpcClientTest::OperationComplete, 182 base::Bind(&SecurityKeyIpcClientTest::OperationComplete,
188 base::Unretained(this), /*failed=*/true)); 183 base::Unretained(this), /*failed=*/true));
189 WaitForOperationComplete(); 184 WaitForOperationComplete();
190 ASSERT_NE(operation_failed_, expect_success); 185 ASSERT_NE(operation_failed_, expect_success);
191 } 186 }
192 187
193 void RemoteSecurityKeyIpcClientTest::SendRequestAndResponse( 188 void SecurityKeyIpcClientTest::SendRequestAndResponse(
194 const std::string& request_data, 189 const std::string& request_data,
195 const std::string& response_data) { 190 const std::string& response_data) {
196 ASSERT_TRUE(remote_security_key_ipc_client_.SendSecurityKeyRequest( 191 ASSERT_TRUE(security_key_ipc_client_.SendSecurityKeyRequest(
197 request_data, 192 request_data, base::Bind(&SecurityKeyIpcClientTest::ClientMessageReceived,
198 base::Bind(&RemoteSecurityKeyIpcClientTest::ClientMessageReceived, 193 base::Unretained(this))));
199 base::Unretained(this))));
200 WaitForOperationComplete(); 194 WaitForOperationComplete();
201 ASSERT_FALSE(operation_failed_); 195 ASSERT_FALSE(operation_failed_);
202 ASSERT_EQ(last_connection_id_received_, kTestConnectionId); 196 ASSERT_EQ(last_connection_id_received_, kTestConnectionId);
203 ASSERT_EQ(last_message_received_, request_data); 197 ASSERT_EQ(last_message_received_, request_data);
204 198
205 ASSERT_TRUE(fake_ipc_server_.SendResponse(response_data)); 199 ASSERT_TRUE(fake_ipc_server_.SendResponse(response_data));
206 WaitForOperationComplete(); 200 WaitForOperationComplete();
207 ASSERT_FALSE(operation_failed_); 201 ASSERT_FALSE(operation_failed_);
208 ASSERT_EQ(last_message_received_, response_data); 202 ASSERT_EQ(last_message_received_, response_data);
209 } 203 }
210 204
211 TEST_F(RemoteSecurityKeyIpcClientTest, GenerateSingleGnubbyRequest) { 205 TEST_F(SecurityKeyIpcClientTest, GenerateSingleSecurityKeyRequest) {
212 EstablishConnection(/*expect_success=*/true); 206 EstablishConnection(/*expect_success=*/true);
213 207
214 SendRequestAndResponse("Auth me!", "You've been authed!"); 208 SendRequestAndResponse("Auth me!", "You've been authed!");
215 209
216 remote_security_key_ipc_client_.CloseIpcConnection(); 210 security_key_ipc_client_.CloseIpcConnection();
217 } 211 }
218 212
219 TEST_F(RemoteSecurityKeyIpcClientTest, GenerateLargeGnubbyRequest) { 213 TEST_F(SecurityKeyIpcClientTest, GenerateLargeSecurityKeyRequest) {
220 EstablishConnection(/*expect_success=*/true); 214 EstablishConnection(/*expect_success=*/true);
221 215
222 SendRequestAndResponse(std::string(kLargeMessageSizeBytes, 'Y'), 216 SendRequestAndResponse(std::string(kLargeMessageSizeBytes, 'Y'),
223 std::string(kLargeMessageSizeBytes, 'Z')); 217 std::string(kLargeMessageSizeBytes, 'Z'));
224 218
225 remote_security_key_ipc_client_.CloseIpcConnection(); 219 security_key_ipc_client_.CloseIpcConnection();
226 } 220 }
227 221
228 TEST_F(RemoteSecurityKeyIpcClientTest, GenerateReallyLargeGnubbyRequest) { 222 TEST_F(SecurityKeyIpcClientTest, GenerateReallyLargeSecurityKeyRequest) {
229 EstablishConnection(/*expect_success=*/true); 223 EstablishConnection(/*expect_success=*/true);
230 224
231 SendRequestAndResponse(std::string(kLargeMessageSizeBytes * 2, 'Y'), 225 SendRequestAndResponse(std::string(kLargeMessageSizeBytes * 2, 'Y'),
232 std::string(kLargeMessageSizeBytes * 2, 'Z')); 226 std::string(kLargeMessageSizeBytes * 2, 'Z'));
233 227
234 remote_security_key_ipc_client_.CloseIpcConnection(); 228 security_key_ipc_client_.CloseIpcConnection();
235 } 229 }
236 230
237 TEST_F(RemoteSecurityKeyIpcClientTest, GenerateMultipleGnubbyRequest) { 231 TEST_F(SecurityKeyIpcClientTest, GenerateMultipleSecurityKeyRequest) {
238 EstablishConnection(/*expect_success=*/true); 232 EstablishConnection(/*expect_success=*/true);
239 233
240 SendRequestAndResponse("Auth me 1!", "You've been authed once!"); 234 SendRequestAndResponse("Auth me 1!", "You've been authed once!");
241 SendRequestAndResponse("Auth me 2!", "You've been authed twice!"); 235 SendRequestAndResponse("Auth me 2!", "You've been authed twice!");
242 SendRequestAndResponse("Auth me 3!", "You've been authed thrice!"); 236 SendRequestAndResponse("Auth me 3!", "You've been authed thrice!");
243 237
244 remote_security_key_ipc_client_.CloseIpcConnection(); 238 security_key_ipc_client_.CloseIpcConnection();
245 } 239 }
246 240
247 TEST_F(RemoteSecurityKeyIpcClientTest, 241 TEST_F(SecurityKeyIpcClientTest, ServerClosesConnectionAfterRequestTimeout) {
248 ServerClosesConnectionAfterRequestTimeout) {
249 EstablishConnection(/*expect_success=*/true); 242 EstablishConnection(/*expect_success=*/true);
250 fake_ipc_server_.CloseChannel(); 243 fake_ipc_server_.CloseChannel();
251 WaitForOperationComplete(); 244 WaitForOperationComplete();
252 ASSERT_FALSE(operation_failed_); 245 ASSERT_FALSE(operation_failed_);
253 } 246 }
254 247
255 TEST_F(RemoteSecurityKeyIpcClientTest, 248 TEST_F(SecurityKeyIpcClientTest,
256 SecondGnubbyRequestBeforeFirstResponseReceived) { 249 SecondSecurityKeyRequestBeforeFirstResponseReceived) {
257 EstablishConnection(/*expect_success=*/true); 250 EstablishConnection(/*expect_success=*/true);
258 251
259 ASSERT_TRUE(remote_security_key_ipc_client_.SendSecurityKeyRequest( 252 ASSERT_TRUE(security_key_ipc_client_.SendSecurityKeyRequest(
260 "First Request", 253 "First Request",
261 base::Bind(&RemoteSecurityKeyIpcClientTest::ClientMessageReceived, 254 base::Bind(&SecurityKeyIpcClientTest::ClientMessageReceived,
262 base::Unretained(this)))); 255 base::Unretained(this))));
263 WaitForOperationComplete(); 256 WaitForOperationComplete();
264 ASSERT_FALSE(operation_failed_); 257 ASSERT_FALSE(operation_failed_);
265 258
266 ASSERT_FALSE(remote_security_key_ipc_client_.SendSecurityKeyRequest( 259 ASSERT_FALSE(security_key_ipc_client_.SendSecurityKeyRequest(
267 "Second Request", 260 "Second Request",
268 base::Bind(&RemoteSecurityKeyIpcClientTest::ClientMessageReceived, 261 base::Bind(&SecurityKeyIpcClientTest::ClientMessageReceived,
269 base::Unretained(this)))); 262 base::Unretained(this))));
270 } 263 }
271 264
272 TEST_F(RemoteSecurityKeyIpcClientTest, ReceiveGnubbyResponseWithEmptyPayload) { 265 TEST_F(SecurityKeyIpcClientTest, ReceiveSecurityKeyResponseWithEmptyPayload) {
273 EstablishConnection(/*expect_success=*/true); 266 EstablishConnection(/*expect_success=*/true);
274 267
275 ASSERT_TRUE(remote_security_key_ipc_client_.SendSecurityKeyRequest( 268 ASSERT_TRUE(security_key_ipc_client_.SendSecurityKeyRequest(
276 "Valid request", 269 "Valid request",
277 base::Bind(&RemoteSecurityKeyIpcClientTest::ClientMessageReceived, 270 base::Bind(&SecurityKeyIpcClientTest::ClientMessageReceived,
278 base::Unretained(this)))); 271 base::Unretained(this))));
279 WaitForOperationComplete(); 272 WaitForOperationComplete();
280 ASSERT_FALSE(operation_failed_); 273 ASSERT_FALSE(operation_failed_);
281 274
282 ASSERT_TRUE(fake_ipc_server_.SendResponse("")); 275 ASSERT_TRUE(fake_ipc_server_.SendResponse(""));
283 WaitForOperationComplete(); 276 WaitForOperationComplete();
284 ASSERT_TRUE(operation_failed_); 277 ASSERT_TRUE(operation_failed_);
285 } 278 }
286 279
287 TEST_F(RemoteSecurityKeyIpcClientTest, 280 TEST_F(SecurityKeyIpcClientTest, SendRequestBeforeEstablishingConnection) {
288 SendRequestBeforeEstablishingConnection) {
289 // Sending a request will fail since the IPC connection has not been 281 // Sending a request will fail since the IPC connection has not been
290 // established. 282 // established.
291 ASSERT_FALSE(remote_security_key_ipc_client_.SendSecurityKeyRequest( 283 ASSERT_FALSE(security_key_ipc_client_.SendSecurityKeyRequest(
292 "Too soon!!", 284 "Too soon!!", base::Bind(&SecurityKeyIpcClientTest::ClientMessageReceived,
293 base::Bind(&RemoteSecurityKeyIpcClientTest::ClientMessageReceived, 285 base::Unretained(this))));
294 base::Unretained(this))));
295 } 286 }
296 287
297 TEST_F(RemoteSecurityKeyIpcClientTest, NonExistentMainIpcServerChannel) { 288 TEST_F(SecurityKeyIpcClientTest, NonExistentMainIpcServerChannel) {
298 std::string ipc_server_channel_name(kNonexistentIpcChannelName); 289 std::string ipc_server_channel_name(kNonexistentIpcChannelName);
299 remote_security_key_ipc_client_.SetInitialIpcChannelNameForTest( 290 security_key_ipc_client_.SetInitialIpcChannelNameForTest(
300 ipc_server_channel_name); 291 ipc_server_channel_name);
301 292
302 // Attempt to establish the conection (should fail since the IPC channel does 293 // Attempt to establish the conection (should fail since the IPC channel does
303 // not exist). 294 // not exist).
304 remote_security_key_ipc_client_.EstablishIpcConnection( 295 security_key_ipc_client_.EstablishIpcConnection(
305 base::Bind(&RemoteSecurityKeyIpcClientTest::OperationComplete, 296 base::Bind(&SecurityKeyIpcClientTest::OperationComplete,
306 base::Unretained(this), /*failed=*/false), 297 base::Unretained(this), /*failed=*/false),
307 base::Bind(&RemoteSecurityKeyIpcClientTest::OperationComplete, 298 base::Bind(&SecurityKeyIpcClientTest::OperationComplete,
308 base::Unretained(this), /*failed=*/true)); 299 base::Unretained(this), /*failed=*/true));
309 WaitForOperationComplete(); 300 WaitForOperationComplete();
310 ASSERT_TRUE(operation_failed_); 301 ASSERT_TRUE(operation_failed_);
311 } 302 }
312 303
313 TEST_F(RemoteSecurityKeyIpcClientTest, NonExistentIpcSessionChannel) { 304 TEST_F(SecurityKeyIpcClientTest, NonExistentIpcSessionChannel) {
314 fake_gnubby_auth_handler_.set_ipc_security_key_channel_name( 305 fake_security_key_auth_handler_.set_ipc_security_key_channel_name(
315 kNonexistentIpcChannelName); 306 kNonexistentIpcChannelName);
316 307
317 // Set up the channel name for the initial IPC channel. 308 // Set up the channel name for the initial IPC channel.
318 std::string ipc_server_channel_name = GenerateUniqueTestChannelName(); 309 std::string ipc_server_channel_name = GenerateUniqueTestChannelName();
319 fake_gnubby_auth_handler_.set_ipc_server_channel_name( 310 fake_security_key_auth_handler_.set_ipc_server_channel_name(
320 ipc_server_channel_name); 311 ipc_server_channel_name);
321 remote_security_key_ipc_client_.SetInitialIpcChannelNameForTest( 312 security_key_ipc_client_.SetInitialIpcChannelNameForTest(
322 ipc_server_channel_name); 313 ipc_server_channel_name);
323 314
324 // Create the initial IPC channel and verify it was set up correctly. 315 // Create the initial IPC channel and verify it was set up correctly.
325 ASSERT_FALSE( 316 ASSERT_FALSE(security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel());
326 remote_security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel()); 317 fake_security_key_auth_handler_.CreateSecurityKeyConnection();
327 fake_gnubby_auth_handler_.CreateGnubbyConnection();
328 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(ipc_server_channel_name)); 318 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(ipc_server_channel_name));
329 ASSERT_TRUE( 319 ASSERT_TRUE(security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel());
330 remote_security_key_ipc_client_.WaitForSecurityKeyIpcServerChannel());
331 320
332 // Attempt to establish the conection (should fail since the IPC channel does 321 // Attempt to establish the conection (should fail since the IPC channel does
333 // not exist). 322 // not exist).
334 remote_security_key_ipc_client_.EstablishIpcConnection( 323 security_key_ipc_client_.EstablishIpcConnection(
335 base::Bind(&RemoteSecurityKeyIpcClientTest::OperationComplete, 324 base::Bind(&SecurityKeyIpcClientTest::OperationComplete,
336 base::Unretained(this), /*failed=*/false), 325 base::Unretained(this), /*failed=*/false),
337 base::Bind(&RemoteSecurityKeyIpcClientTest::OperationComplete, 326 base::Bind(&SecurityKeyIpcClientTest::OperationComplete,
338 base::Unretained(this), /*failed=*/true)); 327 base::Unretained(this), /*failed=*/true));
339 WaitForOperationComplete(); 328 WaitForOperationComplete();
340 ASSERT_TRUE(operation_failed_); 329 ASSERT_TRUE(operation_failed_);
341 } 330 }
342 331
343 #if defined(OS_WIN) 332 #if defined(OS_WIN)
344 TEST_F(RemoteSecurityKeyIpcClientTest, GnubbyIpcServerRunningInWrongSession) { 333 TEST_F(SecurityKeyIpcClientTest, SecurityKeyIpcServerRunningInWrongSession) {
345 // Set the expected session Id to a different session than we are running in. 334 // Set the expected session Id to a different session than we are running in.
346 remote_security_key_ipc_client_.SetExpectedIpcServerSessionIdForTest( 335 security_key_ipc_client_.SetExpectedIpcServerSessionIdForTest(session_id_ +
347 session_id_ + 1); 336 1);
348 337
349 // Attempting to establish a connection should fail here since the IPC Server 338 // Attempting to establish a connection should fail here since the IPC Server
350 // is 'running' in a different session than expected. 339 // is 'running' in a different session than expected.
351 EstablishConnection(/*expect_success=*/false); 340 EstablishConnection(/*expect_success=*/false);
352 } 341 }
353 #endif // defined(OS_WIN) 342 #endif // defined(OS_WIN)
354 343
355 } // namespace remoting 344 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/security_key/security_key_ipc_client.cc ('k') | remoting/host/security_key/security_key_ipc_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698