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

Side by Side Diff: webrtc/pc/webrtcsdp_unittest.cc

Issue 2761143002: Support encrypted RTP extensions (RFC 6904) (Closed)
Patch Set: Fix compile error on win_x64 bots. Created 3 years, 5 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/pc/webrtcsdp.cc ('k') | webrtc/pc/webrtcsession.cc » ('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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " 87 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
88 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"; 88 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
89 static const char kFingerprint[] = "a=fingerprint:sha-1 " 89 static const char kFingerprint[] = "a=fingerprint:sha-1 "
90 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"; 90 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
91 static const int kExtmapId = 1; 91 static const int kExtmapId = 1;
92 static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime"; 92 static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
93 static const char kExtmap[] = 93 static const char kExtmap[] =
94 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n"; 94 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
95 static const char kExtmapWithDirectionAndAttribute[] = 95 static const char kExtmapWithDirectionAndAttribute[] =
96 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n"; 96 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
97 static const char kExtmapWithDirectionAndAttributeEncrypted[] =
98 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
99 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
97 100
98 static const uint8_t kIdentityDigest[] = { 101 static const uint8_t kIdentityDigest[] = {
99 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02, 102 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
100 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB}; 103 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
101 104
102 static const char kDtlsSctp[] = "DTLS/SCTP"; 105 static const char kDtlsSctp[] = "DTLS/SCTP";
103 static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP"; 106 static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
104 static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP"; 107 static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
105 108
106 struct CodecParams { 109 struct CodecParams {
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 EXPECT_EQ(cd1->streams(), cd2->streams()); 1209 EXPECT_EQ(cd1->streams(), cd2->streams());
1207 1210
1208 // extmap 1211 // extmap
1209 ASSERT_EQ(cd1->rtp_header_extensions().size(), 1212 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1210 cd2->rtp_header_extensions().size()); 1213 cd2->rtp_header_extensions().size());
1211 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) { 1214 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
1212 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i); 1215 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1213 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i); 1216 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
1214 EXPECT_EQ(ext1.uri, ext2.uri); 1217 EXPECT_EQ(ext1.uri, ext2.uri);
1215 EXPECT_EQ(ext1.id, ext2.id); 1218 EXPECT_EQ(ext1.id, ext2.id);
1219 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
1216 } 1220 }
1217 } 1221 }
1218 1222
1219 void CompareDataContentDescription(const DataContentDescription* dcd1, 1223 void CompareDataContentDescription(const DataContentDescription* dcd1,
1220 const DataContentDescription* dcd2) { 1224 const DataContentDescription* dcd2) {
1221 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap()); 1225 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1222 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2); 1226 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1223 } 1227 }
1224 1228
1225 void CompareSessionDescription(const SessionDescription& desc1, 1229 void CompareSessionDescription(const SessionDescription& desc1,
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice, 1431 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1428 cricket::ICEMODE_FULL, 1432 cricket::ICEMODE_FULL,
1429 cricket::CONNECTIONROLE_NONE, &fingerprint)))); 1433 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1430 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( 1434 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1431 kVideoContentName, 1435 kVideoContentName,
1432 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo, 1436 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1433 cricket::ICEMODE_FULL, 1437 cricket::ICEMODE_FULL,
1434 cricket::CONNECTIONROLE_NONE, &fingerprint)))); 1438 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1435 } 1439 }
1436 1440
1437 void AddExtmap() { 1441 void AddExtmap(bool encrypted) {
1438 audio_desc_ = static_cast<AudioContentDescription*>( 1442 audio_desc_ = static_cast<AudioContentDescription*>(
1439 audio_desc_->Copy()); 1443 audio_desc_->Copy());
1440 video_desc_ = static_cast<VideoContentDescription*>( 1444 video_desc_ = static_cast<VideoContentDescription*>(
1441 video_desc_->Copy()); 1445 video_desc_->Copy());
1442 audio_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId)); 1446 audio_desc_->AddRtpHeaderExtension(
1443 video_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId)); 1447 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1448 video_desc_->AddRtpHeaderExtension(
1449 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1444 desc_.RemoveContentByName(kAudioContentName); 1450 desc_.RemoveContentByName(kAudioContentName);
1445 desc_.RemoveContentByName(kVideoContentName); 1451 desc_.RemoveContentByName(kVideoContentName);
1446 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_); 1452 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1447 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_); 1453 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1448 } 1454 }
1449 1455
1450 void RemoveCryptos() { 1456 void RemoveCryptos() {
1451 audio_desc_->set_cryptos(std::vector<CryptoParams>()); 1457 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1452 video_desc_->set_cryptos(std::vector<CryptoParams>()); 1458 video_desc_->set_cryptos(std::vector<CryptoParams>());
1453 } 1459 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 video_rejected ? "" : kPwdVideo); 1575 video_rejected ? "" : kPwdVideo);
1570 JsepSessionDescription jdesc_no_candidates(kDummyString); 1576 JsepSessionDescription jdesc_no_candidates(kDummyString);
1571 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(), 1577 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1572 jdesc_.session_version())) { 1578 jdesc_.session_version())) {
1573 return false; 1579 return false;
1574 } 1580 }
1575 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); 1581 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1576 return true; 1582 return true;
1577 } 1583 }
1578 1584
1579 void TestDeserializeExtmap(bool session_level, bool media_level) { 1585 void TestDeserializeExtmap(bool session_level, bool media_level,
1580 AddExtmap(); 1586 bool encrypted) {
1587 AddExtmap(encrypted);
1581 JsepSessionDescription new_jdesc("dummy"); 1588 JsepSessionDescription new_jdesc("dummy");
1582 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), 1589 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1583 jdesc_.session_id(), 1590 jdesc_.session_id(),
1584 jdesc_.session_version())); 1591 jdesc_.session_version()));
1585 JsepSessionDescription jdesc_with_extmap("dummy"); 1592 JsepSessionDescription jdesc_with_extmap("dummy");
1586 std::string sdp_with_extmap = kSdpString; 1593 std::string sdp_with_extmap = kSdpString;
1587 if (session_level) { 1594 if (session_level) {
1588 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute, 1595 InjectAfter(kSessionTime,
1596 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1597 : kExtmapWithDirectionAndAttribute,
1589 &sdp_with_extmap); 1598 &sdp_with_extmap);
1590 } 1599 }
1591 if (media_level) { 1600 if (media_level) {
1592 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute, 1601 InjectAfter(kAttributeIcePwdVoice,
1602 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1603 : kExtmapWithDirectionAndAttribute,
1593 &sdp_with_extmap); 1604 &sdp_with_extmap);
1594 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute, 1605 InjectAfter(kAttributeIcePwdVideo,
1606 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1607 : kExtmapWithDirectionAndAttribute,
1595 &sdp_with_extmap); 1608 &sdp_with_extmap);
1596 } 1609 }
1597 // The extmap can't be present at the same time in both session level and 1610 // The extmap can't be present at the same time in both session level and
1598 // media level. 1611 // media level.
1599 if (session_level && media_level) { 1612 if (session_level && media_level) {
1600 SdpParseError error; 1613 SdpParseError error;
1601 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap, 1614 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1602 &jdesc_with_extmap, &error)); 1615 &jdesc_with_extmap, &error));
1603 EXPECT_NE(std::string::npos, error.description.find("a=extmap")); 1616 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1604 } else { 1617 } else {
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
2009 std::string expected_sdp = kSdpString; 2022 std::string expected_sdp = kSdpString;
2010 expected_sdp.append(kSdpRtpDataChannelString); 2023 expected_sdp.append(kSdpRtpDataChannelString);
2011 // Serializing data content shouldn't ignore bandwidth settings. 2024 // Serializing data content shouldn't ignore bandwidth settings.
2012 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n", 2025 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
2013 "b=AS:100\r\n", 2026 "b=AS:100\r\n",
2014 &expected_sdp); 2027 &expected_sdp);
2015 EXPECT_EQ(expected_sdp, message); 2028 EXPECT_EQ(expected_sdp, message);
2016 } 2029 }
2017 2030
2018 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) { 2031 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
2019 AddExtmap(); 2032 bool encrypted = false;
2033 AddExtmap(encrypted);
2020 JsepSessionDescription desc_with_extmap("dummy"); 2034 JsepSessionDescription desc_with_extmap("dummy");
2021 MakeDescriptionWithoutCandidates(&desc_with_extmap); 2035 MakeDescriptionWithoutCandidates(&desc_with_extmap);
2022 std::string message = webrtc::SdpSerialize(desc_with_extmap, false); 2036 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
2023 2037
2024 std::string sdp_with_extmap = kSdpString; 2038 std::string sdp_with_extmap = kSdpString;
2025 InjectAfter("a=mid:audio_content_name\r\n", 2039 InjectAfter("a=mid:audio_content_name\r\n",
2026 kExtmap, &sdp_with_extmap); 2040 kExtmap, &sdp_with_extmap);
2027 InjectAfter("a=mid:video_content_name\r\n", 2041 InjectAfter("a=mid:video_content_name\r\n",
2028 kExtmap, &sdp_with_extmap); 2042 kExtmap, &sdp_with_extmap);
2029 2043
2030 EXPECT_EQ(sdp_with_extmap, message); 2044 EXPECT_EQ(sdp_with_extmap, message);
2031 } 2045 }
2032 2046
2047 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2048 bool encrypted = true;
2049 AddExtmap(encrypted);
2050 JsepSessionDescription desc_with_extmap("dummy");
2051 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2052 kSessionId, kSessionVersion));
2053 TestSerialize(desc_with_extmap, false);
2054 }
2055
2033 TEST_F(WebRtcSdpTest, SerializeCandidates) { 2056 TEST_F(WebRtcSdpTest, SerializeCandidates) {
2034 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_); 2057 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
2035 EXPECT_EQ(std::string(kRawCandidate), message); 2058 EXPECT_EQ(std::string(kRawCandidate), message);
2036 2059
2037 Candidate candidate_with_ufrag(candidates_.front()); 2060 Candidate candidate_with_ufrag(candidates_.front());
2038 candidate_with_ufrag.set_username("ABC"); 2061 candidate_with_ufrag.set_username("ABC");
2039 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0, 2062 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2040 candidate_with_ufrag)); 2063 candidate_with_ufrag));
2041 message = webrtc::SdpSerializeCandidate(*jcandidate_); 2064 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2042 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message); 2065 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
2668 "b=AS:100\r\n", 2691 "b=AS:100\r\n",
2669 &sdp_with_bandwidth); 2692 &sdp_with_bandwidth);
2670 JsepSessionDescription jdesc_with_bandwidth(kDummyString); 2693 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2671 2694
2672 // SCTP has congestion control, so we shouldn't limit the bandwidth 2695 // SCTP has congestion control, so we shouldn't limit the bandwidth
2673 // as we do for RTP. 2696 // as we do for RTP.
2674 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); 2697 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2675 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth)); 2698 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2676 } 2699 }
2677 2700
2678 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) { 2701 class WebRtcSdpExtmapTest
2679 TestDeserializeExtmap(true, false); 2702 : public WebRtcSdpTest, public testing::WithParamInterface<bool> {
2703 };
2704
2705 TEST_P(WebRtcSdpExtmapTest,
2706 DeserializeSessionDescriptionWithSessionLevelExtmap) {
2707 bool encrypted = GetParam();
2708 TestDeserializeExtmap(true, false, encrypted);
2680 } 2709 }
2681 2710
2682 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) { 2711 TEST_P(WebRtcSdpExtmapTest,
2683 TestDeserializeExtmap(false, true); 2712 DeserializeSessionDescriptionWithMediaLevelExtmap) {
2713 bool encrypted = GetParam();
2714 TestDeserializeExtmap(false, true, encrypted);
2684 } 2715 }
2685 2716
2686 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) { 2717 TEST_P(WebRtcSdpExtmapTest,
2687 TestDeserializeExtmap(true, true); 2718 DeserializeSessionDescriptionWithInvalidExtmap) {
2719 bool encrypted = GetParam();
2720 TestDeserializeExtmap(true, true, encrypted);
2688 } 2721 }
2689 2722
2723 INSTANTIATE_TEST_CASE_P(Encrypted,
2724 WebRtcSdpExtmapTest,
2725 ::testing::Values(false, true));
2726
2690 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) { 2727 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2691 JsepSessionDescription jdesc(kDummyString); 2728 JsepSessionDescription jdesc(kDummyString);
2692 std::string sdp = kSdpFullString; 2729 std::string sdp = kSdpFullString;
2693 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end. 2730 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2694 // Deserialize 2731 // Deserialize
2695 SdpParseError error; 2732 SdpParseError error;
2696 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error)); 2733 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2697 const std::string lastline = "a=ssrc:3 label:video_track_id_1"; 2734 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
2698 EXPECT_EQ(lastline, error.line); 2735 EXPECT_EQ(lastline, error.line);
2699 EXPECT_EQ("Invalid SDP line.", error.description); 2736 EXPECT_EQ("Invalid SDP line.", error.description);
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
3501 EXPECT_TRUE(SdpDeserialize(message, &jdesc)); 3538 EXPECT_TRUE(SdpDeserialize(message, &jdesc));
3502 auto audio_desc = static_cast<cricket::MediaContentDescription*>( 3539 auto audio_desc = static_cast<cricket::MediaContentDescription*>(
3503 jdesc.description()->GetContentByName(kAudioContentName)->description); 3540 jdesc.description()->GetContentByName(kAudioContentName)->description);
3504 auto video_desc = static_cast<cricket::MediaContentDescription*>( 3541 auto video_desc = static_cast<cricket::MediaContentDescription*>(
3505 jdesc.description()->GetContentByName(kVideoContentName)->description); 3542 jdesc.description()->GetContentByName(kVideoContentName)->description);
3506 EXPECT_EQ(audio_desc_->connection_address().ToString(), 3543 EXPECT_EQ(audio_desc_->connection_address().ToString(),
3507 audio_desc->connection_address().ToString()); 3544 audio_desc->connection_address().ToString());
3508 EXPECT_EQ(video_desc_->connection_address().ToString(), 3545 EXPECT_EQ(video_desc_->connection_address().ToString(),
3509 video_desc->connection_address().ToString()); 3546 video_desc->connection_address().ToString());
3510 } 3547 }
OLDNEW
« no previous file with comments | « webrtc/pc/webrtcsdp.cc ('k') | webrtc/pc/webrtcsession.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698