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

Side by Side Diff: talk/app/webrtc/webrtcsession_unittest.cc

Issue 1269843005: Added DtlsCertificate, a ref counted object owning an SSLIdentity (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: webrtcsession unittest added to ensure when a cert is provided it is used 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 * libjingle 2 * libjingle
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation 11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution. 12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products 13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "talk/app/webrtc/audiotrack.h" 28 #include "talk/app/webrtc/audiotrack.h"
29 #include "talk/app/webrtc/dtlscertificate.h"
29 #include "talk/app/webrtc/fakemetricsobserver.h" 30 #include "talk/app/webrtc/fakemetricsobserver.h"
30 #include "talk/app/webrtc/jsepicecandidate.h" 31 #include "talk/app/webrtc/jsepicecandidate.h"
31 #include "talk/app/webrtc/jsepsessiondescription.h" 32 #include "talk/app/webrtc/jsepsessiondescription.h"
32 #include "talk/app/webrtc/mediastreamsignaling.h" 33 #include "talk/app/webrtc/mediastreamsignaling.h"
33 #include "talk/app/webrtc/streamcollection.h" 34 #include "talk/app/webrtc/streamcollection.h"
34 #include "talk/app/webrtc/test/fakeconstraints.h" 35 #include "talk/app/webrtc/test/fakeconstraints.h"
35 #include "talk/app/webrtc/test/fakedtlsidentityservice.h" 36 #include "talk/app/webrtc/test/fakedtlsidentityservice.h"
36 #include "talk/app/webrtc/test/fakemediastreamsignaling.h" 37 #include "talk/app/webrtc/test/fakemediastreamsignaling.h"
37 #include "talk/app/webrtc/videotrack.h" 38 #include "talk/app/webrtc/videotrack.h"
38 #include "talk/app/webrtc/webrtcsession.h" 39 #include "talk/app/webrtc/webrtcsession.h"
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 desc_factory_->set_add_legacy_streams(false); 353 desc_factory_->set_add_legacy_streams(false);
353 allocator_->set_step_delay(cricket::kMinimumStepDelay); 354 allocator_->set_step_delay(cricket::kMinimumStepDelay);
354 } 355 }
355 356
356 void AddInterface(const SocketAddress& addr) { 357 void AddInterface(const SocketAddress& addr) {
357 network_manager_.AddInterface(addr); 358 network_manager_.AddInterface(addr);
358 } 359 }
359 360
360 void Init( 361 void Init(
361 DTLSIdentityServiceInterface* identity_service, 362 DTLSIdentityServiceInterface* identity_service,
363 rtc::scoped_refptr<webrtc::DtlsCertificate> certificate,
362 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { 364 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
363 ASSERT_TRUE(session_.get() == NULL); 365 ASSERT_TRUE(session_.get() == NULL);
364 session_.reset(new WebRtcSessionForTest( 366 session_.reset(new WebRtcSessionForTest(
365 channel_manager_.get(), rtc::Thread::Current(), 367 channel_manager_.get(), rtc::Thread::Current(),
366 rtc::Thread::Current(), allocator_.get(), 368 rtc::Thread::Current(), allocator_.get(),
367 &observer_, 369 &observer_,
368 &mediastream_signaling_)); 370 &mediastream_signaling_));
369 371
370 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, 372 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
371 observer_.ice_connection_state_); 373 observer_.ice_connection_state_);
372 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, 374 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
373 observer_.ice_gathering_state_); 375 observer_.ice_gathering_state_);
374 376
375 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(), 377 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
376 identity_service, rtc_configuration)); 378 identity_service, certificate,
379 rtc_configuration));
377 session_->set_metrics_observer(metrics_observer_); 380 session_->set_metrics_observer(metrics_observer_);
378 } 381 }
379 382
380 void Init() { 383 void Init() {
381 PeerConnectionInterface::RTCConfiguration configuration; 384 PeerConnectionInterface::RTCConfiguration configuration;
382 Init(NULL, configuration); 385 Init(nullptr, nullptr, configuration);
383 } 386 }
384 387
385 void InitWithIceTransport( 388 void InitWithIceTransport(
386 PeerConnectionInterface::IceTransportsType ice_transport_type) { 389 PeerConnectionInterface::IceTransportsType ice_transport_type) {
387 PeerConnectionInterface::RTCConfiguration configuration; 390 PeerConnectionInterface::RTCConfiguration configuration;
388 configuration.type = ice_transport_type; 391 configuration.type = ice_transport_type;
389 Init(NULL, configuration); 392 Init(nullptr, nullptr, configuration);
390 } 393 }
391 394
392 void InitWithBundlePolicy( 395 void InitWithBundlePolicy(
393 PeerConnectionInterface::BundlePolicy bundle_policy) { 396 PeerConnectionInterface::BundlePolicy bundle_policy) {
394 PeerConnectionInterface::RTCConfiguration configuration; 397 PeerConnectionInterface::RTCConfiguration configuration;
395 configuration.bundle_policy = bundle_policy; 398 configuration.bundle_policy = bundle_policy;
396 Init(NULL, configuration); 399 Init(nullptr, nullptr, configuration);
397 } 400 }
398 401
399 void InitWithRtcpMuxPolicy( 402 void InitWithRtcpMuxPolicy(
400 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { 403 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
401 PeerConnectionInterface::RTCConfiguration configuration; 404 PeerConnectionInterface::RTCConfiguration configuration;
402 configuration.rtcp_mux_policy = rtcp_mux_policy; 405 configuration.rtcp_mux_policy = rtcp_mux_policy;
403 Init(NULL, configuration); 406 Init(nullptr, nullptr, configuration);
404 } 407 }
405 408
406 void InitWithDtls(bool identity_request_should_fail = false) { 409 void InitWithDtls(bool identity_request_should_fail = false) {
407 FakeIdentityService* identity_service = new FakeIdentityService(); 410 FakeIdentityService* identity_service = new FakeIdentityService();
408 identity_service->set_should_fail(identity_request_should_fail); 411 identity_service->set_should_fail(identity_request_should_fail);
409 PeerConnectionInterface::RTCConfiguration configuration; 412 PeerConnectionInterface::RTCConfiguration configuration;
410 Init(identity_service, configuration); 413 Init(identity_service, nullptr, configuration);
411 } 414 }
412 415
413 void InitWithDtmfCodec() { 416 void InitWithDtmfCodec() {
414 // Add kTelephoneEventCodec for dtmf test. 417 // Add kTelephoneEventCodec for dtmf test.
415 const cricket::AudioCodec kTelephoneEventCodec( 418 const cricket::AudioCodec kTelephoneEventCodec(
416 106, "telephone-event", 8000, 0, 1, 0); 419 106, "telephone-event", 8000, 0, 1, 0);
417 std::vector<cricket::AudioCodec> codecs; 420 std::vector<cricket::AudioCodec> codecs;
418 codecs.push_back(kTelephoneEventCodec); 421 codecs.push_back(kTelephoneEventCodec);
419 media_engine_->SetAudioCodecs(codecs); 422 media_engine_->SetAudioCodecs(codecs);
420 desc_factory_->set_audio_codecs(codecs); 423 desc_factory_->set_audio_codecs(codecs);
(...skipping 3164 matching lines...) Expand 10 before | Expand all | Expand 10 after
3585 3588
3586 ASSERT_EQ(1UL, ch->recv_codecs().size()); 3589 ASSERT_EQ(1UL, ch->recv_codecs().size());
3587 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id); 3590 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
3588 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName, 3591 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
3589 ch->recv_codecs()[0].name.c_str())); 3592 ch->recv_codecs()[0].name.c_str()));
3590 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort, 3593 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3591 &portnum)); 3594 &portnum));
3592 EXPECT_EQ(new_recv_port, portnum); 3595 EXPECT_EQ(new_recv_port, portnum);
3593 } 3596 }
3594 3597
3598 // Verifies that if a certificate is provided it is the one that will be used.
3599 TEST_F(WebRtcSessionTest, TestUsesProvidedCertificate) {
3600 rtc::scoped_refptr<webrtc::DtlsCertificate> certificate =
3601 FakeIdentityService::GenerateCertificate();
3602
3603 PeerConnectionInterface::RTCConfiguration configuration;
3604 Init(nullptr, certificate, configuration);
3605 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate(), 1000);
3606
3607 EXPECT_EQ(session_->get_certificate(), certificate);
3608 }
3609
3595 // Verifies that CreateOffer succeeds when CreateOffer is called before async 3610 // Verifies that CreateOffer succeeds when CreateOffer is called before async
3596 // identity generation is finished. 3611 // identity generation is finished.
3597 TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) { 3612 TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3598 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); 3613 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3599 InitWithDtls(); 3614 InitWithDtls();
3600 3615
3601 EXPECT_TRUE(session_->waiting_for_identity()); 3616 EXPECT_TRUE(session_->waiting_for_certificate());
3602 mediastream_signaling_.SendAudioVideoStream1(); 3617 mediastream_signaling_.SendAudioVideoStream1();
3603 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); 3618 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3604 3619
3605 EXPECT_TRUE(offer != NULL); 3620 EXPECT_TRUE(offer != NULL);
3606 VerifyNoCryptoParams(offer->description(), true); 3621 VerifyNoCryptoParams(offer->description(), true);
3607 VerifyFingerprintStatus(offer->description(), true); 3622 VerifyFingerprintStatus(offer->description(), true);
3608 } 3623 }
3609 3624
3610 // Verifies that CreateAnswer succeeds when CreateOffer is called before async 3625 // Verifies that CreateAnswer succeeds when CreateOffer is called before async
3611 // identity generation is finished. 3626 // identity generation is finished.
(...skipping 14 matching lines...) Expand all
3626 VerifyNoCryptoParams(answer->description(), true); 3641 VerifyNoCryptoParams(answer->description(), true);
3627 VerifyFingerprintStatus(answer->description(), true); 3642 VerifyFingerprintStatus(answer->description(), true);
3628 } 3643 }
3629 3644
3630 // Verifies that CreateOffer succeeds when CreateOffer is called after async 3645 // Verifies that CreateOffer succeeds when CreateOffer is called after async
3631 // identity generation is finished. 3646 // identity generation is finished.
3632 TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) { 3647 TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
3633 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); 3648 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3634 InitWithDtls(); 3649 InitWithDtls();
3635 3650
3636 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000); 3651 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate(), 1000);
3637 3652
3638 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); 3653 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3639 EXPECT_TRUE(offer != NULL); 3654 EXPECT_TRUE(offer != NULL);
3640 } 3655 }
3641 3656
3642 // Verifies that CreateOffer fails when CreateOffer is called after async 3657 // Verifies that CreateOffer fails when CreateOffer is called after async
3643 // identity generation fails. 3658 // identity generation fails.
3644 TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) { 3659 TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
3645 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); 3660 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3646 InitWithDtls(true); 3661 InitWithDtls(true);
3647 3662
3648 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000); 3663 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate(), 1000);
3649 3664
3650 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); 3665 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3651 EXPECT_TRUE(offer == NULL); 3666 EXPECT_TRUE(offer == NULL);
3652 } 3667 }
3653 3668
3654 // Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made 3669 // Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3655 // before async identity generation is finished. 3670 // before async identity generation is finished.
3656 TEST_F(WebRtcSessionTest, 3671 TEST_F(WebRtcSessionTest,
3657 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) { 3672 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
3658 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); 3673 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
3941 // terminated. The offer creation may or may not have succeeded, but we 3956 // terminated. The offer creation may or may not have succeeded, but we
3942 // must have received a notification which, so the only invalid state 3957 // must have received a notification which, so the only invalid state
3943 // is kInit. 3958 // is kInit.
3944 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state()); 3959 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
3945 } 3960 }
3946 } 3961 }
3947 3962
3948 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test 3963 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3949 // currently fails because upon disconnection and reconnection OnIceComplete is 3964 // currently fails because upon disconnection and reconnection OnIceComplete is
3950 // called more than once without returning to IceGatheringGathering. 3965 // called more than once without returning to IceGatheringGathering.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698