Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: webrtc/p2p/client/portallocator_unittest.cc

Issue 1215713003: Ensuring that UDP TURN servers are always used as STUN servers. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Use const ref to avoid unnecessary copies Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/client/basicportallocator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 ASSERT_EQ(2U, ports_.size()); 777 ASSERT_EQ(2U, ports_.size());
778 EXPECT_PRED5(CheckCandidate, candidates_[0], 778 EXPECT_PRED5(CheckCandidate, candidates_[0],
779 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 779 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
780 EXPECT_PRED5(CheckCandidate, candidates_[1], 780 EXPECT_PRED5(CheckCandidate, candidates_[1],
781 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", 781 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
782 rtc::SocketAddress(kNatAddr.ipaddr(), 0)); 782 rtc::SocketAddress(kNatAddr.ipaddr(), 0));
783 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 783 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
784 EXPECT_EQ(3U, candidates_.size()); 784 EXPECT_EQ(3U, candidates_.size());
785 } 785 }
786 786
787 // Test TURN port in shared socket mode with UDP and TCP TURN server adderesses. 787 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses.
788 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { 788 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) {
789 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); 789 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
790 AddInterface(kClientAddr); 790 AddInterface(kClientAddr);
791 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); 791 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_));
792 792
793 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 793 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
794 794
795 allocator_->set_step_delay(cricket::kMinimumStepDelay); 795 allocator_->set_step_delay(cricket::kMinimumStepDelay);
796 allocator_->set_flags(allocator().flags() | 796 allocator_->set_flags(allocator().flags() |
797 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 797 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 909 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
910 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); 910 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address());
911 911
912 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 912 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
913 EXPECT_EQ(3U, candidates_.size()); 913 EXPECT_EQ(3U, candidates_.size());
914 // Local port will be created first and then TURN port. 914 // Local port will be created first and then TURN port.
915 EXPECT_EQ(2U, ports_[0]->Candidates().size()); 915 EXPECT_EQ(2U, ports_[0]->Candidates().size());
916 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 916 EXPECT_EQ(1U, ports_[1]->Candidates().size());
917 } 917 }
918 918
919 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the
920 // TURN server is used as the STUN server and we get 'local', 'stun', and
921 // 'relay' candidates.
pthatcher1 2015/07/06 22:28:32 Non-shared sockets will be deleted soon (I'm surpr
Taylor Brandstetter 2015/07/07 00:00:04 Well, when that happens we can easily just remove
922 TEST_F(PortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) {
923 AddInterface(kClientAddr);
924 // Use an empty SocketAddress to add a NAT without STUN server.
925 ResetWithNatServer(SocketAddress());
926 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
927
928 allocator_->set_flags(allocator().flags() |
929 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
930 cricket::PORTALLOCATOR_DISABLE_TCP);
931
932 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
933 session_->StartGettingPorts();
934
935 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
936 ASSERT_EQ(3U, ports_.size());
937 EXPECT_PRED5(CheckCandidate, candidates_[0],
938 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
939 EXPECT_PRED5(CheckCandidate, candidates_[1],
940 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
941 rtc::SocketAddress(kNatAddr.ipaddr(), 0));
942 EXPECT_PRED5(CheckCandidate, candidates_[2],
943 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
944 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
945 // Not using shared socket, so the STUN request's server reflexive address
946 // should be different than the TURN request's server reflexive address.
947 EXPECT_NE(candidates_[2].related_address(), candidates_[1].address());
948
949 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
950 EXPECT_EQ(3U, candidates_.size());
951 EXPECT_EQ(1U, ports_[0]->Candidates().size());
952 EXPECT_EQ(1U, ports_[1]->Candidates().size());
953 EXPECT_EQ(1U, ports_[2]->Candidates().size());
954 }
955
956 // Test that even when both a STUN and TURN server are configured, the TURN
957 // server is used as a STUN server and we get a 'stun' candidate.
958 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) {
959 AddInterface(kClientAddr);
960 // Configure with STUN server but destroy it, so we can ensure that it's
961 // the TURN server actually being used as a STUN server.
962 ResetWithNatServer(kStunAddr);
963 stun_server_.reset();
964 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
965
966 allocator_->set_flags(allocator().flags() |
967 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
968 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
969 cricket::PORTALLOCATOR_DISABLE_TCP);
970
971 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
972 session_->StartGettingPorts();
973
974 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
975 EXPECT_PRED5(CheckCandidate, candidates_[0],
976 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
977 EXPECT_PRED5(CheckCandidate, candidates_[1],
978 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
979 rtc::SocketAddress(kNatAddr.ipaddr(), 0));
980 EXPECT_PRED5(CheckCandidate, candidates_[2],
981 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
982 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
983 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address());
984
985 // Don't bother waiting for STUN timeout, since we already verified
986 // that we got a STUN candidate from the TURN server.
987 }
988
989 // Test that when only a TCP TURN server is available, we do NOT use it as
990 // a UDP STUN server, as this could leak our IP address. Thus we should only
991 // expect two ports, a UDPPort and TurnPort.
992 TEST_F(PortAllocatorTest, TestNonSharedSocketWithoutNatUsingTurnTcp) {
993 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
994 AddInterface(kClientAddr);
995 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_));
996
997 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr);
998
999 allocator_->set_step_delay(cricket::kMinimumStepDelay);
1000 allocator_->set_flags(allocator().flags() |
1001 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1002 cricket::PORTALLOCATOR_DISABLE_TCP);
1003
1004 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1005 session_->StartGettingPorts();
1006
1007 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout);
1008 ASSERT_EQ(2U, ports_.size());
1009 EXPECT_PRED5(CheckCandidate, candidates_[0],
1010 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
1011 EXPECT_PRED5(CheckCandidate, candidates_[1],
1012 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
1013 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1014 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1015 EXPECT_EQ(2U, candidates_.size());
1016 EXPECT_EQ(1U, ports_[0]->Candidates().size());
1017 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1018 }
1019
919 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled 1020 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled
920 // and fail to generate STUN candidate, local UDP candidate is generated 1021 // and fail to generate STUN candidate, local UDP candidate is generated
921 // properly. 1022 // properly.
922 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) { 1023 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) {
923 allocator().set_flags(allocator().flags() | 1024 allocator().set_flags(allocator().flags() |
924 cricket::PORTALLOCATOR_DISABLE_RELAY | 1025 cricket::PORTALLOCATOR_DISABLE_RELAY |
925 cricket::PORTALLOCATOR_DISABLE_TCP | 1026 cricket::PORTALLOCATOR_DISABLE_TCP |
926 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 1027 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
927 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1028 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
928 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); 1029 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1146 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1046 session_->StartGettingPorts(); 1147 session_->StartGettingPorts();
1047 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 1148 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout);
1048 EXPECT_EQ(4U, ports_.size()); 1149 EXPECT_EQ(4U, ports_.size());
1049 1150
1050 auto it = ports_.begin(); 1151 auto it = ports_.begin();
1051 for (; it != ports_.end(); ++it) { 1152 for (; it != ports_.end(); ++it) {
1052 (reinterpret_cast<cricket::Port*>(*it))->Destroy(); 1153 (reinterpret_cast<cricket::Port*>(*it))->Destroy();
1053 } 1154 }
1054 } 1155 }
OLDNEW
« no previous file with comments | « webrtc/p2p/client/basicportallocator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698