2 * @file sipe-sipmsg-tests.c
6 * Copyright (C) 2011-2019 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Some non-NTLM tests code was factored out from sipe-sec-ntlm-test.c:
25 *------------- Copyright notices from "sipe-sec-ntlm-tests.c" -------------
26 * Copyright (C) 2011-2016 SIPE Project <http://sipe.sourceforge.net/>
27 * Copyright (C) 2010 pier11 <pier11@operamail.com>
28 * Copyright (C) 2008 Novell, Inc.
29 *------------- Copyright notices from "sipe-sec-ntlm-tests.c" -------------
42 #include "sipe-common.h"
43 #include "sipe-backend.h"
44 #include "sipe-crypt.h"
45 #include "sipe-mime.h"
47 #include "sipe-sign.h"
48 #include "sipe-utils.h"
49 #include "sip-transport.h"
57 gboolean
sipe_backend_debug_enabled(void)
62 void sipe_backend_debug_literal(sipe_debug_level level
,
65 printf("DEBUG(%d): %s\n", level
, msg
);
68 void sipe_backend_debug(sipe_debug_level level
,
73 gchar
*newformat
= g_strdup_printf("DEBUG(%d): %s\n", level
, format
);
76 vprintf(newformat
, ap
);
82 gchar
*sipe_backend_markup_css_property(SIPE_UNUSED_PARAMETER
const gchar
*style
,
83 SIPE_UNUSED_PARAMETER
const gchar
*option
)
88 void sipe_mime_parts_foreach(SIPE_UNUSED_PARAMETER
const gchar
*type
,
89 SIPE_UNUSED_PARAMETER
const gchar
*body
,
90 SIPE_UNUSED_PARAMETER sipe_mime_parts_cb callback
,
91 SIPE_UNUSED_PARAMETER gpointer user_data
)
95 gchar
*sipe_rtf_to_html(SIPE_UNUSED_PARAMETER
const gchar
*rtf
)
100 const gchar
*sip_transport_epid(SIPE_UNUSED_PARAMETER
struct sipe_core_private
*sipe_private
)
105 const gchar
*sip_transport_ip_address(SIPE_UNUSED_PARAMETER
struct sipe_core_private
*sipe_private
)
110 /* needed when linking against NSS */
111 void md4sum(const uint8_t *data
, uint32_t length
, uint8_t *digest
);
112 void md4sum(SIPE_UNUSED_PARAMETER
const uint8_t *data
,
113 SIPE_UNUSED_PARAMETER
uint32_t length
,
114 SIPE_UNUSED_PARAMETER
uint8_t *digest
)
121 static guint succeeded
= 0;
122 static guint failed
= 0;
124 static void assert_equal(const char *expected
, const gchar
*got
)
126 if (sipe_strequal(expected
, got
)) {
129 printf("FAILED: %s\n %s\n", got
, expected
);
134 static void msg_tests(void) {
135 /* Address parsing */
137 const gchar
*responses
[] = {
139 "From: \"J.D. User\" <sip:foo.bar@company.com>;something else\r\n"
140 "To: \"Test Recipient\" <SIP:test@recipient.com>\r\n"
141 "X-Some-Header: <SiP:joe.header@test.com>\r\n"
142 "Content-Length: 0\r\n"
145 "From: sip:foo.bar@company.com;something else\r\n"
146 "To: SIP:test@recipient.com\r\n"
147 "X-Some-Header: SiP:joe.header@test.com\r\n"
148 "Content-Length: 0\r\n"
154 for (resp
= responses
; *resp
; resp
++) {
155 struct sipmsg
*msg
= sipmsg_parse_msg(*resp
);
158 address
= sipmsg_parse_from_address(msg
);
159 assert_equal("sip:foo.bar@company.com", address
);
162 address
= sipmsg_parse_to_address(msg
);
163 assert_equal("SIP:test@recipient.com", address
);
166 address
= sipmsg_parse_address_from_header(msg
, "x-some-header");
167 assert_equal("SiP:joe.header@test.com", address
);
174 /* P-Asserted-Identity parsing */
178 const gchar
*sip_uri
;
179 const gchar
*tel_uri
;
182 "\"Cullen Jennings\" <sip:fluffy@cisco.com>",
183 "sip:fluffy@cisco.com",
192 "\"Lunch, Lucas\" <sip:llucas@cisco.com>,<tel:+420123456;ext=88463>",
193 "sip:llucas@cisco.com",
194 "tel:+420123456;ext=88463"
203 for (testcase
= testcases
; testcase
->header
; testcase
++) {
204 gchar
*sip_uri
= NULL
;
205 gchar
*tel_uri
= NULL
;
207 sipmsg_parse_p_asserted_identity(testcase
->header
,
210 assert_equal(testcase
->sip_uri
, sip_uri
);
211 assert_equal(testcase
->tel_uri
, tel_uri
);
218 /* Test Authentication Algorithm's v4 Signature String */
220 const gchar
*response
=
221 "SIP/2.0 180 Ringing\r\n"
222 "Authentication-Info: NTLM rspauth=\"010000003EA8D688BA51D5CD64000000\", srand=\"1B6D47A1\", snum=\"11\", opaque=\"357E6F72\", qop=\"auth\", targetname=\"LOC-COMPANYT-FE03.COMPANY.COM\", realm=\"SIP Communications Service\"\r\n"
223 "Via: SIP/2.0/tls 192.168.44.10:50230;received=10.117.245.254;ms-received-port=50230;ms-received-cid=37ABE00\r\n"
224 "FROM: \"Sender\"<sip:sender@company.com>;tag=2420628112;epid=54392f1bbf01\r\n"
225 "TO: \"recipient\"<sip:recipient@company.com>;tag=7aee15546a;epid=3102EB8BD1\r\n"
227 "CALL-ID: 41CEg82ECa0AC8i3DD7mE673t9CF4b19DAxF780x\r\n"
228 "RECORD-ROUTE: <sip:LOC-COMPANYT-OCSR2P01.COMPANY.COM:5061;transport=tls;ms-fe=LOC-COMPANYT-FE03.COMPANY.COM;opaque=state:F:T:Eu:Ci.R37abe00;lr;ms-route-sig=gdOGgL7NiL3hv_oBc0NdrJOxZk_r-8naq-k_DtpgAA>\r\n"
229 "CONTACT: <sip:recipient@company.com;opaque=user:epid:-gLwenLTVVqy-Ak8TJn1ZAAA;gruu>;text;audio;video\r\n"
230 "CONTENT-LENGTH: 0\r\n"
231 "SUPPORTED: gruu-10\r\n"
233 "P-ASSERTED-IDENTITY: \"recipient\"<SIP:recipient@company.com>\r\n"
234 "SERVER: RTCC/3.5.0.0 MCXService/3.5.0.0 communicator.NOKIAS60R2.JVP.EN_US/1.0.6875.0\r\n"
236 const gchar
*response_sig
= "<NTLM><1B6D47A1><11><SIP Communications Service><LOC-COMPANYT-FE03.COMPANY.COM><41CEg82ECa0AC8i3DD7mE673t9CF4b19DAxF780x><1><INVITE><sip:sender@company.com><2420628112><sip:recipient@company.com><7aee15546a><SIP:recipient@company.com><><><180>";
237 struct sipmsg_breakdown msgbd
;
240 msgbd
.msg
= sipmsg_parse_msg(response
);
241 sipmsg_breakdown_parse(&msgbd
,
242 "SIP Communications Service",
243 "LOC-COMPANYT-FE03.COMPANY.COM",
245 msg_str
= sipmsg_breakdown_get_string(4, &msgbd
);
247 assert_equal(response_sig
, msg_str
);
250 sipmsg_free(msgbd
.msg
);
251 sipmsg_breakdown_free(&msgbd
);
254 /* Test parsing of address fields where URIs wrapped in "<...>" */
256 const gchar
*response
=
257 "SIP/2.0 180 Ringing\r\n"
258 "Authentication-Info: NTLM rspauth=\"010000003EA8D688BA51D5CD64000000\", srand=\"1B6D47A1\", snum=\"11\", opaque=\"357E6F72\", qop=\"auth\", targetname=\"bar\", realm=\"foo\"\r\n"
259 "From: sip:sender@company.com;tag=2420628112;epid=54392f1bbf01\r\n"
260 "To: sip:recipient@company.com;tag=7aee15546a;epid=3102EB8BD1\r\n"
262 "Call-ID: 41CEg82ECa0AC8i3DD7mE673t9CF4b19DAxF780x\r\n"
263 "Content-Length: 0\r\n"
264 "P-Asserted-Identity: <SIP:recipient@company.com>\r\n"
266 const gchar
*response_sig
= "<NTLM><1B6D47A1><11><foo><bar><41CEg82ECa0AC8i3DD7mE673t9CF4b19DAxF780x><1><INVITE><sip:sender@company.com><2420628112><sip:recipient@company.com><7aee15546a><SIP:recipient@company.com><><><180>";
267 struct sipmsg_breakdown msgbd
;
270 msgbd
.msg
= sipmsg_parse_msg(response
);
271 sipmsg_breakdown_parse(&msgbd
,
275 msg_str
= sipmsg_breakdown_get_string(4, &msgbd
);
277 assert_equal(response_sig
, msg_str
);
280 sipmsg_free(msgbd
.msg
);
281 sipmsg_breakdown_free(&msgbd
);
284 /* UUID tests - begin tests from MS-SIPRE */
286 const char *testEpid
= "01010101";
287 const char *expectedUUID
= "4b1682a8-f968-5701-83fc-7c6741dc6697";
288 gchar
*gotUUID
= generateUUIDfromEPID(testEpid
);
290 assert_equal(expectedUUID
, gotUUID
);
296 int main(SIPE_UNUSED_PARAMETER
int argc
,
297 SIPE_UNUSED_PARAMETER
char *argv
[])
299 /* Initialization for crypto backend (test mode) */
300 sipe_crypto_init(FALSE
);
304 printf("Result: %d PASSED %d FAILED\n", succeeded
, failed
);