Chromium Code Reviews

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

Issue 1595613004: Reset TURN port NONCE when a new socket is created. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« 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)
(...skipping 587 matching lines...)
598 } 598 }
599 599
600 // Try to do a TURN allocation with an invalid password. 600 // Try to do a TURN allocation with an invalid password.
601 TEST_F(TurnPortTest, TestTurnAllocateBadPassword) { 601 TEST_F(TurnPortTest, TestTurnAllocateBadPassword) {
602 CreateTurnPort(kTurnUsername, "bad", kTurnUdpProtoAddr); 602 CreateTurnPort(kTurnUsername, "bad", kTurnUdpProtoAddr);
603 turn_port_->PrepareAddress(); 603 turn_port_->PrepareAddress();
604 EXPECT_TRUE_WAIT(turn_error_, kTimeout); 604 EXPECT_TRUE_WAIT(turn_error_, kTimeout);
605 ASSERT_EQ(0U, turn_port_->Candidates().size()); 605 ASSERT_EQ(0U, turn_port_->Candidates().size());
606 } 606 }
607 607
608 // Tests that TURN port NONCE will be reset even when receiving an
pthatcher1 2016/01/19 01:48:38 even when => when
honghaiz3 2016/01/20 00:54:38 Done.
609 // ALLOCATE MISMATCH error.
610 TEST_F(TurnPortTest, TestTurnAllocateNonceRestAfterAllocateMismatch) {
611 // Do a normal allocation first.
612 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
613 turn_port_->PrepareAddress();
614 EXPECT_TRUE_WAIT(turn_ready_, kTimeout);
615 rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress());
616 // Clear connected_ flag on turnport to suppress the release of
617 // the allocation.
618 turn_port_->OnSocketClose(turn_port_->socket(), 0);
619
620 std::string old_nonce = turn_port_->nonce();
621 std::string old_hash = turn_port_->hash();
622 // Forces the socket server to assign the same port.
623 ss_->SetNextPortForTesting(first_addr.port());
624 turn_ready_ = false;
625 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
626
627 // These are needed in order to check that the client will reset NONCE when
628 // receiving ALLOCATE_MISMATCH error.
629 turn_port_->set_nonce(old_nonce);
630 turn_port_->set_hash(old_hash);
pthatcher1 2016/01/19 01:48:38 Instead of altering the nonce+hash of the client,
honghaiz3 2016/01/20 00:54:38 Done. We cannot directly change the NONCE but the
631 turn_port_->PrepareAddress();
632
633 EXPECT_TRUE_WAIT(turn_ready_, kTimeout);
634 EXPECT_NE(old_nonce, turn_port_->nonce());
635 }
636
608 // Tests that a new local address is created after 637 // Tests that a new local address is created after
609 // STUN_ERROR_ALLOCATION_MISMATCH. 638 // STUN_ERROR_ALLOCATION_MISMATCH.
610 TEST_F(TurnPortTest, TestTurnAllocateMismatch) { 639 TEST_F(TurnPortTest, TestTurnAllocateMismatch) {
611 // Do a normal allocation first. 640 // Do a normal allocation first.
612 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); 641 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
613 turn_port_->PrepareAddress(); 642 turn_port_->PrepareAddress();
614 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); 643 EXPECT_TRUE_WAIT(turn_ready_, kTimeout);
615 rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress()); 644 rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress());
616 645
617 // Clear connected_ flag on turnport to suppress the release of 646 // Clear connected_ flag on turnport to suppress the release of
618 // the allocation. 647 // the allocation.
619 turn_port_->OnSocketClose(turn_port_->socket(), 0); 648 turn_port_->OnSocketClose(turn_port_->socket(), 0);
620 649
621 // Forces the socket server to assign the same port. 650 // Forces the socket server to assign the same port.
622 ss_->SetNextPortForTesting(first_addr.port()); 651 ss_->SetNextPortForTesting(first_addr.port());
623 652
624 turn_ready_ = false; 653 turn_ready_ = false;
625 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); 654 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
655
626 turn_port_->PrepareAddress(); 656 turn_port_->PrepareAddress();
627 657
628 // Verifies that the new port has the same address. 658 // Verifies that the new port has the same address.
629 EXPECT_EQ(first_addr, turn_port_->socket()->GetLocalAddress()); 659 EXPECT_EQ(first_addr, turn_port_->socket()->GetLocalAddress());
630 660
631 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); 661 EXPECT_TRUE_WAIT(turn_ready_, kTimeout);
632 662
633 // Verifies that the new port has a different address now. 663 // Verifies that the new port has a different address now.
634 EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress()); 664 EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress());
635 } 665 }
(...skipping 355 matching lines...)
991 turn_port_->PrepareAddress(); 1021 turn_port_->PrepareAddress();
992 ASSERT_TRUE_WAIT(turn_error_, kResolverTimeout); 1022 ASSERT_TRUE_WAIT(turn_error_, kResolverTimeout);
993 EXPECT_TRUE(turn_port_->Candidates().empty()); 1023 EXPECT_TRUE(turn_port_->Candidates().empty());
994 turn_port_.reset(); 1024 turn_port_.reset();
995 rtc::Thread::Current()->Post(this, MSG_TESTFINISH); 1025 rtc::Thread::Current()->Post(this, MSG_TESTFINISH);
996 // Waiting for above message to be processed. 1026 // Waiting for above message to be processed.
997 ASSERT_TRUE_WAIT(test_finish_, kTimeout); 1027 ASSERT_TRUE_WAIT(test_finish_, kTimeout);
998 EXPECT_EQ(last_fd_count, GetFDCount()); 1028 EXPECT_EQ(last_fd_count, GetFDCount());
999 } 1029 }
1000 #endif 1030 #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