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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 using testing::Return; | 45 using testing::Return; |
46 using testing::SaveArg; | 46 using testing::SaveArg; |
47 using testing::SetArgumentPointee; | 47 using testing::SetArgumentPointee; |
48 using testing::WithArg; | 48 using testing::WithArg; |
49 | 49 |
50 namespace remoting { | 50 namespace remoting { |
51 namespace protocol { | 51 namespace protocol { |
52 | 52 |
53 namespace { | 53 namespace { |
54 | 54 |
55 const char kHostJid[] = "host@gmail.com/123"; | 55 const char kHostJid[] = "Host@gmail.com/123"; |
56 const char kClientJid[] = "client@gmail.com/321"; | 56 const char kClientJid[] = "Client@gmail.com/321"; |
| 57 |
| 58 // kHostJid the way it would be stored in the directory. |
| 59 const char kNormalizedHostJid[] = "host@gmail.com/123"; |
57 | 60 |
58 class MockSessionManagerListener { | 61 class MockSessionManagerListener { |
59 public: | 62 public: |
60 MOCK_METHOD2(OnIncomingSession, | 63 MOCK_METHOD2(OnIncomingSession, |
61 void(Session*, | 64 void(Session*, |
62 SessionManager::IncomingSessionResponse*)); | 65 SessionManager::IncomingSessionResponse*)); |
63 }; | 66 }; |
64 | 67 |
65 class MockSessionEventHandler : public Session::EventHandler { | 68 class MockSessionEventHandler : public Session::EventHandler { |
66 public: | 69 public: |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 CloseSessions(); | 178 CloseSessions(); |
176 CloseSessionManager(); | 179 CloseSessionManager(); |
177 base::RunLoop().RunUntilIdle(); | 180 base::RunLoop().RunUntilIdle(); |
178 } | 181 } |
179 | 182 |
180 void CloseSessions() { | 183 void CloseSessions() { |
181 host_session_.reset(); | 184 host_session_.reset(); |
182 client_session_.reset(); | 185 client_session_.reset(); |
183 } | 186 } |
184 | 187 |
185 void CreateSessionManagers(int auth_round_trips, int messages_till_start, | 188 void CreateSessionManagers(FakeAuthenticator::Config auth_config, |
186 FakeAuthenticator::Action auth_action) { | 189 int messages_till_start) { |
187 if (!host_signal_strategy_) { | 190 host_signal_strategy_ = |
188 host_signal_strategy_.reset( | 191 base::MakeUnique<FakeSignalStrategy>(SignalingAddress(kHostJid)); |
189 new FakeSignalStrategy(SignalingAddress(kHostJid))); | 192 client_signal_strategy_ = |
190 } | 193 base::MakeUnique<FakeSignalStrategy>(SignalingAddress(kClientJid)); |
191 if (!client_signal_strategy_) { | 194 |
192 client_signal_strategy_.reset( | |
193 new FakeSignalStrategy(SignalingAddress(kClientJid))); | |
194 } | |
195 FakeSignalStrategy::Connect(host_signal_strategy_.get(), | 195 FakeSignalStrategy::Connect(host_signal_strategy_.get(), |
196 client_signal_strategy_.get()); | 196 client_signal_strategy_.get()); |
197 | 197 |
198 host_server_.reset(new JingleSessionManager(host_signal_strategy_.get())); | 198 host_server_.reset(new JingleSessionManager(host_signal_strategy_.get())); |
199 host_server_->AcceptIncoming( | 199 host_server_->AcceptIncoming( |
200 base::Bind(&MockSessionManagerListener::OnIncomingSession, | 200 base::Bind(&MockSessionManagerListener::OnIncomingSession, |
201 base::Unretained(&host_server_listener_))); | 201 base::Unretained(&host_server_listener_))); |
202 | 202 |
203 std::unique_ptr<AuthenticatorFactory> factory( | 203 std::unique_ptr<AuthenticatorFactory> factory( |
204 new FakeHostAuthenticatorFactory(auth_round_trips, messages_till_start, | 204 new FakeHostAuthenticatorFactory(messages_till_start, auth_config)); |
205 auth_action, true)); | |
206 host_server_->set_authenticator_factory(std::move(factory)); | 205 host_server_->set_authenticator_factory(std::move(factory)); |
207 | 206 |
208 client_server_.reset( | 207 client_server_.reset( |
209 new JingleSessionManager(client_signal_strategy_.get())); | 208 new JingleSessionManager(client_signal_strategy_.get())); |
210 } | 209 } |
211 | 210 |
212 void CreateSessionManagers(int auth_round_trips, | 211 void CreateSessionManagers(FakeAuthenticator::Config auth_config) { |
213 FakeAuthenticator::Action auth_action) { | 212 CreateSessionManagers(auth_config, 0); |
214 CreateSessionManagers(auth_round_trips, 0, auth_action); | |
215 } | 213 } |
216 | 214 |
217 void CloseSessionManager() { | 215 void CloseSessionManager() { |
218 host_server_.reset(); | 216 host_server_.reset(); |
219 client_server_.reset(); | 217 client_server_.reset(); |
220 host_signal_strategy_.reset(); | 218 host_signal_strategy_.reset(); |
221 client_signal_strategy_.reset(); | 219 client_signal_strategy_.reset(); |
222 } | 220 } |
223 | 221 |
224 void SetHostExpectation(bool expect_fail) { | 222 void SetHostExpectation(bool expect_fail) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 OnSessionStateChange(Session::AUTHENTICATED)) | 268 OnSessionStateChange(Session::AUTHENTICATED)) |
271 .Times(1); | 269 .Times(1); |
272 // Expect that the connection will be closed eventually. | 270 // Expect that the connection will be closed eventually. |
273 EXPECT_CALL(client_session_event_handler_, | 271 EXPECT_CALL(client_session_event_handler_, |
274 OnSessionStateChange(Session::CLOSED)) | 272 OnSessionStateChange(Session::CLOSED)) |
275 .Times(AtMost(1)); | 273 .Times(AtMost(1)); |
276 } | 274 } |
277 } | 275 } |
278 | 276 |
279 void ConnectClient(std::unique_ptr<Authenticator> authenticator) { | 277 void ConnectClient(std::unique_ptr<Authenticator> authenticator) { |
280 client_session_ = client_server_->Connect(SignalingAddress(host_jid_), | 278 client_session_ = client_server_->Connect( |
281 std::move(authenticator)); | 279 SignalingAddress(kNormalizedHostJid), std::move(authenticator)); |
282 client_session_->SetEventHandler(&client_session_event_handler_); | 280 client_session_->SetEventHandler(&client_session_event_handler_); |
283 client_session_->SetTransport(&client_transport_); | 281 client_session_->SetTransport(&client_transport_); |
284 client_session_->AddPlugin(&client_plugin_); | 282 client_session_->AddPlugin(&client_plugin_); |
285 base::RunLoop().RunUntilIdle(); | 283 base::RunLoop().RunUntilIdle(); |
286 } | 284 } |
287 | 285 |
288 void InitiateConnection(int auth_round_trips, | 286 void ConnectClient(FakeAuthenticator::Config auth_config) { |
289 FakeAuthenticator::Action auth_action, | 287 ConnectClient(base::MakeUnique<FakeAuthenticator>( |
| 288 FakeAuthenticator::CLIENT, auth_config, |
| 289 client_signal_strategy_->GetLocalAddress().id(), kNormalizedHostJid)); |
| 290 } |
| 291 |
| 292 void InitiateConnection(FakeAuthenticator::Config auth_config, |
290 bool expect_fail) { | 293 bool expect_fail) { |
291 SetHostExpectation(expect_fail); | 294 SetHostExpectation(expect_fail); |
292 SetClientExpectation(expect_fail); | 295 SetClientExpectation(expect_fail); |
293 ConnectClient(base::MakeUnique<FakeAuthenticator>( | 296 ConnectClient(auth_config); |
294 FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); | |
295 } | 297 } |
296 | 298 |
297 void ExpectRouteChange(const std::string& channel_name) { | 299 void ExpectRouteChange(const std::string& channel_name) { |
298 EXPECT_CALL(host_session_event_handler_, | 300 EXPECT_CALL(host_session_event_handler_, |
299 OnSessionRouteChange(channel_name, _)) | 301 OnSessionRouteChange(channel_name, _)) |
300 .Times(AtLeast(1)); | 302 .Times(AtLeast(1)); |
301 EXPECT_CALL(client_session_event_handler_, | 303 EXPECT_CALL(client_session_event_handler_, |
302 OnSessionRouteChange(channel_name, _)) | 304 OnSessionRouteChange(channel_name, _)) |
303 .Times(AtLeast(1)); | 305 .Times(AtLeast(1)); |
304 } | 306 } |
(...skipping 14 matching lines...) Expand all Loading... |
319 } | 321 } |
320 } | 322 } |
321 | 323 |
322 std::unique_ptr<base::MessageLoopForIO> message_loop_; | 324 std::unique_ptr<base::MessageLoopForIO> message_loop_; |
323 | 325 |
324 NetworkSettings network_settings_; | 326 NetworkSettings network_settings_; |
325 | 327 |
326 std::unique_ptr<FakeSignalStrategy> host_signal_strategy_; | 328 std::unique_ptr<FakeSignalStrategy> host_signal_strategy_; |
327 std::unique_ptr<FakeSignalStrategy> client_signal_strategy_; | 329 std::unique_ptr<FakeSignalStrategy> client_signal_strategy_; |
328 | 330 |
329 std::string host_jid_ = kHostJid; | |
330 | |
331 std::unique_ptr<JingleSessionManager> host_server_; | 331 std::unique_ptr<JingleSessionManager> host_server_; |
332 MockSessionManagerListener host_server_listener_; | 332 MockSessionManagerListener host_server_listener_; |
333 std::unique_ptr<JingleSessionManager> client_server_; | 333 std::unique_ptr<JingleSessionManager> client_server_; |
334 | 334 |
335 std::unique_ptr<Session> host_session_; | 335 std::unique_ptr<Session> host_session_; |
336 MockSessionEventHandler host_session_event_handler_; | 336 MockSessionEventHandler host_session_event_handler_; |
337 FakeTransport host_transport_; | 337 FakeTransport host_transport_; |
338 std::unique_ptr<Session> client_session_; | 338 std::unique_ptr<Session> client_session_; |
339 MockSessionEventHandler client_session_event_handler_; | 339 MockSessionEventHandler client_session_event_handler_; |
340 FakeTransport client_transport_; | 340 FakeTransport client_transport_; |
341 | 341 |
342 FakePlugin host_plugin_; | 342 FakePlugin host_plugin_; |
343 FakePlugin client_plugin_; | 343 FakePlugin client_plugin_; |
344 }; | 344 }; |
345 | 345 |
346 | 346 |
347 // Verify that we can create and destroy session managers without a | 347 // Verify that we can create and destroy session managers without a |
348 // connection. | 348 // connection. |
349 TEST_F(JingleSessionTest, CreateAndDestoy) { | 349 TEST_F(JingleSessionTest, CreateAndDestoy) { |
350 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 350 CreateSessionManagers(FakeAuthenticator::Config(FakeAuthenticator::ACCEPT)); |
351 } | 351 } |
352 | 352 |
353 // Verify that an incoming session can be rejected, and that the | 353 // Verify that an incoming session can be rejected, and that the |
354 // status of the connection is set to FAILED in this case. | 354 // status of the connection is set to FAILED in this case. |
355 TEST_F(JingleSessionTest, RejectConnection) { | 355 TEST_F(JingleSessionTest, RejectConnection) { |
356 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 356 CreateSessionManagers(FakeAuthenticator::Config(FakeAuthenticator::ACCEPT)); |
357 | 357 |
358 // Reject incoming session. | 358 // Reject incoming session. |
359 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) | 359 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) |
360 .WillOnce(SetArgumentPointee<1>(protocol::SessionManager::DECLINE)); | 360 .WillOnce(SetArgumentPointee<1>(protocol::SessionManager::DECLINE)); |
361 | 361 |
362 { | 362 { |
363 InSequence dummy; | 363 InSequence dummy; |
364 EXPECT_CALL(client_session_event_handler_, | 364 EXPECT_CALL(client_session_event_handler_, |
365 OnSessionStateChange(Session::FAILED)) | 365 OnSessionStateChange(Session::FAILED)) |
366 .Times(1); | 366 .Times(1); |
367 } | 367 } |
368 | 368 |
369 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator( | 369 ConnectClient(FakeAuthenticator::Config(FakeAuthenticator::ACCEPT)); |
370 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true)); | |
371 client_session_ = client_server_->Connect(SignalingAddress(kHostJid), | |
372 std::move(authenticator)); | |
373 client_session_->SetEventHandler(&client_session_event_handler_); | 370 client_session_->SetEventHandler(&client_session_event_handler_); |
374 | 371 |
375 base::RunLoop().RunUntilIdle(); | 372 base::RunLoop().RunUntilIdle(); |
376 } | 373 } |
377 | 374 |
378 // Verify that we can connect two endpoints with single-step authentication. | 375 // Verify that we can connect two endpoints with single-step authentication. |
379 TEST_F(JingleSessionTest, Connect) { | 376 TEST_F(JingleSessionTest, Connect) { |
380 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 377 CreateSessionManagers(FakeAuthenticator::Config(FakeAuthenticator::ACCEPT)); |
381 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); | 378 InitiateConnection(FakeAuthenticator::Config(), false); |
382 | 379 |
383 // Verify that the client specified correct initiator value. | 380 // Verify that the client specified correct initiator value. |
384 ASSERT_GT(host_signal_strategy_->received_messages().size(), 0U); | 381 ASSERT_GT(host_signal_strategy_->received_messages().size(), 0U); |
385 const buzz::XmlElement* initiate_xml = | 382 const buzz::XmlElement* initiate_xml = |
386 host_signal_strategy_->received_messages().front(); | 383 host_signal_strategy_->received_messages().front(); |
387 const buzz::XmlElement* jingle_element = | 384 const buzz::XmlElement* jingle_element = |
388 initiate_xml->FirstNamed(buzz::QName("urn:xmpp:jingle:1", "jingle")); | 385 initiate_xml->FirstNamed(buzz::QName("urn:xmpp:jingle:1", "jingle")); |
389 ASSERT_TRUE(jingle_element); | 386 ASSERT_TRUE(jingle_element); |
390 ASSERT_EQ(kClientJid, | 387 ASSERT_EQ(client_signal_strategy_->GetLocalAddress().id(), |
391 jingle_element->Attr(buzz::QName(std::string(), "initiator"))); | 388 jingle_element->Attr(buzz::QName(std::string(), "initiator"))); |
392 } | 389 } |
393 | 390 |
394 TEST_F(JingleSessionTest, MixedCaseHostJid) { | |
395 std::string host_jid = std::string("A") + kHostJid; | |
396 host_signal_strategy_.reset( | |
397 new FakeSignalStrategy(SignalingAddress(host_jid))); | |
398 | |
399 // Imitate host JID being lower-cased when stored in the directory. | |
400 host_jid_ = base::ToLowerASCII(host_jid); | |
401 | |
402 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | |
403 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); | |
404 } | |
405 | |
406 TEST_F(JingleSessionTest, MixedCaseClientJid) { | |
407 client_signal_strategy_.reset( | |
408 new FakeSignalStrategy(SignalingAddress(std::string("A") + kClientJid))); | |
409 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | |
410 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); | |
411 } | |
412 | |
413 // Verify that we can connect two endpoints with multi-step authentication. | 391 // Verify that we can connect two endpoints with multi-step authentication. |
414 TEST_F(JingleSessionTest, ConnectWithMultistep) { | 392 TEST_F(JingleSessionTest, ConnectWithMultistep) { |
415 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | 393 const int kAuthRoundtrips = 3; |
416 InitiateConnection(3, FakeAuthenticator::ACCEPT, false); | 394 FakeAuthenticator::Config auth_config(kAuthRoundtrips, |
| 395 FakeAuthenticator::ACCEPT, true); |
| 396 CreateSessionManagers(auth_config); |
| 397 InitiateConnection(auth_config, false); |
417 } | 398 } |
418 | 399 |
419 TEST_F(JingleSessionTest, ConnectWithOutOfOrderIqs) { | 400 TEST_F(JingleSessionTest, ConnectWithOutOfOrderIqs) { |
420 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 401 CreateSessionManagers(FakeAuthenticator::Config(FakeAuthenticator::ACCEPT)); |
421 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); | 402 InitiateConnection(FakeAuthenticator::Config(), false); |
422 client_signal_strategy_->SimulateMessageReordering(); | 403 client_signal_strategy_->SimulateMessageReordering(); |
423 | 404 |
424 // Verify that out of order transport messages are received correctly. | 405 // Verify that out of order transport messages are received correctly. |
425 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("1")); | 406 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("1")); |
426 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("2")); | 407 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("2")); |
427 base::RunLoop().RunUntilIdle(); | 408 base::RunLoop().RunUntilIdle(); |
428 | 409 |
429 ASSERT_EQ(client_transport_.received_messages().size(), 2U); | 410 ASSERT_EQ(client_transport_.received_messages().size(), 2U); |
430 EXPECT_EQ("1", client_transport_.received_messages()[0]->Attr(buzz::QN_ID)); | 411 EXPECT_EQ("1", client_transport_.received_messages()[0]->Attr(buzz::QN_ID)); |
431 EXPECT_EQ("2", client_transport_.received_messages()[1]->Attr(buzz::QN_ID)); | 412 EXPECT_EQ("2", client_transport_.received_messages()[1]->Attr(buzz::QN_ID)); |
432 } | 413 } |
433 | 414 |
434 // Verify that out-of-order messages are handled correctly when the session is | 415 // Verify that out-of-order messages are handled correctly when the session is |
435 // torn down after the first message. | 416 // torn down after the first message. |
436 TEST_F(JingleSessionTest, ConnectWithOutOfOrderIqsDestroyOnFirstMessage) { | 417 TEST_F(JingleSessionTest, ConnectWithOutOfOrderIqsDestroyOnFirstMessage) { |
437 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 418 CreateSessionManagers(FakeAuthenticator::Config(FakeAuthenticator::ACCEPT)); |
438 InitiateConnection(1, FakeAuthenticator::ACCEPT, false); | 419 InitiateConnection(FakeAuthenticator::Config(), false); |
439 client_signal_strategy_->SimulateMessageReordering(); | 420 client_signal_strategy_->SimulateMessageReordering(); |
440 | 421 |
441 // Verify that out of order transport messages are received correctly. | 422 // Verify that out of order transport messages are received correctly. |
442 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("1")); | 423 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("1")); |
443 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("2")); | 424 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("2")); |
444 | 425 |
445 // Destroy the session as soon as the first message is received. | 426 // Destroy the session as soon as the first message is received. |
446 client_transport_.set_on_message_callback(base::Bind( | 427 client_transport_.set_on_message_callback(base::Bind( |
447 &JingleSessionTest::DeleteClientSession, base::Unretained(this))); | 428 &JingleSessionTest::DeleteClientSession, base::Unretained(this))); |
448 | 429 |
449 base::RunLoop().RunUntilIdle(); | 430 base::RunLoop().RunUntilIdle(); |
450 | 431 |
451 ASSERT_EQ(client_transport_.received_messages().size(), 1U); | 432 ASSERT_EQ(client_transport_.received_messages().size(), 1U); |
452 EXPECT_EQ("1", client_transport_.received_messages()[0]->Attr(buzz::QN_ID)); | 433 EXPECT_EQ("1", client_transport_.received_messages()[0]->Attr(buzz::QN_ID)); |
453 } | 434 } |
454 | 435 |
455 // Verify that connection is terminated when single-step auth fails. | 436 // Verify that connection is terminated when single-step auth fails. |
456 TEST_F(JingleSessionTest, ConnectWithBadAuth) { | 437 TEST_F(JingleSessionTest, ConnectWithBadAuth) { |
457 CreateSessionManagers(1, FakeAuthenticator::REJECT); | 438 CreateSessionManagers(FakeAuthenticator::Config(FakeAuthenticator::REJECT)); |
458 InitiateConnection(1, FakeAuthenticator::ACCEPT, true); | 439 InitiateConnection(FakeAuthenticator::Config(), true); |
459 } | 440 } |
460 | 441 |
461 // Verify that connection is terminated when multi-step auth fails. | 442 // Verify that connection is terminated when multi-step auth fails. |
462 TEST_F(JingleSessionTest, ConnectWithBadMultistepAuth) { | 443 TEST_F(JingleSessionTest, ConnectWithBadMultistepAuth) { |
463 CreateSessionManagers(3, FakeAuthenticator::REJECT); | 444 const int kAuthRoundtrips = 3; |
464 InitiateConnection(3, FakeAuthenticator::ACCEPT, true); | 445 CreateSessionManagers(FakeAuthenticator::Config( |
| 446 kAuthRoundtrips, FakeAuthenticator::REJECT, false)); |
| 447 InitiateConnection(FakeAuthenticator::Config( |
| 448 kAuthRoundtrips, FakeAuthenticator::ACCEPT, false), |
| 449 true); |
465 } | 450 } |
466 | 451 |
467 // Verify that incompatible protocol configuration is handled properly. | 452 // Verify that incompatible protocol configuration is handled properly. |
468 TEST_F(JingleSessionTest, TestIncompatibleProtocol) { | 453 TEST_F(JingleSessionTest, TestIncompatibleProtocol) { |
469 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 454 CreateSessionManagers(FakeAuthenticator::Config(FakeAuthenticator::ACCEPT)); |
470 | 455 |
471 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)).Times(0); | 456 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)).Times(0); |
472 | 457 |
473 EXPECT_CALL(client_session_event_handler_, | 458 EXPECT_CALL(client_session_event_handler_, |
474 OnSessionStateChange(Session::FAILED)) | 459 OnSessionStateChange(Session::FAILED)) |
475 .Times(1); | 460 .Times(1); |
476 | 461 |
477 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator( | |
478 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true)); | |
479 | |
480 std::unique_ptr<CandidateSessionConfig> config = | 462 std::unique_ptr<CandidateSessionConfig> config = |
481 CandidateSessionConfig::CreateDefault(); | 463 CandidateSessionConfig::CreateDefault(); |
482 // Disable all video codecs so the host will reject connection. | 464 // Disable all video codecs so the host will reject connection. |
483 config->mutable_video_configs()->clear(); | 465 config->mutable_video_configs()->clear(); |
484 client_server_->set_protocol_config(std::move(config)); | 466 client_server_->set_protocol_config(std::move(config)); |
485 client_session_ = client_server_->Connect(SignalingAddress(kHostJid), | 467 ConnectClient(FakeAuthenticator::Config(FakeAuthenticator::ACCEPT)); |
486 std::move(authenticator)); | |
487 client_session_->SetEventHandler(&client_session_event_handler_); | |
488 | |
489 base::RunLoop().RunUntilIdle(); | |
490 | 468 |
491 EXPECT_EQ(INCOMPATIBLE_PROTOCOL, client_session_->error()); | 469 EXPECT_EQ(INCOMPATIBLE_PROTOCOL, client_session_->error()); |
492 EXPECT_FALSE(host_session_); | 470 EXPECT_FALSE(host_session_); |
493 } | 471 } |
494 | 472 |
495 // Verify that GICE-only client is rejected with an appropriate error code. | 473 // Verify that GICE-only client is rejected with an appropriate error code. |
496 TEST_F(JingleSessionTest, TestLegacyIceConnection) { | 474 TEST_F(JingleSessionTest, TestLegacyIceConnection) { |
497 CreateSessionManagers(1, FakeAuthenticator::ACCEPT); | 475 CreateSessionManagers(FakeAuthenticator::Config(FakeAuthenticator::ACCEPT)); |
498 | 476 |
499 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)).Times(0); | 477 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)).Times(0); |
500 | 478 |
501 EXPECT_CALL(client_session_event_handler_, | 479 EXPECT_CALL(client_session_event_handler_, |
502 OnSessionStateChange(Session::FAILED)) | 480 OnSessionStateChange(Session::FAILED)) |
503 .Times(1); | 481 .Times(1); |
504 | 482 |
505 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator( | |
506 FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true)); | |
507 | |
508 std::unique_ptr<CandidateSessionConfig> config = | 483 std::unique_ptr<CandidateSessionConfig> config = |
509 CandidateSessionConfig::CreateDefault(); | 484 CandidateSessionConfig::CreateDefault(); |
510 config->set_ice_supported(false); | 485 config->set_ice_supported(false); |
511 client_server_->set_protocol_config(std::move(config)); | 486 client_server_->set_protocol_config(std::move(config)); |
512 client_session_ = client_server_->Connect(SignalingAddress(kHostJid), | 487 ConnectClient(FakeAuthenticator::Config(FakeAuthenticator::ACCEPT)); |
513 std::move(authenticator)); | |
514 client_session_->SetEventHandler(&client_session_event_handler_); | |
515 | |
516 base::RunLoop().RunUntilIdle(); | |
517 | 488 |
518 EXPECT_EQ(INCOMPATIBLE_PROTOCOL, client_session_->error()); | 489 EXPECT_EQ(INCOMPATIBLE_PROTOCOL, client_session_->error()); |
519 EXPECT_FALSE(host_session_); | 490 EXPECT_FALSE(host_session_); |
520 } | 491 } |
521 | 492 |
522 TEST_F(JingleSessionTest, DeleteSessionOnIncomingConnection) { | 493 TEST_F(JingleSessionTest, DeleteSessionOnIncomingConnection) { |
523 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | 494 const int kAuthRoundtrips = 3; |
| 495 FakeAuthenticator::Config auth_config(kAuthRoundtrips, |
| 496 FakeAuthenticator::ACCEPT, true); |
| 497 CreateSessionManagers(auth_config); |
524 | 498 |
525 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) | 499 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) |
526 .WillOnce(DoAll( | 500 .WillOnce(DoAll( |
527 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), | 501 WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), |
528 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); | 502 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); |
529 | 503 |
530 EXPECT_CALL(host_session_event_handler_, | 504 EXPECT_CALL(host_session_event_handler_, |
531 OnSessionStateChange(Session::ACCEPTED)) | 505 OnSessionStateChange(Session::ACCEPTED)) |
532 .Times(AtMost(1)); | 506 .Times(AtMost(1)); |
533 | 507 |
534 EXPECT_CALL(host_session_event_handler_, | 508 EXPECT_CALL(host_session_event_handler_, |
535 OnSessionStateChange(Session::AUTHENTICATING)) | 509 OnSessionStateChange(Session::AUTHENTICATING)) |
536 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteHostSession)); | 510 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteHostSession)); |
537 | 511 |
538 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator( | 512 ConnectClient(auth_config); |
539 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true)); | |
540 | |
541 client_session_ = client_server_->Connect(SignalingAddress(kHostJid), | |
542 std::move(authenticator)); | |
543 | |
544 base::RunLoop().RunUntilIdle(); | |
545 } | 513 } |
546 | 514 |
547 TEST_F(JingleSessionTest, DeleteSessionOnAuth) { | 515 TEST_F(JingleSessionTest, DeleteSessionOnAuth) { |
548 // Same as the previous test, but set messages_till_started to 2 in | 516 // Same as the previous test, but set messages_till_started to 2 in |
549 // CreateSessionManagers so that the session will goes into the | 517 // CreateSessionManagers so that the session will goes into the |
550 // AUTHENTICATING state after two message exchanges. | 518 // AUTHENTICATING state after two message exchanges. |
551 CreateSessionManagers(3, 2, FakeAuthenticator::ACCEPT); | 519 const int kMessagesTillStarted = 2; |
| 520 |
| 521 const int kAuthRoundtrips = 3; |
| 522 FakeAuthenticator::Config auth_config(kAuthRoundtrips, |
| 523 FakeAuthenticator::ACCEPT, true); |
| 524 CreateSessionManagers(auth_config, kMessagesTillStarted); |
552 | 525 |
553 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) | 526 EXPECT_CALL(host_server_listener_, OnIncomingSession(_, _)) |
554 .WillOnce( | 527 .WillOnce( |
555 DoAll(WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), | 528 DoAll(WithArg<0>(Invoke(this, &JingleSessionTest::SetHostSession)), |
556 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); | 529 SetArgumentPointee<1>(protocol::SessionManager::ACCEPT))); |
557 | 530 |
558 EXPECT_CALL(host_session_event_handler_, | 531 EXPECT_CALL(host_session_event_handler_, |
559 OnSessionStateChange(Session::ACCEPTED)) | 532 OnSessionStateChange(Session::ACCEPTED)) |
560 .Times(AtMost(1)); | 533 .Times(AtMost(1)); |
561 | 534 |
562 EXPECT_CALL(host_session_event_handler_, | 535 EXPECT_CALL(host_session_event_handler_, |
563 OnSessionStateChange(Session::AUTHENTICATING)) | 536 OnSessionStateChange(Session::AUTHENTICATING)) |
564 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteHostSession)); | 537 .WillOnce(InvokeWithoutArgs(this, &JingleSessionTest::DeleteHostSession)); |
565 | 538 |
566 std::unique_ptr<Authenticator> authenticator(new FakeAuthenticator( | 539 ConnectClient(auth_config); |
567 FakeAuthenticator::CLIENT, 3, FakeAuthenticator::ACCEPT, true)); | |
568 | |
569 client_session_ = client_server_->Connect(SignalingAddress(kHostJid), | |
570 std::move(authenticator)); | |
571 base::RunLoop().RunUntilIdle(); | |
572 } | |
573 | |
574 // Verify that we can connect with multistep authentication. | |
575 TEST_F(JingleSessionTest, TestMultistepAuth) { | |
576 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | |
577 ASSERT_NO_FATAL_FAILURE( | |
578 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); | |
579 } | 540 } |
580 | 541 |
581 // Verify that incoming transport-info messages are handled correctly while in | 542 // Verify that incoming transport-info messages are handled correctly while in |
582 // AUTHENTICATING state. | 543 // AUTHENTICATING state. |
583 TEST_F(JingleSessionTest, TransportInfoDuringAuthentication) { | 544 TEST_F(JingleSessionTest, TransportInfoDuringAuthentication) { |
584 CreateSessionManagers(2, FakeAuthenticator::ACCEPT); | 545 const int kAuthRoundtrips = 2; |
| 546 FakeAuthenticator::Config auth_config(kAuthRoundtrips, |
| 547 FakeAuthenticator::ACCEPT, true); |
| 548 |
| 549 CreateSessionManagers(auth_config); |
585 | 550 |
586 SetHostExpectation(false); | 551 SetHostExpectation(false); |
587 { | 552 { |
588 InSequence dummy; | 553 InSequence dummy; |
589 | 554 |
590 EXPECT_CALL(client_session_event_handler_, | 555 EXPECT_CALL(client_session_event_handler_, |
591 OnSessionStateChange(Session::ACCEPTED)) | 556 OnSessionStateChange(Session::ACCEPTED)) |
592 .Times(AtMost(1)); | 557 .Times(AtMost(1)); |
593 EXPECT_CALL(client_session_event_handler_, | 558 EXPECT_CALL(client_session_event_handler_, |
594 OnSessionStateChange(Session::AUTHENTICATING)) | 559 OnSessionStateChange(Session::AUTHENTICATING)) |
595 .Times(AtMost(1)); | 560 .Times(AtMost(1)); |
596 } | 561 } |
597 | 562 |
598 // Create connection and pause it before authentication is finished. | 563 // Create connection and pause it before authentication is finished. |
599 FakeAuthenticator* authenticator = new FakeAuthenticator( | 564 FakeAuthenticator* authenticator = new FakeAuthenticator( |
600 FakeAuthenticator::CLIENT, 2, FakeAuthenticator::ACCEPT, true); | 565 FakeAuthenticator::CLIENT, auth_config, |
| 566 client_signal_strategy_->GetLocalAddress().id(), kNormalizedHostJid); |
601 authenticator->set_pause_message_index(4); | 567 authenticator->set_pause_message_index(4); |
602 ConnectClient(base::WrapUnique(authenticator)); | 568 ConnectClient(base::WrapUnique(authenticator)); |
603 | 569 |
604 // Send 2 transport messages. | 570 // Send 2 transport messages. |
605 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("1")); | 571 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("1")); |
606 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("2")); | 572 host_transport_.send_transport_info_callback().Run(CreateTransportInfo("2")); |
607 | 573 |
608 base::RunLoop().RunUntilIdle(); | 574 base::RunLoop().RunUntilIdle(); |
609 | 575 |
610 // The transport-info messages should not be received here because | 576 // The transport-info messages should not be received here because |
(...skipping 10 matching lines...) Expand all Loading... |
621 | 587 |
622 // Verify that transport-info that the first transport-info message was | 588 // Verify that transport-info that the first transport-info message was |
623 // received. | 589 // received. |
624 ASSERT_EQ(client_transport_.received_messages().size(), 1U); | 590 ASSERT_EQ(client_transport_.received_messages().size(), 1U); |
625 EXPECT_EQ("1", client_transport_.received_messages()[0]->Attr(buzz::QN_ID)); | 591 EXPECT_EQ("1", client_transport_.received_messages()[0]->Attr(buzz::QN_ID)); |
626 } | 592 } |
627 | 593 |
628 TEST_F(JingleSessionTest, TestSessionPlugin) { | 594 TEST_F(JingleSessionTest, TestSessionPlugin) { |
629 host_plugin_.Clear(); | 595 host_plugin_.Clear(); |
630 client_plugin_.Clear(); | 596 client_plugin_.Clear(); |
631 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | 597 |
632 ASSERT_NO_FATAL_FAILURE( | 598 const int kAuthRoundtrips = 3; |
633 InitiateConnection(3, FakeAuthenticator::ACCEPT, false)); | 599 FakeAuthenticator::Config auth_config(kAuthRoundtrips, |
| 600 FakeAuthenticator::ACCEPT, true); |
| 601 |
| 602 CreateSessionManagers(auth_config); |
| 603 ASSERT_NO_FATAL_FAILURE(InitiateConnection(auth_config, false)); |
634 ExpectPluginMessagesEqual(); | 604 ExpectPluginMessagesEqual(); |
635 } | 605 } |
636 | 606 |
637 TEST_F(JingleSessionTest, SessionPluginShouldNotBeInvolvedInSessionTerminate) { | 607 TEST_F(JingleSessionTest, SessionPluginShouldNotBeInvolvedInSessionTerminate) { |
638 host_plugin_.Clear(); | 608 host_plugin_.Clear(); |
639 client_plugin_.Clear(); | 609 client_plugin_.Clear(); |
640 CreateSessionManagers(1, FakeAuthenticator::REJECT); | 610 CreateSessionManagers(FakeAuthenticator::Config(FakeAuthenticator::REJECT)); |
641 InitiateConnection(1, FakeAuthenticator::ACCEPT, true); | 611 InitiateConnection(FakeAuthenticator::Config(), true); |
642 // It's expected the client sends one more plugin message than host, the host | 612 // It's expected the client sends one more plugin message than host, the host |
643 // won't send plugin message in the SESSION_TERMINATE message. | 613 // won't send plugin message in the SESSION_TERMINATE message. |
644 ASSERT_EQ(client_plugin_.outgoing_messages().size() - 1, | 614 ASSERT_EQ(client_plugin_.outgoing_messages().size() - 1, |
645 client_plugin_.incoming_messages().size()); | 615 client_plugin_.incoming_messages().size()); |
646 ExpectPluginMessagesEqual(); | 616 ExpectPluginMessagesEqual(); |
647 } | 617 } |
648 | 618 |
649 TEST_F(JingleSessionTest, ImmediatelyCloseSessionAfterConnect) { | 619 TEST_F(JingleSessionTest, ImmediatelyCloseSessionAfterConnect) { |
650 CreateSessionManagers(3, FakeAuthenticator::ACCEPT); | 620 const int kAuthRoundtrips = 3; |
| 621 FakeAuthenticator::Config auth_config(kAuthRoundtrips, |
| 622 FakeAuthenticator::ACCEPT, true); |
| 623 CreateSessionManagers(auth_config); |
651 client_session_ = client_server_->Connect( | 624 client_session_ = client_server_->Connect( |
652 SignalingAddress(host_jid_), | 625 SignalingAddress(kNormalizedHostJid), |
653 base::MakeUnique<FakeAuthenticator>(FakeAuthenticator::CLIENT, 3, | 626 base::MakeUnique<FakeAuthenticator>( |
654 FakeAuthenticator::ACCEPT, true)); | 627 FakeAuthenticator::CLIENT, auth_config, |
| 628 client_signal_strategy_->GetLocalAddress().id(), kNormalizedHostJid)); |
| 629 |
655 client_session_->Close(HOST_OVERLOAD); | 630 client_session_->Close(HOST_OVERLOAD); |
656 base::RunLoop().RunUntilIdle(); | 631 base::RunLoop().RunUntilIdle(); |
657 // We should only send a SESSION_TERMINATE message if the session has been | 632 // We should only send a SESSION_TERMINATE message if the session has been |
658 // closed before SESSION_INITIATE message. | 633 // closed before SESSION_INITIATE message. |
659 ASSERT_EQ(1U, host_signal_strategy_->received_messages().size()); | 634 ASSERT_EQ(1U, host_signal_strategy_->received_messages().size()); |
660 } | 635 } |
661 | 636 |
662 } // namespace protocol | 637 } // namespace protocol |
663 } // namespace remoting | 638 } // namespace remoting |
OLD | NEW |