RTCPeerConnection-addTcpIceCandidate.html (4790B)
1 <!doctype html> 2 <title>Test RTCPeerConnection.prototype.addIceCandidate with TCP candidates</title> 3 <meta name="timeout" content="long"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="RTCPeerConnection-helper.js"></script> 7 <script> 8 'use strict'; 9 10 const sdp = `v=0 11 o=- 166855176514521964 2 IN IP4 127.0.0.1 12 s=- 13 t=0 0 14 a=msid-semantic:WMS * 15 m=audio 9 UDP/TLS/RTP/SAVPF 111 16 c=IN IP4 0.0.0.0 17 a=rtcp:9 IN IP4 0.0.0.0 18 a=ice-ufrag:655Y 19 a=ice-pwd:somelongpwdwithenoughrandomness 20 a=fingerprint:sha-256 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00 21 a=setup:actpass 22 a=mid:audio1 23 a=sendonly 24 a=rtcp-mux 25 a=rtcp-rsize 26 a=rtpmap:111 opus/48000/2 27 a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level 28 a=ssrc:1001 cname:some 29 `; 30 31 // DRY: copied from fetch/api/request/request-bad-port.any.js 32 const BLOCKED_PORTS_LIST = [ 33 1, // tcpmux 34 7, // echo 35 9, // discard 36 11, // systat 37 13, // daytime 38 15, // netstat 39 17, // qotd 40 19, // chargen 41 20, // ftp-data 42 21, // ftp 43 22, // ssh 44 23, // telnet 45 25, // smtp 46 37, // time 47 42, // name 48 43, // nicname 49 53, // domain 50 69, // tftp 51 77, // priv-rjs 52 79, // finger 53 87, // ttylink 54 95, // supdup 55 101, // hostriame 56 102, // iso-tsap 57 103, // gppitnp 58 104, // acr-nema 59 109, // pop2 60 110, // pop3 61 111, // sunrpc 62 113, // auth 63 115, // sftp 64 117, // uucp-path 65 119, // nntp 66 123, // ntp 67 135, // loc-srv / epmap 68 137, // netbios-ns 69 139, // netbios-ssn 70 143, // imap2 71 161, // snmp 72 179, // bgp 73 389, // ldap 74 427, // afp (alternate) 75 465, // smtp (alternate) 76 512, // print / exec 77 513, // login 78 514, // shell 79 515, // printer 80 526, // tempo 81 530, // courier 82 531, // chat 83 532, // netnews 84 540, // uucp 85 548, // afp 86 554, // rtsp 87 556, // remotefs 88 563, // nntp+ssl 89 587, // smtp (outgoing) 90 601, // syslog-conn 91 636, // ldap+ssl 92 989, // ftps-data 93 990, // ftps 94 993, // ldap+ssl 95 995, // pop3+ssl 96 1719, // h323gatestat 97 1720, // h323hostcall 98 1723, // pptp 99 2049, // nfs 100 3659, // apple-sasl 101 4045, // lockd 102 5060, // sip 103 5061, // sips 104 6000, // x11 105 6566, // sane-port 106 6665, // irc (alternate) 107 6666, // irc (alternate) 108 6667, // irc (default) 109 6668, // irc (alternate) 110 6669, // irc (alternate) 111 6697, // irc+tls 112 10080, // amanda 113 ]; 114 115 116 function candidateForPort(port) { 117 return `a=candidate:2983561038 1 tcp 1518214911 127.0.0.1 ${port} typ host tcptype passive generation 0 ufrag 655Y network-id 1 network-cost 10`; 118 } 119 120 promise_test(async t => { 121 const pc = new RTCPeerConnection(); 122 t.add_cleanup(() => pc.close()); 123 await pc.setRemoteDescription({type: 'offer', sdp: sdp + candidateForPort(8001) + '\n'}) 124 const answer = await pc.createAnswer(); 125 await pc.setLocalDescription(answer); 126 await waitForConnectionStateChangeWithTimeout(t, pc, 127 ['failed', 'disconnected'], 1000); 128 }, 'TCP candidate aimed at port 8001 accepted'); 129 130 promise_test(async t => { 131 const pc = new RTCPeerConnection(); 132 t.add_cleanup(() => pc.close()); 133 await pc.setRemoteDescription({type: 'offer', sdp: sdp}) 134 const answer = await pc.createAnswer(); 135 await pc.setLocalDescription(answer); 136 await pc.addIceCandidate(new RTCIceCandidate({ 137 candidate: candidateForPort(8001), 138 sdpMid: 'audio1' 139 })); 140 await waitForConnectionStateChangeWithTimeout( 141 t, pc, ['failed', 'disconnected'], 1000); 142 }, 'TCP addIceCandidate aimed at port 8001 accepted'); 143 144 for (const port of BLOCKED_PORTS_LIST) { 145 promise_test(async t => { 146 const pc = new RTCPeerConnection(); 147 t.add_cleanup(() => pc.close()); 148 await pc.setRemoteDescription({type: 'offer', sdp: sdp + candidateForPort(port) + '\n'}) 149 const answer = await pc.createAnswer(); 150 151 await pc.setLocalDescription(answer); 152 pc.oniceconnectionstatechange = t.unreached_func(); 153 await new Promise(resolve => t.step_timeout(resolve, 500)); 154 }, `TCP candidate aimed at Fetch bad port ${port} ignored`); 155 } 156 157 promise_test(async t => { 158 const pc = new RTCPeerConnection(); 159 t.add_cleanup(() => pc.close()); 160 await pc.setRemoteDescription({type: 'offer', sdp: sdp}) 161 const answer = await pc.createAnswer(); 162 await pc.setLocalDescription(answer); 163 await pc.addIceCandidate(new RTCIceCandidate({ 164 candidate: candidateForPort(2049), 165 sdpMid: 'audio1' 166 })); 167 pc.oniceconnectionstatechange = t.unreached_func(); 168 await new Promise(resolve => t.step_timeout(resolve, 500)); 169 }, `TCP addIceCandidate aimed at Fetch bad port 2049 ignored`); 170 171 </script>