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/gnubby_auth_handler.h" | 5 #include "remoting/host/security_key/security_key_auth_handler.h" |
6 | 6 |
7 #include <cstdint> | 7 #include <cstdint> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.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 "ipc/ipc_listener.h" | 17 #include "ipc/ipc_listener.h" |
18 #include "ipc/ipc_message.h" | 18 #include "ipc/ipc_message.h" |
19 #include "ipc/ipc_message_macros.h" | 19 #include "ipc/ipc_message_macros.h" |
20 #include "remoting/host/host_mock_objects.h" | 20 #include "remoting/host/host_mock_objects.h" |
21 #include "remoting/host/security_key/fake_remote_security_key_ipc_client.h" | 21 #include "remoting/host/security_key/fake_security_key_ipc_client.h" |
22 #include "remoting/host/security_key/fake_remote_security_key_ipc_server.h" | 22 #include "remoting/host/security_key/fake_security_key_ipc_server.h" |
23 #include "remoting/host/security_key/remote_security_key_ipc_constants.h" | 23 #include "remoting/host/security_key/security_key_ipc_constants.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 | 26 |
27 namespace { | 27 namespace { |
28 const int kConnectionId1 = 1; | 28 const int kConnectionId1 = 1; |
29 const int kConnectionId2 = 2; | 29 const int kConnectionId2 = 2; |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 namespace remoting { | 32 namespace remoting { |
33 | 33 |
34 class GnubbyAuthHandlerWinTest : public testing::Test { | 34 class SecurityKeyAuthHandlerWinTest : public testing::Test { |
35 public: | 35 public: |
36 GnubbyAuthHandlerWinTest(); | 36 SecurityKeyAuthHandlerWinTest(); |
37 ~GnubbyAuthHandlerWinTest() override; | 37 ~SecurityKeyAuthHandlerWinTest() override; |
38 | 38 |
39 // Passed to the object used for testing to be called back to signal | 39 // Passed to the object used for testing to be called back to signal |
40 // completion of an IPC channel state change or reception of an IPC message. | 40 // completion of an IPC channel state change or reception of an IPC message. |
41 void OperationComplete(); | 41 void OperationComplete(); |
42 | 42 |
43 protected: | 43 protected: |
44 // Waits until the current |run_loop_| instance is signaled, then resets it. | 44 // Waits until the current |run_loop_| instance is signaled, then resets it. |
45 void WaitForOperationComplete(); | 45 void WaitForOperationComplete(); |
46 | 46 |
47 // Used as a callback given to the object under test, expected to be called | 47 // Used as a callback given to the object under test, expected to be called |
48 // back when a security key request is received by it. | 48 // back when a security key request is received by it. |
49 void SendMessageToClient(int connection_id, const std::string& data); | 49 void SendMessageToClient(int connection_id, const std::string& data); |
50 | 50 |
51 // Creates a new gnubby connection on the object under test. | 51 // Creates a new security key connection on the object under test. |
52 void CreateGnubbyConnection(const std::string& channel_name); | 52 void CreateSecurityKeyConnection(const std::string& channel_name); |
53 | 53 |
54 // Sets |desktop_session_id_| to the id for the current Windows session. | 54 // Sets |desktop_session_id_| to the id for the current Windows session. |
55 void InitializeDesktopSessionId(); | 55 void InitializeDesktopSessionId(); |
56 | 56 |
57 // Uses |fake_ipc_client| to connect to the initial IPC server channel, it | 57 // Uses |fake_ipc_client| to connect to the initial IPC server channel, it |
58 // then validates internal state of the object under test and closes the | 58 // then validates internal state of the object under test and closes the |
59 // connection based on |close_connection|. | 59 // connection based on |close_connection|. |
60 void EstablishInitialIpcConnection( | 60 void EstablishInitialIpcConnection(FakeSecurityKeyIpcClient* fake_ipc_client, |
61 FakeRemoteSecurityKeyIpcClient* fake_ipc_client, | 61 int expected_connection_id, |
62 int expected_connection_id, | 62 const std::string& channel_name, |
63 const std::string& channel_name, | 63 bool close_connection); |
64 bool close_connection); | |
65 | 64 |
66 // Sends a security key response message using |fake_ipc_server| and | 65 // Sends a security key response message using |fake_ipc_server| and |
67 // validates the state of the object under test. | 66 // validates the state of the object under test. |
68 void SendRequestToGnubbyAuthHandler( | 67 void SendRequestToSecurityKeyAuthHandler( |
69 const base::WeakPtr<FakeRemoteSecurityKeyIpcServer>& fake_ipc_server, | 68 const base::WeakPtr<FakeSecurityKeyIpcServer>& fake_ipc_server, |
70 int connection_id, | 69 int connection_id, |
71 const std::string& request_payload); | 70 const std::string& request_payload); |
72 | 71 |
73 // Sends a security key response message to |fake_ipc_server| and validates | 72 // Sends a security key response message to |fake_ipc_server| and validates |
74 // the state of the object under test. | 73 // the state of the object under test. |
75 void SendResponseViaGnubbyAuthHandler( | 74 void SendResponseViaSecurityKeyAuthHandler( |
76 const base::WeakPtr<FakeRemoteSecurityKeyIpcServer>& fake_ipc_server, | 75 const base::WeakPtr<FakeSecurityKeyIpcServer>& fake_ipc_server, |
77 int connection_id, | 76 int connection_id, |
78 const std::string& response_payload); | 77 const std::string& response_payload); |
79 | 78 |
80 // Closes a security key session IPC channel and validates state. | 79 // Closes a security key session IPC channel and validates state. |
81 void CloseSecurityKeySessionIpcChannel( | 80 void CloseSecurityKeySessionIpcChannel( |
82 const base::WeakPtr<FakeRemoteSecurityKeyIpcServer>& fake_ipc_server, | 81 const base::WeakPtr<FakeSecurityKeyIpcServer>& fake_ipc_server, |
83 int connection_id); | 82 int connection_id); |
84 | 83 |
85 // Returns a unique IPC channel name which prevents conflicts when running | 84 // Returns a unique IPC channel name which prevents conflicts when running |
86 // tests concurrently. | 85 // tests concurrently. |
87 std::string GetUniqueTestChannelName(); | 86 std::string GetUniqueTestChannelName(); |
88 | 87 |
89 // IPC tests require a valid MessageLoop to run. | 88 // IPC tests require a valid MessageLoop to run. |
90 base::MessageLoopForIO message_loop_; | 89 base::MessageLoopForIO message_loop_; |
91 | 90 |
92 // Used to allow |message_loop_| to run during tests. The instance is reset | 91 // Used to allow |message_loop_| to run during tests. The instance is reset |
93 // after each stage of the tests has been completed. | 92 // after each stage of the tests has been completed. |
94 std::unique_ptr<base::RunLoop> run_loop_; | 93 std::unique_ptr<base::RunLoop> run_loop_; |
95 | 94 |
96 // The object under test. | 95 // The object under test. |
97 std::unique_ptr<GnubbyAuthHandler> auth_handler_; | 96 std::unique_ptr<SecurityKeyAuthHandler> auth_handler_; |
98 | 97 |
99 // Set as the default factory to create RemoteSecurityKeyIpcServerFactory | 98 // Set as the default factory to create SecurityKeyIpcServerFactory |
100 // instances, this class will track each objects creation and allow the tests | 99 // instances, this class will track each objects creation and allow the tests |
101 // to access it and use it for driving tests and validating state. | 100 // to access it and use it for driving tests and validating state. |
102 FakeRemoteSecurityKeyIpcServerFactory ipc_server_factory_; | 101 FakeSecurityKeyIpcServerFactory ipc_server_factory_; |
103 | 102 |
104 // Used to validate the object under test uses the correct ID when | 103 // Used to validate the object under test uses the correct ID when |
105 // communicating over the IPC channel. | 104 // communicating over the IPC channel. |
106 int last_connection_id_received_ = -1; | 105 int last_connection_id_received_ = -1; |
107 | 106 |
108 // Used to validate that IPC connections are only allowed from a specific | 107 // Used to validate that IPC connections are only allowed from a specific |
109 // Windows session. | 108 // Windows session. |
110 DWORD desktop_session_id_ = UINT32_MAX; | 109 DWORD desktop_session_id_ = UINT32_MAX; |
111 | 110 |
112 // Stores the contents of the last IPC message received for validation. | 111 // Stores the contents of the last IPC message received for validation. |
113 std::string last_message_received_; | 112 std::string last_message_received_; |
114 | 113 |
115 private: | 114 private: |
116 testing::NiceMock<MockClientSessionDetails> mock_client_session_details_; | 115 testing::NiceMock<MockClientSessionDetails> mock_client_session_details_; |
117 | 116 |
118 DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandlerWinTest); | 117 DISALLOW_COPY_AND_ASSIGN(SecurityKeyAuthHandlerWinTest); |
119 }; | 118 }; |
120 | 119 |
121 GnubbyAuthHandlerWinTest::GnubbyAuthHandlerWinTest() | 120 SecurityKeyAuthHandlerWinTest::SecurityKeyAuthHandlerWinTest() |
122 : run_loop_(new base::RunLoop()) { | 121 : run_loop_(new base::RunLoop()) { |
123 auth_handler_ = remoting::GnubbyAuthHandler::Create( | 122 auth_handler_ = remoting::SecurityKeyAuthHandler::Create( |
124 &mock_client_session_details_, | 123 &mock_client_session_details_, |
125 base::Bind(&GnubbyAuthHandlerWinTest::SendMessageToClient, | 124 base::Bind(&SecurityKeyAuthHandlerWinTest::SendMessageToClient, |
126 base::Unretained(this))); | 125 base::Unretained(this))); |
127 } | 126 } |
128 | 127 |
129 GnubbyAuthHandlerWinTest::~GnubbyAuthHandlerWinTest() {} | 128 SecurityKeyAuthHandlerWinTest::~SecurityKeyAuthHandlerWinTest() {} |
130 | 129 |
131 void GnubbyAuthHandlerWinTest::OperationComplete() { | 130 void SecurityKeyAuthHandlerWinTest::OperationComplete() { |
132 run_loop_->Quit(); | 131 run_loop_->Quit(); |
133 } | 132 } |
134 | 133 |
135 void GnubbyAuthHandlerWinTest::WaitForOperationComplete() { | 134 void SecurityKeyAuthHandlerWinTest::WaitForOperationComplete() { |
136 run_loop_->Run(); | 135 run_loop_->Run(); |
137 run_loop_.reset(new base::RunLoop()); | 136 run_loop_.reset(new base::RunLoop()); |
138 } | 137 } |
139 | 138 |
140 void GnubbyAuthHandlerWinTest::SendMessageToClient(int connection_id, | 139 void SecurityKeyAuthHandlerWinTest::SendMessageToClient( |
141 const std::string& data) { | 140 int connection_id, |
| 141 const std::string& data) { |
142 last_connection_id_received_ = connection_id; | 142 last_connection_id_received_ = connection_id; |
143 last_message_received_ = data; | 143 last_message_received_ = data; |
144 OperationComplete(); | 144 OperationComplete(); |
145 } | 145 } |
146 | 146 |
147 void GnubbyAuthHandlerWinTest::CreateGnubbyConnection( | 147 void SecurityKeyAuthHandlerWinTest::CreateSecurityKeyConnection( |
148 const std::string& channel_name) { | 148 const std::string& channel_name) { |
149 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); | 149 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); |
150 | 150 |
151 remoting::SetRemoteSecurityKeyIpcChannelNameForTest(channel_name); | 151 remoting::SetSecurityKeyIpcChannelNameForTest(channel_name); |
152 | 152 |
153 // Create a new Gnubby IPC Server connection. | 153 // Create a new SecurityKey IPC Server connection. |
154 auth_handler_->CreateGnubbyConnection(); | 154 auth_handler_->CreateSecurityKeyConnection(); |
155 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(channel_name)); | 155 ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized(channel_name)); |
156 | 156 |
157 InitializeDesktopSessionId(); | 157 InitializeDesktopSessionId(); |
158 } | 158 } |
159 | 159 |
160 void GnubbyAuthHandlerWinTest::InitializeDesktopSessionId() { | 160 void SecurityKeyAuthHandlerWinTest::InitializeDesktopSessionId() { |
161 ASSERT_TRUE( | 161 ASSERT_TRUE( |
162 ProcessIdToSessionId(GetCurrentProcessId(), &desktop_session_id_)); | 162 ProcessIdToSessionId(GetCurrentProcessId(), &desktop_session_id_)); |
163 | 163 |
164 ON_CALL(mock_client_session_details_, desktop_session_id()) | 164 ON_CALL(mock_client_session_details_, desktop_session_id()) |
165 .WillByDefault(testing::Return(desktop_session_id_)); | 165 .WillByDefault(testing::Return(desktop_session_id_)); |
166 } | 166 } |
167 | 167 |
168 void GnubbyAuthHandlerWinTest::EstablishInitialIpcConnection( | 168 void SecurityKeyAuthHandlerWinTest::EstablishInitialIpcConnection( |
169 FakeRemoteSecurityKeyIpcClient* fake_ipc_client, | 169 FakeSecurityKeyIpcClient* fake_ipc_client, |
170 int expected_connection_id, | 170 int expected_connection_id, |
171 const std::string& channel_name, | 171 const std::string& channel_name, |
172 bool close_connection) { | 172 bool close_connection) { |
173 size_t expected_connection_count = | 173 size_t expected_connection_count = |
174 auth_handler_->GetActiveConnectionCountForTest() + 1; | 174 auth_handler_->GetActiveConnectionCountForTest() + 1; |
175 | 175 |
176 ASSERT_TRUE(fake_ipc_client->ConnectViaIpc(channel_name)); | 176 ASSERT_TRUE(fake_ipc_client->ConnectViaIpc(channel_name)); |
177 // Client and Server will each signal us once when OnChannelConenect() is | 177 // Client and Server will each signal us once when OnChannelConenect() is |
178 // called so we wait on complete twice. The order in which each is signaled | 178 // called so we wait on complete twice. The order in which each is signaled |
179 // is not important. | 179 // is not important. |
180 WaitForOperationComplete(); | 180 WaitForOperationComplete(); |
181 WaitForOperationComplete(); | 181 WaitForOperationComplete(); |
182 | 182 |
183 // Verify the connection details have been passed to the client. | 183 // Verify the connection details have been passed to the client. |
184 std::string new_channel_name = fake_ipc_client->last_message_received(); | 184 std::string new_channel_name = fake_ipc_client->last_message_received(); |
185 ASSERT_FALSE(new_channel_name.empty()); | 185 ASSERT_FALSE(new_channel_name.empty()); |
186 | 186 |
187 // Verify the internal state of the GnubbyAuthHandler is correct. | 187 // Verify the internal state of the SecurityKeyAuthHandler is correct. |
188 ASSERT_TRUE(auth_handler_->IsValidConnectionId(expected_connection_id)); | 188 ASSERT_TRUE(auth_handler_->IsValidConnectionId(expected_connection_id)); |
189 ASSERT_EQ(expected_connection_count, | 189 ASSERT_EQ(expected_connection_count, |
190 auth_handler_->GetActiveConnectionCountForTest()); | 190 auth_handler_->GetActiveConnectionCountForTest()); |
191 | 191 |
192 if (close_connection) { | 192 if (close_connection) { |
193 fake_ipc_client->CloseIpcConnection(); | 193 fake_ipc_client->CloseIpcConnection(); |
194 WaitForOperationComplete(); | 194 WaitForOperationComplete(); |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 void GnubbyAuthHandlerWinTest::SendRequestToGnubbyAuthHandler( | 198 void SecurityKeyAuthHandlerWinTest::SendRequestToSecurityKeyAuthHandler( |
199 const base::WeakPtr<FakeRemoteSecurityKeyIpcServer>& fake_ipc_server, | 199 const base::WeakPtr<FakeSecurityKeyIpcServer>& fake_ipc_server, |
200 int connection_id, | 200 int connection_id, |
201 const std::string& request_payload) { | 201 const std::string& request_payload) { |
202 size_t expected_connection_count = | 202 size_t expected_connection_count = |
203 auth_handler_->GetActiveConnectionCountForTest(); | 203 auth_handler_->GetActiveConnectionCountForTest(); |
204 // Send a gnubby request using the fake IPC server. | 204 // Send a security key request using the fake IPC server. |
205 fake_ipc_server->SendRequest(request_payload); | 205 fake_ipc_server->SendRequest(request_payload); |
206 WaitForOperationComplete(); | 206 WaitForOperationComplete(); |
207 | 207 |
208 // Verify the FakeRemoteSecurityKeyIpcServer instance was not destroyed. | 208 // Verify the FakeSecurityKeyIpcServer instance was not destroyed. |
209 ASSERT_TRUE(fake_ipc_server.get()); | 209 ASSERT_TRUE(fake_ipc_server.get()); |
210 | 210 |
211 // Verify the request was received. | 211 // Verify the request was received. |
212 ASSERT_EQ(connection_id, last_connection_id_received_); | 212 ASSERT_EQ(connection_id, last_connection_id_received_); |
213 ASSERT_EQ(request_payload, last_message_received_); | 213 ASSERT_EQ(request_payload, last_message_received_); |
214 | 214 |
215 // Verify the internal state of the GnubbyAuthHandler is still correct. | 215 // Verify the internal state of the SecurityKeyAuthHandler is still correct. |
216 ASSERT_TRUE(auth_handler_->IsValidConnectionId(connection_id)); | 216 ASSERT_TRUE(auth_handler_->IsValidConnectionId(connection_id)); |
217 ASSERT_EQ(expected_connection_count, | 217 ASSERT_EQ(expected_connection_count, |
218 auth_handler_->GetActiveConnectionCountForTest()); | 218 auth_handler_->GetActiveConnectionCountForTest()); |
219 } | 219 } |
220 | 220 |
221 void GnubbyAuthHandlerWinTest::SendResponseViaGnubbyAuthHandler( | 221 void SecurityKeyAuthHandlerWinTest::SendResponseViaSecurityKeyAuthHandler( |
222 const base::WeakPtr<FakeRemoteSecurityKeyIpcServer>& fake_ipc_server, | 222 const base::WeakPtr<FakeSecurityKeyIpcServer>& fake_ipc_server, |
223 int connection_id, | 223 int connection_id, |
224 const std::string& response_payload) { | 224 const std::string& response_payload) { |
225 size_t expected_connection_count = | 225 size_t expected_connection_count = |
226 auth_handler_->GetActiveConnectionCountForTest(); | 226 auth_handler_->GetActiveConnectionCountForTest(); |
227 | 227 |
228 // Send a gnubby response using the new IPC channel. | 228 // Send a security key response using the new IPC channel. |
229 auth_handler_->SendClientResponse(connection_id, response_payload); | 229 auth_handler_->SendClientResponse(connection_id, response_payload); |
230 WaitForOperationComplete(); | 230 WaitForOperationComplete(); |
231 | 231 |
232 // Verify the gnubby response was received. | 232 // Verify the security key response was received. |
233 ASSERT_EQ(response_payload, fake_ipc_server->last_message_received()); | 233 ASSERT_EQ(response_payload, fake_ipc_server->last_message_received()); |
234 | 234 |
235 // Verify the internal state of the GnubbyAuthHandler is still correct. | 235 // Verify the internal state of the SecurityKeyAuthHandler is still correct. |
236 ASSERT_TRUE(auth_handler_->IsValidConnectionId(connection_id)); | 236 ASSERT_TRUE(auth_handler_->IsValidConnectionId(connection_id)); |
237 ASSERT_EQ(expected_connection_count, | 237 ASSERT_EQ(expected_connection_count, |
238 auth_handler_->GetActiveConnectionCountForTest()); | 238 auth_handler_->GetActiveConnectionCountForTest()); |
239 } | 239 } |
240 | 240 |
241 void GnubbyAuthHandlerWinTest::CloseSecurityKeySessionIpcChannel( | 241 void SecurityKeyAuthHandlerWinTest::CloseSecurityKeySessionIpcChannel( |
242 const base::WeakPtr<FakeRemoteSecurityKeyIpcServer>& fake_ipc_server, | 242 const base::WeakPtr<FakeSecurityKeyIpcServer>& fake_ipc_server, |
243 int connection_id) { | 243 int connection_id) { |
244 size_t expected_connection_count = | 244 size_t expected_connection_count = |
245 auth_handler_->GetActiveConnectionCountForTest() - 1; | 245 auth_handler_->GetActiveConnectionCountForTest() - 1; |
246 | 246 |
247 fake_ipc_server->CloseChannel(); | 247 fake_ipc_server->CloseChannel(); |
248 | 248 |
249 // Verify the internal state has been updated. | 249 // Verify the internal state has been updated. |
250 ASSERT_FALSE(auth_handler_->IsValidConnectionId(connection_id)); | 250 ASSERT_FALSE(auth_handler_->IsValidConnectionId(connection_id)); |
251 ASSERT_EQ(expected_connection_count, | 251 ASSERT_EQ(expected_connection_count, |
252 auth_handler_->GetActiveConnectionCountForTest()); | 252 auth_handler_->GetActiveConnectionCountForTest()); |
253 | 253 |
254 // Verify the FakeRemoteSecurityKeyIpcServer instance was destroyed. | 254 // Verify the FakeSecurityKeyIpcServer instance was destroyed. |
255 ASSERT_FALSE(fake_ipc_server.get()); | 255 ASSERT_FALSE(fake_ipc_server.get()); |
256 } | 256 } |
257 | 257 |
258 std::string GnubbyAuthHandlerWinTest::GetUniqueTestChannelName() { | 258 std::string SecurityKeyAuthHandlerWinTest::GetUniqueTestChannelName() { |
259 std::string channel_name("Uber_Awesome_Super_Mega_Test_Channel."); | 259 std::string channel_name("Uber_Awesome_Super_Mega_Test_Channel."); |
260 channel_name.append(IPC::Channel::GenerateUniqueRandomChannelID()); | 260 channel_name.append(IPC::Channel::GenerateUniqueRandomChannelID()); |
261 | 261 |
262 return channel_name; | 262 return channel_name; |
263 } | 263 } |
264 | 264 |
265 TEST_F(GnubbyAuthHandlerWinTest, HandleSingleGnubbyRequest) { | 265 TEST_F(SecurityKeyAuthHandlerWinTest, HandleSingleSecurityKeyRequest) { |
266 std::string channel_name(GetUniqueTestChannelName()); | 266 std::string channel_name(GetUniqueTestChannelName()); |
267 CreateGnubbyConnection(channel_name); | 267 CreateSecurityKeyConnection(channel_name); |
268 | 268 |
269 // Create a fake client and connect to the IPC server channel. | 269 // Create a fake client and connect to the IPC server channel. |
270 FakeRemoteSecurityKeyIpcClient fake_ipc_client(base::Bind( | 270 FakeSecurityKeyIpcClient fake_ipc_client( |
271 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 271 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
| 272 base::Unretained(this))); |
272 EstablishInitialIpcConnection(&fake_ipc_client, kConnectionId1, channel_name, | 273 EstablishInitialIpcConnection(&fake_ipc_client, kConnectionId1, channel_name, |
273 /*close_connection=*/true); | 274 /*close_connection=*/true); |
274 | 275 |
275 // Connect to the private IPC server channel created for this client. | 276 // Connect to the private IPC server channel created for this client. |
276 std::string new_channel_name = fake_ipc_client.last_message_received(); | 277 std::string new_channel_name = fake_ipc_client.last_message_received(); |
277 | 278 |
278 // Retrieve the IPC server instance created when the client connected. | 279 // Retrieve the IPC server instance created when the client connected. |
279 base::WeakPtr<FakeRemoteSecurityKeyIpcServer> fake_ipc_server = | 280 base::WeakPtr<FakeSecurityKeyIpcServer> fake_ipc_server = |
280 ipc_server_factory_.GetIpcServerObject(kConnectionId1); | 281 ipc_server_factory_.GetIpcServerObject(kConnectionId1); |
281 ASSERT_TRUE(fake_ipc_server.get()); | 282 ASSERT_TRUE(fake_ipc_server.get()); |
282 ASSERT_EQ(new_channel_name, fake_ipc_server->channel_name()); | 283 ASSERT_EQ(new_channel_name, fake_ipc_server->channel_name()); |
283 | 284 |
284 fake_ipc_server->set_send_response_callback(base::Bind( | 285 fake_ipc_server->set_send_response_callback( |
285 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 286 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
| 287 base::Unretained(this))); |
286 | 288 |
287 // Send a gnubby request using the fake IPC server. | 289 // Send a security key request using the fake IPC server. |
288 SendRequestToGnubbyAuthHandler(fake_ipc_server, kConnectionId1, "0123456789"); | 290 SendRequestToSecurityKeyAuthHandler(fake_ipc_server, kConnectionId1, |
| 291 "0123456789"); |
289 | 292 |
290 // Send a gnubby response using the new IPC channel. | 293 // Send a security key response using the new IPC channel. |
291 SendResponseViaGnubbyAuthHandler(fake_ipc_server, kConnectionId1, | 294 SendResponseViaSecurityKeyAuthHandler(fake_ipc_server, kConnectionId1, |
292 "9876543210"); | 295 "9876543210"); |
293 | 296 |
294 CloseSecurityKeySessionIpcChannel(fake_ipc_server, kConnectionId1); | 297 CloseSecurityKeySessionIpcChannel(fake_ipc_server, kConnectionId1); |
295 } | 298 } |
296 | 299 |
297 TEST_F(GnubbyAuthHandlerWinTest, HandleConcurrentGnubbyRequests) { | 300 TEST_F(SecurityKeyAuthHandlerWinTest, HandleConcurrentSecurityKeyRequests) { |
298 std::string channel_name(GetUniqueTestChannelName()); | 301 std::string channel_name(GetUniqueTestChannelName()); |
299 CreateGnubbyConnection(channel_name); | 302 CreateSecurityKeyConnection(channel_name); |
300 | 303 |
301 // Create fake clients and connect each to the IPC server channel. | 304 // Create fake clients and connect each to the IPC server channel. |
302 FakeRemoteSecurityKeyIpcClient fake_ipc_client_1(base::Bind( | 305 FakeSecurityKeyIpcClient fake_ipc_client_1( |
303 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 306 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
304 FakeRemoteSecurityKeyIpcClient fake_ipc_client_2(base::Bind( | 307 base::Unretained(this))); |
305 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 308 FakeSecurityKeyIpcClient fake_ipc_client_2( |
| 309 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
| 310 base::Unretained(this))); |
306 | 311 |
307 EstablishInitialIpcConnection(&fake_ipc_client_1, kConnectionId1, | 312 EstablishInitialIpcConnection(&fake_ipc_client_1, kConnectionId1, |
308 channel_name, | 313 channel_name, |
309 /*close_connection=*/true); | 314 /*close_connection=*/true); |
310 EstablishInitialIpcConnection(&fake_ipc_client_2, kConnectionId2, | 315 EstablishInitialIpcConnection(&fake_ipc_client_2, kConnectionId2, |
311 channel_name, | 316 channel_name, |
312 /*close_connection=*/true); | 317 /*close_connection=*/true); |
313 | 318 |
314 // Verify the connection details have been passed to the client. | 319 // Verify the connection details have been passed to the client. |
315 std::string channel_name_1 = fake_ipc_client_1.last_message_received(); | 320 std::string channel_name_1 = fake_ipc_client_1.last_message_received(); |
316 std::string channel_name_2 = fake_ipc_client_2.last_message_received(); | 321 std::string channel_name_2 = fake_ipc_client_2.last_message_received(); |
317 ASSERT_NE(channel_name_1, channel_name_2); | 322 ASSERT_NE(channel_name_1, channel_name_2); |
318 | 323 |
319 base::WeakPtr<FakeRemoteSecurityKeyIpcServer> fake_ipc_server_1 = | 324 base::WeakPtr<FakeSecurityKeyIpcServer> fake_ipc_server_1 = |
320 ipc_server_factory_.GetIpcServerObject(kConnectionId1); | 325 ipc_server_factory_.GetIpcServerObject(kConnectionId1); |
321 ASSERT_TRUE(fake_ipc_server_1.get()); | 326 ASSERT_TRUE(fake_ipc_server_1.get()); |
322 ASSERT_EQ(channel_name_1, fake_ipc_server_1->channel_name()); | 327 ASSERT_EQ(channel_name_1, fake_ipc_server_1->channel_name()); |
323 | 328 |
324 base::WeakPtr<FakeRemoteSecurityKeyIpcServer> fake_ipc_server_2 = | 329 base::WeakPtr<FakeSecurityKeyIpcServer> fake_ipc_server_2 = |
325 ipc_server_factory_.GetIpcServerObject(kConnectionId2); | 330 ipc_server_factory_.GetIpcServerObject(kConnectionId2); |
326 ASSERT_TRUE(fake_ipc_server_2.get()); | 331 ASSERT_TRUE(fake_ipc_server_2.get()); |
327 ASSERT_EQ(channel_name_2, fake_ipc_server_2->channel_name()); | 332 ASSERT_EQ(channel_name_2, fake_ipc_server_2->channel_name()); |
328 | 333 |
329 fake_ipc_server_1->set_send_response_callback(base::Bind( | 334 fake_ipc_server_1->set_send_response_callback( |
330 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 335 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
331 fake_ipc_server_2->set_send_response_callback(base::Bind( | 336 base::Unretained(this))); |
332 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 337 fake_ipc_server_2->set_send_response_callback( |
| 338 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
| 339 base::Unretained(this))); |
333 | 340 |
334 // Connect and send a gnubby request using the first IPC channel. | 341 // Connect and send a security key request using the first IPC channel. |
335 SendRequestToGnubbyAuthHandler(fake_ipc_server_1, kConnectionId1, | 342 SendRequestToSecurityKeyAuthHandler(fake_ipc_server_1, kConnectionId1, |
336 "aaaaaaaaaa"); | 343 "aaaaaaaaaa"); |
337 | 344 |
338 // Send a gnubby request using the second IPC channel. | 345 // Send a security key request using the second IPC channel. |
339 SendRequestToGnubbyAuthHandler(fake_ipc_server_1, kConnectionId1, | 346 SendRequestToSecurityKeyAuthHandler(fake_ipc_server_1, kConnectionId1, |
340 "bbbbbbbbbb"); | 347 "bbbbbbbbbb"); |
341 | 348 |
342 // Send a gnubby response using the first IPC channel. | 349 // Send a security key response using the first IPC channel. |
343 SendResponseViaGnubbyAuthHandler(fake_ipc_server_2, kConnectionId2, | 350 SendResponseViaSecurityKeyAuthHandler(fake_ipc_server_2, kConnectionId2, |
344 "cccccccccc"); | 351 "cccccccccc"); |
345 | 352 |
346 // Send a gnubby response using the second IPC channel. | 353 // Send a security key response using the second IPC channel. |
347 SendResponseViaGnubbyAuthHandler(fake_ipc_server_2, kConnectionId2, | 354 SendResponseViaSecurityKeyAuthHandler(fake_ipc_server_2, kConnectionId2, |
348 "dddddddddd"); | 355 "dddddddddd"); |
349 | 356 |
350 // Close the IPC channels. | 357 // Close the IPC channels. |
351 CloseSecurityKeySessionIpcChannel(fake_ipc_server_1, kConnectionId1); | 358 CloseSecurityKeySessionIpcChannel(fake_ipc_server_1, kConnectionId1); |
352 CloseSecurityKeySessionIpcChannel(fake_ipc_server_2, kConnectionId2); | 359 CloseSecurityKeySessionIpcChannel(fake_ipc_server_2, kConnectionId2); |
353 } | 360 } |
354 | 361 |
355 TEST_F(GnubbyAuthHandlerWinTest, HandleSequentialGnubbyRequests) { | 362 TEST_F(SecurityKeyAuthHandlerWinTest, HandleSequentialSecurityKeyRequests) { |
356 std::string channel_name(GetUniqueTestChannelName()); | 363 std::string channel_name(GetUniqueTestChannelName()); |
357 CreateGnubbyConnection(channel_name); | 364 CreateSecurityKeyConnection(channel_name); |
358 | 365 |
359 // Create fake clients to connect to the IPC server channel. | 366 // Create fake clients to connect to the IPC server channel. |
360 FakeRemoteSecurityKeyIpcClient fake_ipc_client_1(base::Bind( | 367 FakeSecurityKeyIpcClient fake_ipc_client_1( |
361 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 368 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
| 369 base::Unretained(this))); |
362 | 370 |
363 EstablishInitialIpcConnection(&fake_ipc_client_1, kConnectionId1, | 371 EstablishInitialIpcConnection(&fake_ipc_client_1, kConnectionId1, |
364 channel_name, | 372 channel_name, |
365 /*close_connection=*/true); | 373 /*close_connection=*/true); |
366 | 374 |
367 // Verify the connection details have been passed to the client. | 375 // Verify the connection details have been passed to the client. |
368 std::string channel_name_1 = fake_ipc_client_1.last_message_received(); | 376 std::string channel_name_1 = fake_ipc_client_1.last_message_received(); |
369 | 377 |
370 base::WeakPtr<FakeRemoteSecurityKeyIpcServer> fake_ipc_server_1 = | 378 base::WeakPtr<FakeSecurityKeyIpcServer> fake_ipc_server_1 = |
371 ipc_server_factory_.GetIpcServerObject(kConnectionId1); | 379 ipc_server_factory_.GetIpcServerObject(kConnectionId1); |
372 ASSERT_TRUE(fake_ipc_server_1.get()); | 380 ASSERT_TRUE(fake_ipc_server_1.get()); |
373 ASSERT_EQ(channel_name_1, fake_ipc_server_1->channel_name()); | 381 ASSERT_EQ(channel_name_1, fake_ipc_server_1->channel_name()); |
374 | 382 |
375 fake_ipc_server_1->set_send_response_callback(base::Bind( | 383 fake_ipc_server_1->set_send_response_callback( |
376 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 384 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
| 385 base::Unretained(this))); |
377 | 386 |
378 // Send a gnubby request using the first IPC channel. | 387 // Send a security key request using the first IPC channel. |
379 SendRequestToGnubbyAuthHandler(fake_ipc_server_1, kConnectionId1, | 388 SendRequestToSecurityKeyAuthHandler(fake_ipc_server_1, kConnectionId1, |
380 "aaaaaaaaaa"); | 389 "aaaaaaaaaa"); |
381 | 390 |
382 // Send a gnubby response using the first IPC channel. | 391 // Send a security key response using the first IPC channel. |
383 SendResponseViaGnubbyAuthHandler(fake_ipc_server_1, kConnectionId1, | 392 SendResponseViaSecurityKeyAuthHandler(fake_ipc_server_1, kConnectionId1, |
384 "cccccccccc"); | 393 "cccccccccc"); |
385 | 394 |
386 // Close the IPC channel. | 395 // Close the IPC channel. |
387 CloseSecurityKeySessionIpcChannel(fake_ipc_server_1, kConnectionId1); | 396 CloseSecurityKeySessionIpcChannel(fake_ipc_server_1, kConnectionId1); |
388 | 397 |
389 // Now connect with a second client. | 398 // Now connect with a second client. |
390 FakeRemoteSecurityKeyIpcClient fake_ipc_client_2(base::Bind( | 399 FakeSecurityKeyIpcClient fake_ipc_client_2( |
391 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 400 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
| 401 base::Unretained(this))); |
392 EstablishInitialIpcConnection(&fake_ipc_client_2, kConnectionId2, | 402 EstablishInitialIpcConnection(&fake_ipc_client_2, kConnectionId2, |
393 channel_name, | 403 channel_name, |
394 /*close_connection=*/true); | 404 /*close_connection=*/true); |
395 | 405 |
396 std::string channel_name_2 = fake_ipc_client_2.last_message_received(); | 406 std::string channel_name_2 = fake_ipc_client_2.last_message_received(); |
397 ASSERT_NE(channel_name_1, channel_name_2); | 407 ASSERT_NE(channel_name_1, channel_name_2); |
398 | 408 |
399 base::WeakPtr<FakeRemoteSecurityKeyIpcServer> fake_ipc_server_2 = | 409 base::WeakPtr<FakeSecurityKeyIpcServer> fake_ipc_server_2 = |
400 ipc_server_factory_.GetIpcServerObject(kConnectionId2); | 410 ipc_server_factory_.GetIpcServerObject(kConnectionId2); |
401 ASSERT_TRUE(fake_ipc_server_2.get()); | 411 ASSERT_TRUE(fake_ipc_server_2.get()); |
402 ASSERT_EQ(channel_name_2, fake_ipc_server_2->channel_name()); | 412 ASSERT_EQ(channel_name_2, fake_ipc_server_2->channel_name()); |
403 | 413 |
404 fake_ipc_server_2->set_send_response_callback(base::Bind( | 414 fake_ipc_server_2->set_send_response_callback( |
405 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 415 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
| 416 base::Unretained(this))); |
406 | 417 |
407 // Send a gnubby request using the second IPC channel. | 418 // Send a security key request using the second IPC channel. |
408 SendRequestToGnubbyAuthHandler(fake_ipc_server_2, kConnectionId2, | 419 SendRequestToSecurityKeyAuthHandler(fake_ipc_server_2, kConnectionId2, |
409 "bbbbbbbbbb"); | 420 "bbbbbbbbbb"); |
410 | 421 |
411 // Send a gnubby response using the second IPC channel. | 422 // Send a security key response using the second IPC channel. |
412 SendResponseViaGnubbyAuthHandler(fake_ipc_server_2, kConnectionId2, | 423 SendResponseViaSecurityKeyAuthHandler(fake_ipc_server_2, kConnectionId2, |
413 "dddddddddd"); | 424 "dddddddddd"); |
414 | 425 |
415 // Close the IPC channel. | 426 // Close the IPC channel. |
416 CloseSecurityKeySessionIpcChannel(fake_ipc_server_2, kConnectionId2); | 427 CloseSecurityKeySessionIpcChannel(fake_ipc_server_2, kConnectionId2); |
417 } | 428 } |
418 | 429 |
419 TEST_F(GnubbyAuthHandlerWinTest, ClientNeverDisconnectsFromInitialIpcChannel) { | 430 TEST_F(SecurityKeyAuthHandlerWinTest, |
| 431 ClientNeverDisconnectsFromInitialIpcChannel) { |
420 const int kLowConnectionTimeoutInMs = 25; | 432 const int kLowConnectionTimeoutInMs = 25; |
421 auth_handler_->SetRequestTimeoutForTest( | 433 auth_handler_->SetRequestTimeoutForTest( |
422 base::TimeDelta::FromMilliseconds(kLowConnectionTimeoutInMs)); | 434 base::TimeDelta::FromMilliseconds(kLowConnectionTimeoutInMs)); |
423 | 435 |
424 std::string channel_name(GetUniqueTestChannelName()); | 436 std::string channel_name(GetUniqueTestChannelName()); |
425 CreateGnubbyConnection(channel_name); | 437 CreateSecurityKeyConnection(channel_name); |
426 | 438 |
427 // Create a fake client and connect to the IPC server channel. | 439 // Create a fake client and connect to the IPC server channel. |
428 FakeRemoteSecurityKeyIpcClient fake_ipc_client(base::Bind( | 440 FakeSecurityKeyIpcClient fake_ipc_client( |
429 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 441 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
| 442 base::Unretained(this))); |
430 EstablishInitialIpcConnection(&fake_ipc_client, kConnectionId1, channel_name, | 443 EstablishInitialIpcConnection(&fake_ipc_client, kConnectionId1, channel_name, |
431 /*close_connection=*/false); | 444 /*close_connection=*/false); |
432 | 445 |
433 // Don't close the channel here, instead wait for the GnubbyAuthHandler to | 446 // Don't close the channel here, instead wait for the SecurityKeyAuthHandler |
434 // close the connection due to the timeout. | 447 // to close the connection due to the timeout. |
435 WaitForOperationComplete(); | 448 WaitForOperationComplete(); |
436 | 449 |
437 // Verify the connection that was set up still exists. | 450 // Verify the connection that was set up still exists. |
438 ASSERT_TRUE(auth_handler_->IsValidConnectionId(kConnectionId1)); | 451 ASSERT_TRUE(auth_handler_->IsValidConnectionId(kConnectionId1)); |
439 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); | 452 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); |
440 | 453 |
441 // Attempt to connect again after the error. | 454 // Attempt to connect again after the error. |
442 EstablishInitialIpcConnection(&fake_ipc_client, kConnectionId2, channel_name, | 455 EstablishInitialIpcConnection(&fake_ipc_client, kConnectionId2, channel_name, |
443 /*close_connection=*/true); | 456 /*close_connection=*/true); |
444 } | 457 } |
445 | 458 |
446 TEST_F(GnubbyAuthHandlerWinTest, HandleGnubbyRequestTimeout) { | 459 TEST_F(SecurityKeyAuthHandlerWinTest, HandleSecurityKeyRequestTimeout) { |
447 std::string channel_name(GetUniqueTestChannelName()); | 460 std::string channel_name(GetUniqueTestChannelName()); |
448 CreateGnubbyConnection(channel_name); | 461 CreateSecurityKeyConnection(channel_name); |
449 | 462 |
450 // Create a fake client and connect to the IPC server channel. | 463 // Create a fake client and connect to the IPC server channel. |
451 FakeRemoteSecurityKeyIpcClient fake_ipc_client(base::Bind( | 464 FakeSecurityKeyIpcClient fake_ipc_client( |
452 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 465 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
| 466 base::Unretained(this))); |
453 EstablishInitialIpcConnection(&fake_ipc_client, kConnectionId1, channel_name, | 467 EstablishInitialIpcConnection(&fake_ipc_client, kConnectionId1, channel_name, |
454 /*close_connection=*/true); | 468 /*close_connection=*/true); |
455 | 469 |
456 // Connect to the private IPC server channel created for this client. | 470 // Connect to the private IPC server channel created for this client. |
457 std::string new_channel_name = fake_ipc_client.last_message_received(); | 471 std::string new_channel_name = fake_ipc_client.last_message_received(); |
458 | 472 |
459 // Retrieve the IPC server instance created when the client connected. | 473 // Retrieve the IPC server instance created when the client connected. |
460 base::WeakPtr<FakeRemoteSecurityKeyIpcServer> fake_ipc_server = | 474 base::WeakPtr<FakeSecurityKeyIpcServer> fake_ipc_server = |
461 ipc_server_factory_.GetIpcServerObject(kConnectionId1); | 475 ipc_server_factory_.GetIpcServerObject(kConnectionId1); |
462 ASSERT_TRUE(fake_ipc_server.get()); | 476 ASSERT_TRUE(fake_ipc_server.get()); |
463 ASSERT_EQ(new_channel_name, fake_ipc_server->channel_name()); | 477 ASSERT_EQ(new_channel_name, fake_ipc_server->channel_name()); |
464 | 478 |
465 fake_ipc_server->set_send_response_callback(base::Bind( | 479 fake_ipc_server->set_send_response_callback( |
466 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 480 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
| 481 base::Unretained(this))); |
467 | 482 |
468 // Simulate a timeout and verify the IPC server is cleaned up. | 483 // Simulate a timeout and verify the IPC server is cleaned up. |
469 CloseSecurityKeySessionIpcChannel(fake_ipc_server, kConnectionId1); | 484 CloseSecurityKeySessionIpcChannel(fake_ipc_server, kConnectionId1); |
470 | 485 |
471 // Attempt to connect again after the error. | 486 // Attempt to connect again after the error. |
472 EstablishInitialIpcConnection(&fake_ipc_client, kConnectionId2, channel_name, | 487 EstablishInitialIpcConnection(&fake_ipc_client, kConnectionId2, channel_name, |
473 /*close_connection=*/true); | 488 /*close_connection=*/true); |
474 } | 489 } |
475 | 490 |
476 TEST_F(GnubbyAuthHandlerWinTest, HandleGnubbyErrorResponse) { | 491 TEST_F(SecurityKeyAuthHandlerWinTest, HandleSecurityKeyErrorResponse) { |
477 std::string channel_name(GetUniqueTestChannelName()); | 492 std::string channel_name(GetUniqueTestChannelName()); |
478 CreateGnubbyConnection(channel_name); | 493 CreateSecurityKeyConnection(channel_name); |
479 | 494 |
480 // Create a fake client and connect to the IPC server channel. | 495 // Create a fake client and connect to the IPC server channel. |
481 FakeRemoteSecurityKeyIpcClient fake_ipc_client(base::Bind( | 496 FakeSecurityKeyIpcClient fake_ipc_client( |
482 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 497 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
| 498 base::Unretained(this))); |
483 EstablishInitialIpcConnection(&fake_ipc_client, kConnectionId1, channel_name, | 499 EstablishInitialIpcConnection(&fake_ipc_client, kConnectionId1, channel_name, |
484 /*close_connection=*/true); | 500 /*close_connection=*/true); |
485 | 501 |
486 // Connect to the private IPC server channel created for this client. | 502 // Connect to the private IPC server channel created for this client. |
487 std::string new_channel_name = fake_ipc_client.last_message_received(); | 503 std::string new_channel_name = fake_ipc_client.last_message_received(); |
488 | 504 |
489 // Retrieve the IPC server instance created when the client connected. | 505 // Retrieve the IPC server instance created when the client connected. |
490 base::WeakPtr<FakeRemoteSecurityKeyIpcServer> fake_ipc_server = | 506 base::WeakPtr<FakeSecurityKeyIpcServer> fake_ipc_server = |
491 ipc_server_factory_.GetIpcServerObject(kConnectionId1); | 507 ipc_server_factory_.GetIpcServerObject(kConnectionId1); |
492 ASSERT_TRUE(fake_ipc_server.get()); | 508 ASSERT_TRUE(fake_ipc_server.get()); |
493 ASSERT_EQ(new_channel_name, fake_ipc_server->channel_name()); | 509 ASSERT_EQ(new_channel_name, fake_ipc_server->channel_name()); |
494 | 510 |
495 fake_ipc_server->set_send_response_callback(base::Bind( | 511 fake_ipc_server->set_send_response_callback( |
496 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 512 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
| 513 base::Unretained(this))); |
497 | 514 |
498 // Send a gnubby request using the fake IPC server. | 515 // Send a security key request using the fake IPC server. |
499 SendRequestToGnubbyAuthHandler(fake_ipc_server, kConnectionId1, "0123456789"); | 516 SendRequestToSecurityKeyAuthHandler(fake_ipc_server, kConnectionId1, |
| 517 "0123456789"); |
500 | 518 |
501 // Simulate a gnubby error from the client. | 519 // Simulate a security key error from the client. |
502 auth_handler_->SendErrorAndCloseConnection(kConnectionId1); | 520 auth_handler_->SendErrorAndCloseConnection(kConnectionId1); |
503 // Wait for the ipc server channel to be torn down. | 521 // Wait for the ipc server channel to be torn down. |
504 WaitForOperationComplete(); | 522 WaitForOperationComplete(); |
505 | 523 |
506 // Verify the connection was cleaned up. | 524 // Verify the connection was cleaned up. |
507 ASSERT_FALSE(fake_ipc_server.get()); | 525 ASSERT_FALSE(fake_ipc_server.get()); |
508 ASSERT_FALSE(auth_handler_->IsValidConnectionId(kConnectionId1)); | 526 ASSERT_FALSE(auth_handler_->IsValidConnectionId(kConnectionId1)); |
509 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); | 527 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); |
510 | 528 |
511 // Attempt to connect again after the error. | 529 // Attempt to connect again after the error. |
512 EstablishInitialIpcConnection(&fake_ipc_client, kConnectionId2, channel_name, | 530 EstablishInitialIpcConnection(&fake_ipc_client, kConnectionId2, channel_name, |
513 /*close_connection=*/true); | 531 /*close_connection=*/true); |
514 } | 532 } |
515 | 533 |
516 TEST_F(GnubbyAuthHandlerWinTest, IpcConnectionFailsFromInvalidSession) { | 534 TEST_F(SecurityKeyAuthHandlerWinTest, IpcConnectionFailsFromInvalidSession) { |
517 std::string channel_name(GetUniqueTestChannelName()); | 535 std::string channel_name(GetUniqueTestChannelName()); |
518 CreateGnubbyConnection(channel_name); | 536 CreateSecurityKeyConnection(channel_name); |
519 | 537 |
520 // Set the current session id to a 'different' session. | 538 // Set the current session id to a 'different' session. |
521 desktop_session_id_ += 1; | 539 desktop_session_id_ += 1; |
522 | 540 |
523 // Create a fake client and connect to the IPC server channel. | 541 // Create a fake client and connect to the IPC server channel. |
524 FakeRemoteSecurityKeyIpcClient fake_ipc_client(base::Bind( | 542 FakeSecurityKeyIpcClient fake_ipc_client( |
525 &GnubbyAuthHandlerWinTest::OperationComplete, base::Unretained(this))); | 543 base::Bind(&SecurityKeyAuthHandlerWinTest::OperationComplete, |
| 544 base::Unretained(this))); |
526 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); | 545 ASSERT_TRUE(fake_ipc_client.ConnectViaIpc(channel_name)); |
527 // Wait for the error callback to be signaled. | 546 // Wait for the error callback to be signaled. |
528 WaitForOperationComplete(); | 547 WaitForOperationComplete(); |
529 | 548 |
530 // Verify the connection was not set up. | 549 // Verify the connection was not set up. |
531 ASSERT_FALSE(auth_handler_->IsValidConnectionId(kConnectionId1)); | 550 ASSERT_FALSE(auth_handler_->IsValidConnectionId(kConnectionId1)); |
532 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); | 551 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); |
533 } | 552 } |
534 | 553 |
535 } // namespace remoting | 554 } // namespace remoting |
OLD | NEW |