Index: webrtc/p2p/base/turnport_unittest.cc |
diff --git a/webrtc/p2p/base/turnport_unittest.cc b/webrtc/p2p/base/turnport_unittest.cc |
index a503c2baa1c48390c3d147c7617b36dc089c723b..7649b5a0d153ed344e34510199792692b0c8b862 100644 |
--- a/webrtc/p2p/base/turnport_unittest.cc |
+++ b/webrtc/p2p/base/turnport_unittest.cc |
@@ -605,6 +605,39 @@ TEST_F(TurnPortTest, TestTurnAllocateBadPassword) { |
ASSERT_EQ(0U, turn_port_->Candidates().size()); |
} |
+// Tests that TURN port nonce will be reset when receiving an ALLOCATE MISMATCH |
+// error. |
+TEST_F(TurnPortTest, TestTurnAllocateNonceResetAfterAllocateMismatch) { |
+ // Do a normal allocation first. |
+ CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); |
+ turn_port_->PrepareAddress(); |
+ EXPECT_TRUE_WAIT(turn_ready_, kTimeout); |
+ rtc::SocketAddress first_addr(turn_port_->socket()->GetLocalAddress()); |
+ // Destroy the turnport while keeping the drop probability to 1 to |
+ // suppress the release of the allocation at the server. |
+ ss_->set_drop_probability(1.0); |
+ turn_port_.reset(); |
+ rtc::Thread::Current()->ProcessMessages(0); |
+ ss_->set_drop_probability(0.0); |
+ |
+ // Force the socket server to assign the same port. |
+ ss_->SetNextPortForTesting(first_addr.port()); |
+ turn_ready_ = false; |
+ CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); |
+ |
+ // It is expected that the turn port will first get a nonce from the server |
+ // using timestamp |ts_before| but then get an allocate mismatch error and |
+ // receive an even newer nonce based on the system clock. |ts_before| is |
+ // chosen so that the two NONCEs generated by the server will be different. |
+ uint32_t ts_before = rtc::Time() - 1; |
+ std::string first_nonce = |
+ turn_server_.server()->SetTimestampForNextNonce(ts_before); |
+ turn_port_->PrepareAddress(); |
+ |
+ EXPECT_TRUE_WAIT(turn_ready_, kTimeout); |
+ EXPECT_NE(first_nonce, turn_port_->nonce()); |
+} |
+ |
// Tests that a new local address is created after |
// STUN_ERROR_ALLOCATION_MISMATCH. |
TEST_F(TurnPortTest, TestTurnAllocateMismatch) { |