| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/protocol/jingle_session.h" | 5 #include "remoting/protocol/jingle_session.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/string_util.h" |
| 14 #include "base/test/test_timeouts.h" | 15 #include "base/test/test_timeouts.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "net/socket/socket.h" | 17 #include "net/socket/socket.h" |
| 17 #include "net/socket/stream_socket.h" | 18 #include "net/socket/stream_socket.h" |
| 18 #include "net/url_request/url_request_context_getter.h" | 19 #include "net/url_request/url_request_context_getter.h" |
| 19 #include "remoting/base/constants.h" | 20 #include "remoting/base/constants.h" |
| 20 #include "remoting/protocol/authenticator.h" | 21 #include "remoting/protocol/authenticator.h" |
| 21 #include "remoting/protocol/channel_authenticator.h" | 22 #include "remoting/protocol/channel_authenticator.h" |
| 22 #include "remoting/protocol/chromium_port_allocator_factory.h" | 23 #include "remoting/protocol/chromium_port_allocator_factory.h" |
| 23 #include "remoting/protocol/connection_tester.h" | 24 #include "remoting/protocol/connection_tester.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 base::RunLoop().RunUntilIdle(); | 137 base::RunLoop().RunUntilIdle(); |
| 137 } | 138 } |
| 138 | 139 |
| 139 void CloseSessions() { | 140 void CloseSessions() { |
| 140 host_session_.reset(); | 141 host_session_.reset(); |
| 141 client_session_.reset(); | 142 client_session_.reset(); |
| 142 } | 143 } |
| 143 | 144 |
| 144 void CreateSessionManagers(int auth_round_trips, int messages_till_start, | 145 void CreateSessionManagers(int auth_round_trips, int messages_till_start, |
| 145 FakeAuthenticator::Action auth_action) { | 146 FakeAuthenticator::Action auth_action) { |
| 146 host_signal_strategy_.reset(new FakeSignalStrategy(kHostJid)); | 147 if (!host_signal_strategy_) |
| 147 client_signal_strategy_.reset(new FakeSignalStrategy(kClientJid)); | 148 host_signal_strategy_.reset(new FakeSignalStrategy(kHostJid)); |
| 149 if (!client_signal_strategy_) |
| 150 client_signal_strategy_.reset(new FakeSignalStrategy(kClientJid)); |
| 148 FakeSignalStrategy::Connect(host_signal_strategy_.get(), | 151 FakeSignalStrategy::Connect(host_signal_strategy_.get(), |
| 149 client_signal_strategy_.get()); | 152 client_signal_strategy_.get()); |
| 150 | 153 |
| 151 host_server_.reset(new JingleSessionManager(host_signal_strategy_.get())); | 154 host_server_.reset(new JingleSessionManager(host_signal_strategy_.get())); |
| 152 host_server_->AcceptIncoming( | 155 host_server_->AcceptIncoming( |
| 153 base::Bind(&MockSessionManagerListener::OnIncomingSession, | 156 base::Bind(&MockSessionManagerListener::OnIncomingSession, |
| 154 base::Unretained(&host_server_listener_))); | 157 base::Unretained(&host_server_listener_))); |
| 155 | 158 |
| 156 std::unique_ptr<AuthenticatorFactory> factory( | 159 std::unique_ptr<AuthenticatorFactory> factory( |
| 157 new FakeHostAuthenticatorFactory(auth_round_trips, messages_till_start, | 160 new FakeHostAuthenticatorFactory(auth_round_trips, messages_till_start, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 .Times(1); | 227 .Times(1); |
| 225 // Expect that the connection will be closed eventually. | 228 // Expect that the connection will be closed eventually. |
| 226 EXPECT_CALL(client_session_event_handler_, | 229 EXPECT_CALL(client_session_event_handler_, |
| 227 OnSessionStateChange(Session::CLOSED)) | 230 OnSessionStateChange(Session::CLOSED)) |
| 228 .Times(AtMost(1)); | 231 .Times(AtMost(1)); |
| 229 } | 232 } |
| 230 } | 233 } |
| 231 | 234 |
| 232 void ConnectClient(std::unique_ptr<Authenticator> authenticator) { | 235 void ConnectClient(std::unique_ptr<Authenticator> authenticator) { |
| 233 client_session_ = | 236 client_session_ = |
| 234 client_server_->Connect(kHostJid, std::move(authenticator)); | 237 client_server_->Connect(host_jid_, std::move(authenticator)); |
| 235 client_session_->SetEventHandler(&client_session_event_handler_); | 238 client_session_->SetEventHandler(&client_session_event_handler_); |
| 236 client_session_->SetTransport(&client_transport_); | 239 client_session_->SetTransport(&client_transport_); |
| 237 base::RunLoop().RunUntilIdle(); | 240 base::RunLoop().RunUntilIdle(); |
| 238 } | 241 } |
| 239 | 242 |
| 240 void InitiateConnection(int auth_round_trips, | 243 void InitiateConnection(int auth_round_trips, |
| 241 FakeAuthenticator::Action auth_action, | 244 FakeAuthenticator::Action auth_action, |
| 242 bool expect_fail) { | 245 bool expect_fail) { |
| 243 SetHostExpectation(expect_fail); | 246 SetHostExpectation(expect_fail); |
| 244 SetClientExpectation(expect_fail); | 247 SetClientExpectation(expect_fail); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 255 .Times(AtLeast(1)); | 258 .Times(AtLeast(1)); |
| 256 } | 259 } |
| 257 | 260 |
| 258 std::unique_ptr<base::MessageLoopForIO> message_loop_; | 261 std::unique_ptr<base::MessageLoopForIO> message_loop_; |
| 259 | 262 |
| 260 NetworkSettings network_settings_; | 263 NetworkSettings network_settings_; |
| 261 | 264 |
| 262 std::unique_ptr<FakeSignalStrategy> host_signal_strategy_; | 265 std::unique_ptr<FakeSignalStrategy> host_signal_strategy_; |
| 263 std::unique_ptr<FakeSignalStrategy> client_signal_strategy_; | 266 std::unique_ptr<FakeSignalStrategy> client_signal_strategy_; |
| 264 | 267 |
| 268 std::string host_jid_ = kHostJid; |
| 269 |
| 265 std::unique_ptr<JingleSessionManager> host_server_; | 270 std::unique_ptr<JingleSessionManager> host_server_; |
| 266 MockSessionManagerListener host_server_listener_; | 271 MockSessionManagerListener host_server_listener_; |
| 267 std::unique_ptr<JingleSessionManager> client_server_; | 272 std::unique_ptr<JingleSessionManager> client_server_; |
| 268 | 273 |
| 269 std::unique_ptr<Session> host_session_; | 274 std::unique_ptr<Session> host_session_; |
| 270 MockSessionEventHandler host_session_event_handler_; | 275 MockSessionEventHandler host_session_event_handler_; |
| 271 FakeTransport host_transport_; | 276 FakeTransport host_transport_; |
| 272 std::unique_ptr<Session> client_session_; | 277 std::unique_ptr<Session> client_session_; |
| 273 MockSessionEventHandler client_session_event_handler_; | 278 MockSessionEventHandler client_session_event_handler_; |
| 274 FakeTransport client_transport_; | 279 FakeTransport client_transport_; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 ASSERT_GT(host_signal_strategy_->received_messages().size(), 0U); | 319 ASSERT_GT(host_signal_strategy_->received_messages().size(), 0U); |
| 315 const buzz::XmlElement* initiate_xml = | 320 const buzz::XmlElement* initiate_xml = |
| 316 host_signal_strategy_->received_messages().front(); | 321 host_signal_strategy_->received_messages().front(); |
| 317 const buzz::XmlElement* jingle_element = | 322 const buzz::XmlElement* jingle_element = |
| 318 initiate_xml->FirstNamed(buzz::QName("urn:xmpp:jingle:1", "jingle")); | 323 initiate_xml->FirstNamed(buzz::QName("urn:xmpp:jingle:1", "jingle")); |
| 319 ASSERT_TRUE(jingle_element); | 324 ASSERT_TRUE(jingle_element); |
| 320 ASSERT_EQ(kClientJid, | 325 ASSERT_EQ(kClientJid, |
| 321 jingle_element->Attr(buzz::QName(std::string(), "initiator"))); | 326 jingle_element->Attr(buzz::QName(std::string(), "initiator"))); |
| 322 } | 327 } |
| 323 | 328 |
| 329 TEST_F(JingleSessionTest, MixedCaseHostJid) { |
| 330 std::string host_jid = std::string("A") + kHostJid; |
| 331 host_signal_strategy_.reset(new FakeSignalStrategy(host_jid)); |
| 332 |
| 333 // Imitate host JID being lower-cased when stored in the directory. |
| 334 host_jid_ = base::ToLowerASCII(host_jid); |
| 335 |
| 336 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
| 337 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); |
| 338 } |
| 339 |
| 340 TEST_F(JingleSessionTest, MixedCaseClientJid) { |
| 341 client_signal_strategy_.reset( |
| 342 new FakeSignalStrategy(std::string("A") + kClientJid)); |
| 343 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
| 344 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); |
| 345 } |
| 346 |
| 324 // Verify that we can connect two endpoints with multi-step authentication. | 347 // Verify that we can connect two endpoints with multi-step authentication. |
| 325 TEST_F(JingleSessionTest, ConnectWithMultistep) { | 348 TEST_F(JingleSessionTest, ConnectWithMultistep) { |
| 326 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | 349 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); |
| 327 InitiateConnection(3, FakeAuthenticator::ACCEPT, false); | 350 InitiateConnection(3, FakeAuthenticator::ACCEPT, false); |
| 328 } | 351 } |
| 329 | 352 |
| 330 TEST_F(JingleSessionTest, ConnectWithOutOfOrderIqs) { | 353 TEST_F(JingleSessionTest, ConnectWithOutOfOrderIqs) { |
| 331 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 354 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); |
| 332 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); | 355 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); |
| 333 client_signal_strategy_->SimulateMessageReordering(); | 356 client_signal_strategy_->SimulateMessageReordering(); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 base::RunLoop().RunUntilIdle(); | 550 base::RunLoop().RunUntilIdle(); |
| 528 | 551 |
| 529 // Verify that transport-info that the first transport-info message was | 552 // Verify that transport-info that the first transport-info message was |
| 530 // received. | 553 // received. |
| 531 ASSERT_EQ(client_transport_.received_messages().size(), 1U); | 554 ASSERT_EQ(client_transport_.received_messages().size(), 1U); |
| 532 EXPECT_EQ("1", client_transport_.received_messages()[0]->Attr(buzz::QN_ID)); | 555 EXPECT_EQ("1", client_transport_.received_messages()[0]->Attr(buzz::QN_ID)); |
| 533 } | 556 } |
| 534 | 557 |
| 535 } // namespace protocol | 558 } // namespace protocol |
| 536 } // namespace remoting | 559 } // namespace remoting |
| OLD | NEW |