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

Unified Diff: webrtc/ortc/ortcfactory_integrationtest.cc

Issue 2714813004: Create the SrtpTransportInterface. (Closed)
Patch Set: Merge and modified the tests. Created 3 years, 10 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/ortc/ortcfactory_integrationtest.cc
diff --git a/webrtc/ortc/ortcfactory_integrationtest.cc b/webrtc/ortc/ortcfactory_integrationtest.cc
index e935f068a319caebdedd47a2e50056363d1344ed..8cab28e1451cada8716ebc1ac6ba8490f5ebe6f2 100644
--- a/webrtc/ortc/ortcfactory_integrationtest.cc
+++ b/webrtc/ortc/ortcfactory_integrationtest.cc
@@ -25,13 +25,26 @@
namespace {
-const int kDefaultTimeout = 10000; // 10 seconds.
+const int kDefaultTimeout = 10000; // 10 seconds.
+const int kReceivingTimeout = 1000; // 1 second.
Taylor Brandstetter 2017/03/01 19:18:08 nit: This isn't really a "timeout", since the test
Zhi Huang 2017/03/02 23:35:39 Yes, this would be better.
// Default number of audio/video frames to wait for before considering a test a
// success.
const int kDefaultNumFrames = 3;
const rtc::IPAddress kIPv4LocalHostAddress =
rtc::IPAddress(0x7F000001); // 127.0.0.1
+static const char kTestKeyParams1[] =
+ "inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz";
+static const char kTestKeyParams2[] =
+ "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR";
+static const cricket::CryptoParams kTestCryptoParams1(1,
+ "AES_CM_128_HMAC_SHA1_80",
+ kTestKeyParams1,
+ "");
+static const cricket::CryptoParams kTestCryptoParams2(1,
+ "AES_CM_128_HMAC_SHA1_80",
+ kTestKeyParams2,
+ "");
} // namespace
namespace webrtc {
@@ -71,6 +84,9 @@ class OrtcFactoryIntegrationTest : public testing::Test {
typedef std::pair<std::unique_ptr<RtpTransportInterface>,
std::unique_ptr<RtpTransportInterface>>
RtpTransportPair;
+ typedef std::pair<std::unique_ptr<SrtpTransportInterface>,
+ std::unique_ptr<SrtpTransportInterface>>
+ SrtpTransportPair;
typedef std::pair<std::unique_ptr<RtpTransportControllerInterface>,
std::unique_ptr<RtpTransportControllerInterface>>
RtpTransportControllerPair;
@@ -115,6 +131,20 @@ class OrtcFactoryIntegrationTest : public testing::Test {
return {transport_result1.MoveValue(), transport_result2.MoveValue()};
}
+ SrtpTransportPair CreateSrtpTransportPair(
+ const RtcpParameters& rtcp_parameters,
+ const UdpTransportPair& rtp_udp_transports,
+ const UdpTransportPair& rtcp_udp_transports,
+ const RtpTransportControllerPair& transport_controllers) {
+ auto transport_result1 = ortc_factory1_->CreateSrtpTransport(
+ rtcp_parameters, rtp_udp_transports.first.get(),
+ rtcp_udp_transports.first.get(), transport_controllers.first.get());
+ auto transport_result2 = ortc_factory2_->CreateSrtpTransport(
+ rtcp_parameters, rtp_udp_transports.second.get(),
+ rtcp_udp_transports.second.get(), transport_controllers.second.get());
+ return {transport_result1.MoveValue(), transport_result2.MoveValue()};
+ }
+
// For convenience when |rtcp_udp_transports| and |transport_controllers|
// aren't needed.
RtpTransportPair CreateRtpTransportPair(
@@ -125,6 +155,37 @@ class OrtcFactoryIntegrationTest : public testing::Test {
RtpTransportControllerPair());
}
+ SrtpTransportPair CreateSrtpTransportPairAndSetKeys(
+ const RtcpParameters& rtcp_parameters,
+ const UdpTransportPair& rtp_udp_transports) {
+ SrtpTransportPair srtp_transports = CreateSrtpTransportPair(
+ rtcp_parameters, rtp_udp_transports, UdpTransportPair(),
+ RtpTransportControllerPair());
+ auto transport1 = std::move(srtp_transports.first);
+ auto transport2 = std::move(srtp_transports.second);
+ EXPECT_TRUE(transport1->SetSrtpSendKey(kTestCryptoParams1).ok());
+ EXPECT_TRUE(transport1->SetSrtpReceiveKey(kTestCryptoParams2).ok());
+ EXPECT_TRUE(transport2->SetSrtpSendKey(kTestCryptoParams2).ok());
+ EXPECT_TRUE(transport2->SetSrtpReceiveKey(kTestCryptoParams1).ok());
+ return {std::move(transport1), std::move(transport2)};
Taylor Brandstetter 2017/03/01 19:18:08 Is it possible to return "std::move(srtp_transport
Zhi Huang 2017/03/02 23:35:39 Done.
+ }
+
+ SrtpTransportPair CreateSrtpTransportPairAndSetMismatchingKeys(
+ const RtcpParameters& rtcp_parameters,
+ const UdpTransportPair& rtp_udp_transports) {
+ SrtpTransportPair srtp_transports = CreateSrtpTransportPair(
+ rtcp_parameters, rtp_udp_transports, UdpTransportPair(),
+ RtpTransportControllerPair());
+ auto transport1 = std::move(srtp_transports.first);
+ auto transport2 = std::move(srtp_transports.second);
+ // Set mismatching keys.
+ EXPECT_TRUE(transport1->SetSrtpSendKey(kTestCryptoParams1).ok());
+ EXPECT_TRUE(transport1->SetSrtpReceiveKey(kTestCryptoParams2).ok());
+ EXPECT_TRUE(transport2->SetSrtpSendKey(kTestCryptoParams1).ok());
+ EXPECT_TRUE(transport2->SetSrtpReceiveKey(kTestCryptoParams2).ok());
+ return {std::move(transport1), std::move(transport2)};
+ }
+
// Ends up using fake audio capture module, which was passed into OrtcFactory
// on creation.
rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack(
@@ -152,6 +213,111 @@ class OrtcFactoryIntegrationTest : public testing::Test {
ortc_factory->CreateVideoTrack(id, source));
}
+ // Helper function used to test two way RTP senders and receivers with basic
+ // configurations.
Taylor Brandstetter 2017/03/01 19:18:07 Could you add a comment saying: "If |expect_succes
Zhi Huang 2017/03/02 23:35:39 Done.
+ void BasicsTwoWayRtpSendersAndReceiversTest(UdpTransportPair udp_transports,
Taylor Brandstetter 2017/03/01 19:18:07 nit: "Basic" instead of "Basics"
Taylor Brandstetter 2017/03/01 19:18:07 It doesn't look like the udp_transports parameter
Zhi Huang 2017/03/02 23:35:39 Oh, I'm so careless.
+ RtpTransportPair srtp_transports,
+ bool expect_success) {
+ received_audio_frame1_ = 0;
+ received_audio_frame2_ = 0;
+ rendered_video_frame1_ = 0;
+ rendered_video_frame2_ = 0;
Taylor Brandstetter 2017/03/01 19:18:07 nit: "frames", plural?
Zhi Huang 2017/03/02 23:35:39 Done.
+ // Create all the senders and receivers (four per endpoint).
+ auto audio_sender_result1 = ortc_factory1_->CreateRtpSender(
+ cricket::MEDIA_TYPE_AUDIO, srtp_transports.first.get());
+ auto video_sender_result1 = ortc_factory1_->CreateRtpSender(
+ cricket::MEDIA_TYPE_VIDEO, srtp_transports.first.get());
+ auto audio_receiver_result1 = ortc_factory1_->CreateRtpReceiver(
+ cricket::MEDIA_TYPE_AUDIO, srtp_transports.first.get());
+ auto video_receiver_result1 = ortc_factory1_->CreateRtpReceiver(
+ cricket::MEDIA_TYPE_VIDEO, srtp_transports.first.get());
+ ASSERT_TRUE(audio_sender_result1.ok());
+ ASSERT_TRUE(video_sender_result1.ok());
+ ASSERT_TRUE(audio_receiver_result1.ok());
+ ASSERT_TRUE(video_receiver_result1.ok());
+ auto audio_sender1 = audio_sender_result1.MoveValue();
+ auto video_sender1 = video_sender_result1.MoveValue();
+ auto audio_receiver1 = audio_receiver_result1.MoveValue();
+ auto video_receiver1 = video_receiver_result1.MoveValue();
+
+ auto audio_sender_result2 = ortc_factory2_->CreateRtpSender(
+ cricket::MEDIA_TYPE_AUDIO, srtp_transports.second.get());
+ auto video_sender_result2 = ortc_factory2_->CreateRtpSender(
+ cricket::MEDIA_TYPE_VIDEO, srtp_transports.second.get());
+ auto audio_receiver_result2 = ortc_factory2_->CreateRtpReceiver(
+ cricket::MEDIA_TYPE_AUDIO, srtp_transports.second.get());
+ auto video_receiver_result2 = ortc_factory2_->CreateRtpReceiver(
+ cricket::MEDIA_TYPE_VIDEO, srtp_transports.second.get());
+ ASSERT_TRUE(audio_sender_result2.ok());
+ ASSERT_TRUE(video_sender_result2.ok());
+ ASSERT_TRUE(audio_receiver_result2.ok());
+ ASSERT_TRUE(video_receiver_result2.ok());
+ auto audio_sender2 = audio_sender_result2.MoveValue();
+ auto video_sender2 = video_sender_result2.MoveValue();
+ auto audio_receiver2 = audio_receiver_result2.MoveValue();
+ auto video_receiver2 = video_receiver_result2.MoveValue();
+
+ // Add fake tracks.
+ RTCError error = audio_sender1->SetTrack(
+ CreateLocalAudioTrack("audio", ortc_factory1_.get()));
+ EXPECT_TRUE(error.ok());
+ error = video_sender1->SetTrack(
+ CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory1_.get()));
+ EXPECT_TRUE(error.ok());
+ error = audio_sender2->SetTrack(
+ CreateLocalAudioTrack("audio", ortc_factory2_.get()));
+ EXPECT_TRUE(error.ok());
+ error = video_sender2->SetTrack(
+ CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory2_.get()));
+ EXPECT_TRUE(error.ok());
+
+ // "sent_X_parameters1" are the parameters that endpoint 1 sends with and
+ // endpoint 2 receives with.
+ RtpParameters sent_opus_parameters1 =
+ MakeMinimalOpusParametersWithSsrc(0xdeadbeef);
+ RtpParameters sent_vp8_parameters1 =
+ MakeMinimalVp8ParametersWithSsrc(0xbaadfeed);
+ RtpParameters sent_opus_parameters2 =
+ MakeMinimalOpusParametersWithSsrc(0x13333337);
+ RtpParameters sent_vp8_parameters2 =
+ MakeMinimalVp8ParametersWithSsrc(0x12345678);
+
+ // Configure the senders' and receivers' parameters.
+ EXPECT_TRUE(audio_receiver1->Receive(sent_opus_parameters2).ok());
+ EXPECT_TRUE(video_receiver1->Receive(sent_vp8_parameters2).ok());
+ EXPECT_TRUE(audio_receiver2->Receive(sent_opus_parameters1).ok());
+ EXPECT_TRUE(video_receiver2->Receive(sent_vp8_parameters1).ok());
+ EXPECT_TRUE(audio_sender1->Send(sent_opus_parameters1).ok());
+ EXPECT_TRUE(video_sender1->Send(sent_vp8_parameters1).ok());
+ EXPECT_TRUE(audio_sender2->Send(sent_opus_parameters2).ok());
+ EXPECT_TRUE(video_sender2->Send(sent_vp8_parameters2).ok());
+
+ FakeVideoTrackRenderer fake_video_renderer1(
+ static_cast<VideoTrackInterface*>(video_receiver1->GetTrack().get()));
+ FakeVideoTrackRenderer fake_video_renderer2(
+ static_cast<VideoTrackInterface*>(video_receiver2->GetTrack().get()));
+
+ // If the test is expected to succeed, at least |kDefaultNumFrames| of
+ // frames should be rendered within |kDefaultTimeout|.
+ // If the test is expected to fail, no frames should be rendered after
+ // waiting for |kReceivingTimeout|.
+ if (expect_success) {
+ EXPECT_TRUE_WAIT(
+ fake_audio_capture_module1_->frames_received() > kDefaultNumFrames &&
+ fake_video_renderer1.num_rendered_frames() > kDefaultNumFrames &&
+ fake_audio_capture_module2_->frames_received() >
+ kDefaultNumFrames &&
+ fake_video_renderer1.num_rendered_frames() > kDefaultNumFrames,
+ kDefaultTimeout);
+ } else {
+ WAIT(false, kReceivingTimeout);
+ rendered_video_frame1_ = fake_video_renderer1.num_rendered_frames();
+ rendered_video_frame2_ = fake_video_renderer2.num_rendered_frames();
+ received_audio_frame1_ = fake_audio_capture_module1_->frames_received();
+ received_audio_frame2_ = fake_audio_capture_module2_->frames_received();
+ }
+ }
+
rtc::PhysicalSocketServer physical_socket_server_;
rtc::VirtualSocketServer virtual_socket_server_;
rtc::Thread network_thread_;
@@ -162,6 +328,10 @@ class OrtcFactoryIntegrationTest : public testing::Test {
std::unique_ptr<OrtcFactoryInterface> ortc_factory2_;
// Actually owned by video tracks.
std::vector<cricket::FakeVideoCapturer*> fake_video_capturers_;
+ int received_audio_frame1_ = 0;
+ int received_audio_frame2_ = 0;
+ int rendered_video_frame1_ = 0;
+ int rendered_video_frame2_ = 0;
};
// Very basic end-to-end test with a single pair of audio RTP sender and
@@ -285,90 +455,9 @@ TEST_F(OrtcFactoryIntegrationTest,
auto udp_transports = CreateAndConnectUdpTransportPair();
auto rtp_transports =
CreateRtpTransportPair(MakeRtcpMuxParameters(), udp_transports);
-
- // Create all the senders and receivers (four per endpoint).
- auto audio_sender_result1 = ortc_factory1_->CreateRtpSender(
- cricket::MEDIA_TYPE_AUDIO, rtp_transports.first.get());
- auto video_sender_result1 = ortc_factory1_->CreateRtpSender(
- cricket::MEDIA_TYPE_VIDEO, rtp_transports.first.get());
- auto audio_receiver_result1 = ortc_factory1_->CreateRtpReceiver(
- cricket::MEDIA_TYPE_AUDIO, rtp_transports.first.get());
- auto video_receiver_result1 = ortc_factory1_->CreateRtpReceiver(
- cricket::MEDIA_TYPE_VIDEO, rtp_transports.first.get());
- ASSERT_TRUE(audio_sender_result1.ok());
- ASSERT_TRUE(video_sender_result1.ok());
- ASSERT_TRUE(audio_receiver_result1.ok());
- ASSERT_TRUE(video_receiver_result1.ok());
- auto audio_sender1 = audio_sender_result1.MoveValue();
- auto video_sender1 = video_sender_result1.MoveValue();
- auto audio_receiver1 = audio_receiver_result1.MoveValue();
- auto video_receiver1 = video_receiver_result1.MoveValue();
-
- auto audio_sender_result2 = ortc_factory2_->CreateRtpSender(
- cricket::MEDIA_TYPE_AUDIO, rtp_transports.second.get());
- auto video_sender_result2 = ortc_factory2_->CreateRtpSender(
- cricket::MEDIA_TYPE_VIDEO, rtp_transports.second.get());
- auto audio_receiver_result2 = ortc_factory2_->CreateRtpReceiver(
- cricket::MEDIA_TYPE_AUDIO, rtp_transports.second.get());
- auto video_receiver_result2 = ortc_factory2_->CreateRtpReceiver(
- cricket::MEDIA_TYPE_VIDEO, rtp_transports.second.get());
- ASSERT_TRUE(audio_sender_result2.ok());
- ASSERT_TRUE(video_sender_result2.ok());
- ASSERT_TRUE(audio_receiver_result2.ok());
- ASSERT_TRUE(video_receiver_result2.ok());
- auto audio_sender2 = audio_sender_result2.MoveValue();
- auto video_sender2 = video_sender_result2.MoveValue();
- auto audio_receiver2 = audio_receiver_result2.MoveValue();
- auto video_receiver2 = video_receiver_result2.MoveValue();
-
- // Add fake tracks.
- RTCError error = audio_sender1->SetTrack(
- CreateLocalAudioTrack("audio", ortc_factory1_.get()));
- EXPECT_TRUE(error.ok());
- error = video_sender1->SetTrack(
- CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory1_.get()));
- EXPECT_TRUE(error.ok());
- error = audio_sender2->SetTrack(
- CreateLocalAudioTrack("audio", ortc_factory2_.get()));
- EXPECT_TRUE(error.ok());
- error = video_sender2->SetTrack(
- CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory2_.get()));
- EXPECT_TRUE(error.ok());
-
- // "sent_X_parameters1" are the parameters that endpoint 1 sends with and
- // endpoint 2 receives with.
- RtpParameters sent_opus_parameters1 =
- MakeMinimalOpusParametersWithSsrc(0xdeadbeef);
- RtpParameters sent_vp8_parameters1 =
- MakeMinimalVp8ParametersWithSsrc(0xbaadfeed);
- RtpParameters sent_opus_parameters2 =
- MakeMinimalOpusParametersWithSsrc(0x13333337);
- RtpParameters sent_vp8_parameters2 =
- MakeMinimalVp8ParametersWithSsrc(0x12345678);
-
- // Configure the senders' and receivers' parameters.
- EXPECT_TRUE(audio_receiver1->Receive(sent_opus_parameters2).ok());
- EXPECT_TRUE(video_receiver1->Receive(sent_vp8_parameters2).ok());
- EXPECT_TRUE(audio_receiver2->Receive(sent_opus_parameters1).ok());
- EXPECT_TRUE(video_receiver2->Receive(sent_vp8_parameters1).ok());
- EXPECT_TRUE(audio_sender1->Send(sent_opus_parameters1).ok());
- EXPECT_TRUE(video_sender1->Send(sent_vp8_parameters1).ok());
- EXPECT_TRUE(audio_sender2->Send(sent_opus_parameters2).ok());
- EXPECT_TRUE(video_sender2->Send(sent_vp8_parameters2).ok());
-
- FakeVideoTrackRenderer fake_video_renderer1(
- static_cast<VideoTrackInterface*>(video_receiver1->GetTrack().get()));
- FakeVideoTrackRenderer fake_video_renderer2(
- static_cast<VideoTrackInterface*>(video_receiver2->GetTrack().get()));
-
- // Senders and receivers are connected and configured; audio and video frames
- // should be able to flow at this point.
- EXPECT_TRUE_WAIT(
- fake_audio_capture_module1_->frames_received() > kDefaultNumFrames &&
- fake_video_renderer1.num_rendered_frames() > kDefaultNumFrames &&
- fake_audio_capture_module2_->frames_received() > kDefaultNumFrames &&
- fake_video_renderer2.num_rendered_frames() > kDefaultNumFrames,
- kDefaultTimeout);
+ BasicsTwoWayRtpSendersAndReceiversTest(std::move(udp_transports),
+ std::move(rtp_transports),
+ true /*expect_success*/);
Taylor Brandstetter 2017/03/01 19:18:08 nit: Our style (at least, from what I've learned f
Zhi Huang 2017/03/02 23:35:39 Done.
}
// End-to-end test with two pairs of RTP senders and receivers, for audio and
@@ -500,6 +589,58 @@ TEST_F(OrtcFactoryIntegrationTest, FullTwoWayAudioVideoRtpSendersAndReceivers) {
kDefaultTimeout);
}
+TEST_F(OrtcFactoryIntegrationTest,
Taylor Brandstetter 2017/03/01 19:18:07 Could these new tests be added above the "FullTwoW
Zhi Huang 2017/03/02 23:35:39 Done.
+ BasicTwoWayAudioVideoSrtpSendersAndReceivers) {
+ auto udp_transports = CreateAndConnectUdpTransportPair();
+ auto srtp_transports = CreateSrtpTransportPairAndSetKeys(
+ MakeRtcpMuxParameters(), udp_transports);
+ BasicsTwoWayRtpSendersAndReceiversTest(std::move(udp_transports),
+ std::move(srtp_transports),
+ true /*expect_success*/);
+}
+
+// Tests that the packet cannot be decoded if the keys are mismatched.
Taylor Brandstetter 2017/03/01 19:18:07 nit: "Tests that packets..."
Zhi Huang 2017/03/02 23:35:39 Done.
+TEST_F(OrtcFactoryIntegrationTest, SrtpSendersAndReceiversWithMismatchingKeys) {
+ auto udp_transports = CreateAndConnectUdpTransportPair();
+ auto srtp_transports = CreateSrtpTransportPairAndSetMismatchingKeys(
+ MakeRtcpMuxParameters(), udp_transports);
+ BasicsTwoWayRtpSendersAndReceiversTest(std::move(udp_transports),
+ std::move(srtp_transports),
+ false /*expect_success*/);
+ // No frame is expected to be decoded.
Taylor Brandstetter 2017/03/01 19:18:08 nit: "No frames are..."
Zhi Huang 2017/03/02 23:35:39 Done.
+ EXPECT_TRUE(received_audio_frame1_ == 0 && received_audio_frame2_ == 0 &&
+ rendered_video_frame1_ == 0 && rendered_video_frame2_ == 0);
+}
+
+// Tests that the frame cannot be decoded if only one side uses SRTP.
+TEST_F(OrtcFactoryIntegrationTest, OneSideSrtpSenderAndReceiver) {
+ auto rtcp_parameters = MakeRtcpMuxParameters();
+ auto udp_transports = CreateAndConnectUdpTransportPair();
+ auto rtcp_udp_transports = UdpTransportPair();
+ auto transport_controllers = RtpTransportControllerPair();
+ auto transport_result1 = ortc_factory1_->CreateRtpTransport(
+ rtcp_parameters, udp_transports.first.get(),
+ rtcp_udp_transports.first.get(), transport_controllers.first.get());
+ auto transport_result2 = ortc_factory2_->CreateSrtpTransport(
+ rtcp_parameters, udp_transports.second.get(),
+ rtcp_udp_transports.second.get(), transport_controllers.second.get());
+
+ auto rtp_transport = transport_result1.MoveValue();
+ auto srtp_transport = transport_result2.MoveValue();
+ EXPECT_TRUE(srtp_transport->SetSrtpSendKey(kTestCryptoParams1).ok());
+ EXPECT_TRUE(srtp_transport->SetSrtpReceiveKey(kTestCryptoParams2).ok());
+ BasicsTwoWayRtpSendersAndReceiversTest(
+ std::move(udp_transports),
+ {std::move(rtp_transport), std::move(srtp_transport)},
+ false /*expect_success*/);
+
+ // The SRTP side is not expected to decode any audio and video frames.
Taylor Brandstetter 2017/03/01 19:18:07 nit: "audio or video"
Zhi Huang 2017/03/02 23:35:39 Done.
+ // The RTP side is not expected to decode any video frames while it is
+ // possible that the encrypted audio frames can be accidentally decoded.
Taylor Brandstetter 2017/03/01 19:18:08 Could you add: "which is why received_audio_frames
Zhi Huang 2017/03/02 23:35:39 Done.
+ EXPECT_TRUE(received_audio_frame2_ == 0 && rendered_video_frame1_ == 0 &&
+ rendered_video_frame2_ == 0);
+}
+
// TODO(deadbeef): End-to-end test for multiple senders/receivers of the same
// media type, once that's supported. Currently, it is not because the
// BaseChannel model relies on there being a single VoiceChannel and

Powered by Google App Engine
This is Rietveld 408576698