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

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: merge Created 5 years 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/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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 166 }
166 void OnTurnPortError(Port* port) { 167 void OnTurnPortError(Port* port) {
167 turn_error_ = true; 168 turn_error_ = true;
168 } 169 }
169 void OnTurnUnknownAddress(PortInterface* port, const SocketAddress& addr, 170 void OnTurnUnknownAddress(PortInterface* port, const SocketAddress& addr,
170 cricket::ProtocolType proto, 171 cricket::ProtocolType proto,
171 cricket::IceMessage* msg, const std::string& rf, 172 cricket::IceMessage* msg, const std::string& rf,
172 bool /*port_muxed*/) { 173 bool /*port_muxed*/) {
173 turn_unknown_address_ = true; 174 turn_unknown_address_ = true;
174 } 175 }
175 void OnTurnCreatePermissionResult(TurnPort* port, const SocketAddress& addr, 176 void OnTurnCreatePermissionResult(TurnPort* port,
176 int code) { 177 const SocketAddress& addr,
178 int code) {
177 // Ignoring the address. 179 // Ignoring the address.
178 if (code == 0) { 180 turn_create_permission_success_ = (code == 0);
179 turn_create_permission_success_ = true; 181 }
180 } 182
183 void OnTurnRefreshResult(TurnPort* port, int code) {
184 turn_refresh_success_ = (code == 0);
181 } 185 }
182 void OnTurnReadPacket(Connection* conn, const char* data, size_t size, 186 void OnTurnReadPacket(Connection* conn, const char* data, size_t size,
183 const rtc::PacketTime& packet_time) { 187 const rtc::PacketTime& packet_time) {
184 turn_packets_.push_back(rtc::Buffer(data, size)); 188 turn_packets_.push_back(rtc::Buffer(data, size));
185 } 189 }
186 void OnUdpPortComplete(Port* port) { 190 void OnUdpPortComplete(Port* port) {
187 udp_ready_ = true; 191 udp_ready_ = true;
188 } 192 }
189 void OnUdpReadPacket(Connection* conn, const char* data, size_t size, 193 void OnUdpReadPacket(Connection* conn, const char* data, size_t size,
190 const rtc::PacketTime& packet_time) { 194 const rtc::PacketTime& packet_time) {
191 udp_packets_.push_back(rtc::Buffer(data, size)); 195 udp_packets_.push_back(rtc::Buffer(data, size));
192 } 196 }
197 void OnConnectionDestroyed(Connection* conn) { connection_destroyed_ = true; }
193 void OnSocketReadPacket(rtc::AsyncPacketSocket* socket, 198 void OnSocketReadPacket(rtc::AsyncPacketSocket* socket,
194 const char* data, size_t size, 199 const char* data, size_t size,
195 const rtc::SocketAddress& remote_addr, 200 const rtc::SocketAddress& remote_addr,
196 const rtc::PacketTime& packet_time) { 201 const rtc::PacketTime& packet_time) {
197 turn_port_->HandleIncomingPacket(socket, data, size, remote_addr, 202 turn_port_->HandleIncomingPacket(socket, data, size, remote_addr,
198 packet_time); 203 packet_time);
199 } 204 }
200 rtc::AsyncSocket* CreateServerSocket(const SocketAddress addr) { 205 rtc::AsyncSocket* CreateServerSocket(const SocketAddress addr) {
201 rtc::AsyncSocket* socket = ss_->CreateAsyncSocket(SOCK_STREAM); 206 rtc::AsyncSocket* socket = ss_->CreateAsyncSocket(SOCK_STREAM);
202 EXPECT_GE(socket->Bind(addr), 0); 207 EXPECT_GE(socket->Bind(addr), 0);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 271
267 void ConnectSignals() { 272 void ConnectSignals() {
268 turn_port_->SignalPortComplete.connect(this, 273 turn_port_->SignalPortComplete.connect(this,
269 &TurnPortTest::OnTurnPortComplete); 274 &TurnPortTest::OnTurnPortComplete);
270 turn_port_->SignalPortError.connect(this, 275 turn_port_->SignalPortError.connect(this,
271 &TurnPortTest::OnTurnPortError); 276 &TurnPortTest::OnTurnPortError);
272 turn_port_->SignalUnknownAddress.connect(this, 277 turn_port_->SignalUnknownAddress.connect(this,
273 &TurnPortTest::OnTurnUnknownAddress); 278 &TurnPortTest::OnTurnUnknownAddress);
274 turn_port_->SignalCreatePermissionResult.connect(this, 279 turn_port_->SignalCreatePermissionResult.connect(this,
275 &TurnPortTest::OnTurnCreatePermissionResult); 280 &TurnPortTest::OnTurnCreatePermissionResult);
281 turn_port_->SignalTurnRefreshResult.connect(
282 this, &TurnPortTest::OnTurnRefreshResult);
283 }
284 void ConnectConnectionDestroyedSignal(Connection* conn) {
285 conn->SignalDestroyed.connect(this, &TurnPortTest::OnConnectionDestroyed);
276 } 286 }
277 287
278 void CreateUdpPort() { CreateUdpPort(kLocalAddr2); } 288 void CreateUdpPort() { CreateUdpPort(kLocalAddr2); }
279 289
280 void CreateUdpPort(const SocketAddress& address) { 290 void CreateUdpPort(const SocketAddress& address) {
281 udp_port_.reset(UDPPort::Create(main_, &socket_factory_, &network_, 291 udp_port_.reset(UDPPort::Create(main_, &socket_factory_, &network_,
282 address.ipaddr(), 0, 0, kIceUfrag2, 292 address.ipaddr(), 0, 0, kIceUfrag2,
283 kIcePwd2, std::string(), false)); 293 kIcePwd2, std::string(), false));
284 // UDP port will be controlled. 294 // UDP port will be controlled.
285 udp_port_->SetIceRole(cricket::ICEROLE_CONTROLLED); 295 udp_port_->SetIceRole(cricket::ICEROLE_CONTROLLED);
286 udp_port_->SignalPortComplete.connect( 296 udp_port_->SignalPortComplete.connect(
287 this, &TurnPortTest::OnUdpPortComplete); 297 this, &TurnPortTest::OnUdpPortComplete);
288 } 298 }
289 299
300 void PrepareTurnAndUdpPorts() {
301 // turn_port_ should have been created.
302 ASSERT_TRUE(turn_port_ != nullptr);
303 turn_port_->PrepareAddress();
304 ASSERT_TRUE_WAIT(turn_ready_, kTimeout);
305
306 CreateUdpPort();
307 udp_port_->PrepareAddress();
308 ASSERT_TRUE_WAIT(udp_ready_, kTimeout);
309 }
310
311 bool CheckConnectionDestroyed() {
312 turn_port_->FlushRequests();
313 rtc::Thread::Current()->ProcessMessages(50);
314 return connection_destroyed_;
315 }
316
290 void TestTurnAlternateServer(cricket::ProtocolType protocol_type) { 317 void TestTurnAlternateServer(cricket::ProtocolType protocol_type) {
291 std::vector<rtc::SocketAddress> redirect_addresses; 318 std::vector<rtc::SocketAddress> redirect_addresses;
292 redirect_addresses.push_back(kTurnAlternateIntAddr); 319 redirect_addresses.push_back(kTurnAlternateIntAddr);
293 320
294 cricket::TestTurnRedirector redirector(redirect_addresses); 321 cricket::TestTurnRedirector redirector(redirect_addresses);
295 322
296 turn_server_.AddInternalSocket(kTurnIntAddr, protocol_type); 323 turn_server_.AddInternalSocket(kTurnIntAddr, protocol_type);
297 turn_server_.AddInternalSocket(kTurnAlternateIntAddr, protocol_type); 324 turn_server_.AddInternalSocket(kTurnAlternateIntAddr, protocol_type);
298 turn_server_.set_redirect_hook(&redirector); 325 turn_server_.set_redirect_hook(&redirector);
299 CreateTurnPort(kTurnUsername, kTurnPassword, 326 CreateTurnPort(kTurnUsername, kTurnPassword,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 CreateTurnPort(kTurnUsername, kTurnPassword, 390 CreateTurnPort(kTurnUsername, kTurnPassword,
364 cricket::ProtocolAddress(kTurnIntAddr, protocol_type)); 391 cricket::ProtocolAddress(kTurnIntAddr, protocol_type));
365 392
366 turn_port_->PrepareAddress(); 393 turn_port_->PrepareAddress();
367 EXPECT_TRUE_WAIT(turn_error_, kTimeout); 394 EXPECT_TRUE_WAIT(turn_error_, kTimeout);
368 ASSERT_EQ(0U, turn_port_->Candidates().size()); 395 ASSERT_EQ(0U, turn_port_->Candidates().size());
369 } 396 }
370 397
371 void TestTurnConnection() { 398 void TestTurnConnection() {
372 // Create ports and prepare addresses. 399 // Create ports and prepare addresses.
373 ASSERT_TRUE(turn_port_ != NULL); 400 PrepareTurnAndUdpPorts();
374 turn_port_->PrepareAddress();
375 ASSERT_TRUE_WAIT(turn_ready_, kTimeout);
376 CreateUdpPort();
377 udp_port_->PrepareAddress();
378 ASSERT_TRUE_WAIT(udp_ready_, kTimeout);
379 401
380 // Send ping from UDP to TURN. 402 // Send ping from UDP to TURN.
381 Connection* conn1 = udp_port_->CreateConnection( 403 Connection* conn1 = udp_port_->CreateConnection(
382 turn_port_->Candidates()[0], Port::ORIGIN_MESSAGE); 404 turn_port_->Candidates()[0], Port::ORIGIN_MESSAGE);
383 ASSERT_TRUE(conn1 != NULL); 405 ASSERT_TRUE(conn1 != NULL);
384 conn1->Ping(0); 406 conn1->Ping(0);
385 WAIT(!turn_unknown_address_, kTimeout); 407 WAIT(!turn_unknown_address_, kTimeout);
386 EXPECT_FALSE(turn_unknown_address_); 408 EXPECT_FALSE(turn_unknown_address_);
387 EXPECT_FALSE(conn1->receiving()); 409 EXPECT_FALSE(conn1->receiving());
388 EXPECT_EQ(Connection::STATE_WRITE_INIT, conn1->write_state()); 410 EXPECT_EQ(Connection::STATE_WRITE_INIT, conn1->write_state());
(...skipping 10 matching lines...) Expand all
399 EXPECT_TRUE(conn2->receiving()); 421 EXPECT_TRUE(conn2->receiving());
400 EXPECT_EQ(Connection::STATE_WRITE_INIT, conn1->write_state()); 422 EXPECT_EQ(Connection::STATE_WRITE_INIT, conn1->write_state());
401 423
402 // Send another ping from UDP to TURN. 424 // Send another ping from UDP to TURN.
403 conn1->Ping(0); 425 conn1->Ping(0);
404 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, conn1->write_state(), kTimeout); 426 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, conn1->write_state(), kTimeout);
405 EXPECT_TRUE(conn2->receiving()); 427 EXPECT_TRUE(conn2->receiving());
406 } 428 }
407 429
408 void TestDestroyTurnConnection() { 430 void TestDestroyTurnConnection() {
409 turn_port_->PrepareAddress(); 431 PrepareTurnAndUdpPorts();
410 ASSERT_TRUE_WAIT(turn_ready_, kTimeout);
411 // Create a remote UDP port
412 CreateUdpPort();
413 udp_port_->PrepareAddress();
414 ASSERT_TRUE_WAIT(udp_ready_, kTimeout);
415 432
416 // Create connections on both ends. 433 // Create connections on both ends.
417 Connection* conn1 = udp_port_->CreateConnection(turn_port_->Candidates()[0], 434 Connection* conn1 = udp_port_->CreateConnection(turn_port_->Candidates()[0],
418 Port::ORIGIN_MESSAGE); 435 Port::ORIGIN_MESSAGE);
419 Connection* conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0], 436 Connection* conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
420 Port::ORIGIN_MESSAGE); 437 Port::ORIGIN_MESSAGE);
421 ASSERT_TRUE(conn2 != NULL); 438 ASSERT_TRUE(conn2 != NULL);
422 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout); 439 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout);
423 // Make sure turn connection can receive. 440 // Make sure turn connection can receive.
424 conn1->Ping(0); 441 conn1->Ping(0);
(...skipping 16 matching lines...) Expand all
441 458
442 // If the connection is created again, it will start to receive pings. 459 // If the connection is created again, it will start to receive pings.
443 conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0], 460 conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
444 Port::ORIGIN_MESSAGE); 461 Port::ORIGIN_MESSAGE);
445 conn1->Ping(0); 462 conn1->Ping(0);
446 EXPECT_TRUE_WAIT(conn2->receiving(), kTimeout); 463 EXPECT_TRUE_WAIT(conn2->receiving(), kTimeout);
447 EXPECT_FALSE(turn_unknown_address_); 464 EXPECT_FALSE(turn_unknown_address_);
448 } 465 }
449 466
450 void TestTurnSendData() { 467 void TestTurnSendData() {
451 turn_port_->PrepareAddress(); 468 PrepareTurnAndUdpPorts();
452 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); 469
453 CreateUdpPort();
454 udp_port_->PrepareAddress();
455 EXPECT_TRUE_WAIT(udp_ready_, kTimeout);
456 // Create connections and send pings. 470 // Create connections and send pings.
457 Connection* conn1 = turn_port_->CreateConnection( 471 Connection* conn1 = turn_port_->CreateConnection(
458 udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE); 472 udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE);
459 Connection* conn2 = udp_port_->CreateConnection( 473 Connection* conn2 = udp_port_->CreateConnection(
460 turn_port_->Candidates()[0], Port::ORIGIN_MESSAGE); 474 turn_port_->Candidates()[0], Port::ORIGIN_MESSAGE);
461 ASSERT_TRUE(conn1 != NULL); 475 ASSERT_TRUE(conn1 != NULL);
462 ASSERT_TRUE(conn2 != NULL); 476 ASSERT_TRUE(conn2 != NULL);
463 conn1->SignalReadPacket.connect(static_cast<TurnPortTest*>(this), 477 conn1->SignalReadPacket.connect(static_cast<TurnPortTest*>(this),
464 &TurnPortTest::OnTurnReadPacket); 478 &TurnPortTest::OnTurnReadPacket);
465 conn2->SignalReadPacket.connect(static_cast<TurnPortTest*>(this), 479 conn2->SignalReadPacket.connect(static_cast<TurnPortTest*>(this),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 rtc::scoped_ptr<rtc::AsyncPacketSocket> socket_; 515 rtc::scoped_ptr<rtc::AsyncPacketSocket> socket_;
502 cricket::TestTurnServer turn_server_; 516 cricket::TestTurnServer turn_server_;
503 rtc::scoped_ptr<TurnPort> turn_port_; 517 rtc::scoped_ptr<TurnPort> turn_port_;
504 rtc::scoped_ptr<UDPPort> udp_port_; 518 rtc::scoped_ptr<UDPPort> udp_port_;
505 bool turn_ready_; 519 bool turn_ready_;
506 bool turn_error_; 520 bool turn_error_;
507 bool turn_unknown_address_; 521 bool turn_unknown_address_;
508 bool turn_create_permission_success_; 522 bool turn_create_permission_success_;
509 bool udp_ready_; 523 bool udp_ready_;
510 bool test_finish_; 524 bool test_finish_;
525 bool turn_refresh_success_ = false;
526 bool connection_destroyed_ = false;
511 std::vector<rtc::Buffer> turn_packets_; 527 std::vector<rtc::Buffer> turn_packets_;
512 std::vector<rtc::Buffer> udp_packets_; 528 std::vector<rtc::Buffer> udp_packets_;
513 rtc::PacketOptions options; 529 rtc::PacketOptions options;
514 }; 530 };
515 531
516 // Do a normal TURN allocation. 532 // Do a normal TURN allocation.
517 TEST_F(TurnPortTest, TestTurnAllocate) { 533 TEST_F(TurnPortTest, TestTurnAllocate) {
518 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); 534 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
519 EXPECT_EQ(0, turn_port_->SetOption(rtc::Socket::OPT_SNDBUF, 10*1024)); 535 EXPECT_EQ(0, turn_port_->SetOption(rtc::Socket::OPT_SNDBUF, 10*1024));
520 turn_port_->PrepareAddress(); 536 turn_port_->PrepareAddress();
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 684
669 // Verifies that the new port has the same address. 685 // Verifies that the new port has the same address.
670 EXPECT_EQ(first_addr, turn_port_->socket()->GetLocalAddress()); 686 EXPECT_EQ(first_addr, turn_port_->socket()->GetLocalAddress());
671 687
672 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); 688 EXPECT_TRUE_WAIT(turn_ready_, kTimeout);
673 689
674 // Verifies that the new port has a different address now. 690 // Verifies that the new port has a different address now.
675 EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress()); 691 EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress());
676 } 692 }
677 693
694 TEST_F(TurnPortTest, TestRefreshRequestGetsErrorResponse) {
695 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
696 turn_port_->PrepareAddress();
697 EXPECT_TRUE_WAIT(turn_ready_, kTimeout);
698 // Set bad credentials.
699 cricket::RelayCredentials bad_credentials("bad_user", "bad_pwd");
700 turn_port_->set_credentials(bad_credentials);
701 turn_refresh_success_ = false;
702 // This sends out the first RefreshRequest with correct credentials.
703 // When this succeeds, it will schedule a new RefreshRequest with the bad
704 // credential.
705 turn_port_->FlushRequests();
706 EXPECT_TRUE_WAIT(turn_refresh_success_, kTimeout);
707 // Flush it again, it will receive a bad response.
708 turn_port_->FlushRequests();
709 EXPECT_TRUE_WAIT(!turn_refresh_success_, kTimeout);
710 EXPECT_TRUE(turn_port_->connections().empty());
711 EXPECT_FALSE(turn_port_->connected());
712 }
713
678 // Test that CreateConnection will return null if port becomes disconnected. 714 // Test that CreateConnection will return null if port becomes disconnected.
679 TEST_F(TurnPortTest, TestCreateConnectionWhenSocketClosed) { 715 TEST_F(TurnPortTest, TestCreateConnectionWhenSocketClosed) {
680 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); 716 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
681 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr); 717 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr);
682 turn_port_->PrepareAddress(); 718 PrepareTurnAndUdpPorts();
683 ASSERT_TRUE_WAIT(turn_ready_, kTimeout);
684
685 CreateUdpPort();
686 udp_port_->PrepareAddress();
687 ASSERT_TRUE_WAIT(udp_ready_, kTimeout);
688 // Create a connection. 719 // Create a connection.
689 Connection* conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0], 720 Connection* conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
690 Port::ORIGIN_MESSAGE); 721 Port::ORIGIN_MESSAGE);
691 ASSERT_TRUE(conn1 != NULL); 722 ASSERT_TRUE(conn1 != NULL);
692 723
693 // Close the socket and create a connection again. 724 // Close the socket and create a connection again.
694 turn_port_->OnSocketClose(turn_port_->socket(), 1); 725 turn_port_->OnSocketClose(turn_port_->socket(), 1);
695 conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0], 726 conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
696 Port::ORIGIN_MESSAGE); 727 Port::ORIGIN_MESSAGE);
697 ASSERT_TRUE(conn1 == NULL); 728 ASSERT_TRUE(conn1 == NULL);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 // Run TurnConnectionTest with one-time-use nonce feature. 816 // Run TurnConnectionTest with one-time-use nonce feature.
786 // Here server will send a 438 STALE_NONCE error message for 817 // Here server will send a 438 STALE_NONCE error message for
787 // every TURN transaction. 818 // every TURN transaction.
788 TEST_F(TurnPortTest, TestTurnConnectionUsingOTUNonce) { 819 TEST_F(TurnPortTest, TestTurnConnectionUsingOTUNonce) {
789 turn_server_.set_enable_otu_nonce(true); 820 turn_server_.set_enable_otu_nonce(true);
790 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); 821 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
791 TestTurnConnection(); 822 TestTurnConnection();
792 } 823 }
793 824
794 // Test that CreatePermissionRequest will be scheduled after the success 825 // Test that CreatePermissionRequest will be scheduled after the success
795 // of the first create permission request. 826 // of the first create permission request and the request will get an
827 // ErrorResponse if the ufrag and pwd are incorrect.
796 TEST_F(TurnPortTest, TestRefreshCreatePermissionRequest) { 828 TEST_F(TurnPortTest, TestRefreshCreatePermissionRequest) {
797 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); 829 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
798 830 PrepareTurnAndUdpPorts();
799 ASSERT_TRUE(turn_port_ != NULL);
800 turn_port_->PrepareAddress();
801 ASSERT_TRUE_WAIT(turn_ready_, kTimeout);
802 CreateUdpPort();
803 udp_port_->PrepareAddress();
804 ASSERT_TRUE_WAIT(udp_ready_, kTimeout);
805 831
806 Connection* conn = turn_port_->CreateConnection(udp_port_->Candidates()[0], 832 Connection* conn = turn_port_->CreateConnection(udp_port_->Candidates()[0],
807 Port::ORIGIN_MESSAGE); 833 Port::ORIGIN_MESSAGE);
834 ConnectConnectionDestroyedSignal(conn);
808 ASSERT_TRUE(conn != NULL); 835 ASSERT_TRUE(conn != NULL);
809 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout); 836 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout);
810 turn_create_permission_success_ = false; 837 turn_create_permission_success_ = false;
811 // A create-permission-request should be pending. 838 // A create-permission-request should be pending.
839 // After the next create-permission-response is received, it will schedule
840 // another request with bad_ufrag and bad_pwd.
841 cricket::RelayCredentials bad_credentials("bad_user", "bad_pwd");
842 turn_port_->set_credentials(bad_credentials);
812 turn_port_->FlushRequests(); 843 turn_port_->FlushRequests();
813 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout); 844 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout);
845 // Flush the requests again; the create-permission-request will fail.
846 turn_port_->FlushRequests();
847 EXPECT_TRUE_WAIT(!turn_create_permission_success_, kTimeout);
848 EXPECT_TRUE_WAIT(connection_destroyed_, kTimeout);
849 }
850
851 TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) {
852 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
853 PrepareTurnAndUdpPorts();
854 Connection* conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
855 Port::ORIGIN_MESSAGE);
856 ASSERT_TRUE(conn1 != nullptr);
857 Connection* conn2 = udp_port_->CreateConnection(turn_port_->Candidates()[0],
858 Port::ORIGIN_MESSAGE);
859 ASSERT_TRUE(conn2 != nullptr);
860 ConnectConnectionDestroyedSignal(conn1);
861 conn1->Ping(0);
862 ASSERT_TRUE_WAIT(conn1->writable(), kTimeout);
863
864 std::string data = "ABC";
865 conn1->Send(data.data(), data.length(), options);
866 bool success =
867 turn_port_->SetEntryChannelId(udp_port_->Candidates()[0].address(), -1);
868 ASSERT_TRUE(success);
869 // Next time when the binding request is sent, it will get an ErrorResponse.
870 EXPECT_TRUE_WAIT(CheckConnectionDestroyed(), kTimeout);
814 } 871 }
815 872
816 // Do a TURN allocation, establish a UDP connection, and send some data. 873 // Do a TURN allocation, establish a UDP connection, and send some data.
817 TEST_F(TurnPortTest, TestTurnSendDataTurnUdpToUdp) { 874 TEST_F(TurnPortTest, TestTurnSendDataTurnUdpToUdp) {
818 // Create ports and prepare addresses. 875 // Create ports and prepare addresses.
819 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); 876 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
820 TestTurnSendData(); 877 TestTurnSendData();
821 EXPECT_EQ(cricket::UDP_PROTOCOL_NAME, 878 EXPECT_EQ(cricket::UDP_PROTOCOL_NAME,
822 turn_port_->Candidates()[0].relay_protocol()); 879 turn_port_->Candidates()[0].relay_protocol());
823 } 880 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 turn_port_->PrepareAddress(); 985 turn_port_->PrepareAddress();
929 ASSERT_TRUE_WAIT(turn_error_, kTimeout); 986 ASSERT_TRUE_WAIT(turn_error_, kTimeout);
930 EXPECT_TRUE(turn_port_->Candidates().empty()); 987 EXPECT_TRUE(turn_port_->Candidates().empty());
931 turn_port_.reset(); 988 turn_port_.reset();
932 rtc::Thread::Current()->Post(this, MSG_TESTFINISH); 989 rtc::Thread::Current()->Post(this, MSG_TESTFINISH);
933 // Waiting for above message to be processed. 990 // Waiting for above message to be processed.
934 ASSERT_TRUE_WAIT(test_finish_, kTimeout); 991 ASSERT_TRUE_WAIT(test_finish_, kTimeout);
935 EXPECT_EQ(last_fd_count, GetFDCount()); 992 EXPECT_EQ(last_fd_count, GetFDCount());
936 } 993 }
937 #endif 994 #endif
OLDNEW
« no previous file with comments | « webrtc/p2p/base/turnport.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698