2323using System . Threading ;
2424using System . Threading . Tasks ;
2525using Microsoft . Extensions . Logging ;
26+ using Polyfills ;
2627using SIPSorcery . Media ;
2728using SIPSorcery . Net ;
2829using SIPSorcery . SIP . App ;
@@ -44,6 +45,36 @@ public SIPUserAgentUnitTest(Xunit.Abstractions.ITestOutputHelper output)
4445
4546 private string m_CRLF = SIPConstants . CRLF ;
4647
48+ private string CreateInviteRequestWithSdp ( ) =>
49+ """
50+ INVITE sip:192.168.11.50:5060 SIP/2.0
51+ Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3691
52+ To: <sip:2@192.168.11.50>;tag=ZUJSXRRGXQ
53+ From: <sip:aaron@192.168.11.50>;tag=4a60ce364b774258873ff199e5e39938
54+ Call-ID: 17324d6df8744d978008c8997bfd208d
55+ CSeq: 3532 INVITE
56+ Contact: <sip:aaron@192.168.11.50:60163;ob>
57+ Max-Forwards: 70
58+ User-Agent: MicroSIP/3.19.22
59+ Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
60+ Supported: replaces, 100rel, timer, norefersub
61+ Content-Length: 343
62+ Content-Type: application/sdp
63+ Session-Expires: 1800
64+ Min-SE: 90
65+
66+ v=0
67+ o=- 3785527268 3785527269 IN IP4 192.168.11.50
68+ s=pjmedia
69+ t=0 0
70+ m=audio 4032 RTP/AVP 0 101
71+ c=IN IP4 192.168.11.50
72+ a=rtpmap:0 PCMU/8000
73+ a=rtpmap:101 telephone-event/8000
74+ a=fmtp:101 0-16
75+ a=sendrecv
76+ """ . ReplaceLineEndings ( m_CRLF ) ;
77+
4778 /// <summary>
4879 /// Tests that the Blind Transfer function doesn't do anything unexpected. The transfer
4980 /// request should return false since the Accepted response never arrives.
@@ -59,7 +90,7 @@ public async Task BlindTransferUnitTest()
5990
6091 SIPUserAgent userAgent = new SIPUserAgent ( transport , null ) ;
6192
62- string inviteReqStr = $ "INVITE sip:192.168.11.50:5060 SIP/2.0{ m_CRLF } Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3691{ m_CRLF } To: <sip:2@192.168.11.50>;tag=ZUJSXRRGXQ{ m_CRLF } From: <sip:aaron@192.168.11.50>;tag=4a60ce364b774258873ff199e5e39938{ m_CRLF } Call-ID: 17324d6df8744d978008c8997bfd208d{ m_CRLF } CSeq: 3532 INVITE{ m_CRLF } Contact: <sip:aaron@192.168.11.50:60163;ob>{ m_CRLF } Max-Forwards: 70{ m_CRLF } User-Agent: MicroSIP/3.19.22{ m_CRLF } Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS{ m_CRLF } Supported: replaces, 100rel, timer, norefersub{ m_CRLF } Content-Length: 343{ m_CRLF } Content-Type: application/sdp{ m_CRLF } Session-Expires: 1800{ m_CRLF } Min-SE: 90{ m_CRLF } { m_CRLF } v=0{ m_CRLF } o=- 3785527268 3785527269 IN IP4 192.168.11.50{ m_CRLF } s=pjmedia{ m_CRLF } t=0 0{ m_CRLF } m=audio 4032 RTP/AVP 0 101{ m_CRLF } c=IN IP4 192.168.11.50{ m_CRLF } a=rtpmap:0 PCMU/8000{ m_CRLF } a=rtpmap:101 telephone-event/8000{ m_CRLF } a=fmtp:101 0-16{ m_CRLF } a=sendrecv";
93+ var inviteReqStr = CreateInviteRequestWithSdp ( ) ;
6394
6495 SIPEndPoint dummySipEndPoint = new SIPEndPoint ( new IPEndPoint ( IPAddress . Any , 0 ) ) ;
6596 SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer . ParseSIPMessage ( inviteReqStr , dummySipEndPoint , dummySipEndPoint ) ;
@@ -89,7 +120,7 @@ public async Task BlindTransferCancelUnitTest()
89120
90121 SIPUserAgent userAgent = new SIPUserAgent ( transport , null ) ;
91122
92- string inviteReqStr = $ "INVITE sip:192.168.11.50:5060 SIP/2.0{ m_CRLF } Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3691{ m_CRLF } To: <sip:2@192.168.11.50>;tag=ZUJSXRRGXQ{ m_CRLF } From: <sip:aaron@192.168.11.50>;tag=4a60ce364b774258873ff199e5e39938{ m_CRLF } Call-ID: 17324d6df8744d978008c8997bfd208d{ m_CRLF } CSeq: 3532 INVITE{ m_CRLF } Contact: <sip:aaron@192.168.11.50:60163;ob>{ m_CRLF } Max-Forwards: 70{ m_CRLF } User-Agent: MicroSIP/3.19.22{ m_CRLF } Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS{ m_CRLF } Supported: replaces, 100rel, timer, norefersub{ m_CRLF } Content-Length: 343{ m_CRLF } Content-Type: application/sdp{ m_CRLF } Session-Expires: 1800{ m_CRLF } Min-SE: 90{ m_CRLF } { m_CRLF } v=0{ m_CRLF } o=- 3785527268 3785527269 IN IP4 192.168.11.50{ m_CRLF } s=pjmedia{ m_CRLF } t=0 0{ m_CRLF } m=audio 4032 RTP/AVP 0 101{ m_CRLF } c=IN IP4 192.168.11.50{ m_CRLF } a=rtpmap:0 PCMU/8000{ m_CRLF } a=rtpmap:101 telephone-event/8000{ m_CRLF } a=fmtp:101 0-16{ m_CRLF } a=sendrecv";
123+ var inviteReqStr = CreateInviteRequestWithSdp ( ) ;
93124
94125 SIPEndPoint dummySipEndPoint = new SIPEndPoint ( new IPEndPoint ( IPAddress . Any , 0 ) ) ;
95126 SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer . ParseSIPMessage ( inviteReqStr , dummySipEndPoint , dummySipEndPoint ) ;
@@ -124,7 +155,7 @@ public async Task HangupUserAgentUnitTest()
124155
125156 SIPUserAgent userAgent = new SIPUserAgent ( transport , null ) ;
126157
127- string inviteReqStr = $ "INVITE sip:192.168.11.50:5060 SIP/2.0{ m_CRLF } Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3691{ m_CRLF } To: <sip:2@192.168.11.50>;tag=ZUJSXRRGXQ{ m_CRLF } From: <sip:aaron@192.168.11.50>;tag=4a60ce364b774258873ff199e5e39938{ m_CRLF } Call-ID: 17324d6df8744d978008c8997bfd208d{ m_CRLF } CSeq: 3532 INVITE{ m_CRLF } Contact: <sip:aaron@192.168.11.50:60163;ob>{ m_CRLF } Max-Forwards: 70{ m_CRLF } User-Agent: MicroSIP/3.19.22{ m_CRLF } Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS{ m_CRLF } Supported: replaces, 100rel, timer, norefersub{ m_CRLF } Content-Length: 343{ m_CRLF } Content-Type: application/sdp{ m_CRLF } Session-Expires: 1800{ m_CRLF } Min-SE: 90{ m_CRLF } { m_CRLF } v=0{ m_CRLF } o=- 3785527268 3785527269 IN IP4 192.168.11.50{ m_CRLF } s=pjmedia{ m_CRLF } t=0 0{ m_CRLF } m=audio 4032 RTP/AVP 0 101{ m_CRLF } c=IN IP4 192.168.11.50{ m_CRLF } a=rtpmap:0 PCMU/8000{ m_CRLF } a=rtpmap:101 telephone-event/8000{ m_CRLF } a=fmtp:101 0-16{ m_CRLF } a=sendrecv";
158+ var inviteReqStr = CreateInviteRequestWithSdp ( ) ;
128159
129160 SIPEndPoint dummySipEndPoint = new SIPEndPoint ( new IPEndPoint ( IPAddress . Loopback , 0 ) ) ;
130161 SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer . ParseSIPMessage ( inviteReqStr , dummySipEndPoint , dummySipEndPoint ) ;
@@ -135,7 +166,21 @@ public async Task HangupUserAgentUnitTest()
135166 await userAgent . Answer ( mockUas , CreateMediaSession ( ) ) ;
136167
137168 // Incremented Cseq and modified Via header from original request. Means the request is the same dialog but different tx.
138- string inviteReqStr2 = $ "BYE sip:192.168.11.50:5060 SIP/2.0{ m_CRLF } Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3700{ m_CRLF } To: <sip:2@192.168.11.50>;tag=ZUJSXRRGXQ{ m_CRLF } From: <sip:aaron@192.168.11.50>;tag=4a60ce364b774258873ff199e5e39938{ m_CRLF } Call-ID: 17324d6df8744d978008c8997bfd208d{ m_CRLF } CSeq: 3533 BYE{ m_CRLF } Contact: <sip:aaron@192.168.11.50:60163;ob>{ m_CRLF } Max-Forwards: 70{ m_CRLF } User-Agent: MicroSIP/3.19.22{ m_CRLF } Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS{ m_CRLF } Supported: replaces, 100rel, timer, norefersub{ m_CRLF } ";
169+ var inviteReqStr2 =
170+ """
171+ BYE sip:192.168.11.50:5060 SIP/2.0
172+ Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3700
173+ To: <sip:2@192.168.11.50>;tag=ZUJSXRRGXQ
174+ From: <sip:aaron@192.168.11.50>;tag=4a60ce364b774258873ff199e5e39938
175+ Call-ID: 17324d6df8744d978008c8997bfd208d
176+ CSeq: 3533 BYE
177+ Contact: <sip:aaron@192.168.11.50:60163;ob>
178+ Max-Forwards: 70
179+ User-Agent: MicroSIP/3.19.22
180+ Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
181+ Supported: replaces, 100rel, timer, norefersub
182+
183+ """ . ReplaceLineEndings ( m_CRLF ) ;
139184
140185 mockChannel . FireMessageReceived ( dummySipEndPoint , dummySipEndPoint , Encoding . UTF8 . GetBytes ( inviteReqStr2 ) ) ;
141186 }
@@ -154,7 +199,24 @@ public async Task IncomingCallNoSdpUnitTest()
154199
155200 SIPUserAgent userAgent = new SIPUserAgent ( transport , null ) ;
156201
157- string inviteReqStr = $ "INVITE sip:192.168.11.50:5060 SIP/2.0{ m_CRLF } Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3691{ m_CRLF } To: <sip:2@192.168.11.50>;tag=ZUJSXRRGXQ{ m_CRLF } From: <sip:aaron@192.168.11.50>;tag=4a60ce364b774258873ff199e5e39938{ m_CRLF } Call-ID: 17324d6df8744d978008c8997bfd208d{ m_CRLF } CSeq: 3532 INVITE{ m_CRLF } Contact: <sip:aaron@192.168.11.50:60163;ob>{ m_CRLF } Max-Forwards: 70{ m_CRLF } Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS{ m_CRLF } Supported: replaces, 100rel, timer, norefersub{ m_CRLF } Content-Length: 0{ m_CRLF } Content-Type: application/sdp{ m_CRLF } Session-Expires: 1800{ m_CRLF } { m_CRLF } ";
202+ var inviteReqStr =
203+ """
204+ INVITE sip:192.168.11.50:5060 SIP/2.0
205+ Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3691
206+ To: <sip:2@192.168.11.50>;tag=ZUJSXRRGXQ
207+ From: <sip:aaron@192.168.11.50>;tag=4a60ce364b774258873ff199e5e39938
208+ Call-ID: 17324d6df8744d978008c8997bfd208d
209+ CSeq: 3532 INVITE
210+ Contact: <sip:aaron@192.168.11.50:60163;ob>
211+ Max-Forwards: 70
212+ Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
213+ Supported: replaces, 100rel, timer, norefersub
214+ Content-Length: 0
215+ Content-Type: application/sdp
216+ Session-Expires: 1800
217+
218+
219+ """ . ReplaceLineEndings ( m_CRLF ) ;
158220
159221 SIPEndPoint dummySipEndPoint = new SIPEndPoint ( new IPEndPoint ( IPAddress . Loopback , 0 ) ) ;
160222 SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer . ParseSIPMessage ( inviteReqStr , dummySipEndPoint , dummySipEndPoint ) ;
@@ -183,7 +245,22 @@ public async Task IncomingCallNoSdpWithACKUnitTest()
183245
184246 SIPUserAgent userAgent = new SIPUserAgent ( transport , null ) ;
185247
186- string inviteReqStr = $ "INVITE sip:1@127.0.0.1 SIP/2.0\r \n Via: SIP/2.0/UDP 127.0.0.1:51200;branch=z9hG4bKbeed9b0cde8d43cc8a2aae91526b6a1d;rport\r \n To: <sip:1@127.0.0.1>\r \n From: <sip:thisis@anonymous.invalid>;tag=GCLNRILCDU\r \n Call-ID: 7265e19f53a146a1bacdf4f4f8ea70b2\r \n CSeq: 1 INVITE\r \n Contact: <sip:127.0.0.1:51200>\r \n Max-Forwards: 70\r \n User-Agent: www.sipsorcery.com\r \n Content-Length: 0\r \n Content-Type: application/sdp{ m_CRLF } { m_CRLF } ";
248+ var inviteReqStr =
249+ """
250+ INVITE sip:1@127.0.0.1 SIP/2.0
251+ Via: SIP/2.0/UDP 127.0.0.1:51200;branch=z9hG4bKbeed9b0cde8d43cc8a2aae91526b6a1d;rport
252+ To: <sip:1@127.0.0.1>
253+ From: <sip:thisis@anonymous.invalid>;tag=GCLNRILCDU
254+ Call-ID: 7265e19f53a146a1bacdf4f4f8ea70b2
255+ CSeq: 1 INVITE
256+ Contact: <sip:127.0.0.1:51200>
257+ Max-Forwards: 70
258+ User-Agent: www.sipsorcery.com
259+ Content-Length: 0
260+ Content-Type: application/sdp
261+
262+
263+ """ . ReplaceLineEndings ( m_CRLF ) ;
187264
188265 SIPEndPoint dummySipEndPoint = new SIPEndPoint ( new IPEndPoint ( IPAddress . Loopback , 0 ) ) ;
189266 SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer . ParseSIPMessage ( inviteReqStr , dummySipEndPoint , dummySipEndPoint ) ;
@@ -196,7 +273,29 @@ public async Task IncomingCallNoSdpWithACKUnitTest()
196273 {
197274 await Task . Delay ( 2000 ) ;
198275
199- string ackReqStr = $ "ACK sip:127.0.0.1:5060 SIP/2.0\r \n Via: SIP/2.0/UDP 127.0.0.1:51200;branch=z9hG4bK76dfb1480ea14f778bd24afed1c8ded0;rport\r \n To: <sip:1@127.0.0.1>;tag=YWPNZPMLPB\r \n From: <sip:thisis@anonymous.invalid>;tag=GCLNRILCDU\r \n Call-ID: 7265e19f53a146a1bacdf4f4f8ea70b2\r \n CSeq: 1 ACK\r \n Max-Forwards: 70\r \n Content-Length: 160\r \n \r \n v=0\r \n o=- 67424 0 IN IP4 127.0.0.1\r \n s=-\r \n c=IN IP4 127.0.0.1\r \n t=0 0\r \n m=audio 16976 RTP/AVP 8 101\r \n a=rtpmap:101 telephone-event/8000\r \n a=fmtp:101 0-16\r \n a=sendrecv{ m_CRLF } { m_CRLF } ";
276+ var ackReqStr =
277+ """
278+ ACK sip:127.0.0.1:5060 SIP/2.0
279+ Via: SIP/2.0/UDP 127.0.0.1:51200;branch=z9hG4bK76dfb1480ea14f778bd24afed1c8ded0;rport
280+ To: <sip:1@127.0.0.1>;tag=YWPNZPMLPB
281+ From: <sip:thisis@anonymous.invalid>;tag=GCLNRILCDU
282+ Call-ID: 7265e19f53a146a1bacdf4f4f8ea70b2
283+ CSeq: 1 ACK
284+ Max-Forwards: 70
285+ Content-Length: 160
286+
287+ v=0
288+ o=- 67424 0 IN IP4 127.0.0.1
289+ s=-
290+ c=IN IP4 127.0.0.1
291+ t=0 0
292+ m=audio 16976 RTP/AVP 8 101
293+ a=rtpmap:101 telephone-event/8000
294+ a=fmtp:101 0-16
295+ a=sendrecv
296+
297+
298+ """ . ReplaceLineEndings ( m_CRLF ) ;
200299
201300 uas . ClientTransaction . ACKReceived ( dummySep , dummySep , SIPRequest . ParseSIPRequest ( ackReqStr ) ) ;
202301 } ) ;
0 commit comments