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

Unified 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. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/p2p/base/turnport_unittest.cc
diff --git a/webrtc/p2p/base/turnport_unittest.cc b/webrtc/p2p/base/turnport_unittest.cc
index 916162575fee803093aff79ea89afde02cae5902..1bca13c233d436262503b4cecebc68d9173917f3 100644
--- a/webrtc/p2p/base/turnport_unittest.cc
+++ b/webrtc/p2p/base/turnport_unittest.cc
@@ -605,6 +605,34 @@ 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, TestTurnAllocateNonceRestAfterAllocateMismatch) {
Taylor Brandstetter 2016/01/26 02:02:06 "NonceReset" instead of "NonceRest"
honghaiz3 2016/01/27 01:45:23 Done.
+ // 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());
+ // Clear connected_ flag on turnport to suppress the release of
+ // the allocation.
+ turn_port_->OnSocketClose(turn_port_->socket(), 0);
Taylor Brandstetter 2016/01/26 02:02:06 I don't think it's ideal to call "OnSocketClose" i
honghaiz3 2016/01/27 01:45:23 Done.
+
+ // Force the socket server to assign the same port.
+ ss_->SetNextPortForTesting(first_addr.port());
+ turn_ready_ = false;
+ CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
+
+ // Make sure the next timestamp will be different from |now|, so that the two
+ // NONCE generated by the server will be different.
Taylor Brandstetter 2016/01/26 02:02:06 I would also add a comment saying: "It's expected
honghaiz3 2016/01/27 01:45:23 Done. Text is slightly different though.
+ uint32_t now = rtc::Time() - 1;
+ turn_server_.server()->SetTimestampForNextNonce(now);
+ std::string next_nonce = turn_server_.server()->GenerateNonce(now);
+ turn_port_->PrepareAddress();
+
+ EXPECT_TRUE_WAIT(turn_ready_, kTimeout);
+ EXPECT_NE(next_nonce, turn_port_->nonce());
+}
+
// Tests that a new local address is created after
// STUN_ERROR_ALLOCATION_MISMATCH.
TEST_F(TurnPortTest, TestTurnAllocateMismatch) {

Powered by Google App Engine
This is Rietveld 408576698