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

Side by Side Diff: webrtc/p2p/base/turnport_unittest.cc

Issue 1453823004: Handle Turn error response to RefreshRequest, CreatePermissionRequest, and ChanelBindRequest (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 1 month 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
« webrtc/p2p/base/turnport.cc ('K') | « webrtc/p2p/base/turnport.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 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)
11 #include <dirent.h> 11 #include <dirent.h>
12 #endif 12 #endif
13 13
14 #include "webrtc/p2p/base/basicpacketsocketfactory.h" 14 #include "webrtc/p2p/base/basicpacketsocketfactory.h"
15 #include "webrtc/p2p/base/constants.h" 15 #include "webrtc/p2p/base/constants.h"
16 #include "webrtc/p2p/base/portallocator.h"
16 #include "webrtc/p2p/base/tcpport.h" 17 #include "webrtc/p2p/base/tcpport.h"
17 #include "webrtc/p2p/base/testturnserver.h" 18 #include "webrtc/p2p/base/testturnserver.h"
18 #include "webrtc/p2p/base/turnport.h" 19 #include "webrtc/p2p/base/turnport.h"
19 #include "webrtc/p2p/base/udpport.h" 20 #include "webrtc/p2p/base/udpport.h"
20 #include "webrtc/base/asynctcpsocket.h" 21 #include "webrtc/base/asynctcpsocket.h"
21 #include "webrtc/base/buffer.h" 22 #include "webrtc/base/buffer.h"
22 #include "webrtc/base/dscp.h" 23 #include "webrtc/base/dscp.h"
23 #include "webrtc/base/firewallsocketserver.h" 24 #include "webrtc/base/firewallsocketserver.h"
24 #include "webrtc/base/gunit.h" 25 #include "webrtc/base/gunit.h"
25 #include "webrtc/base/helpers.h" 26 #include "webrtc/base/helpers.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 148 }
148 void OnTurnPortError(Port* port) { 149 void OnTurnPortError(Port* port) {
149 turn_error_ = true; 150 turn_error_ = true;
150 } 151 }
151 void OnTurnUnknownAddress(PortInterface* port, const SocketAddress& addr, 152 void OnTurnUnknownAddress(PortInterface* port, const SocketAddress& addr,
152 cricket::ProtocolType proto, 153 cricket::ProtocolType proto,
153 cricket::IceMessage* msg, const std::string& rf, 154 cricket::IceMessage* msg, const std::string& rf,
154 bool /*port_muxed*/) { 155 bool /*port_muxed*/) {
155 turn_unknown_address_ = true; 156 turn_unknown_address_ = true;
156 } 157 }
157 void OnTurnCreatePermissionResult(TurnPort* port, const SocketAddress& addr, 158 void OnTurnCreatePermissionResult(TurnPort* port,
158 int code) { 159 const SocketAddress& addr,
160 int code) {
159 // Ignoring the address. 161 // Ignoring the address.
160 if (code == 0) { 162 turn_create_permission_success_ = (code == 0);
161 turn_create_permission_success_ = true; 163 }
162 } 164
165 void OnTurnRefreshResult(TurnPort* port, int code) {
166 turn_refresh_success_ = (code == 0);
163 } 167 }
164 void OnTurnReadPacket(Connection* conn, const char* data, size_t size, 168 void OnTurnReadPacket(Connection* conn, const char* data, size_t size,
165 const rtc::PacketTime& packet_time) { 169 const rtc::PacketTime& packet_time) {
166 turn_packets_.push_back(rtc::Buffer(data, size)); 170 turn_packets_.push_back(rtc::Buffer(data, size));
167 } 171 }
168 void OnUdpPortComplete(Port* port) { 172 void OnUdpPortComplete(Port* port) {
169 udp_ready_ = true; 173 udp_ready_ = true;
170 } 174 }
171 void OnUdpReadPacket(Connection* conn, const char* data, size_t size, 175 void OnUdpReadPacket(Connection* conn, const char* data, size_t size,
172 const rtc::PacketTime& packet_time) { 176 const rtc::PacketTime& packet_time) {
173 udp_packets_.push_back(rtc::Buffer(data, size)); 177 udp_packets_.push_back(rtc::Buffer(data, size));
174 } 178 }
179 void OnConnectionDestroyed(Connection* conn) { connection_destroyed_ = true; }
175 void OnSocketReadPacket(rtc::AsyncPacketSocket* socket, 180 void OnSocketReadPacket(rtc::AsyncPacketSocket* socket,
176 const char* data, size_t size, 181 const char* data, size_t size,
177 const rtc::SocketAddress& remote_addr, 182 const rtc::SocketAddress& remote_addr,
178 const rtc::PacketTime& packet_time) { 183 const rtc::PacketTime& packet_time) {
179 turn_port_->HandleIncomingPacket(socket, data, size, remote_addr, 184 turn_port_->HandleIncomingPacket(socket, data, size, remote_addr,
180 packet_time); 185 packet_time);
181 } 186 }
182 rtc::AsyncSocket* CreateServerSocket(const SocketAddress addr) { 187 rtc::AsyncSocket* CreateServerSocket(const SocketAddress addr) {
183 rtc::AsyncSocket* socket = ss_->CreateAsyncSocket(SOCK_STREAM); 188 rtc::AsyncSocket* socket = ss_->CreateAsyncSocket(SOCK_STREAM);
184 EXPECT_GE(socket->Bind(addr), 0); 189 EXPECT_GE(socket->Bind(addr), 0);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 253
249 void ConnectSignals() { 254 void ConnectSignals() {
250 turn_port_->SignalPortComplete.connect(this, 255 turn_port_->SignalPortComplete.connect(this,
251 &TurnPortTest::OnTurnPortComplete); 256 &TurnPortTest::OnTurnPortComplete);
252 turn_port_->SignalPortError.connect(this, 257 turn_port_->SignalPortError.connect(this,
253 &TurnPortTest::OnTurnPortError); 258 &TurnPortTest::OnTurnPortError);
254 turn_port_->SignalUnknownAddress.connect(this, 259 turn_port_->SignalUnknownAddress.connect(this,
255 &TurnPortTest::OnTurnUnknownAddress); 260 &TurnPortTest::OnTurnUnknownAddress);
256 turn_port_->SignalCreatePermissionResult.connect(this, 261 turn_port_->SignalCreatePermissionResult.connect(this,
257 &TurnPortTest::OnTurnCreatePermissionResult); 262 &TurnPortTest::OnTurnCreatePermissionResult);
263 turn_port_->SignalTurnRefreshResult.connect(
264 this, &TurnPortTest::OnTurnRefreshResult);
265 }
266 void ConnectConnectionDestroyedSignal(Connection* conn) {
267 conn->SignalDestroyed.connect(this, &TurnPortTest::OnConnectionDestroyed);
258 } 268 }
259 void CreateUdpPort() { 269 void CreateUdpPort() {
260 udp_port_.reset(UDPPort::Create(main_, &socket_factory_, &network_, 270 udp_port_.reset(UDPPort::Create(main_, &socket_factory_, &network_,
261 kLocalAddr2.ipaddr(), 0, 0, 271 kLocalAddr2.ipaddr(), 0, 0,
262 kIceUfrag2, kIcePwd2, 272 kIceUfrag2, kIcePwd2,
263 std::string(), false)); 273 std::string(), false));
264 // UDP port will be controlled. 274 // UDP port will be controlled.
265 udp_port_->SetIceRole(cricket::ICEROLE_CONTROLLED); 275 udp_port_->SetIceRole(cricket::ICEROLE_CONTROLLED);
266 udp_port_->SignalPortComplete.connect( 276 udp_port_->SignalPortComplete.connect(
267 this, &TurnPortTest::OnUdpPortComplete); 277 this, &TurnPortTest::OnUdpPortComplete);
268 } 278 }
269 279
280 void PrepareTurnAndUdpPorts() {
281 // turn_port_ should have been created.
282 ASSERT_TRUE(turn_port_ != nullptr);
283 turn_port_->PrepareAddress();
284 ASSERT_TRUE_WAIT(turn_ready_, kTimeout);
285
286 CreateUdpPort();
287 udp_port_->PrepareAddress();
288 ASSERT_TRUE_WAIT(udp_ready_, kTimeout);
289 }
290
291 bool CheckConnectionDestroyed() {
292 turn_port_->FlushRequests();
293 rtc::Thread::Current()->ProcessMessages(50);
294 return connection_destroyed_;
295 }
296
270 void TestTurnAlternateServer(cricket::ProtocolType protocol_type) { 297 void TestTurnAlternateServer(cricket::ProtocolType protocol_type) {
271 std::vector<rtc::SocketAddress> redirect_addresses; 298 std::vector<rtc::SocketAddress> redirect_addresses;
272 redirect_addresses.push_back(kTurnAlternateIntAddr); 299 redirect_addresses.push_back(kTurnAlternateIntAddr);
273 300
274 cricket::TestTurnRedirector redirector(redirect_addresses); 301 cricket::TestTurnRedirector redirector(redirect_addresses);
275 302
276 turn_server_.AddInternalSocket(kTurnIntAddr, protocol_type); 303 turn_server_.AddInternalSocket(kTurnIntAddr, protocol_type);
277 turn_server_.AddInternalSocket(kTurnAlternateIntAddr, protocol_type); 304 turn_server_.AddInternalSocket(kTurnAlternateIntAddr, protocol_type);
278 turn_server_.set_redirect_hook(&redirector); 305 turn_server_.set_redirect_hook(&redirector);
279 CreateTurnPort(kTurnUsername, kTurnPassword, 306 CreateTurnPort(kTurnUsername, kTurnPassword,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 CreateTurnPort(kTurnUsername, kTurnPassword, 370 CreateTurnPort(kTurnUsername, kTurnPassword,
344 cricket::ProtocolAddress(kTurnIntAddr, protocol_type)); 371 cricket::ProtocolAddress(kTurnIntAddr, protocol_type));
345 372
346 turn_port_->PrepareAddress(); 373 turn_port_->PrepareAddress();
347 EXPECT_TRUE_WAIT(turn_error_, kTimeout); 374 EXPECT_TRUE_WAIT(turn_error_, kTimeout);
348 ASSERT_EQ(0U, turn_port_->Candidates().size()); 375 ASSERT_EQ(0U, turn_port_->Candidates().size());
349 } 376 }
350 377
351 void TestTurnConnection() { 378 void TestTurnConnection() {
352 // Create ports and prepare addresses. 379 // Create ports and prepare addresses.
353 ASSERT_TRUE(turn_port_ != NULL); 380 PrepareTurnAndUdpPorts();
354 turn_port_->PrepareAddress();
355 ASSERT_TRUE_WAIT(turn_ready_, kTimeout);
356 CreateUdpPort();
357 udp_port_->PrepareAddress();
358 ASSERT_TRUE_WAIT(udp_ready_, kTimeout);
359 381
360 // Send ping from UDP to TURN. 382 // Send ping from UDP to TURN.
361 Connection* conn1 = udp_port_->CreateConnection( 383 Connection* conn1 = udp_port_->CreateConnection(
362 turn_port_->Candidates()[0], Port::ORIGIN_MESSAGE); 384 turn_port_->Candidates()[0], Port::ORIGIN_MESSAGE);
363 ASSERT_TRUE(conn1 != NULL); 385 ASSERT_TRUE(conn1 != NULL);
364 conn1->Ping(0); 386 conn1->Ping(0);
365 WAIT(!turn_unknown_address_, kTimeout); 387 WAIT(!turn_unknown_address_, kTimeout);
366 EXPECT_FALSE(turn_unknown_address_); 388 EXPECT_FALSE(turn_unknown_address_);
367 EXPECT_FALSE(conn1->receiving()); 389 EXPECT_FALSE(conn1->receiving());
368 EXPECT_EQ(Connection::STATE_WRITE_INIT, conn1->write_state()); 390 EXPECT_EQ(Connection::STATE_WRITE_INIT, conn1->write_state());
(...skipping 10 matching lines...) Expand all
379 EXPECT_TRUE(conn2->receiving()); 401 EXPECT_TRUE(conn2->receiving());
380 EXPECT_EQ(Connection::STATE_WRITE_INIT, conn1->write_state()); 402 EXPECT_EQ(Connection::STATE_WRITE_INIT, conn1->write_state());
381 403
382 // Send another ping from UDP to TURN. 404 // Send another ping from UDP to TURN.
383 conn1->Ping(0); 405 conn1->Ping(0);
384 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, conn1->write_state(), kTimeout); 406 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, conn1->write_state(), kTimeout);
385 EXPECT_TRUE(conn2->receiving()); 407 EXPECT_TRUE(conn2->receiving());
386 } 408 }
387 409
388 void TestDestroyTurnConnection() { 410 void TestDestroyTurnConnection() {
389 turn_port_->PrepareAddress(); 411 PrepareTurnAndUdpPorts();
390 ASSERT_TRUE_WAIT(turn_ready_, kTimeout);
391 // Create a remote UDP port
392 CreateUdpPort();
393 udp_port_->PrepareAddress();
394 ASSERT_TRUE_WAIT(udp_ready_, kTimeout);
395 412
396 // Create connections on both ends. 413 // Create connections on both ends.
397 Connection* conn1 = udp_port_->CreateConnection(turn_port_->Candidates()[0], 414 Connection* conn1 = udp_port_->CreateConnection(turn_port_->Candidates()[0],
398 Port::ORIGIN_MESSAGE); 415 Port::ORIGIN_MESSAGE);
399 Connection* conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0], 416 Connection* conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
400 Port::ORIGIN_MESSAGE); 417 Port::ORIGIN_MESSAGE);
401 ASSERT_TRUE(conn2 != NULL); 418 ASSERT_TRUE(conn2 != NULL);
402 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout); 419 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout);
403 // Make sure turn connection can receive. 420 // Make sure turn connection can receive.
404 conn1->Ping(0); 421 conn1->Ping(0);
(...skipping 16 matching lines...) Expand all
421 438
422 // If the connection is created again, it will start to receive pings. 439 // If the connection is created again, it will start to receive pings.
423 conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0], 440 conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
424 Port::ORIGIN_MESSAGE); 441 Port::ORIGIN_MESSAGE);
425 conn1->Ping(0); 442 conn1->Ping(0);
426 EXPECT_TRUE_WAIT(conn2->receiving(), kTimeout); 443 EXPECT_TRUE_WAIT(conn2->receiving(), kTimeout);
427 EXPECT_FALSE(turn_unknown_address_); 444 EXPECT_FALSE(turn_unknown_address_);
428 } 445 }
429 446
430 void TestTurnSendData() { 447 void TestTurnSendData() {
431 turn_port_->PrepareAddress(); 448 PrepareTurnAndUdpPorts();
432 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); 449
433 CreateUdpPort();
434 udp_port_->PrepareAddress();
435 EXPECT_TRUE_WAIT(udp_ready_, kTimeout);
436 // Create connections and send pings. 450 // Create connections and send pings.
437 Connection* conn1 = turn_port_->CreateConnection( 451 Connection* conn1 = turn_port_->CreateConnection(
438 udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE); 452 udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE);
439 Connection* conn2 = udp_port_->CreateConnection( 453 Connection* conn2 = udp_port_->CreateConnection(
440 turn_port_->Candidates()[0], Port::ORIGIN_MESSAGE); 454 turn_port_->Candidates()[0], Port::ORIGIN_MESSAGE);
441 ASSERT_TRUE(conn1 != NULL); 455 ASSERT_TRUE(conn1 != NULL);
442 ASSERT_TRUE(conn2 != NULL); 456 ASSERT_TRUE(conn2 != NULL);
443 conn1->SignalReadPacket.connect(static_cast<TurnPortTest*>(this), 457 conn1->SignalReadPacket.connect(static_cast<TurnPortTest*>(this),
444 &TurnPortTest::OnTurnReadPacket); 458 &TurnPortTest::OnTurnReadPacket);
445 conn2->SignalReadPacket.connect(static_cast<TurnPortTest*>(this), 459 conn2->SignalReadPacket.connect(static_cast<TurnPortTest*>(this),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 rtc::scoped_ptr<rtc::AsyncPacketSocket> socket_; 495 rtc::scoped_ptr<rtc::AsyncPacketSocket> socket_;
482 cricket::TestTurnServer turn_server_; 496 cricket::TestTurnServer turn_server_;
483 rtc::scoped_ptr<TurnPort> turn_port_; 497 rtc::scoped_ptr<TurnPort> turn_port_;
484 rtc::scoped_ptr<UDPPort> udp_port_; 498 rtc::scoped_ptr<UDPPort> udp_port_;
485 bool turn_ready_; 499 bool turn_ready_;
486 bool turn_error_; 500 bool turn_error_;
487 bool turn_unknown_address_; 501 bool turn_unknown_address_;
488 bool turn_create_permission_success_; 502 bool turn_create_permission_success_;
489 bool udp_ready_; 503 bool udp_ready_;
490 bool test_finish_; 504 bool test_finish_;
505 bool turn_refresh_success_ = false;
506 bool connection_destroyed_ = false;
491 std::vector<rtc::Buffer> turn_packets_; 507 std::vector<rtc::Buffer> turn_packets_;
492 std::vector<rtc::Buffer> udp_packets_; 508 std::vector<rtc::Buffer> udp_packets_;
493 rtc::PacketOptions options; 509 rtc::PacketOptions options;
494 }; 510 };
495 511
496 // Do a normal TURN allocation. 512 // Do a normal TURN allocation.
497 TEST_F(TurnPortTest, TestTurnAllocate) { 513 TEST_F(TurnPortTest, TestTurnAllocate) {
498 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); 514 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
499 EXPECT_EQ(0, turn_port_->SetOption(rtc::Socket::OPT_SNDBUF, 10*1024)); 515 EXPECT_EQ(0, turn_port_->SetOption(rtc::Socket::OPT_SNDBUF, 10*1024));
500 turn_port_->PrepareAddress(); 516 turn_port_->PrepareAddress();
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 664
649 // Verifies that the new port has the same address. 665 // Verifies that the new port has the same address.
650 EXPECT_EQ(first_addr, turn_port_->socket()->GetLocalAddress()); 666 EXPECT_EQ(first_addr, turn_port_->socket()->GetLocalAddress());
651 667
652 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); 668 EXPECT_TRUE_WAIT(turn_ready_, kTimeout);
653 669
654 // Verifies that the new port has a different address now. 670 // Verifies that the new port has a different address now.
655 EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress()); 671 EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress());
656 } 672 }
657 673
674 TEST_F(TurnPortTest, TestRefreshRequestGetErrorResponse) {
pthatcher1 2015/12/08 20:04:20 Get => Gets
honghaiz3 2015/12/10 17:58:30 Done.
675 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
676 turn_port_->PrepareAddress();
677 EXPECT_TRUE_WAIT(turn_ready_, kTimeout);
678 // set bad credentials.
pthatcher1 2015/12/08 20:04:20 set => Set
honghaiz3 2015/12/10 17:58:30 Done.
679 cricket::RelayCredentials bad_credentials("bad_user", "bad_pwd");
680 turn_port_->set_credentials(bad_credentials);
681 turn_refresh_success_ = false;
682 turn_port_->FlushRequests();
683 EXPECT_TRUE_WAIT(turn_refresh_success_, kTimeout);
pthatcher1 2015/12/08 20:04:20 Wait.. it's successful even though the credentials
honghaiz3 2015/12/10 17:58:30 It is right. Because when we call FlushRequest th
684 // Now another RefreshRequest with bad credentials is scheduled.
685 // Flush it again, it will receive a bad response.
686 turn_port_->FlushRequests();
687 EXPECT_TRUE_WAIT(!turn_refresh_success_, kTimeout);
688 EXPECT_TRUE(turn_port_->connections().empty());
689 EXPECT_FALSE(turn_port_->connected());
690 }
691
658 // Test that CreateConnection will return null if port becomes disconnected. 692 // Test that CreateConnection will return null if port becomes disconnected.
659 TEST_F(TurnPortTest, TestCreateConnectionWhenSocketClosed) { 693 TEST_F(TurnPortTest, TestCreateConnectionWhenSocketClosed) {
660 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); 694 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
661 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr); 695 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr);
662 turn_port_->PrepareAddress(); 696 PrepareTurnAndUdpPorts();
663 ASSERT_TRUE_WAIT(turn_ready_, kTimeout);
664
665 CreateUdpPort();
666 udp_port_->PrepareAddress();
667 ASSERT_TRUE_WAIT(udp_ready_, kTimeout);
668 // Create a connection. 697 // Create a connection.
669 Connection* conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0], 698 Connection* conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
670 Port::ORIGIN_MESSAGE); 699 Port::ORIGIN_MESSAGE);
671 ASSERT_TRUE(conn1 != NULL); 700 ASSERT_TRUE(conn1 != NULL);
672 701
673 // Close the socket and create a connection again. 702 // Close the socket and create a connection again.
674 turn_port_->OnSocketClose(turn_port_->socket(), 1); 703 turn_port_->OnSocketClose(turn_port_->socket(), 1);
675 conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0], 704 conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
676 Port::ORIGIN_MESSAGE); 705 Port::ORIGIN_MESSAGE);
677 ASSERT_TRUE(conn1 == NULL); 706 ASSERT_TRUE(conn1 == NULL);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 // Run TurnConnectionTest with one-time-use nonce feature. 794 // Run TurnConnectionTest with one-time-use nonce feature.
766 // Here server will send a 438 STALE_NONCE error message for 795 // Here server will send a 438 STALE_NONCE error message for
767 // every TURN transaction. 796 // every TURN transaction.
768 TEST_F(TurnPortTest, TestTurnConnectionUsingOTUNonce) { 797 TEST_F(TurnPortTest, TestTurnConnectionUsingOTUNonce) {
769 turn_server_.set_enable_otu_nonce(true); 798 turn_server_.set_enable_otu_nonce(true);
770 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); 799 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
771 TestTurnConnection(); 800 TestTurnConnection();
772 } 801 }
773 802
774 // Test that CreatePermissionRequest will be scheduled after the success 803 // Test that CreatePermissionRequest will be scheduled after the success
775 // of the first create permission request. 804 // of the first create permission request and the request will get an
805 // ErrorResponse if the ufrag and pwd are incorrect.
776 TEST_F(TurnPortTest, TestRefreshCreatePermissionRequest) { 806 TEST_F(TurnPortTest, TestRefreshCreatePermissionRequest) {
777 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); 807 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
778 808 PrepareTurnAndUdpPorts();
779 ASSERT_TRUE(turn_port_ != NULL);
780 turn_port_->PrepareAddress();
781 ASSERT_TRUE_WAIT(turn_ready_, kTimeout);
782 CreateUdpPort();
783 udp_port_->PrepareAddress();
784 ASSERT_TRUE_WAIT(udp_ready_, kTimeout);
785 809
786 Connection* conn = turn_port_->CreateConnection(udp_port_->Candidates()[0], 810 Connection* conn = turn_port_->CreateConnection(udp_port_->Candidates()[0],
787 Port::ORIGIN_MESSAGE); 811 Port::ORIGIN_MESSAGE);
812 ConnectConnectionDestroyedSignal(conn);
788 ASSERT_TRUE(conn != NULL); 813 ASSERT_TRUE(conn != NULL);
789 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout); 814 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout);
790 turn_create_permission_success_ = false; 815 turn_create_permission_success_ = false;
791 // A create-permission-request should be pending. 816 // A create-permission-request should be pending.
817 // After the next create-permission-response is received, it will schedule
818 // another request with bad_ufrag and bad_pwd.
819 cricket::RelayCredentials bad_credentials("bad_user", "bad_pwd");
820 turn_port_->set_credentials(bad_credentials);
792 turn_port_->FlushRequests(); 821 turn_port_->FlushRequests();
793 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout); 822 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout);
823 // Flush the requests again; the create-permission-request will fail.
824 turn_port_->FlushRequests();
825 EXPECT_TRUE_WAIT(!turn_create_permission_success_, kTimeout);
826 EXPECT_TRUE_WAIT(connection_destroyed_, kTimeout);
827 }
828
829 TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) {
830 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
831 PrepareTurnAndUdpPorts();
832 Connection* conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
833 Port::ORIGIN_MESSAGE);
834 ASSERT_TRUE(conn1 != nullptr);
835 Connection* conn2 = udp_port_->CreateConnection(turn_port_->Candidates()[0],
836 Port::ORIGIN_MESSAGE);
837 ASSERT_TRUE(conn2 != nullptr);
838 ConnectConnectionDestroyedSignal(conn1);
839 conn1->Ping(0);
840 ASSERT_TRUE_WAIT(conn1->writable(), kTimeout);
841
842 std::string data = "ABC";
843 conn1->Send(data.data(), data.length(), options);
844 bool success =
845 turn_port_->SetEntryChannelId(udp_port_->Candidates()[0].address(), -1);
846 ASSERT_TRUE(success);
847 // Next time when the binding request is sent, it will get an ErrorResponse.
848 EXPECT_TRUE_WAIT(CheckConnectionDestroyed(), kTimeout);
794 } 849 }
795 850
796 // Do a TURN allocation, establish a UDP connection, and send some data. 851 // Do a TURN allocation, establish a UDP connection, and send some data.
797 TEST_F(TurnPortTest, TestTurnSendDataTurnUdpToUdp) { 852 TEST_F(TurnPortTest, TestTurnSendDataTurnUdpToUdp) {
798 // Create ports and prepare addresses. 853 // Create ports and prepare addresses.
799 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); 854 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
800 TestTurnSendData(); 855 TestTurnSendData();
801 EXPECT_EQ(cricket::UDP_PROTOCOL_NAME, 856 EXPECT_EQ(cricket::UDP_PROTOCOL_NAME,
802 turn_port_->Candidates()[0].relay_protocol()); 857 turn_port_->Candidates()[0].relay_protocol());
803 } 858 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 turn_port_->PrepareAddress(); 940 turn_port_->PrepareAddress();
886 ASSERT_TRUE_WAIT(turn_error_, kTimeout); 941 ASSERT_TRUE_WAIT(turn_error_, kTimeout);
887 EXPECT_TRUE(turn_port_->Candidates().empty()); 942 EXPECT_TRUE(turn_port_->Candidates().empty());
888 turn_port_.reset(); 943 turn_port_.reset();
889 rtc::Thread::Current()->Post(this, MSG_TESTFINISH); 944 rtc::Thread::Current()->Post(this, MSG_TESTFINISH);
890 // Waiting for above message to be processed. 945 // Waiting for above message to be processed.
891 ASSERT_TRUE_WAIT(test_finish_, kTimeout); 946 ASSERT_TRUE_WAIT(test_finish_, kTimeout);
892 EXPECT_EQ(last_fd_count, GetFDCount()); 947 EXPECT_EQ(last_fd_count, GetFDCount());
893 } 948 }
894 #endif 949 #endif
OLDNEW
« webrtc/p2p/base/turnport.cc ('K') | « webrtc/p2p/base/turnport.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698