Bug 1147919 - Part 1: Make sure content gets an error callback when it does not use a fingerprint algorithm we support. r=drno, a=sledru
authorByron Campen [:bwc] <docfaraday@gmail.com>
Mon, 06 Apr 2015 11:07:53 -0700
changeset 258286 38cb0f4d54e8
parent 258285 f7d65dc9093b
child 258287 a606f164b2a7
push id4636
push userbcampen@mozilla.com
push date2015-04-06 18:31 +0000
treeherdermozilla-beta@a606f164b2a7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdrno, sledru
bugs1147919
milestone38.0
Bug 1147919 - Part 1: Make sure content gets an error callback when it does not use a fingerprint algorithm we support. r=drno, a=sledru
media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
media/webrtc/signaling/test/jsep_session_unittest.cpp
--- a/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
+++ b/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
@@ -1922,16 +1922,24 @@ JsepSessionImpl::ParseSdp(const std::str
       return NS_ERROR_INVALID_ARG;
     }
 
     if (!mediaAttrs.HasAttribute(SdpAttribute::kFingerprintAttribute)) {
       JSEP_SET_ERROR("Invalid description, no fingerprint attribute");
       return NS_ERROR_INVALID_ARG;
     }
 
+    const SdpFingerprintAttributeList& fingerprints(
+        mediaAttrs.GetFingerprint());
+    if (fingerprints.mFingerprints.empty()) {
+      JSEP_SET_ERROR("Invalid description, no supported fingerprint algorithms "
+                     "present");
+      return NS_ERROR_INVALID_ARG;
+    }
+
     if (mediaAttrs.HasAttribute(SdpAttribute::kSetupAttribute) &&
         mediaAttrs.GetSetup().mRole == SdpSetupAttribute::kHoldconn) {
       JSEP_SET_ERROR("Description has illegal setup attribute "
                      "\"holdconn\" at level "
                      << i);
       return NS_ERROR_INVALID_ARG;
     }
 
--- a/media/webrtc/signaling/test/jsep_session_unittest.cpp
+++ b/media/webrtc/signaling/test/jsep_session_unittest.cpp
@@ -2370,16 +2370,35 @@ TEST_F(JsepSessionTest, ValidateAnswered
         fmtps[2].parameters.get());
 
   ASSERT_EQ((uint32_t)0x42a00d, parsed_h264_0_params.profile_level_id);
   ASSERT_TRUE(parsed_h264_0_params.level_asymmetry_allowed);
   ASSERT_EQ(0U, parsed_h264_0_params.packetization_mode);
 #endif
 }
 
+static void
+Replace(const std::string& toReplace,
+        const std::string& with,
+        std::string* in)
+{
+  size_t pos = in->find(toReplace);
+  ASSERT_NE(std::string::npos, pos);
+  in->replace(pos, toReplace.size(), with);
+}
+
+static void ReplaceAll(const std::string& toReplace,
+                       const std::string& with,
+                       std::string* in)
+{
+  while (in->find(toReplace) != std::string::npos) {
+    Replace(toReplace, with, in);
+  }
+}
+
 TEST_P(JsepSessionTest, TestRejectMline)
 {
   AddTracks(mSessionOff);
   AddTracks(mSessionAns);
 
   switch (types.front()) {
     case SdpMediaSection::kAudio:
       // Sabotage audio
@@ -2618,16 +2637,30 @@ TEST_F(JsepSessionTest, TestUniquePayloa
 
   ASSERT_TRUE(answerPairs[2].mReceiving);
   ASSERT_TRUE(answerPairs[2].mReceiving->GetNegotiatedDetails());
   ASSERT_NE(0U,
       answerPairs[2].mReceiving->GetNegotiatedDetails()->
       GetUniquePayloadTypes().size());
 }
 
+TEST_F(JsepSessionTest, UnknownFingerprintAlgorithm)
+{
+  types.push_back(SdpMediaSection::kAudio);
+  AddTracks(mSessionOff, "audio");
+  AddTracks(mSessionAns, "audio");
+
+  std::string offer(CreateOffer());
+  SetLocalOffer(offer);
+  ReplaceAll("fingerprint:sha", "fingerprint:foo", &offer);
+  nsresult rv = mSessionAns.SetRemoteDescription(kJsepSdpOffer, offer);
+  ASSERT_NE(NS_OK, rv);
+  ASSERT_NE("", mSessionAns.GetLastError());
+}
+
 } // namespace mozilla
 
 int
 main(int argc, char** argv)
 {
   // Prevents some log spew
   ScopedXPCOM xpcom("jsep_session_unittest");