OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 } | 814 } |
815 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd || | 815 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd || |
816 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) { | 816 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) { |
817 EXPECT_FALSE(expect_equal); | 817 EXPECT_FALSE(expect_equal); |
818 return; | 818 return; |
819 } | 819 } |
820 } | 820 } |
821 EXPECT_TRUE(expect_equal); | 821 EXPECT_TRUE(expect_equal); |
822 } | 822 } |
823 | 823 |
| 824 // Compares ufrag/password only for specified media type. |
| 825 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1, |
| 826 const cricket::SessionDescription* desc2, |
| 827 cricket::MediaType media_type, |
| 828 bool expect_equal) { |
| 829 if (desc1->contents().size() != desc2->contents().size()) { |
| 830 EXPECT_FALSE(expect_equal); |
| 831 return; |
| 832 } |
| 833 |
| 834 const cricket::ContentInfo* cinfo = |
| 835 cricket::GetFirstMediaContent(desc1->contents(), media_type); |
| 836 const cricket::TransportDescription* transport_desc1 = |
| 837 desc1->GetTransportDescriptionByName(cinfo->name); |
| 838 const cricket::TransportDescription* transport_desc2 = |
| 839 desc2->GetTransportDescriptionByName(cinfo->name); |
| 840 if (!transport_desc1 || !transport_desc2) { |
| 841 EXPECT_FALSE(expect_equal); |
| 842 return; |
| 843 } |
| 844 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd || |
| 845 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) { |
| 846 EXPECT_FALSE(expect_equal); |
| 847 return; |
| 848 } |
| 849 EXPECT_TRUE(expect_equal); |
| 850 } |
| 851 |
824 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc, | 852 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc, |
825 std::string *sdp) { | 853 std::string *sdp) { |
826 const cricket::SessionDescription* desc = current_desc->description(); | 854 const cricket::SessionDescription* desc = current_desc->description(); |
827 EXPECT_TRUE(current_desc->ToString(sdp)); | 855 EXPECT_TRUE(current_desc->ToString(sdp)); |
828 | 856 |
829 const cricket::ContentInfos& contents = desc->contents(); | 857 const cricket::ContentInfos& contents = desc->contents(); |
830 cricket::ContentInfos::const_iterator it = contents.begin(); | 858 cricket::ContentInfos::const_iterator it = contents.begin(); |
831 // Replace ufrag and pwd lines with empty strings. | 859 // Replace ufrag and pwd lines with empty strings. |
832 for (; it != contents.end(); ++it) { | 860 for (; it != contents.end(); ++it) { |
833 const cricket::TransportDescription* transport_desc = | 861 const cricket::TransportDescription* transport_desc = |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n"; | 895 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n"; |
868 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(), | 896 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(), |
869 mod_ufrag.c_str(), mod_ufrag.length(), | 897 mod_ufrag.c_str(), mod_ufrag.length(), |
870 sdp); | 898 sdp); |
871 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(), | 899 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(), |
872 mod_pwd.c_str(), mod_pwd.length(), | 900 mod_pwd.c_str(), mod_pwd.length(), |
873 sdp); | 901 sdp); |
874 } | 902 } |
875 } | 903 } |
876 | 904 |
| 905 // Modifies ufrag/pwd for specified |media_type|, by directly modifying the |
| 906 // description. |
| 907 void ModifyIceUfragPwd(SessionDescriptionInterface* current_desc, |
| 908 cricket::MediaType media_type, |
| 909 const std::string& modified_ice_ufrag, |
| 910 const std::string& modified_ice_pwd) { |
| 911 cricket::SessionDescription* desc = current_desc->description(); |
| 912 const cricket::ContentInfo* cinfo = |
| 913 cricket::GetFirstMediaContent(desc->contents(), media_type); |
| 914 // Replace ufrag and pwd with |modified_ice_ufrag| and |
| 915 // |modified_ice_pwd| strings. |
| 916 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name); |
| 917 cricket::TransportDescription* transport_desc = |
| 918 &transport_info->description; |
| 919 transport_desc->ice_ufrag = modified_ice_ufrag; |
| 920 transport_desc->ice_pwd = modified_ice_pwd; |
| 921 } |
| 922 |
877 // Creates a remote offer and and applies it as a remote description, | 923 // Creates a remote offer and and applies it as a remote description, |
878 // creates a local answer and applies is as a local description. | 924 // creates a local answer and applies is as a local description. |
879 // Call SendAudioVideoStreamX() before this function | 925 // Call SendAudioVideoStreamX() before this function |
880 // to decide which local and remote streams to create. | 926 // to decide which local and remote streams to create. |
881 void CreateAndSetRemoteOfferAndLocalAnswer() { | 927 void CreateAndSetRemoteOfferAndLocalAnswer() { |
882 SessionDescriptionInterface* offer = CreateRemoteOffer(); | 928 SessionDescriptionInterface* offer = CreateRemoteOffer(); |
883 SetRemoteDescriptionWithoutError(offer); | 929 SetRemoteDescriptionWithoutError(offer); |
884 SessionDescriptionInterface* answer = CreateAnswer(NULL); | 930 SessionDescriptionInterface* answer = CreateAnswer(NULL); |
885 SetLocalDescriptionWithoutError(answer); | 931 SetLocalDescriptionWithoutError(answer); |
886 } | 932 } |
(...skipping 2681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3568 // with new ufrag and password is received. | 3614 // with new ufrag and password is received. |
3569 TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) { | 3615 TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) { |
3570 Init(); | 3616 Init(); |
3571 cricket::MediaSessionOptions options; | 3617 cricket::MediaSessionOptions options; |
3572 options.recv_video = true; | 3618 options.recv_video = true; |
3573 rtc::scoped_ptr<JsepSessionDescription> offer( | 3619 rtc::scoped_ptr<JsepSessionDescription> offer( |
3574 CreateRemoteOffer(options)); | 3620 CreateRemoteOffer(options)); |
3575 SetRemoteDescriptionWithoutError(offer.release()); | 3621 SetRemoteDescriptionWithoutError(offer.release()); |
3576 | 3622 |
3577 SendAudioVideoStream1(); | 3623 SendAudioVideoStream1(); |
3578 rtc::scoped_ptr<SessionDescriptionInterface> answer( | 3624 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(nullptr)); |
3579 CreateAnswer(NULL)); | |
3580 SetLocalDescriptionWithoutError(answer.release()); | 3625 SetLocalDescriptionWithoutError(answer.release()); |
3581 | 3626 |
3582 // Receive an offer with new ufrag and password. | 3627 // Receive an offer with new ufrag and password. |
3583 options.transport_options.ice_restart = true; | 3628 options.audio_ice_restart = true; |
| 3629 options.video_ice_restart = true; |
| 3630 options.data_ice_restart = true; |
3584 rtc::scoped_ptr<JsepSessionDescription> updated_offer1( | 3631 rtc::scoped_ptr<JsepSessionDescription> updated_offer1( |
3585 CreateRemoteOffer(options, session_->remote_description())); | 3632 CreateRemoteOffer(options, session_->remote_description())); |
3586 SetRemoteDescriptionWithoutError(updated_offer1.release()); | 3633 SetRemoteDescriptionWithoutError(updated_offer1.release()); |
3587 | 3634 |
3588 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1( | 3635 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1( |
3589 CreateAnswer(NULL)); | 3636 CreateAnswer(nullptr)); |
3590 | 3637 |
3591 CompareIceUfragAndPassword(updated_answer1->description(), | 3638 CompareIceUfragAndPassword(updated_answer1->description(), |
3592 session_->local_description()->description(), | 3639 session_->local_description()->description(), |
3593 false); | 3640 false); |
3594 | 3641 |
3595 SetLocalDescriptionWithoutError(updated_answer1.release()); | 3642 // If we create another answer, it should still have a different |
| 3643 // ufrag/password than the current local description. |
| 3644 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2( |
| 3645 CreateAnswer(nullptr)); |
| 3646 |
| 3647 CompareIceUfragAndPassword(updated_answer2->description(), |
| 3648 session_->local_description()->description(), |
| 3649 false); |
| 3650 |
| 3651 SetLocalDescriptionWithoutError(updated_answer2.release()); |
3596 } | 3652 } |
3597 | 3653 |
3598 // This test verifies that an answer contains old ufrag and password if an offer | 3654 // This test verifies that an answer contains old ufrag and password if an offer |
3599 // with old ufrag and password is received. | 3655 // with old ufrag and password is received. |
3600 TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) { | 3656 TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) { |
3601 Init(); | 3657 Init(); |
3602 cricket::MediaSessionOptions options; | 3658 cricket::MediaSessionOptions options; |
3603 options.recv_video = true; | 3659 options.recv_video = true; |
3604 rtc::scoped_ptr<JsepSessionDescription> offer( | 3660 rtc::scoped_ptr<JsepSessionDescription> offer( |
3605 CreateRemoteOffer(options)); | 3661 CreateRemoteOffer(options)); |
3606 SetRemoteDescriptionWithoutError(offer.release()); | 3662 SetRemoteDescriptionWithoutError(offer.release()); |
3607 | 3663 |
3608 SendAudioVideoStream1(); | 3664 SendAudioVideoStream1(); |
3609 rtc::scoped_ptr<SessionDescriptionInterface> answer( | 3665 rtc::scoped_ptr<SessionDescriptionInterface> answer( |
3610 CreateAnswer(NULL)); | 3666 CreateAnswer(NULL)); |
3611 SetLocalDescriptionWithoutError(answer.release()); | 3667 SetLocalDescriptionWithoutError(answer.release()); |
3612 | 3668 |
3613 // Receive an offer without changed ufrag or password. | 3669 // Receive an offer without changed ufrag or password. |
3614 options.transport_options.ice_restart = false; | |
3615 rtc::scoped_ptr<JsepSessionDescription> updated_offer2( | 3670 rtc::scoped_ptr<JsepSessionDescription> updated_offer2( |
3616 CreateRemoteOffer(options, session_->remote_description())); | 3671 CreateRemoteOffer(options, session_->remote_description())); |
3617 SetRemoteDescriptionWithoutError(updated_offer2.release()); | 3672 SetRemoteDescriptionWithoutError(updated_offer2.release()); |
3618 | 3673 |
3619 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2( | 3674 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2( |
3620 CreateAnswer(NULL)); | 3675 CreateAnswer(NULL)); |
3621 | 3676 |
3622 CompareIceUfragAndPassword(updated_answer2->description(), | 3677 CompareIceUfragAndPassword(updated_answer2->description(), |
3623 session_->local_description()->description(), | 3678 session_->local_description()->description(), |
3624 true); | 3679 true); |
3625 | 3680 |
3626 SetLocalDescriptionWithoutError(updated_answer2.release()); | 3681 SetLocalDescriptionWithoutError(updated_answer2.release()); |
3627 } | 3682 } |
3628 | 3683 |
| 3684 // This test verifies that if an offer does an ICE restart on some, but not all |
| 3685 // m-lines, the answer will change the ufrag/password on the correct m-lines. |
| 3686 TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) { |
| 3687 Init(); |
| 3688 cricket::MediaSessionOptions options; |
| 3689 options.recv_video = true; |
| 3690 options.recv_audio = true; |
| 3691 options.bundle_enabled = false; |
| 3692 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options)); |
| 3693 |
| 3694 ModifyIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa", |
| 3695 "aaaaaaaaaaaaaaaaaaaaaa"); |
| 3696 ModifyIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb", |
| 3697 "bbbbbbbbbbbbbbbbbbbbbb"); |
| 3698 SetRemoteDescriptionWithoutError(offer.release()); |
| 3699 |
| 3700 SendAudioVideoStream1(); |
| 3701 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(nullptr)); |
| 3702 SetLocalDescriptionWithoutError(answer.release()); |
| 3703 |
| 3704 // Receive an offer with new ufrag and password, but only on the video line. |
| 3705 rtc::scoped_ptr<JsepSessionDescription> updated_offer( |
| 3706 CreateRemoteOffer(options, session_->remote_description())); |
| 3707 ModifyIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc", |
| 3708 "cccccccccccccccccccccc"); |
| 3709 SetRemoteDescriptionWithoutError(updated_offer.release()); |
| 3710 |
| 3711 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer( |
| 3712 CreateAnswer(nullptr)); |
| 3713 |
| 3714 CompareIceUfragAndPassword(updated_answer->description(), |
| 3715 session_->local_description()->description(), |
| 3716 cricket::MEDIA_TYPE_AUDIO, true); |
| 3717 |
| 3718 CompareIceUfragAndPassword(updated_answer->description(), |
| 3719 session_->local_description()->description(), |
| 3720 cricket::MEDIA_TYPE_VIDEO, false); |
| 3721 |
| 3722 SetLocalDescriptionWithoutError(updated_answer.release()); |
| 3723 } |
| 3724 |
3629 TEST_F(WebRtcSessionTest, TestSessionContentError) { | 3725 TEST_F(WebRtcSessionTest, TestSessionContentError) { |
3630 Init(); | 3726 Init(); |
3631 SendAudioVideoStream1(); | 3727 SendAudioVideoStream1(); |
3632 SessionDescriptionInterface* offer = CreateOffer(); | 3728 SessionDescriptionInterface* offer = CreateOffer(); |
3633 const std::string session_id_orig = offer->session_id(); | 3729 const std::string session_id_orig = offer->session_id(); |
3634 const std::string session_version_orig = offer->session_version(); | 3730 const std::string session_version_orig = offer->session_version(); |
3635 SetLocalDescriptionWithoutError(offer); | 3731 SetLocalDescriptionWithoutError(offer); |
3636 | 3732 |
3637 video_channel_ = media_engine_->GetVideoChannel(0); | 3733 video_channel_ = media_engine_->GetVideoChannel(0); |
3638 video_channel_->set_fail_set_send_codecs(true); | 3734 video_channel_->set_fail_set_send_codecs(true); |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4204 } | 4300 } |
4205 | 4301 |
4206 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test | 4302 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
4207 // currently fails because upon disconnection and reconnection OnIceComplete is | 4303 // currently fails because upon disconnection and reconnection OnIceComplete is |
4208 // called more than once without returning to IceGatheringGathering. | 4304 // called more than once without returning to IceGatheringGathering. |
4209 | 4305 |
4210 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, | 4306 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, |
4211 WebRtcSessionTest, | 4307 WebRtcSessionTest, |
4212 testing::Values(ALREADY_GENERATED, | 4308 testing::Values(ALREADY_GENERATED, |
4213 DTLS_IDENTITY_STORE)); | 4309 DTLS_IDENTITY_STORE)); |
OLD | NEW |