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

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: merge with head Created 4 years, 10 months 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') | webrtc/p2p/base/turnserver.h » ('j') | 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...) Expand 10 before | Expand all | Expand 10 after
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 when receiving an ALLOCATE MISMATCH
609 // error.
610 TEST_F(TurnPortTest, TestTurnAllocateNonceResetAfterAllocateMismatch) {
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 // Destroy the turnport while keeping the drop probability to 1 to
617 // suppress the release of the allocation at the server.
618 ss_->set_drop_probability(1.0);
619 turn_port_.reset();
620 rtc::Thread::Current()->ProcessMessages(0);
621 ss_->set_drop_probability(0.0);
622
623 // Force the socket server to assign the same port.
624 ss_->SetNextPortForTesting(first_addr.port());
625 turn_ready_ = false;
626 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
627
628 // It is expected that the turn port will first get a nonce from the server
629 // using timestamp |ts_before| but then get an allocate mismatch error and
630 // receive an even newer nonce based on the system clock. |ts_before| is
631 // chosen so that the two NONCEs generated by the server will be different.
632 uint32_t ts_before = rtc::Time() - 1;
633 std::string first_nonce =
634 turn_server_.server()->SetTimestampForNextNonce(ts_before);
635 turn_port_->PrepareAddress();
636
637 EXPECT_TRUE_WAIT(turn_ready_, kTimeout);
638 EXPECT_NE(first_nonce, turn_port_->nonce());
639 }
640
608 // Tests that a new local address is created after 641 // Tests that a new local address is created after
609 // STUN_ERROR_ALLOCATION_MISMATCH. 642 // STUN_ERROR_ALLOCATION_MISMATCH.
610 TEST_F(TurnPortTest, TestTurnAllocateMismatch) { 643 TEST_F(TurnPortTest, TestTurnAllocateMismatch) {
611 // Do a normal allocation first. 644 // Do a normal allocation first.
612 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); 645 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
613 turn_port_->PrepareAddress(); 646 turn_port_->PrepareAddress();
614 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); 647 EXPECT_TRUE_WAIT(turn_ready_, kTimeout);
615 rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress()); 648 rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress());
616 649
617 // Clear connected_ flag on turnport to suppress the release of 650 // Clear connected_ flag on turnport to suppress the release of
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 turn_port_->PrepareAddress(); 1049 turn_port_->PrepareAddress();
1017 ASSERT_TRUE_WAIT(turn_error_, kResolverTimeout); 1050 ASSERT_TRUE_WAIT(turn_error_, kResolverTimeout);
1018 EXPECT_TRUE(turn_port_->Candidates().empty()); 1051 EXPECT_TRUE(turn_port_->Candidates().empty());
1019 turn_port_.reset(); 1052 turn_port_.reset();
1020 rtc::Thread::Current()->Post(this, MSG_TESTFINISH); 1053 rtc::Thread::Current()->Post(this, MSG_TESTFINISH);
1021 // Waiting for above message to be processed. 1054 // Waiting for above message to be processed.
1022 ASSERT_TRUE_WAIT(test_finish_, kTimeout); 1055 ASSERT_TRUE_WAIT(test_finish_, kTimeout);
1023 EXPECT_EQ(last_fd_count, GetFDCount()); 1056 EXPECT_EQ(last_fd_count, GetFDCount());
1024 } 1057 }
1025 #endif 1058 #endif
OLDNEW
« no previous file with comments | « webrtc/p2p/base/turnport.cc ('k') | webrtc/p2p/base/turnserver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698