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

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

Issue 2202733004: Renaming Linux security key auth handler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 <stddef.h> 5 #include <stddef.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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 0x5e, 0xa3, 0xbc, 0x02, 0x5b, 0xec, 0xe4, 0x4b, 0xae, 0x0e, 0xf2, 0xbd, 45 0x5e, 0xa3, 0xbc, 0x02, 0x5b, 0xec, 0xe4, 0x4b, 0xae, 0x0e, 0xf2, 0xbd,
46 0xc8, 0xaa}; 46 0xc8, 0xaa};
47 47
48 void RunUntilIdle() { 48 void RunUntilIdle() {
49 base::RunLoop run_loop; 49 base::RunLoop run_loop;
50 run_loop.RunUntilIdle(); 50 run_loop.RunUntilIdle();
51 } 51 }
52 52
53 } // namespace 53 } // namespace
54 54
55 class SecurityKeyAuthHandlerLinuxTest : public testing::Test { 55 class SecurityKeyAuthHandlerPosixTest : public testing::Test {
56 public: 56 public:
57 SecurityKeyAuthHandlerLinuxTest() 57 SecurityKeyAuthHandlerPosixTest()
58 : run_loop_(new base::RunLoop()), 58 : run_loop_(new base::RunLoop()),
59 file_thread_("SecurityKeyAuthHandlerLinuxTest_FileThread") { 59 file_thread_("SecurityKeyAuthHandlerPosixTest_FileThread") {
60 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 60 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
61 socket_path_ = temp_dir_.path().Append(kSocketFilename); 61 socket_path_ = temp_dir_.path().Append(kSocketFilename);
62 remoting::SecurityKeyAuthHandler::SetSecurityKeySocketName(socket_path_); 62 remoting::SecurityKeyAuthHandler::SetSecurityKeySocketName(socket_path_);
63 63
64 EXPECT_TRUE(file_thread_.StartWithOptions( 64 EXPECT_TRUE(file_thread_.StartWithOptions(
65 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); 65 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
66 66
67 send_message_callback_ = 67 send_message_callback_ =
68 base::Bind(&SecurityKeyAuthHandlerLinuxTest::SendMessageToClient, 68 base::Bind(&SecurityKeyAuthHandlerPosixTest::SendMessageToClient,
69 base::Unretained(this)); 69 base::Unretained(this));
70 70
71 auth_handler_ = remoting::SecurityKeyAuthHandler::Create( 71 auth_handler_ = remoting::SecurityKeyAuthHandler::Create(
72 /*client_session_details=*/nullptr, send_message_callback_, 72 /*client_session_details=*/nullptr, send_message_callback_,
73 file_thread_.task_runner()); 73 file_thread_.task_runner());
74 EXPECT_NE(auth_handler_.get(), nullptr); 74 EXPECT_NE(auth_handler_.get(), nullptr);
75 } 75 }
76 76
77 void CreateSocketAndWait() { 77 void CreateSocketAndWait() {
78 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); 78 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 SecurityKeyAuthHandler::SendMessageCallback send_message_callback_; 150 SecurityKeyAuthHandler::SendMessageCallback send_message_callback_;
151 151
152 int last_connection_id_received_ = -1; 152 int last_connection_id_received_ = -1;
153 std::string last_message_received_; 153 std::string last_message_received_;
154 154
155 base::ScopedTempDir temp_dir_; 155 base::ScopedTempDir temp_dir_;
156 base::FilePath socket_path_; 156 base::FilePath socket_path_;
157 base::Closure accept_callback_; 157 base::Closure accept_callback_;
158 158
159 private: 159 private:
160 DISALLOW_COPY_AND_ASSIGN(SecurityKeyAuthHandlerLinuxTest); 160 DISALLOW_COPY_AND_ASSIGN(SecurityKeyAuthHandlerPosixTest);
161 }; 161 };
162 162
163 TEST_F(SecurityKeyAuthHandlerLinuxTest, NotClosedAfterRequest) { 163 TEST_F(SecurityKeyAuthHandlerPosixTest, NotClosedAfterRequest) {
164 CreateSocketAndWait(); 164 CreateSocketAndWait();
165 165
166 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); 166 net::UnixDomainClientSocket client_socket(socket_path_.value(), false);
167 net::TestCompletionCallback connect_callback; 167 net::TestCompletionCallback connect_callback;
168 168
169 int rv = client_socket.Connect(connect_callback.callback()); 169 int rv = client_socket.Connect(connect_callback.callback());
170 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); 170 ASSERT_EQ(net::OK, connect_callback.GetResult(rv));
171 171
172 // Write the request and verify the response. 172 // Write the request and verify the response.
173 WriteRequestData(&client_socket); 173 WriteRequestData(&client_socket);
174 WaitForAndVerifyHostMessage(1); 174 WaitForAndVerifyHostMessage(1);
175 175
176 // Verify the connection is now valid. 176 // Verify the connection is now valid.
177 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); 177 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1));
178 178
179 // Verify that completing a request/response cycle didn't close the socket. 179 // Verify that completing a request/response cycle didn't close the socket.
180 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); 180 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest());
181 } 181 }
182 182
183 TEST_F(SecurityKeyAuthHandlerLinuxTest, HandleTwoRequests) { 183 TEST_F(SecurityKeyAuthHandlerPosixTest, HandleTwoRequests) {
184 CreateSocketAndWait(); 184 CreateSocketAndWait();
185 185
186 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); 186 net::UnixDomainClientSocket client_socket(socket_path_.value(), false);
187 net::TestCompletionCallback connect_callback; 187 net::TestCompletionCallback connect_callback;
188 188
189 int rv = client_socket.Connect(connect_callback.callback()); 189 int rv = client_socket.Connect(connect_callback.callback());
190 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); 190 ASSERT_EQ(net::OK, connect_callback.GetResult(rv));
191 191
192 // Write the request and verify the response. 192 // Write the request and verify the response.
193 WriteRequestData(&client_socket); 193 WriteRequestData(&client_socket);
194 WaitForAndVerifyHostMessage(1); 194 WaitForAndVerifyHostMessage(1);
195 195
196 // Verify the connection is now valid. 196 // Verify the connection is now valid.
197 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); 197 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1));
198 198
199 // Repeat the request/response cycle. 199 // Repeat the request/response cycle.
200 WriteRequestData(&client_socket); 200 WriteRequestData(&client_socket);
201 WaitForAndVerifyHostMessage(1); 201 WaitForAndVerifyHostMessage(1);
202 202
203 // Verify the connection is still valid. 203 // Verify the connection is still valid.
204 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); 204 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1));
205 205
206 // Verify that completing two request/response cycles didn't close the 206 // Verify that completing two request/response cycles didn't close the
207 // socket. 207 // socket.
208 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); 208 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest());
209 } 209 }
210 210
211 TEST_F(SecurityKeyAuthHandlerLinuxTest, HandleTwoIndependentRequests) { 211 TEST_F(SecurityKeyAuthHandlerPosixTest, HandleTwoIndependentRequests) {
212 CreateSocketAndWait(); 212 CreateSocketAndWait();
213 213
214 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); 214 net::UnixDomainClientSocket client_socket(socket_path_.value(), false);
215 net::TestCompletionCallback connect_callback; 215 net::TestCompletionCallback connect_callback;
216 216
217 int rv = client_socket.Connect(connect_callback.callback()); 217 int rv = client_socket.Connect(connect_callback.callback());
218 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); 218 ASSERT_EQ(net::OK, connect_callback.GetResult(rv));
219 219
220 // Write the request and verify the response. 220 // Write the request and verify the response.
221 WriteRequestData(&client_socket); 221 WriteRequestData(&client_socket);
(...skipping 12 matching lines...) Expand all
234 WaitForAndVerifyHostMessage(2); 234 WaitForAndVerifyHostMessage(2);
235 235
236 // Verify the second connection is valid and the first is not. 236 // Verify the second connection is valid and the first is not.
237 ASSERT_TRUE(auth_handler_->IsValidConnectionId(2)); 237 ASSERT_TRUE(auth_handler_->IsValidConnectionId(2));
238 ASSERT_FALSE(auth_handler_->IsValidConnectionId(1)); 238 ASSERT_FALSE(auth_handler_->IsValidConnectionId(1));
239 239
240 // Verify that the initial socket was released properly. 240 // Verify that the initial socket was released properly.
241 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); 241 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest());
242 } 242 }
243 243
244 TEST_F(SecurityKeyAuthHandlerLinuxTest, DidReadTimeout) { 244 TEST_F(SecurityKeyAuthHandlerPosixTest, DidReadTimeout) {
245 CreateSocketAndWait(); 245 CreateSocketAndWait();
246 246
247 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); 247 net::UnixDomainClientSocket client_socket(socket_path_.value(), false);
248 net::TestCompletionCallback connect_callback; 248 net::TestCompletionCallback connect_callback;
249 int rv = client_socket.Connect(connect_callback.callback()); 249 int rv = client_socket.Connect(connect_callback.callback());
250 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); 250 ASSERT_EQ(net::OK, connect_callback.GetResult(rv));
251 auth_handler_->SetRequestTimeoutForTest(base::TimeDelta()); 251 auth_handler_->SetRequestTimeoutForTest(base::TimeDelta());
252 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); 252 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest());
253 } 253 }
254 254
255 TEST_F(SecurityKeyAuthHandlerLinuxTest, ClientErrorMessageDelivered) { 255 TEST_F(SecurityKeyAuthHandlerPosixTest, ClientErrorMessageDelivered) {
256 CreateSocketAndWait(); 256 CreateSocketAndWait();
257 257
258 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); 258 net::UnixDomainClientSocket client_socket(socket_path_.value(), false);
259 net::TestCompletionCallback connect_callback; 259 net::TestCompletionCallback connect_callback;
260 int rv = client_socket.Connect(connect_callback.callback()); 260 int rv = client_socket.Connect(connect_callback.callback());
261 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); 261 ASSERT_EQ(net::OK, connect_callback.GetResult(rv));
262 262
263 auth_handler_->SendErrorAndCloseConnection(1); 263 auth_handler_->SendErrorAndCloseConnection(1);
264 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); 264 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest());
265 } 265 }
266 266
267 } // namespace remoting 267 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/security_key/security_key_auth_handler_posix.cc ('k') | remoting/remoting_host_srcs.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698