summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webrtc/legacy/munge-dont.html
blob: b5f0a4cb63ba728d76cdae6c6deeb724dc09f5ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!doctype html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>SDP munging is a bad idea</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';

const sdp = `v=0
o=- 0 3 IN IP4 127.0.0.1
s=-
t=0 0
m=video 9 UDP/TLS/RTP/SAVPF 100
c=IN IP4 0.0.0.0
a=rtcp-mux
a=sendonly
a=mid:video
a=rtpmap:100 VP8/90000
a=fmtp:100 max-fr=30;max-fs=3600
a=fingerprint:sha-256 A7:24:72:CA:6E:02:55:39:BA:66:DF:6E:CC:4C:D8:B0:1A:BF:1A:56:65:7D:F4:03:AD:7E:77:43:2A:29:EC:93
a=ice-ufrag:ETEn
a=ice-pwd:OtSK0WpNtpUjkY4+86js7Z/l
`;
const candidateString = 'candidate:1905690388 1 udp 2113937151 192.168.0.1 58041 typ host generation 0 ufrag thC8';

// See https://bugs.chromium.org/p/chromium/issues/detail?id=662898
// and https://bugs.chromium.org/p/chromium/issues/detail?id=823036
// for why neither of these is feasible to enforce.

// Note that this does not restrict creating a
// new RTCSessionDescription with a modified copy.
test(() => {
  const desc = new RTCSessionDescription({
    type: 'offer',
    sdp,
  });
  assert_throws_js(TypeError, () => {
    desc.type = 'answer';
  });
}, 'RTCSessionDescription.type is read-only');

test(() => {
  const desc = new RTCSessionDescription({
    type: 'offer',
    sdp,
  });
  assert_throws_js(TypeError, () => {
    desc.sdp += 'a=dont-modify-me\r\n';
  });
}, 'RTCSessionDescription.sdp is read-only');

test(() => {
  const candidate = new RTCIceCandidate({
    sdpMid: '0',
    candidate: candidateString,
  });
  assert_throws_js(TypeError, () => {
    candidate.candidate += ' myattribute value';
  });
}, 'RTCIceCandidate.candidate is read-only');

// https://w3c.github.io/webrtc-pc/#dom-peerconnection-setlocaldescription
// If type is "offer", and sdp is not the empty string and not equal to
// connection.[[LastCreatedOffer]], then return a promise rejected with a
// newly created InvalidModificationError and abort these steps.
promise_test(async t => {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());
  pc.addTransceiver('audio');
  const offer = await pc.createOffer();
  return promise_rejects_dom(t, 'InvalidModificationError',
      pc.setLocalDescription({type: 'offer', sdp: offer.sdp + 'a=munging-is-not-good\r\n'}));
}, 'Rejects SDP munging between createOffer and setLocalDescription');

// If type is "answer" or "pranswer", and sdp is not the empty string and not equal to
// connection.[[LastCreatedAnswer]], then return a promise rejected with a
// newly created InvalidModificationError and abort these steps.
promise_test(async t => {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());
  await pc.setRemoteDescription({type: 'offer', sdp});

  const answer = await pc.createAnswer();
  return promise_rejects_dom(t, 'InvalidModificationError',
      pc.setLocalDescription({type: 'answer', sdp: answer.sdp + 'a=munging-is-not-good\r\n'}));
}, 'Rejects SDP munging between createAnswer and setLocalDescription');
</script>