PageRenderTime 60ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/sipsorcery-core/Tests/SIPSorcery.SIP.Core.UnitTests/SIPRequestUnitTest.cs

https://github.com/thecc4re/sipsorcery-mono
C# | 1025 lines | 824 code | 163 blank | 38 comment | 69 complexity | 757d96cb099290567836fe9d69b754ea MD5 | raw file
Possible License(s): CC-BY-SA-3.0

Large files files are truncated, but you can click here to view the full file

  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.Net;
  5. using System.Linq;
  6. using Microsoft.VisualStudio.TestTools.UnitTesting;
  7. using SIPSorcery.SIP;
  8. using SIPSorcery.Sys;
  9. namespace SIPSorcery.SIP.Core.UnitTests
  10. {
  11. [TestClass]
  12. public class SIPRequestUnitTest
  13. {
  14. private static string m_CRLF = SIPConstants.CRLF;
  15. private class MockSIPChannel : SIPChannel
  16. {
  17. public MockSIPChannel(IPEndPoint channelEndPoint)
  18. {
  19. m_localSIPEndPoint = new SIPEndPoint(SIPProtocolsEnum.udp, channelEndPoint);
  20. }
  21. public override void Send(IPEndPoint destinationEndPoint, string message)
  22. { }
  23. public override void Send(IPEndPoint destinationEndPoint, byte[] buffer)
  24. { }
  25. public override void Close()
  26. { }
  27. protected override Dictionary<string, SIPConnection> GetConnectionsList()
  28. {
  29. throw new NotImplementedException();
  30. }
  31. public override bool IsConnectionEstablished(IPEndPoint remoteEndPoint)
  32. {
  33. throw new NotImplementedException();
  34. }
  35. public override void Send(IPEndPoint dstEndPoint, byte[] buffer, string serverCN)
  36. {
  37. throw new ApplicationException("This Send method is not available in the MockSIPChannel, please use an alternative overload.");
  38. }
  39. }
  40. private class MockSIPDNSManager
  41. {
  42. public static SIPDNSLookupResult Resolve(SIPURI sipURI, bool synchronous)
  43. {
  44. // This assumes the input SIP URI has an IP address as the host!
  45. return new SIPDNSLookupResult(sipURI);
  46. }
  47. }
  48. private List<LocalSIPSocket> m_sipSockets = new List<LocalSIPSocket>();
  49. private struct LocalSIPSocket
  50. {
  51. public string Socket;
  52. public SIPProtocolsEnum Protocol;
  53. public LocalSIPSocket(string socket, SIPProtocolsEnum protocol)
  54. {
  55. Socket = socket;
  56. Protocol = protocol;
  57. }
  58. }
  59. public SIPRequestUnitTest()
  60. { }
  61. private TestContext testContextInstance;
  62. public TestContext TestContext
  63. {
  64. get
  65. {
  66. return testContextInstance;
  67. }
  68. set
  69. {
  70. testContextInstance = value;
  71. }
  72. }
  73. private bool IsLocalSIPSocket(string socket, SIPProtocolsEnum protocol)
  74. {
  75. foreach (LocalSIPSocket sipSocket in m_sipSockets)
  76. {
  77. if (sipSocket.Socket == socket && sipSocket.Protocol == protocol)
  78. {
  79. return true;
  80. }
  81. }
  82. return false;
  83. }
  84. [TestMethod]
  85. public void SampleTest()
  86. {
  87. Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);
  88. Assert.IsTrue(true, "True was false.");
  89. }
  90. [TestMethod]
  91. public void ParseXtenINVITEUnitTest()
  92. {
  93. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  94. string sipMsg =
  95. "INVITE sip:303@sip.blueface.ie SIP/2.0" + m_CRLF +
  96. "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
  97. "From: SER Test X <sip:aaronxten@sip.blueface.ie:5065>;tag=196468136" + m_CRLF +
  98. "To: <sip:303@sip.blueface.ie>" + m_CRLF +
  99. "Contact: <sip:aaronxten@192.168.1.2:5065>" + m_CRLF +
  100. "Call-ID: A3DF9A04-0EFE-47E4-98B1-E18AA186F3D6@192.168.1.2" + m_CRLF +
  101. "CSeq: 49429 INVITE" + m_CRLF +
  102. "Max-Forwards: 70" + m_CRLF +
  103. "Content-Type: application/sdp" + m_CRLF +
  104. "User-Agent: X-PRO release 1103v" + m_CRLF +
  105. "Content-Length: 271" + m_CRLF +
  106. m_CRLF +
  107. "v=0" + m_CRLF +
  108. "o=aaronxten 423137371 423137414 IN IP4 192.168.1.2" + m_CRLF +
  109. "s=X-PRO" + m_CRLF +
  110. "c=IN IP4 192.168.1.2" + m_CRLF +
  111. "t=0 0" + m_CRLF +
  112. "m=audio 8004 RTP/AVP 0 8 3 97 101" + m_CRLF +
  113. "a=rtpmap:0 pcmu/8000" + m_CRLF +
  114. "a=rtpmap:8 pcma/8000" + m_CRLF +
  115. "a=rtpmap:3 gsm/8000" + m_CRLF +
  116. "a=rtpmap:97 speex/8000" + m_CRLF +
  117. "a=rtpmap:101 telephone-event/8000" + m_CRLF +
  118. "a=fmtp:101 0-15" + m_CRLF;
  119. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  120. SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessage);
  121. if (inviteReq.Body != null)
  122. {
  123. Console.WriteLine("Body Length = " + inviteReq.Body.Length + ".");
  124. }
  125. Console.WriteLine("Body:\r\n" + inviteReq.Body + ".");
  126. Assert.IsTrue(inviteReq.Method == SIPMethodsEnum.INVITE, "The SIP request method was not parsed correctly.");
  127. Assert.IsTrue(inviteReq.SIPMajorVersion == 2, "The SIP Major version was not parsed correctly.");
  128. Assert.IsTrue(inviteReq.SIPMinorVersion == 0, "The SIP Minor version was not parsed correctly.");
  129. Assert.IsTrue(inviteReq.URI.User == "303", "The SIP request URI Name was not parsed correctly.");
  130. Assert.IsTrue(inviteReq.URI.Host == "sip.blueface.ie", "The SIP request URI Host was not parsed correctly.");
  131. Assert.IsTrue(inviteReq.Body != null && inviteReq.Body.Length == 271, "The SIP content body was not parsed correctly.");
  132. Console.WriteLine("-----------------------------------------");
  133. }
  134. [TestMethod]
  135. [ExpectedException(typeof(SIPValidationException))]
  136. public void MalformedContactHeaderUnitTest()
  137. {
  138. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  139. string sipMsg =
  140. "REGISTER sip:sip.sipsorcery.com SIP/2.0" + m_CRLF +
  141. "CSeq: 1142 REGISTER" + m_CRLF +
  142. "Via: SIP/2.0/UDP 24.183.120.253:5060;branch=z9hG4bKeab06dc6-4b03-1910-9cbd-0ceee68cfdc5;rport" + m_CRLF +
  143. "User-Agent: Ekiga/3.2.7" + m_CRLF +
  144. "Authorization: Digest username='twolmsted', realm='sipsorcery.com', nonce='14116380271465720944', uri='sip:sip.sipsorcery.com', algorithm=MD5, response='e9e190a05c482e0c287829ecf6d42207'" + m_CRLF +
  145. "From: <sip:twolmsted@sip.sipsorcery.com>;tag=0021d3c4-4a03-1910-9c86-0ceee68cfdc5" + m_CRLF +
  146. "Call-ID: 0021d3c4-4a03-1910-9c84-0ceee68cfdc5@two-PC" + m_CRLF +
  147. "To: <sip:twolmsted@sip.sipsorcery.com>" + m_CRLF +
  148. "Contact: <sip:twolmsted@24.183.120.253, sip:5060>" + m_CRLF +
  149. "Allow: INVITE,ACK,OPTIONS,BYE,CANCEL,SUBSCRIBE,NOTIFY,REFER,MESSAGE,INFO,PING" + m_CRLF +
  150. "Expires: 3600" + m_CRLF +
  151. "Content-Length: 0" + m_CRLF +
  152. "Max-Forwards: 70" + m_CRLF + m_CRLF;
  153. SIPRequest sipRequest = SIPRequest.ParseSIPRequest(sipMsg);
  154. }
  155. [TestMethod]
  156. public void ParseAsteriskACKUnitTest()
  157. {
  158. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  159. string sipMsg =
  160. "ACK sip:303@213.168.225.133 SIP/2.0" + m_CRLF +
  161. "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bK3667AD800F014BD685C2E0A8B2AB9D0F" + m_CRLF +
  162. "From: bluesipd <sip:bluesipd@bluesipd:5065>;tag=396492091" + m_CRLF +
  163. "To: <sip:303@bluesipd>;tag=as022cbb0e" + m_CRLF +
  164. "Contact: <sip:bluesipd@192.168.1.2:5065>" + m_CRLF +
  165. "Route: <sip:213.168.225.135;lr>" + m_CRLF +
  166. "Call-ID: EDA17D42-034E-438B-8467-18DF1E4678A7@192.168.1.2" + m_CRLF +
  167. "CSeq: 39639 ACK" + m_CRLF +
  168. "Max-Forwards: 70" + m_CRLF +
  169. "Content-Length: 0" + m_CRLF + m_CRLF;
  170. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  171. SIPRequest ackReq = SIPRequest.ParseSIPRequest(sipMessage);
  172. Assert.IsTrue(ackReq.Method == SIPMethodsEnum.ACK, "The SIP request method was not parsed correctly.");
  173. Assert.IsTrue(ackReq.SIPMajorVersion == 2, "The SIP Major version was not parsed correctly.");
  174. Assert.IsTrue(ackReq.SIPMinorVersion == 0, "The SIP Minor version was not parsed correctly.");
  175. Assert.IsTrue(ackReq.URI.User == "303", "The SIP request URI was not parsed correctly.");
  176. Assert.IsTrue(ackReq.URI.Host == "213.168.225.133", "The SIP request URI Host was not parsed correctly.");
  177. Console.WriteLine("-----------------------------------------");
  178. }
  179. [TestMethod]
  180. public void ParseCiscoACKUnitTest()
  181. {
  182. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  183. string sipMsg =
  184. "ACK sip:303@213.168.225.133:5061 SIP/2.0" + m_CRLF +
  185. "Via: SIP/2.0/UDP 89.100.92.186:5060;branch=z9hG4bK1254dba9" + m_CRLF +
  186. "From: dev <sip:aaron@azaclauson.dyndns.org>" + m_CRLF +
  187. "To: <sip:303@azaclauson.dyndns.org>;tag=as108bd3ae" + m_CRLF +
  188. "Call-ID: 0013c339-acec0041-61c7c61e-3eb0b7c0@89.100.92.186" + m_CRLF +
  189. "Max-Forwards: 70" + m_CRLF +
  190. "Date: Mon, 07 Aug 2006 14:57:40 GMT" + m_CRLF +
  191. "CSeq: 102 ACK" + m_CRLF +
  192. "User-Agent: Cisco-CP7960G/8.0" + m_CRLF +
  193. "Route: <sip:89.100.92.186:6060;lr>" + m_CRLF +
  194. "Proxy-Authorization: Digest username=\"aaron\",realm=\"sip.blueface.ie\",uri=\"sip:303@azaclauson.dyndns.org\",response=\"638c8fb6186fe865e80f6232cc417c3f\",nonce=\"44f121a2\",algorithm=md5" + m_CRLF +
  195. "Remote-Party-ID: \"dev\" <sip:aaron@89.100.92.186>;party=calling;id-type=subscriber;privacy=off;screen=yes" + m_CRLF +
  196. "Content-Length: 0" + m_CRLF + m_CRLF;
  197. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  198. SIPRequest ackReq = SIPRequest.ParseSIPRequest(sipMessage);
  199. Assert.IsTrue(ackReq.Method == SIPMethodsEnum.ACK, "The SIP request method was not parsed correctly.");
  200. Assert.IsTrue(ackReq.SIPMajorVersion == 2, "The SIP Major version was not parsed correctly.");
  201. Assert.IsTrue(ackReq.SIPMinorVersion == 0, "The SIP Minor version was not parsed correctly.");
  202. Assert.IsTrue(ackReq.URI.User == "303", "The SIP request URI was not parsed correctly.");
  203. Assert.IsTrue(ackReq.URI.Host == "213.168.225.133:5061", "The SIP request URI Host was not parsed correctly.");
  204. Console.WriteLine("-----------------------------------------");
  205. }
  206. [TestMethod]
  207. public void ParseXtenByeUnitTest()
  208. {
  209. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  210. string sipMsg =
  211. "BYE sip:303@213.168.225.133 SIP/2.0" + m_CRLF +
  212. "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bK7F023DE3FF8941008DE7DCE71A20CB78" + m_CRLF +
  213. "From: bluesipd <sip:bluesipd@bluesipd:5065>;tag=396492091" + m_CRLF +
  214. "To: <sip:303@bluesipd>;tag=as022cbb0e" + m_CRLF +
  215. "Contact: <sip:bluesipd@192.168.1.2:5065>" + m_CRLF +
  216. "Route: <sip:213.168.225.135;lr>" + m_CRLF +
  217. "Call-ID: EDA17D42-034E-438B-8467-18DF1E4678A7@192.168.1.2" + m_CRLF +
  218. "CSeq: 39640 BYE" + m_CRLF +
  219. "Max-Forwards: 70" + m_CRLF +
  220. "User-Agent: X-PRO release 1103v" + m_CRLF +
  221. "Content-Length: 0" + m_CRLF + m_CRLF;
  222. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  223. SIPRequest byeReq = SIPRequest.ParseSIPRequest(sipMessage);
  224. Assert.IsTrue(byeReq.Method == SIPMethodsEnum.BYE, "The SIP request method was not parsed correctly.");
  225. Assert.IsTrue(byeReq.SIPMajorVersion == 2, "The SIP Major version was not parsed correctly.");
  226. Assert.IsTrue(byeReq.SIPMinorVersion == 0, "The SIP Minor version was not parsed correctly.");
  227. Assert.IsTrue(byeReq.URI.User == "303", "The SIP request URI name was not parsed correctly.");
  228. Console.WriteLine("-----------------------------------------");
  229. }
  230. [TestMethod]
  231. public void ParseAsteriskBYEUnitTest()
  232. {
  233. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  234. string sipMsg =
  235. "BYE sip:bluesipd@192.168.1.2:5065 SIP/2.0" + m_CRLF +
  236. "Via: SIP/2.0/UDP 213.168.225.133:5060;branch=z9hG4bK74ab714b;rport" + m_CRLF +
  237. "Route: <sip:bluesipd@192.168.1.2:5065>" + m_CRLF +
  238. "From: <sip:303@bluesipd>;tag=as6a65fae3" + m_CRLF +
  239. "To: bluesipd <sip:bluesipd@bluesipd:5065>;tag=1898247079" + m_CRLF +
  240. "Contact: <sip:303@213.168.225.133>" + m_CRLF +
  241. "Call-ID: 80B34165-8C89-4623-B862-40AFB1884071@192.168.1.2" + m_CRLF +
  242. "CSeq: 102 BYE" + m_CRLF +
  243. "User-Agent: asterisk" + m_CRLF +
  244. "Content-Length: 0" + m_CRLF + m_CRLF;
  245. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  246. SIPRequest byeReq = SIPRequest.ParseSIPRequest(sipMessage);
  247. Assert.IsTrue(byeReq.Method == SIPMethodsEnum.BYE, "The SIP request method was not parsed correctly.");
  248. Assert.IsTrue(byeReq.SIPMajorVersion == 2, "The SIP Major version was not parsed correctly.");
  249. Assert.IsTrue(byeReq.SIPMinorVersion == 0, "The SIP Minor version was not parsed correctly.");
  250. Assert.IsTrue(byeReq.URI.User == "bluesipd", "The SIP request URI Name was not parsed correctly.");
  251. Assert.IsTrue(byeReq.URI.Host == "192.168.1.2:5065", "The SIP request URI Host was not parsed correctly.");
  252. Console.WriteLine("-----------------------------------------");
  253. }
  254. [TestMethod]
  255. public void TopRouteUnitTest()
  256. {
  257. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  258. string sipMsg =
  259. "BYE sip:bluesipd@192.168.1.2:5065 SIP/2.0" + m_CRLF +
  260. "Via: SIP/2.0/UDP 213.168.225.133:5060;branch=z9hG4bK483ca249;rport" + m_CRLF +
  261. "Route: <sip:220.240.255.198:64300;lr>,<sip:bluesipd@192.168.1.2:5065>" + m_CRLF +
  262. "From: <sip:303@bluesipd>;tag=as7a10c774" + m_CRLF +
  263. "To: bluesipd <sip:bluesipd@bluesipd:5065>;tag=2561975990" + m_CRLF +
  264. "Contact: <sip:303@213.168.225.133>" + m_CRLF +
  265. "Call-ID: D9D08936-5455-476C-A5A2-A069D4B8DBFF@192.168.1.2" + m_CRLF +
  266. "CSeq: 102 BYE" + m_CRLF +
  267. "User-Agent: asterisk" + m_CRLF +
  268. "Content-Length: 0" + m_CRLF + m_CRLF;
  269. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  270. SIPRequest byeReq = SIPRequest.ParseSIPRequest(sipMessage);
  271. SIPRoute topRoute = byeReq.Header.Routes.PopRoute();
  272. Assert.IsTrue(topRoute.Host == "220.240.255.198:64300", "The top route was not parsed correctly, top route IP address was " + topRoute.Host + ".");
  273. Console.WriteLine("-----------------------------------------");
  274. }
  275. [TestMethod]
  276. public void SubscribeRequestUnitTest()
  277. {
  278. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  279. string sipMsg =
  280. "SUBSCRIBE sip:0123456@127.0.0.1 SIP/2.0" + m_CRLF +
  281. "Via: SIP/2.0/UDP 192.168.1.10:15796" + m_CRLF +
  282. "Max-Forwards: 70" + m_CRLF +
  283. "From: \"user@sip.domain.com\" <sip:user@sipdomain.com>;tag=a6cf9fe4cdee4e1cad88240403b95669;epid=1bb41c1f89" + m_CRLF +
  284. "To: <sip:0123456@sip.blueface.ie>;tag=as211b359e" + m_CRLF +
  285. "Call-ID: abebae2060d747c3ba11a0d0cde9ab0b" + m_CRLF +
  286. "CSeq: 81 SUBSCRIBE" + m_CRLF +
  287. "Contact: <sip:192.168.1.10:15796>" + m_CRLF +
  288. "User-Agent: RTC/1.3" + m_CRLF +
  289. "Event: presence" + m_CRLF +
  290. "Accept: application/xpidf+xml, text/xml+msrtc.pidf, application/pidf+xml" + m_CRLF +
  291. "Supported: com.microsoft.autoextend" + m_CRLF +
  292. "Supported: ms-benotify" + m_CRLF +
  293. "Proxy-Require: ms-benotify" + m_CRLF +
  294. "Content-Length: 0" + m_CRLF + m_CRLF;
  295. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  296. SIPRequest subscribeReq = SIPRequest.ParseSIPRequest(sipMessage);
  297. Console.WriteLine(subscribeReq.ToString());
  298. Console.WriteLine("-----------------------------------------");
  299. }
  300. [TestMethod]
  301. public void SpaceInNamesRequestUnitTest()
  302. {
  303. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  304. string sipMsg =
  305. "REGISTER sip:Blue Face SIP/2.0" + m_CRLF +
  306. "Via: SIP/2.0/UDP 127.0.0.1:1720;branch=z9hG4bKlgnUQcaywCOaPcXR" + m_CRLF +
  307. "Max-Forwards: 70" + m_CRLF +
  308. "User-Agent: PA168S" + m_CRLF +
  309. "From: \"user\" <sip:user@Blue Face>;tag=81swjAV7dHG1yjd5" + m_CRLF +
  310. "To: \"user\" <sip:user@Blue Face>" + m_CRLF +
  311. "Call-ID: DHZVs1HFuMoTQ6LO@82.114.95.1" + m_CRLF +
  312. "CSeq: 15754 REGISTER" + m_CRLF +
  313. "Contact: <sip:user@127.0.0.1:1720>" + m_CRLF +
  314. "Expires: 30" + m_CRLF +
  315. "Content-Length: 0" + m_CRLF + m_CRLF;
  316. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  317. SIPRequest registerReq = SIPRequest.ParseSIPRequest(sipMessage);
  318. Console.WriteLine(registerReq.ToString());
  319. Console.WriteLine("-----------------------------------------");
  320. }
  321. /// <summary>
  322. /// Error on this request is a non-numeric port on the Via header.
  323. /// </summary>
  324. [TestMethod]
  325. [ExpectedException(typeof(SIPValidationException))]
  326. public void DodgyAastraRequestUnitTest()
  327. {
  328. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  329. string sipMsg =
  330. "REGISTER sip:sip.blueface.ie SIP/2.0" + m_CRLF +
  331. "Via: SIP/2.0/UDP 83.70.206.42:5060port;branch=z9hG4bK77c61058c08e3a6737e4c76e6241cc3f" + m_CRLF +
  332. "To: <sip:100001@sip.blueface.ie:5060>" + m_CRLF +
  333. "From: <sip:100001@sip.blueface.ie:5060>;tag=AI5A09C508-2F0401CDFF625DD3" + m_CRLF +
  334. "Call-ID: AI5A09C4D6-3122395B17A0C101@192.168.14.250" + m_CRLF +
  335. "CSeq: 25015 REGISTER" + m_CRLF +
  336. "Max-Forwards: 70" + m_CRLF +
  337. "Expires: 3000" + m_CRLF +
  338. "Contact: <sip:100001@83.70.206.42:5060\n" +
  339. "Allow: ACK,BYE,CANCEL,INVITE,NOTIFY,OPTIONS,REFER" + m_CRLF +
  340. "User-Agent: Aastra Intelligate" + m_CRLF +
  341. "Content-Length: 0" + m_CRLF + m_CRLF;
  342. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  343. SIPRequest registerReq = SIPRequest.ParseSIPRequest(sipMessage);
  344. Console.WriteLine("-----------------------------------------");
  345. }
  346. [TestMethod]
  347. public void NetgearInviteRequestUnitTest()
  348. {
  349. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  350. string sipMsg =
  351. "INVITE sip:12345@sip.domain.com:5060;TCID-0 SIP/2.0" + m_CRLF +
  352. "From: UNAVAILABLE<sip:user@sip.domain.com:5060>;tag=c0a83dfe-13c4-26bf01-975a21d0-2d8a" + m_CRLF +
  353. "To: <sip:1234@sipdomain.com:5060>" + m_CRLF +
  354. "Call-ID: 94b6e3f8-c0a83dfe-13c4-26bf01-975a21ce-52c@sip.domain.com" + m_CRLF +
  355. "CSeq: 1 INVITE" + m_CRLF +
  356. "Via: SIP/2.0/UDP 86.9.84.23:5060;branch=z9hG4bK-26bf01-975a21d0-1ffb" + m_CRLF +
  357. "Max-Forwards: 70" + m_CRLF +
  358. "User-Agent: TA612V-V1.2_54" + m_CRLF +
  359. "Supported: timer,replaces" + m_CRLF +
  360. "Contact: <sip:user@88.8.88.88:5060>" + m_CRLF +
  361. "Content-Type: application/SDP" + m_CRLF +
  362. "Content-Length: 386" + m_CRLF +
  363. m_CRLF +
  364. "v=0" + m_CRLF +
  365. "o=b0000 613 888 IN IP4 88.8.88.88" + m_CRLF +
  366. "s=SIP Call" + m_CRLF +
  367. "c=IN IP4 88.8.88.88" + m_CRLF +
  368. "t=0 0" + m_CRLF +
  369. "m=audio 10000 RTP/AVP 0 101 18 100 101 2 103 8" + m_CRLF +
  370. "a=fmtp:101 0-15" + m_CRLF +
  371. "a=fmtp:18 annexb=no" + m_CRLF +
  372. "a=sendrecv" + m_CRLF +
  373. "a=rtpmap:0 PCMU/8000" + m_CRLF +
  374. "a=rtpmap:101 telephone-event/8000" + m_CRLF +
  375. "a=rtpmap:18 G729/8000" + m_CRLF +
  376. "a=rtpmap:100 G726-16/8000" + m_CRLF +
  377. "a=rtpmap:101 G726-24/8000" + m_CRLF +
  378. "a=rtpmap:2 G726-32/8000" + m_CRLF +
  379. "a=rtpmap:103 G726-40/8000" + m_CRLF +
  380. "a=rtpmap:8 PCMA/8000";
  381. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  382. SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessage);
  383. Console.WriteLine(inviteReq.ToString());
  384. Console.WriteLine("-----------------------------------------");
  385. }
  386. [TestMethod]
  387. public void RTCRegisterRequestUnitTest()
  388. {
  389. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  390. string sipMsg =
  391. "REGISTER sip:sip.blueface.ie SIP/2.0" + m_CRLF +
  392. "Via: SIP/2.0/UDP 192.168.1.10:15796" + m_CRLF +
  393. "Max-Forwards: 70" + m_CRLF +
  394. "From: <sip:user@sip.blueface.ie>;tag=1a52c38c46e3439c8b4fe8a58f5ae834;epid=1bb41c1f89" + m_CRLF +
  395. "To: <sip:user@sip.blueface.ie>" + m_CRLF +
  396. "Call-ID: aeb2c6c905a84610a54de60bb6ef476c" + m_CRLF +
  397. "CSeq: 417 REGISTER" + m_CRLF +
  398. "Contact: <sip:192.168.1.10:15796>;methods=\"INVITE, MESSAGE, INFO, SUBSCRIBE, OPTIONS, BYE, CANCEL, NOTIFY, ACK, REFER, BENOTIFY\"" + m_CRLF +
  399. "User-Agent: RTC/1.3.5470 (Messenger 5.1.0680)" + m_CRLF +
  400. "Event: registration" + m_CRLF +
  401. "Allow-Events: presence" + m_CRLF +
  402. "Content-Length: 0" + m_CRLF + m_CRLF;
  403. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  404. SIPRequest registerReq = SIPRequest.ParseSIPRequest(sipMessage);
  405. Console.WriteLine("-----------------------------------------");
  406. }
  407. [TestMethod]
  408. public void CiscoRegisterRequest()
  409. {
  410. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  411. string sipMsg =
  412. "REGISTER sip:194.213.29.11 SIP/2.0" + m_CRLF +
  413. "Via: SIP/2.0/UDP 86.9.88.23:5060;branch=z9hG4bK15dbeda2" + m_CRLF +
  414. "From: <sip:sip2@194.213.29.11;user=phone>" + m_CRLF +
  415. "To: <sip:sip2@194.213.29.11;user=phone>" + m_CRLF +
  416. "Call-ID: 0013c339-acec0005-7488d654-42a83bd0@192.168.1.100" + m_CRLF +
  417. "Date: Sat, 22 Apr 2006 00:47:31 GMT" + m_CRLF +
  418. "CSeq: 10389 REGISTER" + m_CRLF +
  419. "User-Agent: CSCO/7" + m_CRLF +
  420. "Contact: <sip:sip2@86.9.88.23:5060;user=phone>" + m_CRLF +
  421. "Content-Length: 0" + m_CRLF +
  422. "Expires: 3600" + m_CRLF + m_CRLF;
  423. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  424. SIPRequest registerReq = SIPRequest.ParseSIPRequest(sipMessage);
  425. }
  426. [TestMethod]
  427. public void AuthenticatedRegisterRequestUnitTest()
  428. {
  429. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  430. string sipMsg =
  431. "REGISTER sip:blueface.ie SIP/2.0" + m_CRLF +
  432. "Via: SIP/2.0/UDP 86.9.88.23:10060;branch=z9hG4bK1DFDB76492E74691A3DF68AC672DAA7C" + m_CRLF +
  433. "From: Aaron <sip:aaronxten@blueface.ie>;tag=2090971807" + m_CRLF +
  434. "To: Aaron <sip:aaronxten@blueface.ie>" + m_CRLF +
  435. "Call-ID: 19CBFF5EB6CB4668A29BEF0C3DC49910@blueface.ie" + m_CRLF +
  436. "CSeq: 24291 REGISTER" + m_CRLF +
  437. "Max-Forwards: 70" + m_CRLF +
  438. "Contact: \"Aaron\" <sip:aaronxten@86.9.88.23:10060>" + m_CRLF +
  439. "User-Agent: X-PRO release 1103v" + m_CRLF +
  440. "Expires: 1800" + m_CRLF +
  441. "Authorization: Digest realm=\"sip.blueface.ie\",nonce=\"1694683214\",username=\"aaronxten\",response=\"85f2089ac958e69ce4d74f5ae72a9a5f\",uri=\"sip:blueface.ie\"" + m_CRLF +
  442. m_CRLF;
  443. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  444. SIPRequest registerReq = SIPRequest.ParseSIPRequest(sipMessage);
  445. Console.WriteLine(registerReq.ToString());
  446. SIPAuthenticationHeader authHeader = registerReq.Header.AuthenticationHeader;
  447. Assert.IsTrue(authHeader != null, "The Authorization header was not correctly extracted from the SIP Register Request.");
  448. Assert.IsTrue(authHeader.SIPDigest.Nonce == "1694683214", "The Authorization header nonce was not correctly extracted from the SIP Register Request, header nonce = " + authHeader.SIPDigest.Nonce + ".");
  449. Assert.IsTrue(authHeader.SIPDigest.Realm == "sip.blueface.ie", "The Authorization header realm was not correctly extracted from the SIP Register Request.");
  450. Assert.IsTrue(authHeader.SIPDigest.Username == "aaronxten", "The Authorization username nonce was not correctly extracted from the SIP Register Request, header username = " + authHeader.SIPDigest.Username + ".");
  451. Assert.IsTrue(authHeader.SIPDigest.URI == "sip:blueface.ie", "The Authorization header URI was not correctly extracted from the SIP Register Request.");
  452. Assert.IsTrue(authHeader.SIPDigest.Response == "85f2089ac958e69ce4d74f5ae72a9a5f", "The Authorization header response was not correctly extracted from the SIP Register Request.");
  453. }
  454. [TestMethod]
  455. public void MicrosoftMessengerRegisterRequestUnitTest()
  456. {
  457. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  458. string sipMsg =
  459. "REGISTER sip:aaronmsn SIP/2.0" + m_CRLF +
  460. "Via: SIP/2.0/UDP 192.168.1.31:16879" + m_CRLF +
  461. "Max-Forwards: 70" + m_CRLF +
  462. "From: <sip:aaronmsn>;tag=27359cb6dcdb4b8e9570dd9fc4b09c14;epid=5649ab5588" + m_CRLF +
  463. "To: <sip:aaronmsn>" + m_CRLF +
  464. "Call-ID: 19b7a4c8c6d647b19afe031df5e91332@192.168.1.31" + m_CRLF +
  465. "CSeq: 1 REGISTER" + m_CRLF +
  466. "Contact: <sip:192.168.1.31:16879>;methods=\"INVITE, MESSAGE, INFO, SUBSCRIBE, OPTIONS, BYE, CANCEL, NOTIFY, ACK, REFER\"" + m_CRLF +
  467. "User-Agent: RTC/1.2.4949" + m_CRLF +
  468. "Event: registration" + m_CRLF +
  469. "Allow-Events: presence" + m_CRLF +
  470. "Content-Length: 0" + m_CRLF + m_CRLF;
  471. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  472. SIPRequest registerReq = SIPRequest.ParseSIPRequest(sipMessage);
  473. Console.WriteLine(registerReq.ToString());
  474. }
  475. [TestMethod]
  476. public void CreateBranchIdUnitTest()
  477. {
  478. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  479. string sipMsg =
  480. "INVITE sip:303@sip.blueface.ie SIP/2.0" + m_CRLF +
  481. "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
  482. "From: SER Test X <sip:aaronxten@sip.blueface.ie:5065>;tag=196468136" + m_CRLF +
  483. "To: <sip:303@sip.blueface.ie>" + m_CRLF +
  484. "Contact: <sip:aaronxten@192.168.1.2:5065>" + m_CRLF +
  485. "Call-ID: A3DF9A04-0EFE-47E4-98B1-E18AA186F3D6@192.168.1.2" + m_CRLF +
  486. "CSeq: 49429 INVITE" + m_CRLF +
  487. "Max-Forwards: 70" + m_CRLF +
  488. "Content-Type: application/sdp" + m_CRLF +
  489. "User-Agent: X-PRO release 1103v" + m_CRLF +
  490. m_CRLF;
  491. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  492. SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessage);
  493. string branchId = CallProperties.CreateBranchId();
  494. Console.WriteLine("branchid=" + branchId);
  495. int length = branchId.Length - SIPConstants.SIP_BRANCH_MAGICCOOKIE.Length;
  496. Console.WriteLine("length=" + length);
  497. Assert.IsTrue(branchId != null, "The branchid was not created correctly.");
  498. Console.WriteLine("-----------------------------------------");
  499. }
  500. /*[Test]
  501. public void LoopDetectUnitTest()
  502. {
  503. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  504. string sipMsg =
  505. "INVITE sip:303@sip.blueface.ie SIP/2.0" + m_CRLF +
  506. "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
  507. "From: SER Test X <sip:aaronxten@sip.blueface.ie:5065>;tag=196468136" + m_CRLF +
  508. "To: <sip:303@sip.blueface.ie>" + m_CRLF +
  509. "Contact: <sip:aaronxten@192.168.1.2:5065>" + m_CRLF +
  510. "Call-ID: A3DF9A04-0EFE-47E4-98B1-E18AA186F3D6@192.168.1.2" + m_CRLF +
  511. "CSeq: 49429 INVITE" + m_CRLF +
  512. "Max-Forwards: 70" + m_CRLF +
  513. "Content-Type: application/sdp" + m_CRLF +
  514. "User-Agent: X-PRO release 1103v" + m_CRLF +
  515. m_CRLF;
  516. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null);
  517. SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessage);
  518. string branchId = inviteReq.CreateBranchId();
  519. SIPViaHeader requestVia = new SIPViaHeader("192.168.1.2", 5065, branchId);
  520. inviteReq.Header.Via.PushViaHeader(requestVia);
  521. Assert.IsTrue(inviteReq.IsLoop("192.168.1.2", 5065, branchId), "The SIP request was not correctly detected as a loop.");
  522. Console.WriteLine("-----------------------------------------");
  523. }*/
  524. [TestMethod]
  525. public void LooseRouteForProxyUnitTest()
  526. {
  527. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  528. string sipMsg =
  529. "INVITE sip:303@sip.blueface.ie SIP/2.0" + m_CRLF +
  530. "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
  531. "Route: <sip:82.195.148.216:5062;lr>,<sip:89.100.92.186:45270;lr>" + m_CRLF +
  532. "From: SER Test X <sip:aaronxten@sip.blueface.ie:5065>;tag=196468136" + m_CRLF +
  533. "To: <sip:303@sip.blueface.ie>" + m_CRLF +
  534. "Contact: <sip:aaronxten@192.168.1.2:5065>" + m_CRLF +
  535. "Call-ID: A3DF9A04-0EFE-47E4-98B1-E18AA186F3D6@192.168.1.2" + m_CRLF +
  536. "CSeq: 49429 INVITE" + m_CRLF +
  537. "Max-Forwards: 70" + m_CRLF +
  538. "Content-Type: application/sdp" + m_CRLF +
  539. "User-Agent: X-PRO release 1103v" + m_CRLF +
  540. m_CRLF;
  541. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  542. SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessage);
  543. MockSIPChannel mockSIPChannel = new MockSIPChannel(IPSocket.ParseSocketString("82.195.148.216:5062"));
  544. SIPTransport mockSIPTransport = new SIPTransport(MockSIPDNSManager.Resolve, null, mockSIPChannel, false);
  545. mockSIPTransport.PreProcessRouteInfo(inviteReq);
  546. Assert.IsTrue(inviteReq.URI.ToString() == "sip:303@sip.blueface.ie", "The request URI was incorrectly modified.");
  547. Assert.IsTrue(inviteReq.Header.Routes.TopRoute.ToString() == "<sip:89.100.92.186:45270;lr>", "The request route information was not correctly preprocessed.");
  548. Assert.IsTrue(inviteReq.Header.Routes.Length == 1, "The route set was an incorrect length.");
  549. }
  550. [TestMethod]
  551. public void LooseRouteForProxyMultipleContactsUnitTest()
  552. {
  553. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  554. string sipMsg =
  555. "INVITE sip:303@sip.blueface.ie SIP/2.0" + m_CRLF +
  556. "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
  557. "Route: <sip:82.195.148.216:5062;lr>,<sip:89.100.92.186:45270;lr>" + m_CRLF +
  558. "From: SER Test X <sip:aaronxten@sip.blueface.ie:5065>;tag=196468136" + m_CRLF +
  559. "To: <sip:303@sip.blueface.ie>" + m_CRLF +
  560. "Contact: <sip:aaronxten@192.168.1.2:5065>" + m_CRLF +
  561. "Call-ID: A3DF9A04-0EFE-47E4-98B1-E18AA186F3D6@192.168.1.2" + m_CRLF +
  562. "CSeq: 49429 INVITE" + m_CRLF +
  563. "Max-Forwards: 70" + m_CRLF +
  564. "Content-Type: application/sdp" + m_CRLF +
  565. "User-Agent: X-PRO release 1103v" + m_CRLF +
  566. m_CRLF;
  567. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  568. SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessage);
  569. SIPTransport mockSIPTransport = new SIPTransport(MockSIPDNSManager.Resolve, null, false);
  570. mockSIPTransport.AddSIPChannel(new MockSIPChannel(IPSocket.ParseSocketString("82.195.148.216:5061")));
  571. mockSIPTransport.AddSIPChannel(new MockSIPChannel(IPSocket.ParseSocketString("82.195.148.216:5062")));
  572. mockSIPTransport.PreProcessRouteInfo(inviteReq);
  573. Assert.IsTrue(inviteReq.URI.ToString() == "sip:303@sip.blueface.ie", "The request URI was incorrectly modified.");
  574. Assert.IsTrue(inviteReq.Header.Routes.TopRoute.ToString() == "<sip:89.100.92.186:45270;lr>", "The request route information was not correctly preprocessed.");
  575. Assert.IsTrue(inviteReq.Header.Routes.Length == 1, "The route set was an incorrect length.");
  576. }
  577. [TestMethod]
  578. public void LooseRouteNotForProxyUnitTest()
  579. {
  580. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  581. string sipMsg =
  582. "INVITE sip:303@sip.blueface.ie SIP/2.0" + m_CRLF +
  583. "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
  584. "Route: <sip:82.195.148.216:5062;lr>,<sip:89.100.92.186:45270;lr>" + m_CRLF +
  585. "From: SER Test X <sip:aaronxten@sip.blueface.ie:5065>;tag=196468136" + m_CRLF +
  586. "To: <sip:303@sip.blueface.ie>" + m_CRLF +
  587. "Contact: <sip:aaronxten@192.168.1.2:5065>" + m_CRLF +
  588. "Call-ID: A3DF9A04-0EFE-47E4-98B1-E18AA186F3D6@192.168.1.2" + m_CRLF +
  589. "CSeq: 49429 INVITE" + m_CRLF +
  590. "Max-Forwards: 70" + m_CRLF +
  591. "Content-Type: application/sdp" + m_CRLF +
  592. "User-Agent: X-PRO release 1103v" + m_CRLF +
  593. m_CRLF;
  594. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  595. SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessage);
  596. SIPTransport mockSIPTransport = new SIPTransport(MockSIPDNSManager.Resolve, null, false);
  597. mockSIPTransport.AddSIPChannel(new MockSIPChannel(IPSocket.ParseSocketString("10.10.10.10:5060")));
  598. mockSIPTransport.PreProcessRouteInfo(inviteReq);
  599. Assert.IsTrue(inviteReq.URI.ToString() == "sip:303@sip.blueface.ie", "The request URI was incorrectly modified.");
  600. Assert.IsTrue(inviteReq.Header.Routes.TopRoute.ToString() == "<sip:82.195.148.216:5062;lr>", "The request route information was not correctly preprocessed.");
  601. }
  602. [TestMethod]
  603. public void StrictRoutePriorToProxyUnitTest()
  604. {
  605. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  606. string sipMsg =
  607. "INVITE sip:82.195.148.216:5062;lr SIP/2.0" + m_CRLF +
  608. "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
  609. "Route: <sip:89.100.92.186:45270;lr>,<sip:303@sip.blueface.ie>" + m_CRLF +
  610. "From: SER Test X <sip:aaronxten@sip.blueface.ie:5065>;tag=196468136" + m_CRLF +
  611. "To: <sip:303@sip.blueface.ie>" + m_CRLF +
  612. "Contact: <sip:aaronxten@192.168.1.2:5065>" + m_CRLF +
  613. "Call-ID: A3DF9A04-0EFE-47E4-98B1-E18AA186F3D6@192.168.1.2" + m_CRLF +
  614. "CSeq: 49429 INVITE" + m_CRLF +
  615. "Max-Forwards: 70" + m_CRLF +
  616. "Content-Type: application/sdp" + m_CRLF +
  617. "User-Agent: X-PRO release 1103v" + m_CRLF +
  618. m_CRLF;
  619. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  620. SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessage);
  621. SIPTransport mockSIPTransport = new SIPTransport(MockSIPDNSManager.Resolve, null, false);
  622. mockSIPTransport.AddSIPChannel(new MockSIPChannel(IPSocket.ParseSocketString("82.195.148.216:5062")));
  623. mockSIPTransport.PreProcessRouteInfo(inviteReq);
  624. Console.WriteLine(inviteReq.ToString());
  625. Console.WriteLine("Next Route=" + inviteReq.Header.Routes.TopRoute.ToString());
  626. Console.WriteLine("Request URI=" + inviteReq.URI.ToString());
  627. Assert.IsTrue(inviteReq.Header.Routes.TopRoute.ToString() == "<sip:89.100.92.186:45270;lr>", "Top route was not correct.");
  628. Assert.IsTrue(inviteReq.URI.ToString() == "sip:303@sip.blueface.ie", "The request URI was incorrectly adjusted.");
  629. Assert.IsTrue(inviteReq.Header.Routes.Length == 1, "The route set was not correct.");
  630. }
  631. [TestMethod]
  632. public void StrictRouteAfterProxyUnitTest()
  633. {
  634. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  635. string sipMsg =
  636. "INVITE sip:303@sip.blueface.ie SIP/2.0" + m_CRLF +
  637. "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
  638. "Route: <sip:82.195.148.216:5062;lr>,<sip:10.10.10.10>,<sip:89.100.92.186:45270;lr>" + m_CRLF +
  639. "From: SER Test X <sip:aaronxten@sip.blueface.ie:5065>;tag=196468136" + m_CRLF +
  640. "To: <sip:303@sip.blueface.ie>" + m_CRLF +
  641. "Contact: <sip:aaronxten@192.168.1.2:5065>" + m_CRLF +
  642. "Call-ID: A3DF9A04-0EFE-47E4-98B1-E18AA186F3D6@192.168.1.2" + m_CRLF +
  643. "CSeq: 49429 INVITE" + m_CRLF +
  644. "Max-Forwards: 70" + m_CRLF +
  645. "Content-Type: application/sdp" + m_CRLF +
  646. "User-Agent: X-PRO release 1103v" + m_CRLF +
  647. m_CRLF;
  648. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  649. SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessage);
  650. SIPTransport mockSIPTransport = new SIPTransport(MockSIPDNSManager.Resolve, null, false);
  651. mockSIPTransport.AddSIPChannel(new MockSIPChannel(IPSocket.ParseSocketString("82.195.148.216:5062")));
  652. mockSIPTransport.PreProcessRouteInfo(inviteReq);
  653. Console.WriteLine("Next Route=" + inviteReq.Header.Routes.TopRoute.ToString());
  654. Console.WriteLine("Request URI=" + inviteReq.URI.ToString());
  655. Assert.IsTrue(inviteReq.Header.Routes.TopRoute.ToString() == "<sip:89.100.92.186:45270;lr>", "Top route was not correctly recognised.");
  656. Assert.IsTrue(inviteReq.Header.Routes.BottomRoute.ToString() == "<sip:303@sip.blueface.ie>", "Bottom route was not correctly placed.");
  657. Assert.IsTrue(inviteReq.URI.ToString() == "sip:10.10.10.10", "The request URI was not correctly adjusted.");
  658. Assert.IsTrue(inviteReq.Header.Routes.Length == 2, "The route set was not correct.");
  659. }
  660. [TestMethod]
  661. //[Ignore("This SIP stack will not put hostnames into a Route header in order to avoid unnecessary DNS lookups.")]
  662. [Ignore]
  663. public void LooseRouteForProxyHostnameUnitTest()
  664. {
  665. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  666. string sipMsg =
  667. "INVITE sip:303@sip.blueface.ie SIP/2.0" + m_CRLF +
  668. "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
  669. "Route: <sip:sip.blueface.ie;lr>,<sip:89.100.92.186:45270;lr>" + m_CRLF +
  670. "From: SER Test X <sip:aaronxten@sip.blueface.ie:5065>;tag=196468136" + m_CRLF +
  671. "To: <sip:303@sip.blueface.ie>" + m_CRLF +
  672. "Contact: <sip:aaronxten@192.168.1.2:5065>" + m_CRLF +
  673. "Call-ID: A3DF9A04-0EFE-47E4-98B1-E18AA186F3D6@192.168.1.2" + m_CRLF +
  674. "CSeq: 49429 INVITE" + m_CRLF +
  675. "Max-Forwards: 70" + m_CRLF +
  676. "Content-Type: application/sdp" + m_CRLF +
  677. "User-Agent: X-PRO release 1103v" + m_CRLF +
  678. m_CRLF;
  679. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  680. SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessage);
  681. SIPTransport mockSIPTransport = new SIPTransport(MockSIPDNSManager.Resolve, null, false);
  682. mockSIPTransport.AddSIPChannel(new MockSIPChannel(IPSocket.ParseSocketString("194.213.29.100:5060")));
  683. mockSIPTransport.PreProcessRouteInfo(inviteReq);
  684. Assert.IsTrue(inviteReq.URI.ToString() == "sip:303@sip.blueface.ie", "The request URI was incorrectly modified.");
  685. Assert.IsTrue(inviteReq.Header.Routes.TopRoute.ToString() == "<sip:89.100.92.186:45270;lr>", "The request route information was not correctly preprocessed.");
  686. Assert.IsTrue(inviteReq.Header.Routes.Length == 1, "The route set was an incorrect length.");
  687. }
  688. [TestMethod]
  689. [ExpectedException(typeof(SIPValidationException))]
  690. public void SpuriousStartCharsInResponseUnitTest()
  691. {
  692. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  693. // This is an example of a malformed response recieved in the wild. It matches the bnf format for a request,
  694. // if the format of the SIP URI is not taken into account.
  695. string sipMsg =
  696. "16394SIP/2.0 200 OK" + m_CRLF +
  697. "To: <sip:user@83.70.216.94:5056>;tag=56314300b3ccd13fi0" + m_CRLF +
  698. "From: <sip:natkeepalive@194.213.29.52:5064>;tag=7816855980" + m_CRLF +
  699. "Call-ID: 1652975648@194.213.29.52" + m_CRLF +
  700. "CSeq: 685 OPTIONS" + m_CRLF +
  701. "Via: SIP/2.0/UDP 213.168.225.133:5060;branch=z9hG4bK46427189218ce28213adfb77e9df73b8ba6f6f0b" + m_CRLF +
  702. "Via: SIP/2.0/UDP 194.213.29.52:5064;branch=z9hG4bK1531800555" + m_CRLF +
  703. "Server: Linksys/PAP2-3.1.3(LS)" + m_CRLF +
  704. "Content-Length: 5" + m_CRLF +
  705. "Allow: ACK, BYE, CANCEL, INFO, INVITE, NOTIFY, OPTIONS, REFER" + m_CRLF +
  706. "Supported: x-sipura" + m_CRLF + m_CRLF;
  707. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  708. SIPRequest sipRequest = SIPRequest.ParseSIPRequest(sipMessage);
  709. Console.WriteLine("-----------------------------------------");
  710. }
  711. [TestMethod]
  712. public void RegisterZeroExpiryUnitTest()
  713. {
  714. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  715. string sipMsg =
  716. "REGISTER sip:213.200.94.181 SIP/2.0" + m_CRLF +
  717. "Via: SIP/2.0/UDP 192.168.1.32:10254;branch=z9hG4bK-d87543-eb7c9f44883c5955-1--d87543-;rport;received=89.100.104.191" + m_CRLF +
  718. "To: aaronxten <sip:aaronxten@213.200.94.181>" + m_CRLF +
  719. "From: aaronxten <sip:aaronxten@213.200.94.181>;tag=774d2561" + m_CRLF +
  720. "Call-ID: MTBhNGZjZmQ2OTc3MWU5MTZjNWUxMDYxOTk1MjdmYzk." + m_CRLF +
  721. "CSeq: 2 REGISTER" + m_CRLF +
  722. "Contact: <sip:aaronxten@192.168.1.32:10254;rinstance=6d2bbd8014ca7a76>;expires=0" + m_CRLF +
  723. "Max-Forwards: 69" + m_CRLF +
  724. "User-Agent: X-Lite release 1006e stamp 34025" + m_CRLF +
  725. "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO" + m_CRLF + m_CRLF;
  726. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  727. SIPRequest registerReq = SIPRequest.ParseSIPRequest(sipMessage);
  728. Console.WriteLine(registerReq.ToString());
  729. Console.WriteLine("-----------------------------------------");
  730. }
  731. [TestMethod]
  732. public void AvayaInviteUnitTest()
  733. {
  734. Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
  735. string sipMsg =
  736. "INVITE sip:194.213.29.100:5060 SIP/2.0" + m_CRLF +
  737. "Via: SIP/2.0/UDP 10.1.1.241;branch=z9hG4bK94fc63626" + m_CRLF +
  738. "To: UNKNOWN <sip:8219000@sip.194.213.29.100>" + m_CRLF +
  739. "From: 'Joe Bloggs' <sip:ei9gz@blueface.ie>;tag=cc16d34c122e5fe" + m_CRLF +
  740. "Call-ID: 61d0b3a80f5727a9be56ac739e8b0581@blueface.ie" + m_CRLF +
  741. "CSeq: 2009546910 INVITE" + m_CRLF +
  742. "Contact: 'Val Gavin' <sip:ei9gz@10.1.1.241>" + m_CRLF +
  743. "Max-Forwards: 70" + m_CRLF +
  744. "Route: <sip:8219522@sip.194.213.29.100>" + m_CRLF + // Strict Route header (this header is actually a fault but it ends up being a strict route).
  745. "User-Agent: NeuralX MxSF/v3.2.6.26" + m_CRLF +
  746. "Content-Type: application/sdp" + m_CRLF +
  747. "Content-Length: 318" + m_CRLF +
  748. "P-Asserted-Identity: 'Joe Bloggs' <sip:9@blueface.ie>" + m_CRLF +
  749. "Allow: INVITE" + m_CRLF +
  750. "Allow: CANCEL" + m_CRLF +
  751. "Allow: OPTIONS" + m_CRLF +
  752. "Allow: BYE" + m_CRLF +
  753. "Allow: REFER" + m_CRLF +
  754. "Allow: INFO" + m_CRLF +
  755. "Allow: UPDATE" + m_CRLF +
  756. "Supported: replaces" + m_CRLF +
  757. m_CRLF +
  758. "v=0" + m_CRLF +
  759. "o=xxxxx 1174909600 1174909601 IN IP4 10.1.1.241" + m_CRLF +
  760. "s=-" + m_CRLF +
  761. "c=IN IP4 10.1.1.241" + m_CRLF +
  762. "t=0 0" + m_CRLF +
  763. "a=sendrecv" + m_CRLF +
  764. "m=audio 20026 RTP/AVP 8 0 18 101" + m_CRLF +
  765. "a=rtpmap:8 PCMA/8000" + m_CRLF +
  766. "a=rtpmap:0 PCMU/8000" + m_CRLF +
  767. "a=rtpmap:18 G729/8000" + m_CRLF +
  768. "a=rtpmap:101 telephone-event/8000" + m_CRLF +
  769. "a=fmtp:18 annexb=no" + m_CRLF +
  770. "a=fmtp:101 0-15" + m_CRLF +
  771. "a=ptime:20" + m_CRLF +
  772. "a=rtcp:20027 IN IP4 10.1.1.241";
  773. SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
  774. SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessage);
  775. SIPTransport mockSIPTransport = new SIPTransport(MockSIPDNSManager.Resolve, null, false);
  776. mockSIPTransport.AddSIPChannel(new MockSIPChannel(IPSocket.ParseSocketString("194.213.29.100:5060")));
  777. mockSIPTransport.PreProcessRouteInfo(inviteReq);
  778. Console.WriteLine(inviteReq.ToString());
  779. Assert.IsTrue(inviteReq.URI.ToString() == "sip:8219522@sip.194.213.29.100", "The request URI was not updated to the strict route.");
  780. Assert.IsTrue(inviteReq.Header.Ro

Large files files are truncated, but you can click here to view the full file