| 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 | 6 |
| 7 #include <cstdint> |
| 7 #include <memory> | 8 #include <memory> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 17 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
| 18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 19 #include "net/base/test_completion_callback.h" | 20 #include "net/base/test_completion_callback.h" |
| 20 #include "net/socket/unix_domain_client_socket_posix.h" | 21 #include "net/socket/unix_domain_client_socket_posix.h" |
| 21 #include "remoting/host/security_key/security_key_auth_handler.h" | 22 #include "remoting/host/security_key/security_key_auth_handler.h" |
| 22 #include "remoting/host/security_key/security_key_socket.h" | 23 #include "remoting/host/security_key/security_key_socket.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 25 |
| 25 namespace remoting { | 26 namespace remoting { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 const char kSocketFilename[] = "socket_for_testing"; | 30 const char kSocketFilename[] = "socket_for_testing"; |
| 30 | 31 |
| 31 // Test security key request data. | 32 // Test security key request data. |
| 32 const unsigned char kRequestData[] = { | 33 const uint8_t kRequestData[] = { |
| 33 0x00, 0x00, 0x00, 0x9a, 0x65, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, | 34 0x00, 0x00, 0x00, 0x9a, 0x65, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 34 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x60, 0x90, | 35 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x60, 0x90, |
| 35 0x24, 0x71, 0xf8, 0xf2, 0xe5, 0xdf, 0x7f, 0x81, 0xc7, 0x49, 0xc4, 0xa3, | 36 0x24, 0x71, 0xf8, 0xf2, 0xe5, 0xdf, 0x7f, 0x81, 0xc7, 0x49, 0xc4, 0xa3, |
| 36 0x58, 0x5c, 0xf6, 0xcc, 0x40, 0x14, 0x28, 0x0c, 0xa0, 0xfa, 0x03, 0x18, | 37 0x58, 0x5c, 0xf6, 0xcc, 0x40, 0x14, 0x28, 0x0c, 0xa0, 0xfa, 0x03, 0x18, |
| 37 0x38, 0xd8, 0x7d, 0x77, 0x2b, 0x3a, 0x00, 0x00, 0x00, 0x20, 0x64, 0x46, | 38 0x38, 0xd8, 0x7d, 0x77, 0x2b, 0x3a, 0x00, 0x00, 0x00, 0x20, 0x64, 0x46, |
| 38 0x47, 0x2f, 0xdf, 0x6e, 0xed, 0x7b, 0xf3, 0xc3, 0x37, 0x20, 0xf2, 0x36, | 39 0x47, 0x2f, 0xdf, 0x6e, 0xed, 0x7b, 0xf3, 0xc3, 0x37, 0x20, 0xf2, 0x36, |
| 39 0x67, 0x6c, 0x36, 0xe1, 0xb4, 0x5e, 0xbe, 0x04, 0x85, 0xdb, 0x89, 0xa3, | 40 0x67, 0x6c, 0x36, 0xe1, 0xb4, 0x5e, 0xbe, 0x04, 0x85, 0xdb, 0x89, 0xa3, |
| 40 0xcd, 0xfd, 0xd2, 0x4b, 0xd6, 0x9f, 0x00, 0x00, 0x00, 0x40, 0x38, 0x35, | 41 0xcd, 0xfd, 0xd2, 0x4b, 0xd6, 0x9f, 0x00, 0x00, 0x00, 0x40, 0x38, 0x35, |
| 41 0x05, 0x75, 0x1d, 0x13, 0x6e, 0xb3, 0x6b, 0x1d, 0x29, 0xae, 0xd3, 0x43, | 42 0x05, 0x75, 0x1d, 0x13, 0x6e, 0xb3, 0x6b, 0x1d, 0x29, 0xae, 0xd3, 0x43, |
| 42 0xe6, 0x84, 0x8f, 0xa3, 0x9d, 0x65, 0x4e, 0x2f, 0x57, 0xe3, 0xf6, 0xe6, | 43 0xe6, 0x84, 0x8f, 0xa3, 0x9d, 0x65, 0x4e, 0x2f, 0x57, 0xe3, 0xf6, 0xe6, |
| 43 0x20, 0x3c, 0x00, 0xc6, 0xe1, 0x73, 0x34, 0xe2, 0x23, 0x99, 0xc4, 0xfa, | 44 0x20, 0x3c, 0x00, 0xc6, 0xe1, 0x73, 0x34, 0xe2, 0x23, 0x99, 0xc4, 0xfa, |
| 44 0x91, 0xc2, 0xd5, 0x97, 0xc1, 0x8b, 0xd0, 0x3c, 0x13, 0xba, 0xf0, 0xd7, | 45 0x91, 0xc2, 0xd5, 0x97, 0xc1, 0x8b, 0xd0, 0x3c, 0x13, 0xba, 0xf0, 0xd7, |
| 45 0x5e, 0xa3, 0xbc, 0x02, 0x5b, 0xec, 0xe4, 0x4b, 0xae, 0x0e, 0xf2, 0xbd, | 46 0x5e, 0xa3, 0xbc, 0x02, 0x5b, 0xec, 0xe4, 0x4b, 0xae, 0x0e, 0xf2, 0xbd, |
| 46 0xc8, 0xaa}; | 47 0xc8, 0xaa}; |
| 47 | 48 |
| 49 const uint8_t kSshErrorData[] = {0x00, 0x00, 0x00, 0x01, 0x05}; |
| 50 |
| 48 void RunUntilIdle() { | 51 void RunUntilIdle() { |
| 49 base::RunLoop run_loop; | 52 base::RunLoop run_loop; |
| 50 run_loop.RunUntilIdle(); | 53 run_loop.RunUntilIdle(); |
| 51 } | 54 } |
| 52 | 55 |
| 53 } // namespace | 56 } // namespace |
| 54 | 57 |
| 55 class SecurityKeyAuthHandlerPosixTest : public testing::Test { | 58 class SecurityKeyAuthHandlerPosixTest : public testing::Test { |
| 56 public: | 59 public: |
| 57 SecurityKeyAuthHandlerPosixTest() | 60 SecurityKeyAuthHandlerPosixTest() |
| 58 : run_loop_(new base::RunLoop()), | 61 : run_loop_(new base::RunLoop()), |
| 59 file_thread_("SecurityKeyAuthHandlerPosixTest_FileThread") { | 62 file_thread_("SecurityKeyAuthHandlerPosixTest_FileThread"), |
| 63 expected_request_data_(reinterpret_cast<const char*>(kRequestData + 4), |
| 64 sizeof(kRequestData) - 4) { |
| 60 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 65 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 61 socket_path_ = temp_dir_.GetPath().Append(kSocketFilename); | 66 socket_path_ = temp_dir_.GetPath().Append(kSocketFilename); |
| 62 remoting::SecurityKeyAuthHandler::SetSecurityKeySocketName(socket_path_); | 67 remoting::SecurityKeyAuthHandler::SetSecurityKeySocketName(socket_path_); |
| 63 | 68 |
| 64 EXPECT_TRUE(file_thread_.StartWithOptions( | 69 EXPECT_TRUE(file_thread_.StartWithOptions( |
| 65 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 70 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 66 | 71 |
| 67 send_message_callback_ = | 72 send_message_callback_ = |
| 68 base::Bind(&SecurityKeyAuthHandlerPosixTest::SendMessageToClient, | 73 base::Bind(&SecurityKeyAuthHandlerPosixTest::SendMessageToClient, |
| 69 base::Unretained(this)); | 74 base::Unretained(this)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 90 last_connection_id_received_ = connection_id; | 95 last_connection_id_received_ = connection_id; |
| 91 last_message_received_ = data; | 96 last_message_received_ = data; |
| 92 run_loop_->Quit(); | 97 run_loop_->Quit(); |
| 93 } | 98 } |
| 94 | 99 |
| 95 void WaitForSendMessageToClient() { | 100 void WaitForSendMessageToClient() { |
| 96 run_loop_->Run(); | 101 run_loop_->Run(); |
| 97 run_loop_.reset(new base::RunLoop); | 102 run_loop_.reset(new base::RunLoop); |
| 98 } | 103 } |
| 99 | 104 |
| 100 void CheckHostDataMessage(int id, const std::string& expected_data) { | 105 void CheckHostDataMessage(int id) { |
| 101 ASSERT_EQ(id, last_connection_id_received_); | 106 ASSERT_EQ(id, last_connection_id_received_); |
| 102 ASSERT_EQ(expected_data.length(), last_message_received_.length()); | 107 ASSERT_EQ(expected_request_data_.length(), last_message_received_.length()); |
| 103 ASSERT_EQ(expected_data, last_message_received_); | 108 ASSERT_EQ(expected_request_data_, last_message_received_); |
| 104 } | 109 } |
| 105 | 110 |
| 106 void WriteRequestData(net::UnixDomainClientSocket* client_socket) { | 111 void WriteRequestData(net::UnixDomainClientSocket* client_socket) { |
| 107 int request_len = sizeof(kRequestData); | 112 int request_len = sizeof(kRequestData); |
| 108 scoped_refptr<net::DrainableIOBuffer> request_buffer( | 113 scoped_refptr<net::DrainableIOBuffer> request_buffer( |
| 109 new net::DrainableIOBuffer( | 114 new net::DrainableIOBuffer( |
| 110 new net::WrappedIOBuffer( | 115 new net::WrappedIOBuffer( |
| 111 reinterpret_cast<const char*>(kRequestData)), | 116 reinterpret_cast<const char*>(kRequestData)), |
| 112 request_len)); | 117 request_len)); |
| 113 net::TestCompletionCallback write_callback; | 118 net::TestCompletionCallback write_callback; |
| 114 int bytes_written = 0; | 119 int bytes_written = 0; |
| 115 while (bytes_written < request_len) { | 120 while (bytes_written < request_len) { |
| 116 int write_result = client_socket->Write(request_buffer.get(), | 121 int write_result = client_socket->Write(request_buffer.get(), |
| 117 request_buffer->BytesRemaining(), | 122 request_buffer->BytesRemaining(), |
| 118 write_callback.callback()); | 123 write_callback.callback()); |
| 119 write_result = write_callback.GetResult(write_result); | 124 write_result = write_callback.GetResult(write_result); |
| 120 ASSERT_GT(write_result, 0); | 125 ASSERT_GT(write_result, 0); |
| 121 bytes_written += write_result; | 126 bytes_written += write_result; |
| 122 ASSERT_LE(bytes_written, request_len); | 127 ASSERT_LE(bytes_written, request_len); |
| 123 request_buffer->DidConsume(write_result); | 128 request_buffer->DidConsume(write_result); |
| 124 } | 129 } |
| 125 ASSERT_EQ(request_len, bytes_written); | 130 ASSERT_EQ(request_len, bytes_written); |
| 126 } | 131 } |
| 127 | 132 |
| 128 void WaitForAndVerifyHostMessage(int connection_id) { | 133 void WaitForResponseData(net::UnixDomainClientSocket* client_socket) { |
| 129 WaitForSendMessageToClient(); | 134 // The request data is reused for the response data. |
| 130 std::string expected_data; | 135 WaitForData(client_socket, sizeof(kRequestData)); |
| 131 expected_data.reserve(sizeof(kRequestData) - 4); | 136 } |
| 132 | 137 |
| 133 // Skip first four bytes and build up the response string. | 138 void WaitForErrorData(net::UnixDomainClientSocket* client_socket) { |
| 134 for (size_t i = 4; i < sizeof(kRequestData); ++i) { | 139 WaitForData(client_socket, sizeof(kSshErrorData)); |
| 135 expected_data.append(1, static_cast<unsigned char>(kRequestData[i])); | 140 } |
| 141 |
| 142 void WaitForData(net::UnixDomainClientSocket* socket, int request_len) { |
| 143 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(request_len)); |
| 144 scoped_refptr<net::DrainableIOBuffer> read_buffer( |
| 145 new net::DrainableIOBuffer(buffer.get(), request_len)); |
| 146 net::TestCompletionCallback read_callback; |
| 147 int bytes_read = 0; |
| 148 while (bytes_read < request_len) { |
| 149 int read_result = |
| 150 socket->Read(read_buffer.get(), read_buffer->BytesRemaining(), |
| 151 read_callback.callback()); |
| 152 read_result = read_callback.GetResult(read_result); |
| 153 ASSERT_GT(read_result, 0); |
| 154 bytes_read += read_result; |
| 155 ASSERT_LE(bytes_read, request_len); |
| 156 read_buffer->DidConsume(bytes_read); |
| 136 } | 157 } |
| 137 | 158 ASSERT_EQ(request_len, bytes_read); |
| 138 CheckHostDataMessage(connection_id, expected_data); | |
| 139 } | 159 } |
| 140 | 160 |
| 141 protected: | 161 protected: |
| 142 base::MessageLoopForIO message_loop_; | 162 base::MessageLoopForIO message_loop_; |
| 143 std::unique_ptr<base::RunLoop> run_loop_; | 163 std::unique_ptr<base::RunLoop> run_loop_; |
| 144 | 164 |
| 145 base::Thread file_thread_; | 165 base::Thread file_thread_; |
| 146 | 166 |
| 147 // Object under test. | 167 // Object under test. |
| 148 std::unique_ptr<SecurityKeyAuthHandler> auth_handler_; | 168 std::unique_ptr<SecurityKeyAuthHandler> auth_handler_; |
| 149 | 169 |
| 150 SecurityKeyAuthHandler::SendMessageCallback send_message_callback_; | 170 SecurityKeyAuthHandler::SendMessageCallback send_message_callback_; |
| 151 | 171 |
| 152 int last_connection_id_received_ = -1; | 172 int last_connection_id_received_ = -1; |
| 153 std::string last_message_received_; | 173 std::string last_message_received_; |
| 154 | 174 |
| 175 const std::string expected_request_data_; |
| 176 |
| 155 base::ScopedTempDir temp_dir_; | 177 base::ScopedTempDir temp_dir_; |
| 156 base::FilePath socket_path_; | 178 base::FilePath socket_path_; |
| 157 base::Closure accept_callback_; | 179 base::Closure accept_callback_; |
| 158 | 180 |
| 159 private: | 181 private: |
| 160 DISALLOW_COPY_AND_ASSIGN(SecurityKeyAuthHandlerPosixTest); | 182 DISALLOW_COPY_AND_ASSIGN(SecurityKeyAuthHandlerPosixTest); |
| 161 }; | 183 }; |
| 162 | 184 |
| 163 TEST_F(SecurityKeyAuthHandlerPosixTest, NotClosedAfterRequest) { | 185 TEST_F(SecurityKeyAuthHandlerPosixTest, NotClosedAfterRequest) { |
| 164 CreateSocketAndWait(); | 186 CreateSocketAndWait(); |
| 165 | 187 |
| 166 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); | 188 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); |
| 167 net::TestCompletionCallback connect_callback; | 189 net::TestCompletionCallback connect_callback; |
| 168 | 190 |
| 169 int rv = client_socket.Connect(connect_callback.callback()); | 191 int rv = client_socket.Connect(connect_callback.callback()); |
| 170 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); | 192 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); |
| 171 | 193 |
| 172 // Write the request and verify the response. | 194 // Write the request and verify the response. |
| 173 WriteRequestData(&client_socket); | 195 WriteRequestData(&client_socket); |
| 174 WaitForAndVerifyHostMessage(1); | 196 WaitForSendMessageToClient(); |
| 197 CheckHostDataMessage(1); |
| 198 |
| 199 auth_handler_->SendClientResponse(1, expected_request_data_); |
| 200 WaitForResponseData(&client_socket); |
| 175 | 201 |
| 176 // Verify the connection is now valid. | 202 // Verify the connection is now valid. |
| 177 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); | 203 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 178 | 204 |
| 179 // Verify that completing a request/response cycle didn't close the socket. | 205 // Verify that completing a request/response cycle didn't close the socket. |
| 180 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); | 206 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); |
| 181 } | 207 } |
| 182 | 208 |
| 183 TEST_F(SecurityKeyAuthHandlerPosixTest, HandleTwoRequests) { | 209 TEST_F(SecurityKeyAuthHandlerPosixTest, HandleTwoRequests) { |
| 184 CreateSocketAndWait(); | 210 CreateSocketAndWait(); |
| 185 | 211 |
| 186 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); | 212 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); |
| 187 net::TestCompletionCallback connect_callback; | 213 net::TestCompletionCallback connect_callback; |
| 188 | 214 |
| 189 int rv = client_socket.Connect(connect_callback.callback()); | 215 int rv = client_socket.Connect(connect_callback.callback()); |
| 190 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); | 216 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); |
| 191 | 217 |
| 192 // Write the request and verify the response. | 218 // Write the request and verify the response. |
| 193 WriteRequestData(&client_socket); | 219 WriteRequestData(&client_socket); |
| 194 WaitForAndVerifyHostMessage(1); | 220 WaitForSendMessageToClient(); |
| 221 CheckHostDataMessage(1); |
| 195 | 222 |
| 196 // Verify the connection is now valid. | 223 // Verify the connection is now valid. |
| 197 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); | 224 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 198 | 225 |
| 199 // Repeat the request/response cycle. | 226 // Send a 'client' response to the socket and verify the data is received. |
| 200 WriteRequestData(&client_socket); | 227 auth_handler_->SendClientResponse(1, expected_request_data_); |
| 201 WaitForAndVerifyHostMessage(1); | 228 WaitForResponseData(&client_socket); |
| 202 | 229 |
| 203 // Verify the connection is still valid. | 230 // Verify the connection is still valid. |
| 204 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); | 231 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 232 |
| 233 // Repeat the request/response cycle. |
| 234 WriteRequestData(&client_socket); |
| 235 WaitForSendMessageToClient(); |
| 236 CheckHostDataMessage(1); |
| 237 |
| 238 // Verify the connection is still valid. |
| 239 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 240 |
| 241 auth_handler_->SendClientResponse(1, expected_request_data_); |
| 242 WaitForResponseData(&client_socket); |
| 243 |
| 244 // Verify the connection is still valid. |
| 245 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 205 | 246 |
| 206 // Verify that completing two request/response cycles didn't close the | 247 // Verify that completing two request/response cycles didn't close the |
| 207 // socket. | 248 // socket. |
| 208 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); | 249 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); |
| 209 } | 250 } |
| 210 | 251 |
| 211 TEST_F(SecurityKeyAuthHandlerPosixTest, HandleTwoIndependentRequests) { | 252 TEST_F(SecurityKeyAuthHandlerPosixTest, HandleTwoIndependentRequests) { |
| 212 CreateSocketAndWait(); | 253 CreateSocketAndWait(); |
| 213 | 254 |
| 214 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); | 255 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); |
| 215 net::TestCompletionCallback connect_callback; | 256 net::TestCompletionCallback connect_callback; |
| 216 | 257 |
| 217 int rv = client_socket.Connect(connect_callback.callback()); | 258 int rv = client_socket.Connect(connect_callback.callback()); |
| 218 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); | 259 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); |
| 219 | 260 |
| 220 // Write the request and verify the response. | 261 // Write the request and verify the response. |
| 221 WriteRequestData(&client_socket); | 262 WriteRequestData(&client_socket); |
| 222 WaitForAndVerifyHostMessage(1); | 263 WaitForSendMessageToClient(); |
| 264 CheckHostDataMessage(1); |
| 223 | 265 |
| 224 // Verify the first connection is now valid. | 266 // Verify the first connection is now valid. |
| 225 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); | 267 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 226 | 268 |
| 269 // Send a 'client' response to the socket and verify the data is received. |
| 270 auth_handler_->SendClientResponse(1, expected_request_data_); |
| 271 WaitForResponseData(&client_socket); |
| 272 |
| 273 // Verify the connection is still valid. |
| 274 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 275 |
| 227 // Disconnect and establish a new connection. | 276 // Disconnect and establish a new connection. |
| 228 client_socket.Disconnect(); | 277 client_socket.Disconnect(); |
| 278 |
| 229 rv = client_socket.Connect(connect_callback.callback()); | 279 rv = client_socket.Connect(connect_callback.callback()); |
| 230 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); | 280 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); |
| 231 | 281 |
| 232 // Repeat the request/response cycle. | 282 // Repeat the request/response cycle. |
| 233 WriteRequestData(&client_socket); | 283 WriteRequestData(&client_socket); |
| 234 WaitForAndVerifyHostMessage(2); | 284 WaitForSendMessageToClient(); |
| 285 CheckHostDataMessage(2); |
| 286 |
| 287 // Verify the connection is now valid. |
| 288 ASSERT_TRUE(auth_handler_->IsValidConnectionId(2)); |
| 289 |
| 290 // Send a 'client' response to the socket and verify the data is received. |
| 291 auth_handler_->SendClientResponse(2, expected_request_data_); |
| 292 WaitForResponseData(&client_socket); |
| 235 | 293 |
| 236 // Verify the second connection is valid and the first is not. | 294 // Verify the second connection is valid and the first is not. |
| 237 ASSERT_TRUE(auth_handler_->IsValidConnectionId(2)); | 295 ASSERT_TRUE(auth_handler_->IsValidConnectionId(2)); |
| 238 ASSERT_FALSE(auth_handler_->IsValidConnectionId(1)); | 296 ASSERT_FALSE(auth_handler_->IsValidConnectionId(1)); |
| 239 | |
| 240 // Verify that the initial socket was released properly. | |
| 241 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); | 297 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); |
| 242 } | 298 } |
| 243 | 299 |
| 244 TEST_F(SecurityKeyAuthHandlerPosixTest, DidReadTimeout) { | 300 TEST_F(SecurityKeyAuthHandlerPosixTest, DoReadTimeout) { |
| 245 CreateSocketAndWait(); | 301 CreateSocketAndWait(); |
| 246 | 302 |
| 303 auth_handler_->SetRequestTimeoutForTest(base::TimeDelta()); |
| 304 |
| 247 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); | 305 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); |
| 248 net::TestCompletionCallback connect_callback; | 306 net::TestCompletionCallback connect_callback; |
| 249 int rv = client_socket.Connect(connect_callback.callback()); | 307 int rv = client_socket.Connect(connect_callback.callback()); |
| 250 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); | 308 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); |
| 251 auth_handler_->SetRequestTimeoutForTest(base::TimeDelta()); | 309 |
| 310 // SSH Error should be received when the connection times out. |
| 311 WaitForErrorData(&client_socket); |
| 312 |
| 313 // Connection should no longer be valid. |
| 314 ASSERT_FALSE(auth_handler_->IsValidConnectionId(1)); |
| 252 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); | 315 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); |
| 253 } | 316 } |
| 254 | 317 |
| 255 TEST_F(SecurityKeyAuthHandlerPosixTest, ClientErrorMessageDelivered) { | 318 TEST_F(SecurityKeyAuthHandlerPosixTest, ClientErrorMessageDelivered) { |
| 256 CreateSocketAndWait(); | 319 CreateSocketAndWait(); |
| 257 | 320 |
| 258 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); | 321 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); |
| 259 net::TestCompletionCallback connect_callback; | 322 net::TestCompletionCallback connect_callback; |
| 260 int rv = client_socket.Connect(connect_callback.callback()); | 323 int rv = client_socket.Connect(connect_callback.callback()); |
| 261 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); | 324 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); |
| 262 | 325 |
| 326 // 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. |
| 328 WriteRequestData(&client_socket); |
| 329 WaitForSendMessageToClient(); |
| 330 CheckHostDataMessage(1); |
| 331 |
| 332 // Send a 'client' response to the socket and verify the data is received. |
| 333 auth_handler_->SendClientResponse(1, expected_request_data_); |
| 334 WaitForResponseData(&client_socket); |
| 335 |
| 336 ASSERT_TRUE(auth_handler_->IsValidConnectionId(1)); |
| 337 ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest()); |
| 338 |
| 263 auth_handler_->SendErrorAndCloseConnection(1); | 339 auth_handler_->SendErrorAndCloseConnection(1); |
| 340 |
| 341 // Connection should be removed immediately. |
| 342 ASSERT_FALSE(auth_handler_->IsValidConnectionId(1)); |
| 264 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); | 343 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); |
| 344 |
| 345 // SSH Error should be received. |
| 346 WaitForErrorData(&client_socket); |
| 265 } | 347 } |
| 266 | 348 |
| 267 } // namespace remoting | 349 } // namespace remoting |
| OLD | NEW |