| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 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 #if defined(WEBRTC_POSIX) | 10 #if defined(WEBRTC_POSIX) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 using cricket::Connection; | 37 using cricket::Connection; |
| 38 using cricket::Port; | 38 using cricket::Port; |
| 39 using cricket::PortInterface; | 39 using cricket::PortInterface; |
| 40 using cricket::TurnPort; | 40 using cricket::TurnPort; |
| 41 using cricket::UDPPort; | 41 using cricket::UDPPort; |
| 42 | 42 |
| 43 static const SocketAddress kLocalAddr1("11.11.11.11", 0); | 43 static const SocketAddress kLocalAddr1("11.11.11.11", 0); |
| 44 static const SocketAddress kLocalAddr2("22.22.22.22", 0); | 44 static const SocketAddress kLocalAddr2("22.22.22.22", 0); |
| 45 static const SocketAddress kLocalIPv6Addr( | 45 static const SocketAddress kLocalIPv6Addr( |
| 46 "2401:fa00:4:1000:be30:5bff:fee5:c3", 0); | 46 "2401:fa00:4:1000:be30:5bff:fee5:c3", 0); |
| 47 static const SocketAddress kLocalIPv6Addr2( |
| 48 "2401:fa00:4:2000:be30:5bff:fee5:d4", 0); |
| 47 static const SocketAddress kTurnUdpIntAddr("99.99.99.3", | 49 static const SocketAddress kTurnUdpIntAddr("99.99.99.3", |
| 48 cricket::TURN_SERVER_PORT); | 50 cricket::TURN_SERVER_PORT); |
| 49 static const SocketAddress kTurnTcpIntAddr("99.99.99.4", | 51 static const SocketAddress kTurnTcpIntAddr("99.99.99.4", |
| 50 cricket::TURN_SERVER_PORT); | 52 cricket::TURN_SERVER_PORT); |
| 51 static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0); | 53 static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0); |
| 52 static const SocketAddress kTurnAlternateIntAddr("99.99.99.6", | 54 static const SocketAddress kTurnAlternateIntAddr("99.99.99.6", |
| 53 cricket::TURN_SERVER_PORT); | 55 cricket::TURN_SERVER_PORT); |
| 54 static const SocketAddress kTurnIntAddr("99.99.99.7", | 56 static const SocketAddress kTurnIntAddr("99.99.99.7", |
| 55 cricket::TURN_SERVER_PORT); | 57 cricket::TURN_SERVER_PORT); |
| 56 static const SocketAddress kTurnIPv6IntAddr( | 58 static const SocketAddress kTurnIPv6IntAddr( |
| 57 "2400:4030:2:2c00:be30:abcd:efab:cdef", | 59 "2400:4030:2:2c00:be30:abcd:efab:cdef", |
| 58 cricket::TURN_SERVER_PORT); | 60 cricket::TURN_SERVER_PORT); |
| 59 static const SocketAddress kTurnUdpIPv6IntAddr( | 61 static const SocketAddress kTurnUdpIPv6IntAddr( |
| 60 "2400:4030:1:2c00:be30:abcd:efab:cdef", cricket::TURN_SERVER_PORT); | 62 "2400:4030:1:2c00:be30:abcd:efab:cdef", cricket::TURN_SERVER_PORT); |
| 61 static const SocketAddress kTurnUdpIPv6ExtAddr( | |
| 62 "2620:0:1000:1b03:2e41:38ff:fea6:f2a4", 0); | |
| 63 | 63 |
| 64 static const char kCandidateFoundation[] = "foundation"; |
| 64 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; | 65 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; |
| 65 static const char kIceUfrag2[] = "TESTICEUFRAG0002"; | 66 static const char kIceUfrag2[] = "TESTICEUFRAG0002"; |
| 66 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; | 67 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; |
| 67 static const char kIcePwd2[] = "TESTICEPWD00000000000002"; | 68 static const char kIcePwd2[] = "TESTICEPWD00000000000002"; |
| 68 static const char kTurnUsername[] = "test"; | 69 static const char kTurnUsername[] = "test"; |
| 69 static const char kTurnPassword[] = "test"; | 70 static const char kTurnPassword[] = "test"; |
| 70 static const char kTestOrigin[] = "http://example.com"; | 71 static const char kTestOrigin[] = "http://example.com"; |
| 71 static const unsigned int kTimeout = 1000; | 72 static const unsigned int kTimeout = 1000; |
| 72 | 73 |
| 73 static const cricket::ProtocolAddress kTurnUdpProtoAddr( | 74 static const cricket::ProtocolAddress kTurnUdpProtoAddr( |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 turn_port_->PrepareAddress(); | 590 turn_port_->PrepareAddress(); |
| 590 EXPECT_TRUE_WAIT(turn_error_, kTimeout); | 591 EXPECT_TRUE_WAIT(turn_error_, kTimeout); |
| 591 // As VSS doesn't provide a DNS resolution, name resolve will fail. TurnPort | 592 // As VSS doesn't provide a DNS resolution, name resolve will fail. TurnPort |
| 592 // will proceed in creating a TCP socket which will fail as there is no | 593 // will proceed in creating a TCP socket which will fail as there is no |
| 593 // server on the above domain and error will be set to SOCKET_ERROR. | 594 // server on the above domain and error will be set to SOCKET_ERROR. |
| 594 EXPECT_EQ(SOCKET_ERROR, turn_port_->error()); | 595 EXPECT_EQ(SOCKET_ERROR, turn_port_->error()); |
| 595 } | 596 } |
| 596 | 597 |
| 597 // In case of UDP on address resolve failure, TurnPort will not create socket | 598 // In case of UDP on address resolve failure, TurnPort will not create socket |
| 598 // and return allocate failure. | 599 // and return allocate failure. |
| 599 TEST_F(TurnPortTest, DISABLED_TestTurnUdpOnAdressResolveFailure) { | 600 TEST_F(TurnPortTest, DISABLED_TestTurnUdpOnAddressResolveFailure) { |
| 600 CreateTurnPort(kTurnUsername, kTurnPassword, cricket::ProtocolAddress( | 601 CreateTurnPort(kTurnUsername, kTurnPassword, cricket::ProtocolAddress( |
| 601 rtc::SocketAddress("www.webrtc-blah-blah.com", 3478), | 602 rtc::SocketAddress("www.webrtc-blah-blah.com", 3478), |
| 602 cricket::PROTO_UDP)); | 603 cricket::PROTO_UDP)); |
| 603 turn_port_->PrepareAddress(); | 604 turn_port_->PrepareAddress(); |
| 604 EXPECT_TRUE_WAIT(turn_error_, kTimeout); | 605 EXPECT_TRUE_WAIT(turn_error_, kTimeout); |
| 605 // Error from turn port will not be socket error. | 606 // Error from turn port will not be socket error. |
| 606 EXPECT_NE(SOCKET_ERROR, turn_port_->error()); | 607 EXPECT_NE(SOCKET_ERROR, turn_port_->error()); |
| 607 } | 608 } |
| 608 | 609 |
| 609 // Try to do a TURN allocation with an invalid password. | 610 // Try to do a TURN allocation with an invalid password. |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword, | 1008 CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword, |
| 1008 kTurnUdpIPv6ProtoAddr); | 1009 kTurnUdpIPv6ProtoAddr); |
| 1009 turn_port_->PrepareAddress(); | 1010 turn_port_->PrepareAddress(); |
| 1010 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); | 1011 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); |
| 1011 ASSERT_EQ(1U, turn_port_->Candidates().size()); | 1012 ASSERT_EQ(1U, turn_port_->Candidates().size()); |
| 1012 EXPECT_EQ(kTurnUdpExtAddr.ipaddr(), | 1013 EXPECT_EQ(kTurnUdpExtAddr.ipaddr(), |
| 1013 turn_port_->Candidates()[0].address().ipaddr()); | 1014 turn_port_->Candidates()[0].address().ipaddr()); |
| 1014 EXPECT_NE(0, turn_port_->Candidates()[0].address().port()); | 1015 EXPECT_NE(0, turn_port_->Candidates()[0].address().port()); |
| 1015 } | 1016 } |
| 1016 | 1017 |
| 1018 // Tests that the local and remote candidate address families should match when |
| 1019 // a connection is created. Specifically, if a TURN port has an IPv6 address, |
| 1020 // its local candidate will still be an IPv4 address and it can only create |
| 1021 // connections with IPv4 remote candidates. |
| 1022 TEST_F(TurnPortTest, TestCandidateAddressFamilyMatch) { |
| 1023 turn_server_.AddInternalSocket(kTurnUdpIPv6IntAddr, cricket::PROTO_UDP); |
| 1024 |
| 1025 CreateTurnPort(kLocalIPv6Addr, kTurnUsername, kTurnPassword, |
| 1026 kTurnUdpIPv6ProtoAddr); |
| 1027 turn_port_->PrepareAddress(); |
| 1028 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); |
| 1029 ASSERT_EQ(1U, turn_port_->Candidates().size()); |
| 1030 |
| 1031 // Create an IPv4 candidate. It will match the TURN candidate. |
| 1032 cricket::Candidate remote_candidate(cricket::ICE_CANDIDATE_COMPONENT_RTP, |
| 1033 "udp", kLocalAddr2, 0, "", "", "local", 0, |
| 1034 kCandidateFoundation); |
| 1035 remote_candidate.set_address(kLocalAddr2); |
| 1036 Connection* conn = |
| 1037 turn_port_->CreateConnection(remote_candidate, Port::ORIGIN_MESSAGE); |
| 1038 EXPECT_NE(nullptr, conn); |
| 1039 |
| 1040 // Set the candidate address family to IPv6. It won't match the TURN |
| 1041 // candidate. |
| 1042 remote_candidate.set_address(kLocalIPv6Addr2); |
| 1043 conn = turn_port_->CreateConnection(remote_candidate, Port::ORIGIN_MESSAGE); |
| 1044 EXPECT_EQ(nullptr, conn); |
| 1045 } |
| 1046 |
| 1017 TEST_F(TurnPortTest, TestOriginHeader) { | 1047 TEST_F(TurnPortTest, TestOriginHeader) { |
| 1018 CreateTurnPortWithOrigin(kLocalAddr1, kTurnUsername, kTurnPassword, | 1048 CreateTurnPortWithOrigin(kLocalAddr1, kTurnUsername, kTurnPassword, |
| 1019 kTurnUdpProtoAddr, kTestOrigin); | 1049 kTurnUdpProtoAddr, kTestOrigin); |
| 1020 turn_port_->PrepareAddress(); | 1050 turn_port_->PrepareAddress(); |
| 1021 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); | 1051 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); |
| 1022 ASSERT_GT(turn_server_.server()->allocations().size(), 0U); | 1052 ASSERT_GT(turn_server_.server()->allocations().size(), 0U); |
| 1023 SocketAddress local_address = turn_port_->GetLocalAddress(); | 1053 SocketAddress local_address = turn_port_->GetLocalAddress(); |
| 1024 ASSERT_TRUE(turn_server_.FindAllocation(local_address) != NULL); | 1054 ASSERT_TRUE(turn_server_.FindAllocation(local_address) != NULL); |
| 1025 EXPECT_EQ(kTestOrigin, turn_server_.FindAllocation(local_address)->origin()); | 1055 EXPECT_EQ(kTestOrigin, turn_server_.FindAllocation(local_address)->origin()); |
| 1026 } | 1056 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 turn_port_->PrepareAddress(); | 1124 turn_port_->PrepareAddress(); |
| 1095 ASSERT_TRUE_WAIT(turn_error_, kResolverTimeout); | 1125 ASSERT_TRUE_WAIT(turn_error_, kResolverTimeout); |
| 1096 EXPECT_TRUE(turn_port_->Candidates().empty()); | 1126 EXPECT_TRUE(turn_port_->Candidates().empty()); |
| 1097 turn_port_.reset(); | 1127 turn_port_.reset(); |
| 1098 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TESTFINISH); | 1128 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TESTFINISH); |
| 1099 // Waiting for above message to be processed. | 1129 // Waiting for above message to be processed. |
| 1100 ASSERT_TRUE_WAIT(test_finish_, kTimeout); | 1130 ASSERT_TRUE_WAIT(test_finish_, kTimeout); |
| 1101 EXPECT_EQ(last_fd_count, GetFDCount()); | 1131 EXPECT_EQ(last_fd_count, GetFDCount()); |
| 1102 } | 1132 } |
| 1103 #endif | 1133 #endif |
| OLD | NEW |