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: Addressed comments 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 |
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 when receiving an ALLOCATE MISMATCH
pthatcher1 2016/01/29 17:37:46 NONCE => nonce, here and below
honghaiz3 2016/01/29 18:46:36 Done.
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);
pthatcher1 2016/01/29 17:37:46 What's the point of doing a normal allocation firs
honghaiz3 2016/01/29 18:46:36 The first allocation is needed to generate the mis
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 |now| but then get an allocate mismatch error and receive
630 // an even newer NONCE based on the system clock. |now| is chosen so that
631 // the two NONCEs generated by the server will be different.
632 uint32_t now = rtc::Time() - 1;
pthatcher1 2016/01/29 17:37:46 Well it's not really "now", is it? Isn't it "befo
honghaiz3 2016/01/29 18:46:36 Done.
633 turn_server_.server()->SetTimestampForNextNonce(now);
634 std::string next_nonce = turn_server_.server()->GenerateNonce(now);
pthatcher1 2016/01/29 17:37:46 Wouldn't a better name be first_nonce?
honghaiz3 2016/01/29 18:46:36 Done.
635 turn_port_->PrepareAddress();
636
637 EXPECT_TRUE_WAIT(turn_ready_, kTimeout);
638 EXPECT_NE(next_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 373 matching lines...)
991 turn_port_->PrepareAddress(); 1024 turn_port_->PrepareAddress();
992 ASSERT_TRUE_WAIT(turn_error_, kResolverTimeout); 1025 ASSERT_TRUE_WAIT(turn_error_, kResolverTimeout);
993 EXPECT_TRUE(turn_port_->Candidates().empty()); 1026 EXPECT_TRUE(turn_port_->Candidates().empty());
994 turn_port_.reset(); 1027 turn_port_.reset();
995 rtc::Thread::Current()->Post(this, MSG_TESTFINISH); 1028 rtc::Thread::Current()->Post(this, MSG_TESTFINISH);
996 // Waiting for above message to be processed. 1029 // Waiting for above message to be processed.
997 ASSERT_TRUE_WAIT(test_finish_, kTimeout); 1030 ASSERT_TRUE_WAIT(test_finish_, kTimeout);
998 EXPECT_EQ(last_fd_count, GetFDCount()); 1031 EXPECT_EQ(last_fd_count, GetFDCount());
999 } 1032 }
1000 #endif 1033 #endif
OLDNEW

Powered by Google App Engine