Skip to content

Commit a9c30ca

Browse files
committed
Use raw string for SIP crypto test payload
Replace the long SIP/SDP test fixture with a raw string literal and normalize it with ReplaceLineEndings(CRLF) so the protocol payload stays stable across LF and CRLF checkouts. Set the unit test project to C# 14 and import Polyfills so the call also compiles for net462.
1 parent 9254cc2 commit a9c30ca

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

test/unit/SIPSorcery.UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<IsPackable>false</IsPackable>
66
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
77
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
8+
<LangVersion>14.0</LangVersion>
89
</PropertyGroup>
910

1011
<ItemGroup>

test/unit/net/SDP/SDPSecurityDescriptionUnitTest.cs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Text;
33
using Microsoft.Extensions.Logging;
4+
using Polyfills;
45
using SIPSorcery.SIP;
56
using SIPSorcery.UnitTests;
67
using Xunit;
@@ -165,8 +166,44 @@ public void ParseCryptoSIPMessage()
165166
logger.BeginScope(TestHelper.GetCurrentMethodName());
166167

167168
string sipMsg =
168-
$"INVITE sip:33@10.2.0.110:5061;transport=tls SIP/2.0{CRLF}Via: SIP/2.0/TLS 10.2.19.102:58179;rport;branch=z9hG4bKPj9893426a070f4c26ab494ceb746836a6{CRLF}Max-Forwards: 70{CRLF}From: <sip:a@10.2.0.110>;tag=b0d60b9dda9043818dea1f0e8ff9667c{CRLF}To: <sip:33@10.2.0.110>{CRLF}Contact: <sip:a@10.2.19.102:58179;ob>{CRLF}Call-ID: 6410bc5eb6724efd8717831ac2af5c35{CRLF}CSeq: 9941 INVITE{CRLF}Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS{CRLF}Supported: replaces, 100rel, timer, norefersub{CRLF}Session-Expires: 1800{CRLF}Min-SE: 90{CRLF}User-Agent: MicroSIP/3.19.8{CRLF}Content-Type: application/sdp{CRLF}Content-Length: 720{CRLF}{CRLF}v=0{CRLF}o=- 3784977145 3784977145 IN IP4 10.2.19.102{CRLF}s=pjmedia{CRLF}b=AS:84{CRLF}t=0 0{CRLF}a=X-nat:0{CRLF}m=audio 4000 RTP/AVP 8 0 101{CRLF}c=IN IP4 10.2.19.102{CRLF}b=TIAS:64000{CRLF}a=rtcp:4001 IN IP4 10.2.19.102{CRLF}a=sendrecv{CRLF}a=rtpmap:8 PCMA/8000{CRLF}a=rtpmap:0 PCMU/8000{CRLF}a=rtpmap:101 telephone-event/8000{CRLF}a=fmtp:101 0-16{CRLF}a=ssrc:370289018 cname:089912e5446c1847{CRLF}a=crypto:1 AES_256_CM_HMAC_SHA1_80 inline:i/aQZXuTQXF8NcIPG/8ClKLXjzJZiZkFqNerJJaWtX9ShjuamMQgFocXUEkWCQ=={CRLF}a=crypto:2 AES_256_CM_HMAC_SHA1_32 inline:WEXYOzOomH16+KpVRc8RKHkGUEW6DdvYHWSFKePVy9RzC5DB2Ciw+4t9huV8KA=={CRLF}a=crypto:3 AES_CM_128_HMAC_SHA1_80 inline:6wGxadTFLGO9iKPSC8XfRQsOFDRFgJdmpBfdWp9r{CRLF}a=crypto:4 AES_CM_128_HMAC_SHA1_32 inline:SdihJallj5frjwWc5yeXbMZlJSLlS+o2bkH3Jsle"
169-
;
169+
"""
170+
INVITE sip:33@10.2.0.110:5061;transport=tls SIP/2.0
171+
Via: SIP/2.0/TLS 10.2.19.102:58179;rport;branch=z9hG4bKPj9893426a070f4c26ab494ceb746836a6
172+
Max-Forwards: 70
173+
From: <sip:a@10.2.0.110>;tag=b0d60b9dda9043818dea1f0e8ff9667c
174+
To: <sip:33@10.2.0.110>
175+
Contact: <sip:a@10.2.19.102:58179;ob>
176+
Call-ID: 6410bc5eb6724efd8717831ac2af5c35
177+
CSeq: 9941 INVITE
178+
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
179+
Supported: replaces, 100rel, timer, norefersub
180+
Session-Expires: 1800
181+
Min-SE: 90
182+
User-Agent: MicroSIP/3.19.8
183+
Content-Type: application/sdp
184+
Content-Length: 720
185+
186+
v=0
187+
o=- 3784977145 3784977145 IN IP4 10.2.19.102
188+
s=pjmedia
189+
b=AS:84
190+
t=0 0
191+
a=X-nat:0
192+
m=audio 4000 RTP/AVP 8 0 101
193+
c=IN IP4 10.2.19.102
194+
b=TIAS:64000
195+
a=rtcp:4001 IN IP4 10.2.19.102
196+
a=sendrecv
197+
a=rtpmap:8 PCMA/8000
198+
a=rtpmap:0 PCMU/8000
199+
a=rtpmap:101 telephone-event/8000
200+
a=fmtp:101 0-16
201+
a=ssrc:370289018 cname:089912e5446c1847
202+
a=crypto:1 AES_256_CM_HMAC_SHA1_80 inline:i/aQZXuTQXF8NcIPG/8ClKLXjzJZiZkFqNerJJaWtX9ShjuamMQgFocXUEkWCQ==
203+
a=crypto:2 AES_256_CM_HMAC_SHA1_32 inline:WEXYOzOomH16+KpVRc8RKHkGUEW6DdvYHWSFKePVy9RzC5DB2Ciw+4t9huV8KA==
204+
a=crypto:3 AES_CM_128_HMAC_SHA1_80 inline:6wGxadTFLGO9iKPSC8XfRQsOFDRFgJdmpBfdWp9r
205+
a=crypto:4 AES_CM_128_HMAC_SHA1_32 inline:SdihJallj5frjwWc5yeXbMZlJSLlS+o2bkH3Jsle
206+
""".ReplaceLineEndings(CRLF);
170207

171208
SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
172209
Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly.");

0 commit comments

Comments
 (0)