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

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

Issue 2606123002: Remove the dependency of TransportChannel and TransportChannelImpl. (Closed)
Patch Set: Fix the memory leak. Created 3 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 unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/dtlstransportchannel.cc ('k') | webrtc/p2p/base/dtlstransportinternal.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 2011 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2011 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 10
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 new cricket::JsepTransport("dtls content name", certificate_)); 90 new cricket::JsepTransport("dtls content name", certificate_));
91 for (int i = 0; i < count; ++i) { 91 for (int i = 0; i < count; ++i) {
92 cricket::FakeIceTransport* fake_ice_channel = 92 cricket::FakeIceTransport* fake_ice_channel =
93 new cricket::FakeIceTransport(transport_->mid(), i); 93 new cricket::FakeIceTransport(transport_->mid(), i);
94 fake_ice_channel->SetAsync(true); 94 fake_ice_channel->SetAsync(true);
95 fake_ice_channel->SetAsyncDelay(async_delay_ms); 95 fake_ice_channel->SetAsyncDelay(async_delay_ms);
96 // Hook the raw packets so that we can verify they are encrypted. 96 // Hook the raw packets so that we can verify they are encrypted.
97 fake_ice_channel->SignalReadPacket.connect( 97 fake_ice_channel->SignalReadPacket.connect(
98 this, &DtlsTestClient::OnFakeTransportChannelReadPacket); 98 this, &DtlsTestClient::OnFakeTransportChannelReadPacket);
99 99
100 cricket::DtlsTransportChannelWrapper* channel = 100 cricket::DtlsTransport* dtls =
101 new cricket::DtlsTransportChannelWrapper(fake_ice_channel); 101 new cricket::DtlsTransport(fake_ice_channel);
102 channel->SetLocalCertificate(certificate_); 102 dtls->SetLocalCertificate(certificate_);
103 channel->SetIceRole(role); 103 dtls->ice_transport()->SetIceRole(role);
104 channel->SetIceTiebreaker((role == cricket::ICEROLE_CONTROLLING) ? 1 : 2); 104 dtls->ice_transport()->SetIceTiebreaker(
105 channel->SetSslMaxProtocolVersion(ssl_max_version_); 105 (role == cricket::ICEROLE_CONTROLLING) ? 1 : 2);
106 channel->SignalWritableState.connect(this, 106 dtls->SetSslMaxProtocolVersion(ssl_max_version_);
107 &DtlsTestClient::OnTransportChannelWritableState); 107 dtls->SignalWritableState.connect(
108 channel->SignalReadPacket.connect(this, 108 this, &DtlsTestClient::OnTransportChannelWritableState);
109 &DtlsTestClient::OnTransportChannelReadPacket); 109 dtls->SignalReadPacket.connect(
110 channel->SignalSentPacket.connect( 110 this, &DtlsTestClient::OnTransportChannelReadPacket);
111 dtls->SignalSentPacket.connect(
111 this, &DtlsTestClient::OnTransportChannelSentPacket); 112 this, &DtlsTestClient::OnTransportChannelSentPacket);
112 channels_.push_back( 113 fake_dtls_transports_.push_back(
113 std::unique_ptr<cricket::DtlsTransportChannelWrapper>(channel)); 114 std::unique_ptr<cricket::DtlsTransport>(dtls));
114 fake_channels_.push_back( 115 fake_ice_transports_.push_back(
115 std::unique_ptr<cricket::FakeIceTransport>(fake_ice_channel)); 116 std::unique_ptr<cricket::FakeIceTransport>(fake_ice_channel));
116 transport_->AddChannel(channel, i); 117 transport_->AddChannel(dtls, i);
117 } 118 }
118 } 119 }
119 120
120 cricket::JsepTransport* transport() { return transport_.get(); } 121 cricket::JsepTransport* transport() { return transport_.get(); }
121 122
122 cricket::FakeIceTransport* GetFakeChannel(int component) { 123 cricket::FakeIceTransport* GetFakeIceTransort(int component) {
123 for (const auto& ch : fake_channels_) { 124 for (const auto& ch : fake_ice_transports_) {
124 if (ch->component() == component) { 125 if (ch->component() == component) {
125 return ch.get(); 126 return ch.get();
126 } 127 }
127 } 128 }
128 return nullptr; 129 return nullptr;
129 } 130 }
130 131
131 cricket::DtlsTransportChannelWrapper* GetDtlsChannel(int component) { 132 cricket::DtlsTransport* GetDtlsTransport(int component) {
132 for (const auto& ch : channels_) { 133 for (const auto& dtls : fake_dtls_transports_) {
133 if (ch->component() == component) { 134 if (dtls->component() == component) {
134 return ch.get(); 135 return dtls.get();
135 } 136 }
136 } 137 }
137 return nullptr; 138 return nullptr;
138 } 139 }
139 140
140 // Offer DTLS if we have an identity; pass in a remote fingerprint only if 141 // Offer DTLS if we have an identity; pass in a remote fingerprint only if
141 // both sides support DTLS. 142 // both sides support DTLS.
142 void Negotiate(DtlsTestClient* peer, cricket::ContentAction action, 143 void Negotiate(DtlsTestClient* peer, cricket::ContentAction action,
143 ConnectionRole local_role, ConnectionRole remote_role, 144 ConnectionRole local_role, ConnectionRole remote_role,
144 int flags) { 145 int flags) {
145 Negotiate(certificate_, certificate_ ? peer->certificate_ : nullptr, action, 146 Negotiate(certificate_, certificate_ ? peer->certificate_ : nullptr, action,
146 local_role, remote_role, flags); 147 local_role, remote_role, flags);
147 } 148 }
148 149
149 void MaybeSetSrtpCryptoSuites() { 150 void MaybeSetSrtpCryptoSuites() {
150 if (!use_dtls_srtp_) { 151 if (!use_dtls_srtp_) {
151 return; 152 return;
152 } 153 }
153 std::vector<int> ciphers; 154 std::vector<int> ciphers;
154 ciphers.push_back(rtc::SRTP_AES128_CM_SHA1_80); 155 ciphers.push_back(rtc::SRTP_AES128_CM_SHA1_80);
155 // SRTP ciphers will be set only in the beginning. 156 // SRTP ciphers will be set only in the beginning.
156 for (const auto& channel : channels_) { 157 for (const auto& dtls : fake_dtls_transports_) {
157 EXPECT_TRUE(channel->SetSrtpCryptoSuites(ciphers)); 158 EXPECT_TRUE(dtls->SetSrtpCryptoSuites(ciphers));
158 } 159 }
159 } 160 }
160 161
161 void SetLocalTransportDescription( 162 void SetLocalTransportDescription(
162 const rtc::scoped_refptr<rtc::RTCCertificate>& cert, 163 const rtc::scoped_refptr<rtc::RTCCertificate>& cert,
163 cricket::ContentAction action, 164 cricket::ContentAction action,
164 ConnectionRole role, 165 ConnectionRole role,
165 int flags) { 166 int flags) {
166 // If |NF_EXPECT_FAILURE| is set, expect SRTD or SLTD to fail when 167 // If |NF_EXPECT_FAILURE| is set, expect SRTD or SLTD to fail when
167 // content action is CA_ANSWER. 168 // content action is CA_ANSWER.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 SetRemoteTransportDescription(remote_cert, cricket::CA_OFFER, remote_role, 207 SetRemoteTransportDescription(remote_cert, cricket::CA_OFFER, remote_role,
207 flags); 208 flags);
208 // If remote if the offerer and has no DTLS support, answer will be 209 // If remote if the offerer and has no DTLS support, answer will be
209 // without any fingerprint. 210 // without any fingerprint.
210 SetLocalTransportDescription(remote_cert ? local_cert : nullptr, 211 SetLocalTransportDescription(remote_cert ? local_cert : nullptr,
211 cricket::CA_ANSWER, local_role, flags); 212 cricket::CA_ANSWER, local_role, flags);
212 } 213 }
213 } 214 }
214 215
215 bool Connect(DtlsTestClient* peer, bool asymmetric) { 216 bool Connect(DtlsTestClient* peer, bool asymmetric) {
216 for (auto& channel : fake_channels_) { 217 for (auto& ice : fake_ice_transports_) {
217 channel->SetDestination(peer->GetFakeChannel(channel->component()), 218 ice->SetDestination(peer->GetFakeIceTransort(ice->component()),
218 asymmetric); 219 asymmetric);
219 } 220 }
220 return true; 221 return true;
221 } 222 }
222 223
223 bool all_channels_writable() const { 224 bool all_dtls_transports_writable() const {
224 if (channels_.empty()) { 225 if (fake_dtls_transports_.empty()) {
225 return false; 226 return false;
226 } 227 }
227 for (const auto& channel : channels_) { 228 for (const auto& dtls : fake_dtls_transports_) {
228 if (!channel->writable()) { 229 if (!dtls->writable()) {
229 return false; 230 return false;
230 } 231 }
231 } 232 }
232 return true; 233 return true;
233 } 234 }
234 235
235 bool all_raw_channels_writable() const { 236 bool all_ice_transports_writable() const {
236 if (channels_.empty()) { 237 if (fake_dtls_transports_.empty()) {
237 return false; 238 return false;
238 } 239 }
239 for (const auto& channel : channels_) { 240 for (const auto& dtls : fake_dtls_transports_) {
240 if (!channel->channel()->writable()) { 241 if (!dtls->ice_transport()->writable()) {
241 return false; 242 return false;
242 } 243 }
243 } 244 }
244 return true; 245 return true;
245 } 246 }
246 247
247 int received_dtls_client_hellos() const { 248 int received_dtls_client_hellos() const {
248 return received_dtls_client_hellos_; 249 return received_dtls_client_hellos_;
249 } 250 }
250 251
(...skipping 12 matching lines...) Expand all
263 if (role == rtc::SSL_CLIENT) { 264 if (role == rtc::SSL_CLIENT) {
264 ASSERT_EQ(0, received_dtls_client_hellos_); 265 ASSERT_EQ(0, received_dtls_client_hellos_);
265 ASSERT_GT(received_dtls_server_hellos_, 0); 266 ASSERT_GT(received_dtls_server_hellos_, 0);
266 } else { 267 } else {
267 ASSERT_GT(received_dtls_client_hellos_, 0); 268 ASSERT_GT(received_dtls_client_hellos_, 0);
268 ASSERT_EQ(0, received_dtls_server_hellos_); 269 ASSERT_EQ(0, received_dtls_server_hellos_);
269 } 270 }
270 } 271 }
271 272
272 void CheckSrtp(int expected_crypto_suite) { 273 void CheckSrtp(int expected_crypto_suite) {
273 for (const auto& channel : channels_) { 274 for (const auto& dtls : fake_dtls_transports_) {
274 int crypto_suite; 275 int crypto_suite;
275 276
276 bool rv = channel->GetSrtpCryptoSuite(&crypto_suite); 277 bool rv = dtls->GetSrtpCryptoSuite(&crypto_suite);
277 if (negotiated_dtls() && expected_crypto_suite) { 278 if (negotiated_dtls() && expected_crypto_suite) {
278 ASSERT_TRUE(rv); 279 ASSERT_TRUE(rv);
279 280
280 ASSERT_EQ(crypto_suite, expected_crypto_suite); 281 ASSERT_EQ(crypto_suite, expected_crypto_suite);
281 } else { 282 } else {
282 ASSERT_FALSE(rv); 283 ASSERT_FALSE(rv);
283 } 284 }
284 } 285 }
285 } 286 }
286 287
287 void CheckSsl() { 288 void CheckSsl() {
288 for (const auto& channel : channels_) { 289 for (const auto& dtls : fake_dtls_transports_) {
289 int cipher; 290 int cipher;
290 291
291 bool rv = channel->GetSslCipherSuite(&cipher); 292 bool rv = dtls->GetSslCipherSuite(&cipher);
292 if (negotiated_dtls()) { 293 if (negotiated_dtls()) {
293 ASSERT_TRUE(rv); 294 ASSERT_TRUE(rv);
294 295
295 EXPECT_TRUE( 296 EXPECT_TRUE(
296 rtc::SSLStreamAdapter::IsAcceptableCipher(cipher, rtc::KT_DEFAULT)); 297 rtc::SSLStreamAdapter::IsAcceptableCipher(cipher, rtc::KT_DEFAULT));
297 } else { 298 } else {
298 ASSERT_FALSE(rv); 299 ASSERT_FALSE(rv);
299 } 300 }
300 } 301 }
301 } 302 }
302 303
303 void SendPackets(size_t channel, size_t size, size_t count, bool srtp) { 304 void SendPackets(size_t transport, size_t size, size_t count, bool srtp) {
304 RTC_CHECK(channel < channels_.size()); 305 RTC_CHECK(transport < fake_dtls_transports_.size());
305 std::unique_ptr<char[]> packet(new char[size]); 306 std::unique_ptr<char[]> packet(new char[size]);
306 size_t sent = 0; 307 size_t sent = 0;
307 do { 308 do {
308 // Fill the packet with a known value and a sequence number to check 309 // Fill the packet with a known value and a sequence number to check
309 // against, and make sure that it doesn't look like DTLS. 310 // against, and make sure that it doesn't look like DTLS.
310 memset(packet.get(), sent & 0xff, size); 311 memset(packet.get(), sent & 0xff, size);
311 packet[0] = (srtp) ? 0x80 : 0x00; 312 packet[0] = (srtp) ? 0x80 : 0x00;
312 rtc::SetBE32(packet.get() + kPacketNumOffset, 313 rtc::SetBE32(packet.get() + kPacketNumOffset,
313 static_cast<uint32_t>(sent)); 314 static_cast<uint32_t>(sent));
314 315
315 // Only set the bypass flag if we've activated DTLS. 316 // Only set the bypass flag if we've activated DTLS.
316 int flags = (certificate_ && srtp) ? cricket::PF_SRTP_BYPASS : 0; 317 int flags = (certificate_ && srtp) ? cricket::PF_SRTP_BYPASS : 0;
317 rtc::PacketOptions packet_options; 318 rtc::PacketOptions packet_options;
318 packet_options.packet_id = kFakePacketId; 319 packet_options.packet_id = kFakePacketId;
319 int rv = channels_[channel]->SendPacket( 320 int rv = fake_dtls_transports_[transport]->SendPacket(
320 packet.get(), size, packet_options, flags); 321 packet.get(), size, packet_options, flags);
321 ASSERT_GT(rv, 0); 322 ASSERT_GT(rv, 0);
322 ASSERT_EQ(size, static_cast<size_t>(rv)); 323 ASSERT_EQ(size, static_cast<size_t>(rv));
323 ++sent; 324 ++sent;
324 } while (sent < count); 325 } while (sent < count);
325 } 326 }
326 327
327 int SendInvalidSrtpPacket(size_t channel, size_t size) { 328 int SendInvalidSrtpPacket(size_t transport, size_t size) {
328 RTC_CHECK(channel < channels_.size()); 329 RTC_CHECK(transport < fake_dtls_transports_.size());
329 std::unique_ptr<char[]> packet(new char[size]); 330 std::unique_ptr<char[]> packet(new char[size]);
330 // Fill the packet with 0 to form an invalid SRTP packet. 331 // Fill the packet with 0 to form an invalid SRTP packet.
331 memset(packet.get(), 0, size); 332 memset(packet.get(), 0, size);
332 333
333 rtc::PacketOptions packet_options; 334 rtc::PacketOptions packet_options;
334 return channels_[channel]->SendPacket( 335 return fake_dtls_transports_[transport]->SendPacket(
335 packet.get(), size, packet_options, cricket::PF_SRTP_BYPASS); 336 packet.get(), size, packet_options, cricket::PF_SRTP_BYPASS);
336 } 337 }
337 338
338 void ExpectPackets(size_t channel, size_t size) { 339 void ExpectPackets(size_t transport, size_t size) {
339 packet_size_ = size; 340 packet_size_ = size;
340 received_.clear(); 341 received_.clear();
341 } 342 }
342 343
343 size_t NumPacketsReceived() { 344 size_t NumPacketsReceived() {
344 return received_.size(); 345 return received_.size();
345 } 346 }
346 347
347 bool VerifyPacket(const char* data, size_t size, uint32_t* out_num) { 348 bool VerifyPacket(const char* data, size_t size, uint32_t* out_num) {
348 if (size != packet_size_ || 349 if (size != packet_size_ ||
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 ASSERT_TRUE(VerifyEncryptedPacket(data, size)); 429 ASSERT_TRUE(VerifyEncryptedPacket(data, size));
429 } else if (IsRtpLeadByte(data[0])) { 430 } else if (IsRtpLeadByte(data[0])) {
430 ASSERT_TRUE(VerifyPacket(data, size, NULL)); 431 ASSERT_TRUE(VerifyPacket(data, size, NULL));
431 } 432 }
432 } 433 }
433 } 434 }
434 435
435 private: 436 private:
436 std::string name_; 437 std::string name_;
437 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; 438 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
438 std::vector<std::unique_ptr<cricket::FakeIceTransport>> fake_channels_; 439 std::vector<std::unique_ptr<cricket::FakeIceTransport>> fake_ice_transports_;
439 std::vector<std::unique_ptr<cricket::DtlsTransportChannelWrapper>> channels_; 440 std::vector<std::unique_ptr<cricket::DtlsTransport>> fake_dtls_transports_;
440 std::unique_ptr<cricket::JsepTransport> transport_; 441 std::unique_ptr<cricket::JsepTransport> transport_;
441 size_t packet_size_ = 0u; 442 size_t packet_size_ = 0u;
442 std::set<int> received_; 443 std::set<int> received_;
443 bool use_dtls_srtp_ = false; 444 bool use_dtls_srtp_ = false;
444 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; 445 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12;
445 int received_dtls_client_hellos_ = 0; 446 int received_dtls_client_hellos_ = 0;
446 int received_dtls_server_hellos_ = 0; 447 int received_dtls_server_hellos_ = 0;
447 rtc::SentPacket sent_packet_; 448 rtc::SentPacket sent_packet_;
448 }; 449 };
449 450
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 client2_.certificate(), cricket::CA_ANSWER, client2_role, 0); 521 client2_.certificate(), cricket::CA_ANSWER, client2_role, 0);
521 rv = client1_.Connect(&client2_, false); 522 rv = client1_.Connect(&client2_, false);
522 client1_.SetRemoteTransportDescription( 523 client1_.SetRemoteTransportDescription(
523 client2_.certificate(), cricket::CA_ANSWER, client2_role, 0); 524 client2_.certificate(), cricket::CA_ANSWER, client2_role, 0);
524 } 525 }
525 526
526 EXPECT_TRUE(rv); 527 EXPECT_TRUE(rv);
527 if (!rv) 528 if (!rv)
528 return false; 529 return false;
529 530
530 EXPECT_TRUE_SIMULATED_WAIT( 531 EXPECT_TRUE_SIMULATED_WAIT(client1_.all_dtls_transports_writable() &&
531 client1_.all_channels_writable() && client2_.all_channels_writable(), 532 client2_.all_dtls_transports_writable(),
532 kTimeout, fake_clock_); 533 kTimeout, fake_clock_);
533 if (!client1_.all_channels_writable() || !client2_.all_channels_writable()) 534 if (!client1_.all_dtls_transports_writable() ||
535 !client2_.all_dtls_transports_writable())
534 return false; 536 return false;
535 537
536 // Check that we used the right roles. 538 // Check that we used the right roles.
537 if (use_dtls_) { 539 if (use_dtls_) {
538 rtc::SSLRole client1_ssl_role = 540 rtc::SSLRole client1_ssl_role =
539 (client1_role == cricket::CONNECTIONROLE_ACTIVE || 541 (client1_role == cricket::CONNECTIONROLE_ACTIVE ||
540 (client2_role == cricket::CONNECTIONROLE_PASSIVE && 542 (client2_role == cricket::CONNECTIONROLE_PASSIVE &&
541 client1_role == cricket::CONNECTIONROLE_ACTPASS)) ? 543 client1_role == cricket::CONNECTIONROLE_ACTPASS)) ?
542 rtc::SSL_CLIENT : rtc::SSL_SERVER; 544 rtc::SSL_CLIENT : rtc::SSL_SERVER;
543 545
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 client2_.Negotiate(&client1_, cricket::CA_ANSWER, 611 client2_.Negotiate(&client1_, cricket::CA_ANSWER,
610 client2_role, client1_role, flags); 612 client2_role, client1_role, flags);
611 } else { 613 } else {
612 client2_.Negotiate(&client1_, cricket::CA_OFFER, 614 client2_.Negotiate(&client1_, cricket::CA_OFFER,
613 client2_role, client1_role, flags); 615 client2_role, client1_role, flags);
614 client1_.Negotiate(&client2_, cricket::CA_ANSWER, 616 client1_.Negotiate(&client2_, cricket::CA_ANSWER,
615 client1_role, client2_role, flags); 617 client1_role, client2_role, flags);
616 } 618 }
617 } 619 }
618 620
619 void TestTransfer(size_t channel, size_t size, size_t count, bool srtp) { 621 void TestTransfer(size_t transport, size_t size, size_t count, bool srtp) {
620 LOG(LS_INFO) << "Expect packets, size=" << size; 622 LOG(LS_INFO) << "Expect packets, size=" << size;
621 client2_.ExpectPackets(channel, size); 623 client2_.ExpectPackets(transport, size);
622 client1_.SendPackets(channel, size, count, srtp); 624 client1_.SendPackets(transport, size, count, srtp);
623 EXPECT_EQ_SIMULATED_WAIT(count, client2_.NumPacketsReceived(), kTimeout, 625 EXPECT_EQ_SIMULATED_WAIT(count, client2_.NumPacketsReceived(), kTimeout,
624 fake_clock_); 626 fake_clock_);
625 } 627 }
626 628
627 protected: 629 protected:
628 rtc::ScopedFakeClock fake_clock_; 630 rtc::ScopedFakeClock fake_clock_;
629 DtlsTestClient client1_; 631 DtlsTestClient client1_;
630 DtlsTestClient client2_; 632 DtlsTestClient client2_;
631 int channel_ct_; 633 int channel_ct_;
632 bool use_dtls_; 634 bool use_dtls_;
633 bool use_dtls_srtp_; 635 bool use_dtls_srtp_;
634 rtc::SSLProtocolVersion ssl_expected_version_; 636 rtc::SSLProtocolVersion ssl_expected_version_;
635 }; 637 };
636 638
637 class DtlsTransportChannelTest : public DtlsTransportChannelTestBase, 639 class DtlsTransportChannelTest : public DtlsTransportChannelTestBase,
638 public ::testing::Test {}; 640 public ::testing::Test {};
639 641
640 // Test that transport negotiation of ICE, no DTLS works properly. 642 // Test that transport negotiation of ICE, no DTLS works properly.
641 TEST_F(DtlsTransportChannelTest, TestChannelSetupIce) { 643 TEST_F(DtlsTransportChannelTest, TestChannelSetupIce) {
642 Negotiate(); 644 Negotiate();
643 cricket::FakeIceTransport* channel1 = client1_.GetFakeChannel(0); 645 cricket::FakeIceTransport* channel1 = client1_.GetFakeIceTransort(0);
644 cricket::FakeIceTransport* channel2 = client2_.GetFakeChannel(0); 646 cricket::FakeIceTransport* channel2 = client2_.GetFakeIceTransort(0);
645 ASSERT_TRUE(channel1 != NULL); 647 ASSERT_TRUE(channel1 != NULL);
646 ASSERT_TRUE(channel2 != NULL); 648 ASSERT_TRUE(channel2 != NULL);
647 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); 649 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole());
648 EXPECT_EQ(1U, channel1->IceTiebreaker()); 650 EXPECT_EQ(1U, channel1->IceTiebreaker());
649 EXPECT_EQ(kIceUfrag1, channel1->ice_ufrag()); 651 EXPECT_EQ(kIceUfrag1, channel1->ice_ufrag());
650 EXPECT_EQ(kIcePwd1, channel1->ice_pwd()); 652 EXPECT_EQ(kIcePwd1, channel1->ice_pwd());
651 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole()); 653 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole());
652 EXPECT_EQ(2U, channel2->IceTiebreaker()); 654 EXPECT_EQ(2U, channel2->IceTiebreaker());
653 } 655 }
654 656
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 MAYBE_SKIP_TEST(HaveDtlsSrtp); 915 MAYBE_SKIP_TEST(HaveDtlsSrtp);
914 SetChannelCount(2); 916 SetChannelCount(2);
915 PrepareDtls(true, true, rtc::KT_DEFAULT); 917 PrepareDtls(true, true, rtc::KT_DEFAULT);
916 PrepareDtlsSrtp(true, true); 918 PrepareDtlsSrtp(true, true);
917 Negotiate(); 919 Negotiate();
918 920
919 Renegotiate(&client1_, cricket::CONNECTIONROLE_ACTPASS, 921 Renegotiate(&client1_, cricket::CONNECTIONROLE_ACTPASS,
920 cricket::CONNECTIONROLE_ACTIVE, NF_REOFFER); 922 cricket::CONNECTIONROLE_ACTIVE, NF_REOFFER);
921 bool rv = client1_.Connect(&client2_, false); 923 bool rv = client1_.Connect(&client2_, false);
922 EXPECT_TRUE(rv); 924 EXPECT_TRUE(rv);
923 EXPECT_TRUE_SIMULATED_WAIT( 925 EXPECT_TRUE_SIMULATED_WAIT(client1_.all_dtls_transports_writable() &&
924 client1_.all_channels_writable() && client2_.all_channels_writable(), 926 client2_.all_dtls_transports_writable(),
925 kTimeout, fake_clock_); 927 kTimeout, fake_clock_);
926 928
927 TestTransfer(0, 1000, 100, true); 929 TestTransfer(0, 1000, 100, true);
928 TestTransfer(1, 1000, 100, true); 930 TestTransfer(1, 1000, 100, true);
929 } 931 }
930 932
931 // Test Certificates state after negotiation but before connection. 933 // Test Certificates state after negotiation but before connection.
932 TEST_F(DtlsTransportChannelTest, TestCertificatesBeforeConnect) { 934 TEST_F(DtlsTransportChannelTest, TestCertificatesBeforeConnect) {
933 MAYBE_SKIP_TEST(HaveDtls); 935 MAYBE_SKIP_TEST(HaveDtls);
934 PrepareDtls(true, true, rtc::KT_DEFAULT); 936 PrepareDtls(true, true, rtc::KT_DEFAULT);
935 Negotiate(); 937 Negotiate();
936 938
937 rtc::scoped_refptr<rtc::RTCCertificate> certificate1; 939 rtc::scoped_refptr<rtc::RTCCertificate> certificate1;
938 rtc::scoped_refptr<rtc::RTCCertificate> certificate2; 940 rtc::scoped_refptr<rtc::RTCCertificate> certificate2;
939 std::unique_ptr<rtc::SSLCertificate> remote_cert1; 941 std::unique_ptr<rtc::SSLCertificate> remote_cert1;
940 std::unique_ptr<rtc::SSLCertificate> remote_cert2; 942 std::unique_ptr<rtc::SSLCertificate> remote_cert2;
941 943
942 // After negotiation, each side has a distinct local certificate, but still no 944 // After negotiation, each side has a distinct local certificate, but still no
943 // remote certificate, because connection has not yet occurred. 945 // remote certificate, because connection has not yet occurred.
944 ASSERT_TRUE(client1_.transport()->GetLocalCertificate(&certificate1)); 946 ASSERT_TRUE(client1_.transport()->GetLocalCertificate(&certificate1));
945 ASSERT_TRUE(client2_.transport()->GetLocalCertificate(&certificate2)); 947 ASSERT_TRUE(client2_.transport()->GetLocalCertificate(&certificate2));
946 ASSERT_NE(certificate1->ssl_certificate().ToPEMString(), 948 ASSERT_NE(certificate1->ssl_certificate().ToPEMString(),
947 certificate2->ssl_certificate().ToPEMString()); 949 certificate2->ssl_certificate().ToPEMString());
948 ASSERT_FALSE(client1_.GetDtlsChannel(0)->GetRemoteSSLCertificate()); 950 ASSERT_FALSE(client1_.GetDtlsTransport(0)->GetRemoteSSLCertificate());
949 ASSERT_FALSE(client2_.GetDtlsChannel(0)->GetRemoteSSLCertificate()); 951 ASSERT_FALSE(client2_.GetDtlsTransport(0)->GetRemoteSSLCertificate());
950 } 952 }
951 953
952 // Test Certificates state after connection. 954 // Test Certificates state after connection.
953 TEST_F(DtlsTransportChannelTest, TestCertificatesAfterConnect) { 955 TEST_F(DtlsTransportChannelTest, TestCertificatesAfterConnect) {
954 MAYBE_SKIP_TEST(HaveDtls); 956 MAYBE_SKIP_TEST(HaveDtls);
955 PrepareDtls(true, true, rtc::KT_DEFAULT); 957 PrepareDtls(true, true, rtc::KT_DEFAULT);
956 ASSERT_TRUE(Connect()); 958 ASSERT_TRUE(Connect());
957 959
958 rtc::scoped_refptr<rtc::RTCCertificate> certificate1; 960 rtc::scoped_refptr<rtc::RTCCertificate> certificate1;
959 rtc::scoped_refptr<rtc::RTCCertificate> certificate2; 961 rtc::scoped_refptr<rtc::RTCCertificate> certificate2;
960 962
961 // After connection, each side has a distinct local certificate. 963 // After connection, each side has a distinct local certificate.
962 ASSERT_TRUE(client1_.transport()->GetLocalCertificate(&certificate1)); 964 ASSERT_TRUE(client1_.transport()->GetLocalCertificate(&certificate1));
963 ASSERT_TRUE(client2_.transport()->GetLocalCertificate(&certificate2)); 965 ASSERT_TRUE(client2_.transport()->GetLocalCertificate(&certificate2));
964 ASSERT_NE(certificate1->ssl_certificate().ToPEMString(), 966 ASSERT_NE(certificate1->ssl_certificate().ToPEMString(),
965 certificate2->ssl_certificate().ToPEMString()); 967 certificate2->ssl_certificate().ToPEMString());
966 968
967 // Each side's remote certificate is the other side's local certificate. 969 // Each side's remote certificate is the other side's local certificate.
968 std::unique_ptr<rtc::SSLCertificate> remote_cert1 = 970 std::unique_ptr<rtc::SSLCertificate> remote_cert1 =
969 client1_.GetDtlsChannel(0)->GetRemoteSSLCertificate(); 971 client1_.GetDtlsTransport(0)->GetRemoteSSLCertificate();
970 ASSERT_TRUE(remote_cert1); 972 ASSERT_TRUE(remote_cert1);
971 ASSERT_EQ(remote_cert1->ToPEMString(), 973 ASSERT_EQ(remote_cert1->ToPEMString(),
972 certificate2->ssl_certificate().ToPEMString()); 974 certificate2->ssl_certificate().ToPEMString());
973 std::unique_ptr<rtc::SSLCertificate> remote_cert2 = 975 std::unique_ptr<rtc::SSLCertificate> remote_cert2 =
974 client2_.GetDtlsChannel(0)->GetRemoteSSLCertificate(); 976 client2_.GetDtlsTransport(0)->GetRemoteSSLCertificate();
975 ASSERT_TRUE(remote_cert2); 977 ASSERT_TRUE(remote_cert2);
976 ASSERT_EQ(remote_cert2->ToPEMString(), 978 ASSERT_EQ(remote_cert2->ToPEMString(),
977 certificate1->ssl_certificate().ToPEMString()); 979 certificate1->ssl_certificate().ToPEMString());
978 } 980 }
979 981
980 // Test that packets are retransmitted according to the expected schedule. 982 // Test that packets are retransmitted according to the expected schedule.
981 // Each time a timeout occurs, the retransmission timer should be doubled up to 983 // Each time a timeout occurs, the retransmission timer should be doubled up to
982 // 60 seconds. The timer defaults to 1 second, but for WebRTC we should be 984 // 60 seconds. The timer defaults to 1 second, but for WebRTC we should be
983 // initializing it to 50ms. 985 // initializing it to 50ms.
984 TEST_F(DtlsTransportChannelTest, TestRetransmissionSchedule) { 986 TEST_F(DtlsTransportChannelTest, TestRetransmissionSchedule) {
985 MAYBE_SKIP_TEST(HaveDtls); 987 MAYBE_SKIP_TEST(HaveDtls);
986 // We can only change the retransmission schedule with a recently-added 988 // We can only change the retransmission schedule with a recently-added
987 // BoringSSL API. Skip the test if not built with BoringSSL. 989 // BoringSSL API. Skip the test if not built with BoringSSL.
988 MAYBE_SKIP_TEST(IsBoringSsl); 990 MAYBE_SKIP_TEST(IsBoringSsl);
989 991
990 PrepareDtls(true, true, rtc::KT_DEFAULT); 992 PrepareDtls(true, true, rtc::KT_DEFAULT);
991 // Exchange transport descriptions. 993 // Exchange transport descriptions.
992 Negotiate(cricket::CONNECTIONROLE_ACTPASS, cricket::CONNECTIONROLE_ACTIVE); 994 Negotiate(cricket::CONNECTIONROLE_ACTPASS, cricket::CONNECTIONROLE_ACTIVE);
993 995
994 // Make client2_ writable, but not client1_. 996 // Make client2_ writable, but not client1_.
995 // This means client1_ will send DTLS client hellos but get no response. 997 // This means client1_ will send DTLS client hellos but get no response.
996 EXPECT_TRUE(client2_.Connect(&client1_, true)); 998 EXPECT_TRUE(client2_.Connect(&client1_, true));
997 EXPECT_TRUE_SIMULATED_WAIT(client2_.all_raw_channels_writable(), kTimeout, 999 EXPECT_TRUE_SIMULATED_WAIT(client2_.all_ice_transports_writable(), kTimeout,
998 fake_clock_); 1000 fake_clock_);
999 1001
1000 // Wait for the first client hello to be sent. 1002 // Wait for the first client hello to be sent.
1001 EXPECT_EQ_WAIT(1, client1_.received_dtls_client_hellos(), kTimeout); 1003 EXPECT_EQ_WAIT(1, client1_.received_dtls_client_hellos(), kTimeout);
1002 EXPECT_FALSE(client1_.all_raw_channels_writable()); 1004 EXPECT_FALSE(client1_.all_ice_transports_writable());
1003 1005
1004 static int timeout_schedule_ms[] = {50, 100, 200, 400, 800, 1600, 1006 static int timeout_schedule_ms[] = {50, 100, 200, 400, 800, 1600,
1005 3200, 6400, 12800, 25600, 51200, 60000}; 1007 3200, 6400, 12800, 25600, 51200, 60000};
1006 1008
1007 int expected_hellos = 1; 1009 int expected_hellos = 1;
1008 for (size_t i = 0; 1010 for (size_t i = 0;
1009 i < (sizeof(timeout_schedule_ms) / sizeof(timeout_schedule_ms[0])); 1011 i < (sizeof(timeout_schedule_ms) / sizeof(timeout_schedule_ms[0]));
1010 ++i) { 1012 ++i) {
1011 // For each expected retransmission time, advance the fake clock a 1013 // For each expected retransmission time, advance the fake clock a
1012 // millisecond before the expected time and verify that no unexpected 1014 // millisecond before the expected time and verify that no unexpected
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 ++(remote_desc.identity_fingerprint->digest[0]); 1099 ++(remote_desc.identity_fingerprint->digest[0]);
1098 // Even if certificate verification fails inside this method, 1100 // Even if certificate verification fails inside this method,
1099 // it should return true as long as the fingerprint was formatted 1101 // it should return true as long as the fingerprint was formatted
1100 // correctly. 1102 // correctly.
1101 EXPECT_TRUE(client1_.transport()->SetRemoteTransportDescription( 1103 EXPECT_TRUE(client1_.transport()->SetRemoteTransportDescription(
1102 remote_desc, cricket::CA_ANSWER, nullptr)); 1104 remote_desc, cricket::CA_ANSWER, nullptr));
1103 } 1105 }
1104 break; 1106 break;
1105 case CALLER_WRITABLE: 1107 case CALLER_WRITABLE:
1106 EXPECT_TRUE(client1_.Connect(&client2_, true)); 1108 EXPECT_TRUE(client1_.Connect(&client2_, true));
1107 EXPECT_TRUE_SIMULATED_WAIT(client1_.all_raw_channels_writable(), 1109 EXPECT_TRUE_SIMULATED_WAIT(client1_.all_ice_transports_writable(),
1108 kTimeout, fake_clock_); 1110 kTimeout, fake_clock_);
1109 break; 1111 break;
1110 case CALLER_RECEIVES_CLIENTHELLO: 1112 case CALLER_RECEIVES_CLIENTHELLO:
1111 // Sanity check that a ClientHello hasn't already been received. 1113 // Sanity check that a ClientHello hasn't already been received.
1112 EXPECT_EQ(0, client1_.received_dtls_client_hellos()); 1114 EXPECT_EQ(0, client1_.received_dtls_client_hellos());
1113 // Making client2_ writable will cause it to send the ClientHello. 1115 // Making client2_ writable will cause it to send the ClientHello.
1114 EXPECT_TRUE(client2_.Connect(&client1_, true)); 1116 EXPECT_TRUE(client2_.Connect(&client1_, true));
1115 EXPECT_TRUE_SIMULATED_WAIT(client2_.all_raw_channels_writable(), 1117 EXPECT_TRUE_SIMULATED_WAIT(client2_.all_ice_transports_writable(),
1116 kTimeout, fake_clock_); 1118 kTimeout, fake_clock_);
1117 EXPECT_EQ_SIMULATED_WAIT(1, client1_.received_dtls_client_hellos(), 1119 EXPECT_EQ_SIMULATED_WAIT(1, client1_.received_dtls_client_hellos(),
1118 kTimeout, fake_clock_); 1120 kTimeout, fake_clock_);
1119 break; 1121 break;
1120 case HANDSHAKE_FINISHES: 1122 case HANDSHAKE_FINISHES:
1121 // Sanity check that the handshake hasn't already finished. 1123 // Sanity check that the handshake hasn't already finished.
1122 EXPECT_FALSE(client1_.GetDtlsChannel(0)->IsDtlsConnected() || 1124 EXPECT_FALSE(client1_.GetDtlsTransport(0)->IsDtlsConnected() ||
1123 client1_.GetDtlsChannel(0)->dtls_state() == 1125 client1_.GetDtlsTransport(0)->dtls_state() ==
1124 cricket::DTLS_TRANSPORT_FAILED); 1126 cricket::DTLS_TRANSPORT_FAILED);
1125 EXPECT_TRUE_SIMULATED_WAIT( 1127 EXPECT_TRUE_SIMULATED_WAIT(
1126 client1_.GetDtlsChannel(0)->IsDtlsConnected() || 1128 client1_.GetDtlsTransport(0)->IsDtlsConnected() ||
1127 client1_.GetDtlsChannel(0)->dtls_state() == 1129 client1_.GetDtlsTransport(0)->dtls_state() ==
1128 cricket::DTLS_TRANSPORT_FAILED, 1130 cricket::DTLS_TRANSPORT_FAILED,
1129 kTimeout, fake_clock_); 1131 kTimeout, fake_clock_);
1130 break; 1132 break;
1131 } 1133 }
1132 } 1134 }
1133 1135
1134 cricket::DtlsTransportState expected_final_state = 1136 cricket::DtlsTransportState expected_final_state =
1135 valid_fingerprint ? cricket::DTLS_TRANSPORT_CONNECTED 1137 valid_fingerprint ? cricket::DTLS_TRANSPORT_CONNECTED
1136 : cricket::DTLS_TRANSPORT_FAILED; 1138 : cricket::DTLS_TRANSPORT_FAILED;
1137 EXPECT_EQ_SIMULATED_WAIT(expected_final_state, 1139 EXPECT_EQ_SIMULATED_WAIT(expected_final_state,
1138 client1_.GetDtlsChannel(0)->dtls_state(), kTimeout, 1140 client1_.GetDtlsTransport(0)->dtls_state(),
1139 fake_clock_); 1141 kTimeout, fake_clock_);
1140 EXPECT_EQ_SIMULATED_WAIT(expected_final_state, 1142 EXPECT_EQ_SIMULATED_WAIT(expected_final_state,
1141 client2_.GetDtlsChannel(0)->dtls_state(), kTimeout, 1143 client2_.GetDtlsTransport(0)->dtls_state(),
1142 fake_clock_); 1144 kTimeout, fake_clock_);
1143 1145
1144 // Channel should be writable iff there was a valid fingerprint. 1146 // Channel should be writable iff there was a valid fingerprint.
1145 EXPECT_EQ(valid_fingerprint, client1_.GetDtlsChannel(0)->writable()); 1147 EXPECT_EQ(valid_fingerprint, client1_.GetDtlsTransport(0)->writable());
1146 EXPECT_EQ(valid_fingerprint, client2_.GetDtlsChannel(0)->writable()); 1148 EXPECT_EQ(valid_fingerprint, client2_.GetDtlsTransport(0)->writable());
1147 1149
1148 // Check that no hello needed to be retransmitted. 1150 // Check that no hello needed to be retransmitted.
1149 EXPECT_EQ(1, client1_.received_dtls_client_hellos()); 1151 EXPECT_EQ(1, client1_.received_dtls_client_hellos());
1150 EXPECT_EQ(1, client2_.received_dtls_server_hellos()); 1152 EXPECT_EQ(1, client2_.received_dtls_server_hellos());
1151 1153
1152 if (valid_fingerprint) { 1154 if (valid_fingerprint) {
1153 TestTransfer(0, 1000, 100, false); 1155 TestTransfer(0, 1000, 100, false);
1154 } 1156 }
1155 } 1157 }
1156 }; 1158 };
(...skipping 27 matching lines...) Expand all
1184 std::vector<DtlsTransportEvent>{ 1186 std::vector<DtlsTransportEvent>{
1185 CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT, 1187 CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT,
1186 CALLER_WRITABLE, HANDSHAKE_FINISHES}, 1188 CALLER_WRITABLE, HANDSHAKE_FINISHES},
1187 std::vector<DtlsTransportEvent>{ 1189 std::vector<DtlsTransportEvent>{
1188 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE, 1190 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE,
1189 CALLER_RECEIVES_FINGERPRINT, HANDSHAKE_FINISHES}, 1191 CALLER_RECEIVES_FINGERPRINT, HANDSHAKE_FINISHES},
1190 std::vector<DtlsTransportEvent>{CALLER_RECEIVES_CLIENTHELLO, 1192 std::vector<DtlsTransportEvent>{CALLER_RECEIVES_CLIENTHELLO,
1191 CALLER_WRITABLE, HANDSHAKE_FINISHES, 1193 CALLER_WRITABLE, HANDSHAKE_FINISHES,
1192 CALLER_RECEIVES_FINGERPRINT}), 1194 CALLER_RECEIVES_FINGERPRINT}),
1193 ::testing::Bool())); 1195 ::testing::Bool()));
OLDNEW
« no previous file with comments | « webrtc/p2p/base/dtlstransportchannel.cc ('k') | webrtc/p2p/base/dtlstransportinternal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698