| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <sys/socket.h> |
| 6 | 7 |
| 7 #include <cstdint> | 8 #include <cstdint> |
| 8 #include <memory> | 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 17 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 18 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
| 19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 21 #include "net/base/sockaddr_storage.h" |
| 20 #include "net/base/test_completion_callback.h" | 22 #include "net/base/test_completion_callback.h" |
| 23 #include "net/socket/socket_posix.h" |
| 21 #include "net/socket/unix_domain_client_socket_posix.h" | 24 #include "net/socket/unix_domain_client_socket_posix.h" |
| 22 #include "remoting/host/security_key/security_key_auth_handler.h" | 25 #include "remoting/host/security_key/security_key_auth_handler.h" |
| 23 #include "remoting/host/security_key/security_key_socket.h" | 26 #include "remoting/host/security_key/security_key_socket.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 28 |
| 26 namespace remoting { | 29 namespace remoting { |
| 27 | 30 |
| 28 namespace { | 31 namespace { |
| 29 | 32 |
| 30 const char kSocketFilename[] = "socket_for_testing"; | 33 const char kSocketFilename[] = "socket_for_testing"; |
| 31 | 34 |
| 32 // Test security key request data. | 35 // Test security key request data. |
| 33 const uint8_t kRequestData[] = { | 36 const uint8_t kRequestData[] = { |
| 34 0x00, 0x00, 0x00, 0x9a, 0x65, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, | 37 0x00, 0x00, 0x00, 0x9a, 0x65, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 35 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x60, 0x90, | 38 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x60, 0x90, |
| 36 0x24, 0x71, 0xf8, 0xf2, 0xe5, 0xdf, 0x7f, 0x81, 0xc7, 0x49, 0xc4, 0xa3, | 39 0x24, 0x71, 0xf8, 0xf2, 0xe5, 0xdf, 0x7f, 0x81, 0xc7, 0x49, 0xc4, 0xa3, |
| 37 0x58, 0x5c, 0xf6, 0xcc, 0x40, 0x14, 0x28, 0x0c, 0xa0, 0xfa, 0x03, 0x18, | 40 0x58, 0x5c, 0xf6, 0xcc, 0x40, 0x14, 0x28, 0x0c, 0xa0, 0xfa, 0x03, 0x18, |
| 38 0x38, 0xd8, 0x7d, 0x77, 0x2b, 0x3a, 0x00, 0x00, 0x00, 0x20, 0x64, 0x46, | 41 0x38, 0xd8, 0x7d, 0x77, 0x2b, 0x3a, 0x00, 0x00, 0x00, 0x20, 0x64, 0x46, |
| 39 0x47, 0x2f, 0xdf, 0x6e, 0xed, 0x7b, 0xf3, 0xc3, 0x37, 0x20, 0xf2, 0x36, | 42 0x47, 0x2f, 0xdf, 0x6e, 0xed, 0x7b, 0xf3, 0xc3, 0x37, 0x20, 0xf2, 0x36, |
| 40 0x67, 0x6c, 0x36, 0xe1, 0xb4, 0x5e, 0xbe, 0x04, 0x85, 0xdb, 0x89, 0xa3, | 43 0x67, 0x6c, 0x36, 0xe1, 0xb4, 0x5e, 0xbe, 0x04, 0x85, 0xdb, 0x89, 0xa3, |
| 41 0xcd, 0xfd, 0xd2, 0x4b, 0xd6, 0x9f, 0x00, 0x00, 0x00, 0x40, 0x38, 0x35, | 44 0xcd, 0xfd, 0xd2, 0x4b, 0xd6, 0x9f, 0x00, 0x00, 0x00, 0x40, 0x38, 0x35, |
| 42 0x05, 0x75, 0x1d, 0x13, 0x6e, 0xb3, 0x6b, 0x1d, 0x29, 0xae, 0xd3, 0x43, | 45 0x05, 0x75, 0x1d, 0x13, 0x6e, 0xb3, 0x6b, 0x1d, 0x29, 0xae, 0xd3, 0x43, |
| 43 0xe6, 0x84, 0x8f, 0xa3, 0x9d, 0x65, 0x4e, 0x2f, 0x57, 0xe3, 0xf6, 0xe6, | 46 0xe6, 0x84, 0x8f, 0xa3, 0x9d, 0x65, 0x4e, 0x2f, 0x57, 0xe3, 0xf6, 0xe6, |
| 44 0x20, 0x3c, 0x00, 0xc6, 0xe1, 0x73, 0x34, 0xe2, 0x23, 0x99, 0xc4, 0xfa, | 47 0x20, 0x3c, 0x00, 0xc6, 0xe1, 0x73, 0x34, 0xe2, 0x23, 0x99, 0xc4, 0xfa, |
| 45 0x91, 0xc2, 0xd5, 0x97, 0xc1, 0x8b, 0xd0, 0x3c, 0x13, 0xba, 0xf0, 0xd7, | 48 0x91, 0xc2, 0xd5, 0x97, 0xc1, 0x8b, 0xd0, 0x3c, 0x13, 0xba, 0xf0, 0xd7, |
| 46 0x5e, 0xa3, 0xbc, 0x02, 0x5b, 0xec, 0xe4, 0x4b, 0xae, 0x0e, 0xf2, 0xbd, | 49 0x5e, 0xa3, 0xbc, 0x02, 0x5b, 0xec, 0xe4, 0x4b, 0xae, 0x0e, 0xf2, 0xbd, |
| 47 0xc8, 0xaa}; | 50 0xc8, 0xaa}; |
| 48 | 51 |
| 52 const uint8_t kResponseData[] = {0x00, 0x00, 0x00, 0x01, 0x42}; |
| 53 |
| 49 const uint8_t kSshErrorData[] = {0x00, 0x00, 0x00, 0x01, 0x05}; | 54 const uint8_t kSshErrorData[] = {0x00, 0x00, 0x00, 0x01, 0x05}; |
| 50 | 55 |
| 51 void RunUntilIdle() { | 56 void RunUntilIdle() { |
| 52 base::RunLoop run_loop; | 57 base::RunLoop run_loop; |
| 53 run_loop.RunUntilIdle(); | 58 run_loop.RunUntilIdle(); |
| 54 } | 59 } |
| 55 | 60 |
| 56 } // namespace | 61 } // namespace |
| 57 | 62 |
| 58 class SecurityKeyAuthHandlerPosixTest : public testing::Test { | 63 class SecurityKeyAuthHandlerPosixTest : public testing::Test { |
| 59 public: | 64 public: |
| 60 SecurityKeyAuthHandlerPosixTest() | 65 SecurityKeyAuthHandlerPosixTest() |
| 61 : run_loop_(new base::RunLoop()), | 66 : run_loop_(new base::RunLoop()), |
| 62 file_thread_("SecurityKeyAuthHandlerPosixTest_FileThread"), | 67 file_thread_("SecurityKeyAuthHandlerPosixTest_FileThread"), |
| 63 expected_request_data_(reinterpret_cast<const char*>(kRequestData + 4), | 68 expected_request_data_(reinterpret_cast<const char*>(kRequestData + 4), |
| 64 sizeof(kRequestData) - 4) { | 69 sizeof(kRequestData) - 4), |
| 70 client_response_data_(reinterpret_cast<const char*>(kResponseData + 4), |
| 71 sizeof(kResponseData) - 4) { |
| 65 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 72 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 66 socket_path_ = temp_dir_.GetPath().Append(kSocketFilename); | 73 socket_path_ = temp_dir_.GetPath().Append(kSocketFilename); |
| 67 remoting::SecurityKeyAuthHandler::SetSecurityKeySocketName(socket_path_); | 74 remoting::SecurityKeyAuthHandler::SetSecurityKeySocketName(socket_path_); |
| 68 | 75 |
| 69 EXPECT_TRUE(file_thread_.StartWithOptions( | 76 EXPECT_TRUE(file_thread_.StartWithOptions( |
| 70 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 77 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 71 | 78 |
| 72 send_message_callback_ = | 79 send_message_callback_ = |
| 73 base::Bind(&SecurityKeyAuthHandlerPosixTest::SendMessageToClient, | 80 base::Bind(&SecurityKeyAuthHandlerPosixTest::SendMessageToClient, |
| 74 base::Unretained(this)); | 81 base::Unretained(this)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 write_result = write_callback.GetResult(write_result); | 131 write_result = write_callback.GetResult(write_result); |
| 125 ASSERT_GT(write_result, 0); | 132 ASSERT_GT(write_result, 0); |
| 126 bytes_written += write_result; | 133 bytes_written += write_result; |
| 127 ASSERT_LE(bytes_written, request_len); | 134 ASSERT_LE(bytes_written, request_len); |
| 128 request_buffer->DidConsume(write_result); | 135 request_buffer->DidConsume(write_result); |
| 129 } | 136 } |
| 130 ASSERT_EQ(request_len, bytes_written); | 137 ASSERT_EQ(request_len, bytes_written); |
| 131 } | 138 } |
| 132 | 139 |
| 133 void WaitForResponseData(net::UnixDomainClientSocket* client_socket) { | 140 void WaitForResponseData(net::UnixDomainClientSocket* client_socket) { |
| 134 // The request data is reused for the response data. | 141 WaitForData(client_socket, sizeof(kResponseData)); |
| 135 WaitForData(client_socket, sizeof(kRequestData)); | |
| 136 } | 142 } |
| 137 | 143 |
| 138 void WaitForErrorData(net::UnixDomainClientSocket* client_socket) { | 144 void WaitForErrorData(net::UnixDomainClientSocket* client_socket) { |
| 139 WaitForData(client_socket, sizeof(kSshErrorData)); | 145 WaitForData(client_socket, sizeof(kSshErrorData)); |
| 140 } | 146 } |
| 141 | 147 |
| 142 void WaitForData(net::UnixDomainClientSocket* socket, int request_len) { | 148 void WaitForData(net::UnixDomainClientSocket* socket, int request_len) { |
| 143 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(request_len)); | 149 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(request_len)); |
| 144 scoped_refptr<net::DrainableIOBuffer> read_buffer( | 150 scoped_refptr<net::DrainableIOBuffer> read_buffer( |
| 145 new net::DrainableIOBuffer(buffer.get(), request_len)); | 151 new net::DrainableIOBuffer(buffer.get(), request_len)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 167 // Object under test. | 173 // Object under test. |
| 168 std::unique_ptr<SecurityKeyAuthHandler> auth_handler_; | 174 std::unique_ptr<SecurityKeyAuthHandler> auth_handler_; |
| 169 | 175 |
| 170 SecurityKeyAuthHandler::SendMessageCallback send_message_callback_; | 176 SecurityKeyAuthHandler::SendMessageCallback send_message_callback_; |
| 171 | 177 |
| 172 int last_connection_id_received_ = -1; | 178 int last_connection_id_received_ = -1; |
| 173 std::string last_message_received_; | 179 std::string last_message_received_; |
| 174 | 180 |
| 175 const std::string expected_request_data_; | 181 const std::string expected_request_data_; |
| 176 | 182 |
| 183 const std::string client_response_data_; |
| 184 |
| 177 base::ScopedTempDir temp_dir_; | 185 base::ScopedTempDir temp_dir_; |
| 178 base::FilePath socket_path_; | 186 base::FilePath socket_path_; |
| 179 base::Closure accept_callback_; | 187 base::Closure accept_callback_; |
| 180 | 188 |
| 181 private: | 189 private: |
| 182 DISALLOW_COPY_AND_ASSIGN(SecurityKeyAuthHandlerPosixTest); | 190 DISALLOW_COPY_AND_ASSIGN(SecurityKeyAuthHandlerPosixTest); |
| 183 }; | 191 }; |
| 184 | 192 |
| 185 TEST_F(SecurityKeyAuthHandlerPosixTest, NotClosedAfterRequest) { | 193 TEST_F(SecurityKeyAuthHandlerPosixTest, HandleSingleRequest) { |
| 186 CreateSocketAndWait(); | 194 CreateSocketAndWait(); |
| 187 | 195 |
| 188 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); | 196 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); |
| 189 net::TestCompletionCallback connect_callback; | 197 net::TestCompletionCallback connect_callback; |
| 190 | 198 |
| 191 int rv = client_socket.Connect(connect_callback.callback()); | 199 int rv = client_socket.Connect(connect_callback.callback()); |
| 192 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); | 200 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); |
| 193 | 201 |
| 194 // Write the request and verify the response. | 202 // Write the request and verify the response. |
| 195 WriteRequestData(&client_socket); | 203 WriteRequestData(&client_socket); |
| 196 WaitForSendMessageToClient(); | 204 WaitForSendMessageToClient(); |
| 197 CheckHostDataMessage(1); | 205 CheckHostDataMessage(1); |
| 198 | 206 |
| 199 auth_handler_->SendClientResponse(1, expected_request_data_); | |
| 200 WaitForResponseData(&client_socket); | |
| 201 | |
| 202 // Verify the connection is now valid. | 207 // Verify the connection is now valid. |
| 203 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); | 208 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 204 | 209 |
| 205 // Verify that completing a request/response cycle didn't close the socket. | 210 // Verify that completing a request/response cycle didn't close the socket. |
| 206 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); | 211 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); |
| 212 |
| 213 auth_handler_->SendClientResponse(1, client_response_data_); |
| 214 WaitForResponseData(&client_socket); |
| 215 |
| 216 // Verify that completing a request/response cycle didn't close the socket. |
| 217 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 218 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); |
| 219 } |
| 220 |
| 221 TEST_F(SecurityKeyAuthHandlerPosixTest, HandleSingleRequestWithEof) { |
| 222 CreateSocketAndWait(); |
| 223 |
| 224 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); |
| 225 net::TestCompletionCallback connect_callback; |
| 226 |
| 227 int rv = client_socket.Connect(connect_callback.callback()); |
| 228 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); |
| 229 |
| 230 // Write the request. |
| 231 WriteRequestData(&client_socket); |
| 232 WaitForSendMessageToClient(); |
| 233 |
| 234 // Verify the connection is valid. |
| 235 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 236 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); |
| 237 |
| 238 net::SocketPosix raw_socket; |
| 239 net::SockaddrStorage address; |
| 240 ASSERT_TRUE(net::UnixDomainClientSocket::FillAddress(socket_path_.value(), |
| 241 false, &address)); |
| 242 raw_socket.AdoptConnectedSocket(client_socket.ReleaseConnectedSocket(), |
| 243 address); |
| 244 |
| 245 // Close the write end of the socket. |
| 246 ASSERT_EQ(shutdown(raw_socket.socket_fd(), SHUT_WR), 0); |
| 247 |
| 248 // Verify that socket has not been closed yet. |
| 249 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 250 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); |
| 251 |
| 252 // Wait for the response to be received. |
| 253 CheckHostDataMessage(1); |
| 254 |
| 255 // Verify that socket has not been closed yet. |
| 256 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 257 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); |
| 258 |
| 259 auth_handler_->SendClientResponse(1, client_response_data_); |
| 260 |
| 261 // Verify the connection has been closed and is no longer valid. |
| 262 ASSERT_FALSE(auth_handler_->IsValidConnectionId(1)); |
| 263 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); |
| 207 } | 264 } |
| 208 | 265 |
| 209 TEST_F(SecurityKeyAuthHandlerPosixTest, HandleTwoRequests) { | 266 TEST_F(SecurityKeyAuthHandlerPosixTest, HandleTwoRequests) { |
| 210 CreateSocketAndWait(); | 267 CreateSocketAndWait(); |
| 211 | 268 |
| 212 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); | 269 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); |
| 213 net::TestCompletionCallback connect_callback; | 270 net::TestCompletionCallback connect_callback; |
| 214 | 271 |
| 215 int rv = client_socket.Connect(connect_callback.callback()); | 272 int rv = client_socket.Connect(connect_callback.callback()); |
| 216 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); | 273 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); |
| 217 | 274 |
| 218 // Write the request and verify the response. | 275 // Write the request and verify the response. |
| 219 WriteRequestData(&client_socket); | 276 WriteRequestData(&client_socket); |
| 220 WaitForSendMessageToClient(); | 277 WaitForSendMessageToClient(); |
| 221 CheckHostDataMessage(1); | 278 CheckHostDataMessage(1); |
| 222 | 279 |
| 223 // Verify the connection is now valid. | 280 // Verify the connection is now valid. |
| 224 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); | 281 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 225 | 282 |
| 226 // Send a 'client' response to the socket and verify the data is received. | 283 // Send a 'client' response to the socket and verify the data is received. |
| 227 auth_handler_->SendClientResponse(1, expected_request_data_); | 284 auth_handler_->SendClientResponse(1, client_response_data_); |
| 228 WaitForResponseData(&client_socket); | 285 WaitForResponseData(&client_socket); |
| 229 | 286 |
| 230 // Verify the connection is still valid. | 287 // Verify the connection is still valid. |
| 231 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); | 288 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 232 | 289 |
| 233 // Repeat the request/response cycle. | 290 // Repeat the request/response cycle. |
| 234 WriteRequestData(&client_socket); | 291 WriteRequestData(&client_socket); |
| 235 WaitForSendMessageToClient(); | 292 WaitForSendMessageToClient(); |
| 236 CheckHostDataMessage(1); | 293 CheckHostDataMessage(1); |
| 237 | 294 |
| 238 // Verify the connection is still valid. | 295 // Verify the connection is still valid. |
| 239 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); | 296 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 240 | 297 |
| 241 auth_handler_->SendClientResponse(1, expected_request_data_); | 298 auth_handler_->SendClientResponse(1, client_response_data_); |
| 242 WaitForResponseData(&client_socket); | 299 WaitForResponseData(&client_socket); |
| 243 | 300 |
| 244 // Verify the connection is still valid. | 301 // Verify the connection is still valid. |
| 245 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); | 302 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 246 | 303 |
| 247 // Verify that completing two request/response cycles didn't close the | 304 // Verify that completing two request/response cycles didn't close the |
| 248 // socket. | 305 // socket. |
| 249 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); | 306 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); |
| 250 } | 307 } |
| 251 | 308 |
| 252 TEST_F(SecurityKeyAuthHandlerPosixTest, HandleTwoIndependentRequests) { | 309 TEST_F(SecurityKeyAuthHandlerPosixTest, HandleTwoIndependentRequests) { |
| 253 CreateSocketAndWait(); | 310 CreateSocketAndWait(); |
| 254 | 311 |
| 255 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); | 312 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); |
| 256 net::TestCompletionCallback connect_callback; | 313 net::TestCompletionCallback connect_callback; |
| 257 | 314 |
| 258 int rv = client_socket.Connect(connect_callback.callback()); | 315 int rv = client_socket.Connect(connect_callback.callback()); |
| 259 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); | 316 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); |
| 260 | 317 |
| 261 // Write the request and verify the response. | 318 // Write the request and verify the response. |
| 262 WriteRequestData(&client_socket); | 319 WriteRequestData(&client_socket); |
| 263 WaitForSendMessageToClient(); | 320 WaitForSendMessageToClient(); |
| 264 CheckHostDataMessage(1); | 321 CheckHostDataMessage(1); |
| 265 | 322 |
| 266 // Verify the first connection is now valid. | 323 // Verify the first connection is now valid. |
| 267 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); | 324 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 268 | 325 |
| 269 // Send a 'client' response to the socket and verify the data is received. | 326 // Send a 'client' response to the socket and verify the data is received. |
| 270 auth_handler_->SendClientResponse(1, expected_request_data_); | 327 auth_handler_->SendClientResponse(1, client_response_data_); |
| 271 WaitForResponseData(&client_socket); | 328 WaitForResponseData(&client_socket); |
| 272 | 329 |
| 273 // Verify the connection is still valid. | 330 // Verify the connection is still valid. |
| 274 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); | 331 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 275 | 332 |
| 276 // Disconnect and establish a new connection. | 333 // Disconnect and establish a new connection. |
| 277 client_socket.Disconnect(); | 334 client_socket.Disconnect(); |
| 278 | 335 |
| 279 rv = client_socket.Connect(connect_callback.callback()); | 336 rv = client_socket.Connect(connect_callback.callback()); |
| 280 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); | 337 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); |
| 281 | 338 |
| 282 // Repeat the request/response cycle. | 339 // Repeat the request/response cycle. |
| 283 WriteRequestData(&client_socket); | 340 WriteRequestData(&client_socket); |
| 284 WaitForSendMessageToClient(); | 341 WaitForSendMessageToClient(); |
| 285 CheckHostDataMessage(2); | 342 CheckHostDataMessage(2); |
| 286 | 343 |
| 287 // Verify the connection is now valid. | 344 // Verify the connection is now valid. |
| 288 ASSERT_TRUE(auth_handler_->IsValidConnectionId(2)); | 345 ASSERT_TRUE(auth_handler_->IsValidConnectionId(2)); |
| 289 | 346 |
| 290 // Send a 'client' response to the socket and verify the data is received. | 347 // Send a 'client' response to the socket and verify the data is received. |
| 291 auth_handler_->SendClientResponse(2, expected_request_data_); | 348 auth_handler_->SendClientResponse(2, client_response_data_); |
| 292 WaitForResponseData(&client_socket); | 349 WaitForResponseData(&client_socket); |
| 293 | 350 |
| 294 // Verify the second connection is valid and the first is not. | 351 // Verify the second connection is valid and the first is not. |
| 295 ASSERT_TRUE(auth_handler_->IsValidConnectionId(2)); | 352 ASSERT_TRUE(auth_handler_->IsValidConnectionId(2)); |
| 296 ASSERT_FALSE(auth_handler_->IsValidConnectionId(1)); | 353 ASSERT_FALSE(auth_handler_->IsValidConnectionId(1)); |
| 297 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); | 354 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); |
| 298 } | 355 } |
| 299 | 356 |
| 300 TEST_F(SecurityKeyAuthHandlerPosixTest, DoReadTimeout) { | 357 TEST_F(SecurityKeyAuthHandlerPosixTest, HandleReadTimeout) { |
| 301 CreateSocketAndWait(); | 358 CreateSocketAndWait(); |
| 302 | 359 |
| 303 auth_handler_->SetRequestTimeoutForTest(base::TimeDelta()); | 360 auth_handler_->SetRequestTimeoutForTest(base::TimeDelta()); |
| 304 | 361 |
| 305 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); | 362 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); |
| 306 net::TestCompletionCallback connect_callback; | 363 net::TestCompletionCallback connect_callback; |
| 307 int rv = client_socket.Connect(connect_callback.callback()); | 364 int rv = client_socket.Connect(connect_callback.callback()); |
| 308 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); | 365 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); |
| 309 | 366 |
| 310 // SSH Error should be received when the connection times out. | 367 // SSH Error should be received when the connection times out. |
| 311 WaitForErrorData(&client_socket); | 368 WaitForErrorData(&client_socket); |
| 312 | 369 |
| 313 // Connection should no longer be valid. | 370 // Connection should no longer be valid. |
| 314 ASSERT_FALSE(auth_handler_->IsValidConnectionId(1)); | 371 ASSERT_FALSE(auth_handler_->IsValidConnectionId(1)); |
| 315 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); | 372 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); |
| 316 } | 373 } |
| 317 | 374 |
| 318 TEST_F(SecurityKeyAuthHandlerPosixTest, ClientErrorMessageDelivered) { | 375 TEST_F(SecurityKeyAuthHandlerPosixTest, HandleClientErrorMessage) { |
| 319 CreateSocketAndWait(); | 376 CreateSocketAndWait(); |
| 320 | 377 |
| 321 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); | 378 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); |
| 322 net::TestCompletionCallback connect_callback; | 379 net::TestCompletionCallback connect_callback; |
| 323 int rv = client_socket.Connect(connect_callback.callback()); | 380 int rv = client_socket.Connect(connect_callback.callback()); |
| 324 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); | 381 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); |
| 325 | 382 |
| 326 // Write the request and verify the response. This ensures the socket has | 383 // Write the request and verify the response. This ensures the socket has |
| 327 // been created and is working before sending the error to tear it down. | 384 // been created and is working before sending the error to tear it down. |
| 328 WriteRequestData(&client_socket); | 385 WriteRequestData(&client_socket); |
| 329 WaitForSendMessageToClient(); | 386 WaitForSendMessageToClient(); |
| 330 CheckHostDataMessage(1); | 387 CheckHostDataMessage(1); |
| 331 | 388 |
| 332 // Send a 'client' response to the socket and verify the data is received. | 389 // Send a 'client' response to the socket and verify the data is received. |
| 333 auth_handler_->SendClientResponse(1, expected_request_data_); | 390 auth_handler_->SendClientResponse(1, client_response_data_); |
| 334 WaitForResponseData(&client_socket); | 391 WaitForResponseData(&client_socket); |
| 335 | 392 |
| 336 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); | 393 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 337 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); | 394 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); |
| 338 | 395 |
| 339 auth_handler_->SendErrorAndCloseConnection(1); | 396 auth_handler_->SendErrorAndCloseConnection(1); |
| 340 | 397 |
| 341 // Connection should be removed immediately. | 398 // Connection should be removed immediately. |
| 342 ASSERT_FALSE(auth_handler_->IsValidConnectionId(1)); | 399 ASSERT_FALSE(auth_handler_->IsValidConnectionId(1)); |
| 343 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); | 400 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); |
| 344 | 401 |
| 345 // SSH Error should be received. | 402 // SSH Error should be received. |
| 346 WaitForErrorData(&client_socket); | 403 WaitForErrorData(&client_socket); |
| 347 } | 404 } |
| 348 | 405 |
| 349 } // namespace remoting | 406 } // namespace remoting |
| OLD | NEW |