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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 #endif | 93 #endif |
94 | 94 |
95 class TurnPortTestVirtualSocketServer : public rtc::VirtualSocketServer { | 95 class TurnPortTestVirtualSocketServer : public rtc::VirtualSocketServer { |
96 public: | 96 public: |
97 explicit TurnPortTestVirtualSocketServer(SocketServer* ss) | 97 explicit TurnPortTestVirtualSocketServer(SocketServer* ss) |
98 : VirtualSocketServer(ss) {} | 98 : VirtualSocketServer(ss) {} |
99 | 99 |
100 using rtc::VirtualSocketServer::LookupBinding; | 100 using rtc::VirtualSocketServer::LookupBinding; |
101 }; | 101 }; |
102 | 102 |
| 103 class TestConnectionWrapper : public sigslot::has_slots<> { |
| 104 public: |
| 105 TestConnectionWrapper(Connection* conn) : connection_(conn) { |
| 106 conn->SignalDestroyed.connect( |
| 107 this, &TestConnectionWrapper::OnConnectionDestroyed); |
| 108 } |
| 109 |
| 110 Connection* connection() { return connection_; } |
| 111 |
| 112 private: |
| 113 void OnConnectionDestroyed(Connection* conn) { |
| 114 ASSERT_TRUE(conn == connection_); |
| 115 connection_ = nullptr; |
| 116 } |
| 117 |
| 118 Connection* connection_; |
| 119 }; |
| 120 |
103 class TurnPortTest : public testing::Test, | 121 class TurnPortTest : public testing::Test, |
104 public sigslot::has_slots<>, | 122 public sigslot::has_slots<>, |
105 public rtc::MessageHandler { | 123 public rtc::MessageHandler { |
106 public: | 124 public: |
107 TurnPortTest() | 125 TurnPortTest() |
108 : main_(rtc::Thread::Current()), | 126 : main_(rtc::Thread::Current()), |
109 pss_(new rtc::PhysicalSocketServer), | 127 pss_(new rtc::PhysicalSocketServer), |
110 ss_(new TurnPortTestVirtualSocketServer(pss_.get())), | 128 ss_(new TurnPortTestVirtualSocketServer(pss_.get())), |
111 ss_scope_(ss_.get()), | 129 ss_scope_(ss_.get()), |
112 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), | 130 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 void ConnectSignals() { | 267 void ConnectSignals() { |
250 turn_port_->SignalPortComplete.connect(this, | 268 turn_port_->SignalPortComplete.connect(this, |
251 &TurnPortTest::OnTurnPortComplete); | 269 &TurnPortTest::OnTurnPortComplete); |
252 turn_port_->SignalPortError.connect(this, | 270 turn_port_->SignalPortError.connect(this, |
253 &TurnPortTest::OnTurnPortError); | 271 &TurnPortTest::OnTurnPortError); |
254 turn_port_->SignalUnknownAddress.connect(this, | 272 turn_port_->SignalUnknownAddress.connect(this, |
255 &TurnPortTest::OnTurnUnknownAddress); | 273 &TurnPortTest::OnTurnUnknownAddress); |
256 turn_port_->SignalCreatePermissionResult.connect(this, | 274 turn_port_->SignalCreatePermissionResult.connect(this, |
257 &TurnPortTest::OnTurnCreatePermissionResult); | 275 &TurnPortTest::OnTurnCreatePermissionResult); |
258 } | 276 } |
259 void CreateUdpPort() { | 277 |
| 278 void CreateUdpPort() { CreateUdpPort(kLocalAddr2); } |
| 279 |
| 280 void CreateUdpPort(const SocketAddress& address) { |
260 udp_port_.reset(UDPPort::Create(main_, &socket_factory_, &network_, | 281 udp_port_.reset(UDPPort::Create(main_, &socket_factory_, &network_, |
261 kLocalAddr2.ipaddr(), 0, 0, | 282 address.ipaddr(), 0, 0, kIceUfrag2, |
262 kIceUfrag2, kIcePwd2, | 283 kIcePwd2, std::string(), false)); |
263 std::string(), false)); | |
264 // UDP port will be controlled. | 284 // UDP port will be controlled. |
265 udp_port_->SetIceRole(cricket::ICEROLE_CONTROLLED); | 285 udp_port_->SetIceRole(cricket::ICEROLE_CONTROLLED); |
266 udp_port_->SignalPortComplete.connect( | 286 udp_port_->SignalPortComplete.connect( |
267 this, &TurnPortTest::OnUdpPortComplete); | 287 this, &TurnPortTest::OnUdpPortComplete); |
268 } | 288 } |
269 | 289 |
270 void TestTurnAlternateServer(cricket::ProtocolType protocol_type) { | 290 void TestTurnAlternateServer(cricket::ProtocolType protocol_type) { |
271 std::vector<rtc::SocketAddress> redirect_addresses; | 291 std::vector<rtc::SocketAddress> redirect_addresses; |
272 redirect_addresses.push_back(kTurnAlternateIntAddr); | 292 redirect_addresses.push_back(kTurnAlternateIntAddr); |
273 | 293 |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 CreateTurnPortWithOrigin(kLocalAddr1, kTurnUsername, kTurnPassword, | 784 CreateTurnPortWithOrigin(kLocalAddr1, kTurnUsername, kTurnPassword, |
765 kTurnUdpProtoAddr, kTestOrigin); | 785 kTurnUdpProtoAddr, kTestOrigin); |
766 turn_port_->PrepareAddress(); | 786 turn_port_->PrepareAddress(); |
767 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); | 787 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); |
768 ASSERT_GT(turn_server_.server()->allocations().size(), 0U); | 788 ASSERT_GT(turn_server_.server()->allocations().size(), 0U); |
769 SocketAddress local_address = turn_port_->GetLocalAddress(); | 789 SocketAddress local_address = turn_port_->GetLocalAddress(); |
770 ASSERT_TRUE(turn_server_.FindAllocation(local_address) != NULL); | 790 ASSERT_TRUE(turn_server_.FindAllocation(local_address) != NULL); |
771 EXPECT_EQ(kTestOrigin, turn_server_.FindAllocation(local_address)->origin()); | 791 EXPECT_EQ(kTestOrigin, turn_server_.FindAllocation(local_address)->origin()); |
772 } | 792 } |
773 | 793 |
| 794 // Test that a CreatePermission failure will result in the connection being |
| 795 // destroyed. |
| 796 TEST_F(TurnPortTest, TestConnectionDestroyedOnCreatePermissionFailure) { |
| 797 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
| 798 turn_server_.server()->set_reject_private_addresses(true); |
| 799 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr); |
| 800 turn_port_->PrepareAddress(); |
| 801 ASSERT_TRUE_WAIT(turn_ready_, kTimeout); |
| 802 |
| 803 CreateUdpPort(SocketAddress("10.0.0.10", 0)); |
| 804 udp_port_->PrepareAddress(); |
| 805 ASSERT_TRUE_WAIT(udp_ready_, kTimeout); |
| 806 // Create a connection. |
| 807 TestConnectionWrapper conn(turn_port_->CreateConnection( |
| 808 udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE)); |
| 809 ASSERT_TRUE(conn.connection() != nullptr); |
| 810 |
| 811 // Asynchronously, CreatePermission request should be sent and fail, closing |
| 812 // the connection. |
| 813 EXPECT_TRUE_WAIT(conn.connection() == nullptr, kTimeout); |
| 814 EXPECT_FALSE(turn_create_permission_success_); |
| 815 } |
| 816 |
774 // Test that a TURN allocation is released when the port is closed. | 817 // Test that a TURN allocation is released when the port is closed. |
775 TEST_F(TurnPortTest, TestTurnReleaseAllocation) { | 818 TEST_F(TurnPortTest, TestTurnReleaseAllocation) { |
776 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); | 819 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); |
777 turn_port_->PrepareAddress(); | 820 turn_port_->PrepareAddress(); |
778 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); | 821 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); |
779 | 822 |
780 ASSERT_GT(turn_server_.server()->allocations().size(), 0U); | 823 ASSERT_GT(turn_server_.server()->allocations().size(), 0U); |
781 turn_port_.reset(); | 824 turn_port_.reset(); |
782 EXPECT_EQ_WAIT(0U, turn_server_.server()->allocations().size(), kTimeout); | 825 EXPECT_EQ_WAIT(0U, turn_server_.server()->allocations().size(), kTimeout); |
783 } | 826 } |
(...skipping 23 matching lines...) Expand all Loading... |
807 turn_port_->PrepareAddress(); | 850 turn_port_->PrepareAddress(); |
808 ASSERT_TRUE_WAIT(turn_error_, kTimeout); | 851 ASSERT_TRUE_WAIT(turn_error_, kTimeout); |
809 EXPECT_TRUE(turn_port_->Candidates().empty()); | 852 EXPECT_TRUE(turn_port_->Candidates().empty()); |
810 turn_port_.reset(); | 853 turn_port_.reset(); |
811 rtc::Thread::Current()->Post(this, MSG_TESTFINISH); | 854 rtc::Thread::Current()->Post(this, MSG_TESTFINISH); |
812 // Waiting for above message to be processed. | 855 // Waiting for above message to be processed. |
813 ASSERT_TRUE_WAIT(test_finish_, kTimeout); | 856 ASSERT_TRUE_WAIT(test_finish_, kTimeout); |
814 EXPECT_EQ(last_fd_count, GetFDCount()); | 857 EXPECT_EQ(last_fd_count, GetFDCount()); |
815 } | 858 } |
816 #endif | 859 #endif |
OLD | NEW |