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

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

Issue 1246913005: TransportController refactoring (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Set media engine on voice channel Created 5 years, 4 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
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
11 #include <set> 11 #include <set>
12 12
13 #include "webrtc/p2p/base/dtlstransport.h" 13 #include "webrtc/p2p/base/dtlstransport.h"
14 #include "webrtc/p2p/base/fakesession.h" 14 #include "webrtc/p2p/base/faketransportcontroller.h"
15 #include "webrtc/base/common.h" 15 #include "webrtc/base/common.h"
16 #include "webrtc/base/dscp.h" 16 #include "webrtc/base/dscp.h"
17 #include "webrtc/base/gunit.h" 17 #include "webrtc/base/gunit.h"
18 #include "webrtc/base/helpers.h" 18 #include "webrtc/base/helpers.h"
19 #include "webrtc/base/scoped_ptr.h" 19 #include "webrtc/base/scoped_ptr.h"
20 #include "webrtc/base/ssladapter.h" 20 #include "webrtc/base/ssladapter.h"
21 #include "webrtc/base/sslidentity.h" 21 #include "webrtc/base/sslidentity.h"
22 #include "webrtc/base/sslstreamadapter.h" 22 #include "webrtc/base/sslstreamadapter.h"
23 #include "webrtc/base/stringutils.h" 23 #include "webrtc/base/stringutils.h"
24 #include "webrtc/base/thread.h"
25 24
26 #define MAYBE_SKIP_TEST(feature) \ 25 #define MAYBE_SKIP_TEST(feature) \
27 if (!(rtc::SSLStreamAdapter::feature())) { \ 26 if (!(rtc::SSLStreamAdapter::feature())) { \
28 LOG(LS_INFO) << "Feature disabled... skipping"; \ 27 LOG(LS_INFO) << "Feature disabled... skipping"; \
29 return; \ 28 return; \
30 } 29 }
31 30
32 static const char AES_CM_128_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80"; 31 static const char AES_CM_128_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80";
33 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; 32 static const char kIceUfrag1[] = "TESTICEUFRAG0001";
34 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; 33 static const char kIcePwd1[] = "TESTICEPWD00000000000001";
35 static const size_t kPacketNumOffset = 8; 34 static const size_t kPacketNumOffset = 8;
36 static const size_t kPacketHeaderLen = 12; 35 static const size_t kPacketHeaderLen = 12;
37 36
38 static bool IsRtpLeadByte(uint8 b) { 37 static bool IsRtpLeadByte(uint8 b) {
39 return ((b & 0xC0) == 0x80); 38 return ((b & 0xC0) == 0x80);
40 } 39 }
41 40
42 using cricket::ConnectionRole; 41 using cricket::ConnectionRole;
43 42
44 enum Flags { NF_REOFFER = 0x1, NF_EXPECT_FAILURE = 0x2 }; 43 enum Flags { NF_REOFFER = 0x1, NF_EXPECT_FAILURE = 0x2 };
45 44
46 class DtlsTestClient : public sigslot::has_slots<> { 45 class DtlsTestClient : public sigslot::has_slots<> {
47 public: 46 public:
48 DtlsTestClient(const std::string& name, 47 DtlsTestClient(const std::string& name)
49 rtc::Thread* signaling_thread, 48 : name_(name),
50 rtc::Thread* worker_thread) : 49 protocol_(cricket::ICEPROTO_GOOGLE),
51 name_(name), 50 packet_size_(0),
52 signaling_thread_(signaling_thread), 51 use_dtls_srtp_(false),
53 worker_thread_(worker_thread), 52 ssl_max_version_(rtc::SSL_PROTOCOL_DTLS_10),
54 protocol_(cricket::ICEPROTO_GOOGLE), 53 negotiated_dtls_(false),
55 packet_size_(0), 54 received_dtls_client_hello_(false),
56 use_dtls_srtp_(false), 55 received_dtls_server_hello_(false) {}
57 ssl_max_version_(rtc::SSL_PROTOCOL_DTLS_10),
58 negotiated_dtls_(false),
59 received_dtls_client_hello_(false),
60 received_dtls_server_hello_(false) {
61 }
62 void SetIceProtocol(cricket::TransportProtocol proto) { 56 void SetIceProtocol(cricket::TransportProtocol proto) {
63 protocol_ = proto; 57 protocol_ = proto;
64 } 58 }
65 void CreateIdentity() { 59 void CreateIdentity() {
66 identity_.reset(rtc::SSLIdentity::Generate(name_)); 60 identity_.reset(rtc::SSLIdentity::Generate(name_));
67 } 61 }
68 rtc::SSLIdentity* identity() { return identity_.get(); } 62 rtc::SSLIdentity* identity() { return identity_.get(); }
69 void SetupSrtp() { 63 void SetupSrtp() {
70 ASSERT(identity_.get() != NULL); 64 ASSERT(identity_.get() != NULL);
71 use_dtls_srtp_ = true; 65 use_dtls_srtp_ = true;
72 } 66 }
73 void SetupMaxProtocolVersion(rtc::SSLProtocolVersion version) { 67 void SetupMaxProtocolVersion(rtc::SSLProtocolVersion version) {
74 ASSERT(transport_.get() == NULL); 68 ASSERT(transport_.get() == NULL);
75 ssl_max_version_ = version; 69 ssl_max_version_ = version;
76 } 70 }
77 void SetupChannels(int count, cricket::IceRole role) { 71 void SetupChannels(int count, cricket::IceRole role) {
78 transport_.reset(new cricket::DtlsTransport<cricket::FakeTransport>( 72 transport_.reset(new cricket::DtlsTransport<cricket::FakeTransport>(
79 signaling_thread_, worker_thread_, "dtls content name", NULL, 73 "dtls content name", NULL, identity_.get()));
80 identity_.get()));
81 transport_->SetAsync(true); 74 transport_->SetAsync(true);
82 transport_->SetIceRole(role); 75 transport_->SetIceRole(role);
83 transport_->SetIceTiebreaker( 76 transport_->SetIceTiebreaker(
84 (role == cricket::ICEROLE_CONTROLLING) ? 1 : 2); 77 (role == cricket::ICEROLE_CONTROLLING) ? 1 : 2);
85 transport_->SignalWritableState.connect(this, 78 transport_->SignalWritableState.connect(this,
86 &DtlsTestClient::OnTransportWritableState); 79 &DtlsTestClient::OnTransportWritableState);
87 80
88 for (int i = 0; i < count; ++i) { 81 for (int i = 0; i < count; ++i) {
89 cricket::DtlsTransportChannelWrapper* channel = 82 cricket::DtlsTransportChannelWrapper* channel =
90 static_cast<cricket::DtlsTransportChannelWrapper*>( 83 static_cast<cricket::DtlsTransportChannelWrapper*>(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 187 }
195 negotiated_dtls_ = (local_identity && remote_identity); 188 negotiated_dtls_ = (local_identity && remote_identity);
196 } 189 }
197 190
198 bool Connect(DtlsTestClient* peer) { 191 bool Connect(DtlsTestClient* peer) {
199 transport_->ConnectChannels(); 192 transport_->ConnectChannels();
200 transport_->SetDestination(peer->transport_.get()); 193 transport_->SetDestination(peer->transport_.get());
201 return true; 194 return true;
202 } 195 }
203 196
204 bool writable() const { return transport_->writable(); } 197 bool all_channels_writable() const {
198 return transport_->all_channels_writable();
199 }
205 200
206 void CheckRole(rtc::SSLRole role) { 201 void CheckRole(rtc::SSLRole role) {
207 if (role == rtc::SSL_CLIENT) { 202 if (role == rtc::SSL_CLIENT) {
208 ASSERT_FALSE(received_dtls_client_hello_); 203 ASSERT_FALSE(received_dtls_client_hello_);
209 ASSERT_TRUE(received_dtls_server_hello_); 204 ASSERT_TRUE(received_dtls_server_hello_);
210 } else { 205 } else {
211 ASSERT_TRUE(received_dtls_client_hello_); 206 ASSERT_TRUE(received_dtls_client_hello_);
212 ASSERT_FALSE(received_dtls_server_hello_); 207 ASSERT_FALSE(received_dtls_server_hello_);
213 } 208 }
214 } 209 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 ASSERT_TRUE(VerifyEncryptedPacket(data, size)); 362 ASSERT_TRUE(VerifyEncryptedPacket(data, size));
368 } else if (IsRtpLeadByte(data[0])) { 363 } else if (IsRtpLeadByte(data[0])) {
369 ASSERT_TRUE(VerifyPacket(data, size, NULL)); 364 ASSERT_TRUE(VerifyPacket(data, size, NULL));
370 } 365 }
371 } 366 }
372 } 367 }
373 } 368 }
374 369
375 private: 370 private:
376 std::string name_; 371 std::string name_;
377 rtc::Thread* signaling_thread_;
378 rtc::Thread* worker_thread_;
379 cricket::TransportProtocol protocol_; 372 cricket::TransportProtocol protocol_;
380 rtc::scoped_ptr<rtc::SSLIdentity> identity_; 373 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
381 rtc::scoped_ptr<cricket::FakeTransport> transport_; 374 rtc::scoped_ptr<cricket::FakeTransport> transport_;
382 std::vector<cricket::DtlsTransportChannelWrapper*> channels_; 375 std::vector<cricket::DtlsTransportChannelWrapper*> channels_;
383 size_t packet_size_; 376 size_t packet_size_;
384 std::set<int> received_; 377 std::set<int> received_;
385 bool use_dtls_srtp_; 378 bool use_dtls_srtp_;
386 rtc::SSLProtocolVersion ssl_max_version_; 379 rtc::SSLProtocolVersion ssl_max_version_;
387 bool negotiated_dtls_; 380 bool negotiated_dtls_;
388 bool received_dtls_client_hello_; 381 bool received_dtls_client_hello_;
389 bool received_dtls_server_hello_; 382 bool received_dtls_server_hello_;
390 }; 383 };
391 384
392 385
393 class DtlsTransportChannelTest : public testing::Test { 386 class DtlsTransportChannelTest : public testing::Test {
394 public: 387 public:
395 DtlsTransportChannelTest() : 388 DtlsTransportChannelTest()
396 client1_("P1", rtc::Thread::Current(), 389 : client1_("P1"),
397 rtc::Thread::Current()), 390 client2_("P2"),
398 client2_("P2", rtc::Thread::Current(), 391 channel_ct_(1),
399 rtc::Thread::Current()), 392 use_dtls_(false),
400 channel_ct_(1), 393 use_dtls_srtp_(false),
401 use_dtls_(false), 394 ssl_expected_version_(rtc::SSL_PROTOCOL_DTLS_10) {}
402 use_dtls_srtp_(false),
403 ssl_expected_version_(rtc::SSL_PROTOCOL_DTLS_10) {
404 }
405 395
406 void SetChannelCount(size_t channel_ct) { 396 void SetChannelCount(size_t channel_ct) {
407 channel_ct_ = static_cast<int>(channel_ct); 397 channel_ct_ = static_cast<int>(channel_ct);
408 } 398 }
409 void SetMaxProtocolVersions(rtc::SSLProtocolVersion c1, 399 void SetMaxProtocolVersions(rtc::SSLProtocolVersion c1,
410 rtc::SSLProtocolVersion c2) { 400 rtc::SSLProtocolVersion c2) {
411 client1_.SetupMaxProtocolVersion(c1); 401 client1_.SetupMaxProtocolVersion(c1);
412 client2_.SetupMaxProtocolVersion(c2); 402 client2_.SetupMaxProtocolVersion(c2);
413 ssl_expected_version_ = std::min(c1, c2); 403 ssl_expected_version_ = std::min(c1, c2);
414 } 404 }
(...skipping 21 matching lines...) Expand all
436 } 426 }
437 427
438 bool Connect(ConnectionRole client1_role, ConnectionRole client2_role) { 428 bool Connect(ConnectionRole client1_role, ConnectionRole client2_role) {
439 Negotiate(client1_role, client2_role); 429 Negotiate(client1_role, client2_role);
440 430
441 bool rv = client1_.Connect(&client2_); 431 bool rv = client1_.Connect(&client2_);
442 EXPECT_TRUE(rv); 432 EXPECT_TRUE(rv);
443 if (!rv) 433 if (!rv)
444 return false; 434 return false;
445 435
446 EXPECT_TRUE_WAIT(client1_.writable() && client2_.writable(), 10000); 436 EXPECT_TRUE_WAIT(
447 if (!client1_.writable() || !client2_.writable()) 437 client1_.all_channels_writable() && client2_.all_channels_writable(),
438 10000);
439 if (!client1_.all_channels_writable() || !client2_.all_channels_writable())
448 return false; 440 return false;
449 441
450 // Check that we used the right roles. 442 // Check that we used the right roles.
451 if (use_dtls_) { 443 if (use_dtls_) {
452 rtc::SSLRole client1_ssl_role = 444 rtc::SSLRole client1_ssl_role =
453 (client1_role == cricket::CONNECTIONROLE_ACTIVE || 445 (client1_role == cricket::CONNECTIONROLE_ACTIVE ||
454 (client2_role == cricket::CONNECTIONROLE_PASSIVE && 446 (client2_role == cricket::CONNECTIONROLE_PASSIVE &&
455 client1_role == cricket::CONNECTIONROLE_ACTPASS)) ? 447 client1_role == cricket::CONNECTIONROLE_ACTPASS)) ?
456 rtc::SSL_CLIENT : rtc::SSL_SERVER; 448 rtc::SSL_CLIENT : rtc::SSL_SERVER;
457 449
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 MAYBE_SKIP_TEST(HaveDtlsSrtp); 829 MAYBE_SKIP_TEST(HaveDtlsSrtp);
838 SetChannelCount(2); 830 SetChannelCount(2);
839 PrepareDtls(true, true); 831 PrepareDtls(true, true);
840 PrepareDtlsSrtp(true, true); 832 PrepareDtlsSrtp(true, true);
841 Negotiate(); 833 Negotiate();
842 834
843 Renegotiate(&client1_, cricket::CONNECTIONROLE_ACTPASS, 835 Renegotiate(&client1_, cricket::CONNECTIONROLE_ACTPASS,
844 cricket::CONNECTIONROLE_ACTIVE, NF_REOFFER); 836 cricket::CONNECTIONROLE_ACTIVE, NF_REOFFER);
845 bool rv = client1_.Connect(&client2_); 837 bool rv = client1_.Connect(&client2_);
846 EXPECT_TRUE(rv); 838 EXPECT_TRUE(rv);
847 EXPECT_TRUE_WAIT(client1_.writable() && client2_.writable(), 10000); 839 EXPECT_TRUE_WAIT(
840 client1_.all_channels_writable() && client2_.all_channels_writable(),
841 10000);
848 842
849 TestTransfer(0, 1000, 100, true); 843 TestTransfer(0, 1000, 100, true);
850 TestTransfer(1, 1000, 100, true); 844 TestTransfer(1, 1000, 100, true);
851 } 845 }
852 846
853 // Test Certificates state after negotiation but before connection. 847 // Test Certificates state after negotiation but before connection.
854 TEST_F(DtlsTransportChannelTest, TestCertificatesBeforeConnect) { 848 TEST_F(DtlsTransportChannelTest, TestCertificatesBeforeConnect) {
855 MAYBE_SKIP_TEST(HaveDtls); 849 MAYBE_SKIP_TEST(HaveDtls);
856 PrepareDtls(true, true); 850 PrepareDtls(true, true);
857 Negotiate(); 851 Negotiate();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 // Each side's remote certificate is the other side's local certificate. 889 // Each side's remote certificate is the other side's local certificate.
896 ASSERT_TRUE( 890 ASSERT_TRUE(
897 client1_.transport()->GetRemoteCertificate(remote_cert1.accept())); 891 client1_.transport()->GetRemoteCertificate(remote_cert1.accept()));
898 ASSERT_EQ(remote_cert1->ToPEMString(), 892 ASSERT_EQ(remote_cert1->ToPEMString(),
899 identity2->certificate().ToPEMString()); 893 identity2->certificate().ToPEMString());
900 ASSERT_TRUE( 894 ASSERT_TRUE(
901 client2_.transport()->GetRemoteCertificate(remote_cert2.accept())); 895 client2_.transport()->GetRemoteCertificate(remote_cert2.accept()));
902 ASSERT_EQ(remote_cert2->ToPEMString(), 896 ASSERT_EQ(remote_cert2->ToPEMString(),
903 identity1->certificate().ToPEMString()); 897 identity1->certificate().ToPEMString());
904 } 898 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698