/[resiprocate]/main/resip/stack/test/SipTortureTests.cxx
ViewVC logotype

Contents of /main/resip/stack/test/SipTortureTests.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6069 - (show annotations) (download)
Thu Mar 9 23:06:59 2006 UTC (13 years, 8 months ago) by jason
File MIME type: text/plain
File size: 39438 byte(s)
mods for Solaris - tested for Solaris 10 on x86
fixed numerous compiler errors/warnings


1 #include <iostream>
2 #include <memory>
3
4 #include "TestSupport.hxx"
5 #include "resip/stack/Contents.hxx"
6 #include "resip/stack/SdpContents.hxx"
7 #include "resip/stack/SipMessage.hxx"
8 #include "resip/stack/ExtensionHeader.hxx"
9 #include "resip/stack/Uri.hxx"
10 #include "rutil/Logger.hxx"
11 #include "tassert.h"
12
13 using namespace resip;
14 using namespace std;
15
16 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
17
18 #define BUGTRAILINGSPACE " "
19
20 void
21 test1()
22 {
23 CritLog(<< "2.1 INVITE Parser Torture Test Message" );
24
25 const char *txt = ("INVITE sip:called@called-company.com SIP/2.0\r\n"
26 "TO :\r\n"
27 " sip:called@called-company.com ; tag = 1918181833n\r\n"
28 "From : \"Caller Name \\\\\\\"\" <sip:caller@caller-company.com>\r\n"
29 " ;\r\n"
30 " tag = 98asjd8\r\n"
31 "Max-Forwards: 8\r\n"
32 "Call-ID: 0ha0isndaksdj@10.0.0.1\r\n"
33 "Date: Mon, 02 Jun 1982 08:21:11 GMT\r\n"
34 "CSeq: 8\r\n"
35 " INVITE\r\n"
36 "Via : SIP / 2.0\r\n"
37 " /UDP\r\n"
38 " 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
39 "Subject : \r\n"
40 "NewFangledHeader: newfangled value\r\n"
41 " more newfangled value \r\n"
42 "Content-Type: application/sdp \r\n"
43 "v: SIP / 2.0 / TCP 1192.168.156.222 ;\r\n"
44 " branch = 9ikj8 , \r\n"
45 " SIP / 2.0 / UDP 192.168.255.111 ; hidden\r\n"
46 "m:\"Quoted string\\\"\\\"\"<sip:caller@caller-company.com>; newparam =\r\n"
47 " newvalue ;\r\n"
48 " secondparam = secondvalue ; q = 0.33,\r\n"
49 " tel:4443322 \r\n"
50 "\r\n"
51 "v=0\r\n"
52 "o=mhandley 29739 7272939 IN IP4 126.5.4.3 \r\n"
53 "s=-\r\n"
54 "c=IN IP4 135.180.130.88 \r\n"
55 "t=0 0 \r\n"
56 "m=audio 492170 RTP/AVP 0 12 \r\n"
57 "m=video 3227 RTP/AVP 31 \r\n"
58 "a=rtpmap:31 LPC \r\n\r\n");
59
60
61
62 SipMessage* msg = TestSupport::makeMessage(txt);
63
64
65 tassert_reset();
66 tassert(msg);
67
68 auto_ptr<SipMessage> message(msg);
69
70 tassert(message->isRequest());
71 tassert(message->isResponse() == false);
72
73 tassert(message->exists(h_To));
74 tassert(message->header(h_To).uri().user() == "called");
75 tassert(message->header(h_To).uri().host() == "called-company.com");
76 tassert(message->header(h_To).param(p_tag) == "1918181833n");
77
78 tassert(message->exists(h_From));
79 tassert(message->header(h_From).uri().user() == "caller");
80 tassert(message->header(h_From).uri().host() == "caller-company.com");
81
82 tassert(message->header(h_From).param(p_tag) == "98asjd8");
83
84 tassert(message->exists(h_MaxForwards));
85 tassert(message->header(h_MaxForwards).value() == 8);
86 tassert(message->header(h_MaxForwards).exists(p_tag) == false);
87
88 // !ah! compact headers not working.
89 // skip if ''not present'' -- actually check by unknown hdr... :-)
90 if (message->exists(h_Contacts))
91 {
92
93 tassert(message->exists(h_Contacts) == true);
94 tassert(message->header(h_Contacts).empty() == false);
95 tassert(message->header(h_Contacts).front().uri().user() == "caller");
96 tassert(message->header(h_Contacts).front().uri().host() == "caller-company.com");
97 tassert(message->header(h_Contacts).front().uri().port() == 0);
98
99 }
100 else
101 {
102 CritLog(<<"TODO: Compact headers .. doing by unknown interface!!");
103 tassert(message->exists(h_Contacts) == false);
104 tassert(message->exists(ExtensionHeader("m")) == true);
105 tassert(message->header(ExtensionHeader("m")).empty() == false);
106 //!ah! temporary until compact headers fixed.
107 tassert(message->header(ExtensionHeader("m")).front().value() ==
108 "\"Quoted string\\\"\\\"\"<sip:caller@caller-company.com>;"
109 " newparam = newvalue ; secondparam = secondvalue ; q"
110 " = 0.33, tel:4443322 ");
111 }
112
113 tassert(message->exists(h_CallId));
114 tassert(message->header(h_CallId).value() == "0ha0isndaksdj@10.0.0.1");
115
116 tassert(message->exists(h_CSeq));
117 tassert(message->header(h_CSeq).sequence() == 8);
118 tassert(message->header(h_CSeq).method() == INVITE);
119
120 tassert(message->exists(h_Vias));
121 tassert(message->header(h_Vias).empty() == false);
122 tassert(message->header(h_Vias).front().protocolName() == "SIP");
123 tassert(message->header(h_Vias).front().protocolVersion() == "2.0");
124 tassert(message->header(h_Vias).front().transport() == "UDP");
125 tassert(message->header(h_Vias).front().sentHost() == "135.180.130.133");
126 tassert(message->header(h_Vias).front().sentPort() == 0);
127 tassert(message->header(h_Vias).front().exists(p_branch));
128 tassert(message->header(h_Vias).front().param(p_branch).hasMagicCookie());
129 tassert(message->header(h_Vias).front().param(p_branch).getTransactionId() == "kdjuw");
130 tassert(message->exists(h_Subject));
131 tassert(message->header(h_Subject).value().empty());
132
133 tassert(message->exists(ExtensionHeader("NewFangledHeader")));
134 tassert(message->header(ExtensionHeader("NewFangledHeader")).front().value() == "newfangled value more newfangled value"BUGTRAILINGSPACE);
135 //TODO: Need to check the ContentType header value
136 tassert(message->exists(h_ContentType));
137 CritLog(<<"TODO:Check content type"); // << *message);
138 tassert_verify(1);
139 }
140
141 void
142 test2()
143 {
144 CritLog( << "2.2 INVITE with Proxy-Require and Require");
145
146 const char *txt = ("INVITE sip:called@called-company.com SIP/2.0\r\n"
147 "To: sip:called@called-company.com\r\n"
148 "From: sip:caller@caller-company.com;tag=242etr\r\n"
149 "Max-Forwards: 6\r\n"
150 "Call-ID: 0ha0isndaksdj@10.0.0.1\r\n"
151 "Require: newfeature1, newfeature2\r\n"
152 "Proxy-Require: newfeature3, newfeature4\r\n"
153 "CSeq: 8 INVITE\r\n"
154 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n\r\n");
155
156 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
157
158 tassert_reset();
159
160 tassert(message->isRequest());
161 tassert(message->isResponse() == false);
162
163 tassert(message->exists(h_To));
164 tassert(message->header(h_To).uri().user() == "called");
165 tassert(message->header(h_To).uri().host() == "called-company.com");
166 tassert(!message->header(h_To).exists(p_tag));
167
168 tassert(message->exists(h_From));
169 tassert(message->header(h_From).uri().user() == "caller");
170 tassert(message->header(h_From).uri().host() == "caller-company.com");
171 tassert(message->header(h_From).exists(p_tag));
172 tassert(message->header(h_From).param(p_tag) == "242etr");
173
174 tassert(message->exists(h_MaxForwards));
175 tassert(message->header(h_MaxForwards).value() == 6);
176 tassert(message->header(h_MaxForwards).exists(p_tag) == false);
177
178 tassert(message->exists(h_Contacts) == false);
179
180 tassert(message->exists(h_CallId));
181 tassert(message->header(h_CallId).value() == "0ha0isndaksdj@10.0.0.1");
182
183 //TODO: Check Values
184 CritLog(<<"TODO: Check values h_Requires");
185 tassert(message->exists(h_Requires));
186
187 //TODO: Check values
188 CritLog(<<"TODO: Check values h_ProxyRequires");
189 tassert(message->exists(h_ProxyRequires));
190
191 tassert(message->exists(h_CSeq));
192 tassert(message->header(h_CSeq).sequence() == 8);
193 tassert(message->header(h_CSeq).method() == INVITE);
194
195 tassert(message->exists(h_Vias));
196 tassert(message->header(h_Vias).empty() == false);
197 tassert(message->header(h_Vias).front().protocolName() == "SIP");
198 tassert(message->header(h_Vias).front().protocolVersion() == "2.0");
199 tassert(message->header(h_Vias).front().transport() == "UDP");
200 tassert(message->header(h_Vias).front().sentHost() == "135.180.130.133");
201 tassert(message->header(h_Vias).front().sentPort() == 0);
202 tassert(message->header(h_Vias).front().exists(p_branch));
203
204 // !ah! -- transaction id DOES NOT include the magic cookie
205 // (removed z9hG4bK)
206
207 tassert(message->header(h_Vias).front().param(p_branch).getTransactionId() == "kdjuw");
208 tassert_verify(2);
209
210 }
211
212 void
213 test3()
214 {
215 CritLog( << "2.3 INVITE with Unknown Schemes in URIs");
216
217
218 const char *txt = ("INVITE name:John_Smith SIP/2.0\r\n"
219 "To: isbn:2983792873\r\n"
220 "From: <sip:www.cs.columbia.edu>;tag=3234233\r\n" // was http//
221 "Call-ID: 0ha0isndaksdj@10.0.0.1\r\n"
222 "CSeq: 8 INVITE\r\n"
223 "Max-Forwards: 7\r\n"
224 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
225 "Content-Type: application/sdp\r\n"
226 "\r\n"
227 "v=0\r\n"
228 "o=mhandley 29739 7272939 IN IP4 126.5.4.3 \r\n"
229 "s=- \r\n"
230 "c=IN IP4 135.180.130.88 \r\n"
231 "t=0 0\r\n"
232 "m=audio 492170 RTP/AVP 0 12 \r\n"
233 "m=video 3227 RTP/AVP 31 \r\n"
234 "a=rtpmap:31 LPC \r\n\r\n");
235
236 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
237
238
239 tassert(message->isRequest());
240 tassert(message->isResponse() == false);
241
242
243 // !ah! this will assert(0) in Uri.cxx -- so let's skip this for now
244 CritLog(<<"TODO: fix generic Uri handling.");
245 tassert_push();
246 tassert(message->header(h_RequestLine).getSipVersion() == "SIP/2.0");
247 tassert_pop();
248
249
250 tassert(message->exists(h_To));
251 tassert(!message->header(h_To).exists(p_tag));
252
253 tassert(message->exists(h_From));
254
255 tassert(message->header(h_From).param(p_tag) == "3234233");
256
257
258 tassert(message->exists(h_CallId));
259 tassert(message->header(h_CallId).value() == "0ha0isndaksdj@10.0.0.1");
260
261 tassert(message->exists(h_CSeq));
262 tassert(message->header(h_CSeq).sequence() == 8);
263 tassert(message->header(h_CSeq).method() == INVITE);
264
265 tassert(message->exists(h_MaxForwards));
266 tassert(message->header(h_MaxForwards).value() == 7);
267 tassert(message->header(h_MaxForwards).exists(p_tag) == false);
268
269 tassert(message->exists(h_Contacts) == false);
270
271 tassert(message->exists(h_Vias));
272 tassert(message->header(h_Vias).empty() == false);
273 tassert(message->header(h_Vias).front().protocolName() == "SIP");
274 tassert(message->header(h_Vias).front().protocolVersion() == "2.0");
275 tassert(message->header(h_Vias).front().transport() == "UDP");
276 tassert(message->header(h_Vias).front().sentHost() == "135.180.130.133");
277 tassert(message->header(h_Vias).front().sentPort() == 0);
278 tassert(message->header(h_Vias).front().exists(p_branch));
279 tassert(message->header(h_Vias).front().param(p_branch).getTransactionId() == "kdjuw");
280
281 //TODO: Check value
282 CritLog(<<"TODO: Check value of ContentType");
283 tassert(message->exists(h_ContentType));
284 tassert_verify(3);
285
286 }
287
288 void
289 test4()
290 {
291 CritLog( << "2.4 REGISTER with Y2038 Test (This tests for Absolute Time in Expires)");
292
293 const char *txt = ("REGISTER sip:company.com SIP/2.0\r\n"
294 "To: sip:user@company.com\r\n"
295 "From: sip:user@company.com;tag=3411345\r\n"
296 "Max-Forwards: 8\r\n"
297 "Contact: sip:user@host.company.com\r\n"
298 "Call-ID: 0ha0isndaksdj@10.0.0.1\r\n"
299 "CSeq: 8 REGISTER\r\n"
300 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
301 "Expires: Sat, 01 Dec 2040 16:00:00 GMT\r\n\r\n");
302
303 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
304
305 tassert_reset();
306
307 tassert(message->isRequest());
308 tassert(message->isResponse() == false);
309
310 tassert(message->header(h_RequestLine).getSipVersion() == "SIP/2.0");
311
312 tassert(message->exists(h_To));
313 tassert(message->header(h_To).uri().user() == "user");
314 tassert(message->header(h_To).uri().host() == "company.com");
315 tassert(!message->header(h_To).exists(p_tag));
316
317 tassert(message->exists(h_From));
318 tassert(message->header(h_From).uri().user() == "user");
319 tassert(message->header(h_From).uri().host() == "company.com");
320 tassert(message->header(h_From).exists(p_tag));
321 tassert(message->header(h_From).param(p_tag) == "3411345");
322
323 tassert(message->exists(h_MaxForwards));
324 tassert(message->header(h_MaxForwards).value() == 8);
325 tassert(message->header(h_MaxForwards).exists(p_tag) == false);
326
327 tassert(message->exists(h_Contacts));
328 tassert(message->header(h_Contacts).empty() == false);
329 tassert(message->header(h_Contacts).front().uri().user() == "user");
330 tassert(message->header(h_Contacts).front().uri().host() == "host.company.com");
331 tassert(message->header(h_Contacts).front().uri().port() == 0);
332
333 tassert(message->exists(h_CallId));
334 tassert(message->header(h_CallId).value() == "0ha0isndaksdj@10.0.0.1");
335
336 tassert(message->exists(h_CSeq));
337 tassert(message->header(h_CSeq).sequence() == 8);
338 tassert(message->header(h_CSeq).method() == REGISTER);
339
340 tassert(message->exists(h_Vias));
341 tassert(message->header(h_Vias).empty() == false);
342 tassert(message->header(h_Vias).front().protocolName() == "SIP");
343 tassert(message->header(h_Vias).front().protocolVersion() == "2.0");
344 tassert(message->header(h_Vias).front().transport() == "UDP");
345 tassert(message->header(h_Vias).front().sentHost() == "135.180.130.133");
346 tassert(message->header(h_Vias).front().sentPort() == 0);
347 tassert(message->header(h_Vias).front().exists(p_branch));
348 tassert(message->header(h_Vias).front().param(p_branch).getTransactionId() == "kdjuw");
349
350 tassert(message->exists(h_Expires));
351 /*
352 * Quoted from RFC 3261
353 * The "expires" parameter of a Contact header field value indicates how
354 * long the URI is valid. The value of the parameter is a number
355 * indicating seconds. If this parameter is not provided, the value of
356 * the Expires header field determines how long the URI is valid.
357 * Malformed values SHOULD be treated as equivalent to 3600.
358 * This provides a modest level of backwards compatibility with RFC
359 * 2543, which allowed absolute times in this header field. If an
360 * absolute time is received, it will be treated as malformed, and
361 * then default to 3600.
362 */
363
364 tassert(message->header(h_Expires).value() == 3600);
365 // Asking for something when it doesnt exist
366 tassert(message->exists(h_ContentLength) == false);
367
368 message->header(h_ContentLength).value();
369
370 tassert_verify(4);
371 }
372
373 void
374 test5()
375 {
376 CritLog( << "2.5 INVITE with inconsistent Accept and message body");
377
378 const char *txt = ("INVITE sip:user@company.com SIP/2.0 \r\n"
379 "To: sip:j_user@company.com \r\n"
380 "From: sip:caller@university.edu;tag=234 \r\n"
381 "Max-Forwards: 5 \r\n"
382 "Call-ID: 0ha0isndaksdj@10.0.0.1 \r\n"
383 "Accept: text/newformat \r\n"
384 "CSeq: 8 INVITE \r\n"
385 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw \r\n"
386 "Content-Type: application/sdp \r\n"
387 "\r\n"
388 "v=0 \r\n"
389 "c=IN IP4 135.180.130.88 \r\n"
390 "m=audio 492170 RTP/AVP 0 12 \r\n"
391 "m=video 3227 RTP/AVP 31 \r\n"
392 "a=rtpmap:31 LPC "
393 "\r\n");
394
395 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
396
397 tassert_reset();
398
399 tassert(message->isRequest());
400 tassert(!message->isResponse());
401
402 tassert(message->header(h_RequestLine).getMethod() == INVITE);
403 tassert(message->header(h_RequestLine).getSipVersion() == "SIP/2.0");
404
405 tassert(message->header(h_RequestLine).uri().host() == "company.com");
406 tassert(message->header(h_RequestLine).uri().user() == "user");
407 tassert(message->header(h_RequestLine).uri().scheme() == "sip");
408 tassert(message->header(h_RequestLine).uri().port() == 0);
409 tassert(message->header(h_RequestLine).uri().password() == "");
410
411 tassert(message->header(h_To).uri().host() == "company.com");
412 tassert(message->header(h_To).uri().user() == "j_user");
413 tassert(message->header(h_To).uri().scheme() == "sip");
414 tassert(message->header(h_To).uri().port() == 0);
415 tassert(message->header(h_To).uri().password() == "");
416
417 tassert(message->header(h_From).uri().host() == "university.edu");
418 tassert(message->header(h_From).uri().user() == "caller");
419 tassert(message->header(h_From).uri().scheme() == "sip");
420 tassert(message->header(h_From).uri().port() == 0);
421 tassert(message->header(h_From).uri().password() == "");
422 // The tag is a tag on From: not the uri...
423 tassert(message->header(h_From).param(p_tag) == "234");
424
425 tassert(message->header(h_MaxForwards).value() == 5);
426
427 tassert(message->header(h_CallId).value() == "0ha0isndaksdj@10.0.0.1");
428
429 tassert(message->header(h_Accepts).size() == 1);
430 tassert(message->header(h_Accepts).front().type() == "text");
431 tassert(message->header(h_Accepts).front().subType() == "newformat");
432
433 tassert(message->header(h_CSeq).sequence() == 8);
434 tassert(message->header(h_CSeq).method() == INVITE);
435
436 tassert(message->header(h_Vias).size() == 1);
437 tassert(message->header(h_Vias).front().protocolName() == "SIP");
438 tassert(message->header(h_Vias).front().protocolVersion() == "2.0");
439 tassert(message->header(h_Vias).front().transport() == "UDP");
440 tassert(message->header(h_Vias).front().sentHost() == "135.180.130.133");
441 tassert(message->header(h_Vias).front().sentPort() == 0);
442 tassert(message->header(h_Vias).front().param(p_branch).hasMagicCookie());
443 // !ah! this should go away when parser fixed.
444 tassert(message->header(h_Vias).front().param(p_branch).getTransactionId() == "kdjuw");
445
446 tassert(message->header(h_ContentType).type() == "application");
447 tassert(message->header(h_ContentType).subType() == "sdp");
448
449 tassert_verify(5);
450 // .dlb. someday the body will gack on parse
451 }
452
453 void test6()
454 {
455 CritLog( << "2.6 INVITE with non-SDP message body ");
456
457 const char *txt = ("INVITE sip:user@company.com SIP/2.0\r\n"
458 "To: sip:j.user@company.com\r\n"
459 "From: sip:caller@university.edu;tag=8\r\n"
460 "Max-Forwards: 70 \r\n"
461 "Call-ID: 0ha0isndaksdj@10.0.0.1 \r\n"
462 "CSeq: 8 INVITE \r\n"
463 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw \r\n"
464 "Content-Type: application/newformat \r\n"
465 "\r\n"
466 "<audio> <pcmu port=\"443\"/> </audio> \r\n"
467 "\r\n");
468
469 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
470
471 tassert_reset();
472
473 tassert(message->isRequest());
474 tassert(!message->isResponse());
475
476 tassert(message->header(h_RequestLine).getMethod() == INVITE);
477 tassert(message->header(h_RequestLine).getSipVersion() == "SIP/2.0");
478
479 tassert(message->header(h_RequestLine).uri().host() == "company.com");
480 tassert(message->header(h_RequestLine).uri().user() == "user");
481 tassert(message->header(h_RequestLine).uri().scheme() == "sip");
482 tassert(message->header(h_RequestLine).uri().port() == 0);
483 tassert(message->header(h_RequestLine).uri().password() == "");
484
485 tassert(message->header(h_To).uri().host() == "company.com");
486 tassert(message->header(h_To).uri().user() == "j.user");
487 tassert(message->header(h_To).uri().scheme() == "sip");
488 tassert(message->header(h_To).uri().port() == 0);
489
490 tassert(message->header(h_From).uri().host() == "university.edu");
491 tassert(message->header(h_From).uri().user() == "caller");
492 tassert(message->header(h_From).uri().scheme() == "sip");
493 tassert(message->header(h_From).uri().port() == 0);
494
495 tassert(message->header(h_ContentType).type() == "application");
496 tassert(message->header(h_ContentType).subType() == "newformat");
497
498 // !jf! should send this to a UAS and it should be rejected (don't
499 // understand why) - says because it is not SDP
500
501 tassert_verify(6);
502 }
503
504
505 void test7()
506 {
507 CritLog( << "2.7 Unknown Method Message");
508
509 const char *txt = ("NEWMETHOD sip:user@company.com SIP/2.0 \r\n"
510 "To: sip:j.user@company.com \r\n"
511 "From: sip:caller@university.edu;tag=34525 \r\n"
512 "Max-Forwards: 6 \r\n"
513 "Call-ID: 0ha0isndaksdj@10.0.0.1 \r\n"
514 "CSeq: 8 NEWMETHOD \r\n"
515 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw \r\n"
516 "Content-Type: application/sdp \r\n"
517 "\r\n"
518 "v=0\r\n"
519 "o=mhandley 29739 7272939 IN IP4 126.5.4.3 \r\n"
520 "s=-\r\n"
521 "c=IN IP4 135.180.130.88\r\n"
522 "m=audio 492170 RTP/AVP 0 12\r\n"
523 "m=video 3227 RTP/AVP 31\r\n"
524 "a=rtpmap:31 LPC \r\n"
525 "\r\n");
526
527 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
528
529 tassert_reset();
530
531 tassert(message->isRequest());
532 tassert(!message->isResponse());
533
534 tassert(message->header(h_RequestLine).getMethod() == UNKNOWN);
535 tassert(message->header(h_RequestLine).unknownMethodName() == "NEWMETHOD");
536 tassert(message->header(h_RequestLine).getSipVersion() == "SIP/2.0");
537
538 tassert(message->header(h_RequestLine).uri().host() == "company.com");
539 tassert(message->header(h_RequestLine).uri().user() == "user");
540 tassert(message->header(h_RequestLine).uri().scheme() == "sip");
541 tassert(message->header(h_RequestLine).uri().port() == 0);
542 tassert(message->header(h_RequestLine).uri().password() == "");
543
544 tassert(message->header(h_To).uri().host() == "company.com");
545 tassert(message->header(h_To).uri().user() == "j.user");
546 tassert(message->header(h_To).uri().scheme() == "sip");
547 tassert(message->header(h_To).uri().port() == 0);
548
549 tassert(message->header(h_From).uri().host() == "university.edu");
550 tassert(message->header(h_From).uri().user() == "caller");
551 tassert(message->header(h_From).uri().scheme() == "sip");
552 tassert(message->header(h_From).uri().port() == 0);
553
554 tassert(message->header(h_ContentType).type() == "application");
555 tassert(message->header(h_ContentType).subType() == "sdp");
556
557 DebugLog( << "start map dump" );
558 HashMap<Mime, ContentsFactoryBase*>& m = ContentsFactoryBase::getFactoryMap();
559 HashMap<Mime, ContentsFactoryBase*>::iterator i;
560 i = m.begin();
561 while ( i != m.end() )
562 {
563 DebugLog( << "first=" << i->first );
564 i++;
565 }
566 DebugLog( << "done map dump" );
567
568 Contents* c = message->getContents();
569
570 SdpContents* sdp = dynamic_cast<SdpContents*>(c);
571
572 sdp->session();
573
574 DebugLog( << "got contents of type" << c->getType() );
575
576 // A proxy should forward this using the same retransmission rules as
577 // BYE. A UAS should reject it with an error, and list the available
578 // methods in the response.
579
580 tassert_verify(7);
581 }
582
583
584 void test8()
585 {
586 CritLog( << "2.8 Unknown Method with CSeq Error ");
587
588 const char *txt = ("NEWMETHOD sip:user@comapny.com SIP/2.0\r\n"
589 "To: sip:j.user@company.com\r\n"
590 "From: sip:caller@university.edu;tag=23411413\r\n"
591 "Max-Forwards: 3\r\n"
592 "Call-ID: 0ha0isndaksdj@10.0.1.1\r\n"
593 "CSeq: 8 INVITE\r\n"
594 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
595 "Content-Type: application/sdp\r\n"
596 "\r\n"
597 "v=0\r\n"
598 "o=mhandley 29739 7272939 IN IP4 126.5.4.3\r\n"
599 "s=-\r\n"
600 "c=IN IP4 135.180.130.88\r\n"
601 "t=0 0\r\n"
602 "m=audio 492170 RTP/AVP 0 12\r\n"
603 "m=video 3227 RTP/AVP 31\r\n"
604 "a=rtpmap:31 LPC\r\n");
605
606 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
607 tassert_reset();
608 tassert(message->isRequest());
609 tassert(!message->isResponse());
610
611 tassert(message->header(h_RequestLine).getMethod() == UNKNOWN);
612 tassert(message->header(h_RequestLine).unknownMethodName() == "NEWMETHOD");
613 tassert(message->header(h_CSeq).method() == INVITE);
614 tassert(message->header(h_CSeq).method() != message->header(h_RequestLine).getMethod());
615 tassert_verify(8);
616 }
617
618 void test9()
619 {
620 CritLog( << "2.9 REGISTER with Unknown Authorization Scheme" );
621
622 const char* txt = ("REGISTER sip:company.com SIP/2.0\r\n"
623 "To: sip:j.user@company.com\r\n"
624 "From: sip:j.user@company.com;tag=87321hj23128\r\n"
625 "Max-Forwards: 8\r\n"
626 "Call-ID: 0ha0isndaksdj@10.0.1.1\r\n"
627 "CSeq: 8 REGISTER\r\n"
628 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
629 "Authorization: Super-PGP foo=ajsohdaosdh0asyhdaind08yasdknasd09asidhas0d8\r\n\r\n");
630 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
631 tassert_reset();
632 tassert(message->isRequest());
633 tassert(!message->isResponse());
634
635 tassert(message->header(h_RequestLine).getMethod() == REGISTER);
636 tassert(message->header(h_Authorizations).front().scheme() == "Super-PGP");
637 tassert_verify(9);
638 }
639
640
641 void test10()
642 {
643 CritLog( << "2.10 Multiple SIP Request in a Single Message");
644
645 const char* txt = ("REGISTER sip:company.com SIP/2.0\r\n"
646 "To: sip:j.user@company.com\r\n"
647 "From: sip:j.user@company.com;tag=43251j3j324\r\n"
648 "Max-Forwards: 8\r\n"
649 "Call-ID: 0ha0isndaksdj@10.0.2.2\r\n"
650 "Contact: sip:j.user@host.company.com\r\n"
651 "CSeq: 8 REGISTER\r\n"
652 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
653 "Content-Length: 0\r\n\r\n"
654 "INVITE sip:joe@company.com SIP/2.0\r\n"
655 "To: sip:joe@company.com\r\n"
656 "From: sip:caller@university.edu;tag=141334\r\n"
657 "Max-Forwards: 8\r\n"
658 "Call-ID: 0ha0isnda977644900765@10.0.0.1\r\n"
659 "CSeq: 8 INVITE\r\n"
660 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
661 "Content-Type: application/sdp\r\n"
662 "\r\n"
663 "v=0\r\n"
664 "o=mhandley 29739 7272939 IN IP4 126.5.4.3\r\n"
665 "s=-\r\n"
666 "c=IN IP4 135.180.130.88\r\n"
667 "t=0 0\r\n"
668 "m=audio 492170 RTP/AVP 0 12\r\n"
669 "m =video 3227 RTP/AVP 31\r\n"
670 "a=rtpmap:31 LPC\r\n"
671 "\r\n");
672 tassert_reset();
673 try
674 {
675 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
676 tassert(0);
677 }
678 catch (ParseException& e)
679 {
680 }
681
682 tassert_verify(10);
683 }
684
685 void test11()
686 {
687 CritLog( << "2.11 INVITE missing Required Headers");
688
689 const char* txt = ("INVITE sip:user@company.com SIP/2.0\r\n"
690 "CSeq: 0 INVITE\r\n"
691 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
692 "Content-Type: application/sdp\r\n"
693 "\r\n"
694 "v=0\r\n"
695 "o=mhandley 29739 7272939 IN IP4 126.5.4.3\r\n"
696 "s=-\r\n"
697 "c=IN IP4 135.180.130.88\r\n"
698 "t=0 0\r\n"
699 "m=audio 492170 RTP/AVP 0 12\r\n"
700 "m=video 3227 RTP/AVP 31\r\n"
701 "a=rtpmap:31 LPC\r\n"
702 "\r\n");
703 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
704 tassert_reset();
705 tassert(message->isRequest());
706 tassert(!message->isResponse());
707
708 tassert(!message->exists(h_CallId));
709 tassert(!message->exists(h_From));
710 tassert(!message->exists(h_To));
711 tassert_verify(11);
712 }
713
714 void test12()
715 {
716 CritLog( << "2.12 INVITE with Duplicate Required Headers");
717 //with duplicate headers that are not multi, the first header is kept
718
719 const char* txt = ("INVITE sip:user@company.com SIP/2.0\r\n"
720 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
721 "Max-Forwards: 70\r\n"
722 "CSeq: 0 INVITE\r\n"
723 "Call-ID: 98asdh@10.1.1.1\r\n"
724 "Call-ID: 98asdh@10.1.1.2\r\n"
725 "From: sip:caller@university.edu;tag=3413415\r\n"
726 "From: sip:caller@organization.org\r\n"
727 "To: sip:user@company.com\r\n"
728 "Content-Type: application/sdp\r\n"
729 "\r\n"
730 "v=0\r\n"
731 "o=mhandley 29739 7272939 IN IP4 126.5.4.3\r\n"
732 "s=-\r\n"
733 "c=IN IP4 135.180.130.88\r\n"
734 "t=0 0\r\n"
735 "m=audio 492170 RTP/AVP 0 12\r\n"
736 "m=video 3227 RTP/AVP 31\r\n"
737 "a=rtpmap:31 LPC\r\n"
738 "\r\n");
739
740 tassert_reset();
741 try
742 {
743 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
744 }
745 catch (ParseException& e)
746 {
747 tassert(0);
748 }
749 tassert_verify(12);
750 }
751
752
753 void test13()
754 {
755 CritLog( << "2.13 INVITE with lots of header types");
756 //with duplicate headers that are not multi, the first header is kept
757
758 const char* txt = ("INVITE sip:user@company.com SIP/2.0\r\n"
759 "User-Agent: Lame Agent\r\n"
760 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
761 "Max-Forwards: 70\r\n"
762 "CSeq: 0 INVITE\r\n"
763 "Call-ID: 98asdh@10.1.1.2\r\n"
764 "From: sip:caller@university.edu;tag=3413415\r\n"
765 "From: sip:caller@organization.org\r\n"
766 "To: sip:user@company.com\r\n"
767 "Content-Type: application/sdp\r\n"
768 "\r\n"
769 "v=0\r\n"
770 "o=mhandley 29739 7272939 IN IP4 126.5.4.3\r\n"
771 "s=-\r\n"
772 "c=IN IP4 135.180.130.88\r\n"
773 "t=0 0\r\n"
774 "m=audio 492170 RTP/AVP 0 12\r\n"
775 "m=video 3227 RTP/AVP 31\r\n"
776 "a=rtpmap:31 LPC\r\n"
777 "\r\n");
778
779 tassert_reset();
780 try
781 {
782 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
783
784 tassert(message->header(h_UserAgent).value() == "Lame Agent");
785 message->header(h_UserAgent).value() = "Foo";
786 tassert(message->header(h_UserAgent).value() == "Foo");
787 }
788 catch (ParseException& e)
789 {
790 tassert(0);
791 }
792 tassert_verify(13);
793 }
794
795
796 void test14()
797 {
798 CritLog( << "2.14 Response with lots of headers");
799
800 const char* txt = ("SIP/2.0 200 OK\r\n"
801 "To: <sip:fluffy@example.org>;tag=fb86ad2694115d75c77dce61523c9f07.ca6e\r\n"
802 "From: <sip:fluffy@example.org>;tag=a1fd\r\n"
803 "Via: SIP/2.0/UDP cj14:5002;branch=z9hG4bK-c87542-472987176-1;received=1.2.3.4\r\n"
804 "Call-ID: 048cec32\r\n"
805 "CSeq: 2 REGISTER\r\n"
806 "Contact: <sip:fluffy@1.2.3.4:5002>;q=1.00;expires=1951\r\n"
807 "Contact: <sip:fluffy@example.com:5002>;q=0.50;expires=10\r\n"
808 "Contact: <sip:floppy@example.com:5002>;q=0.00;expires=100\r\n"
809 "Server: The Server\r\n"
810 "Content-Length: 0\r\n"
811 "Warning: junk junk junk \r\n"
812 "\r\n");
813
814 tassert_reset();
815 try
816 {
817 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt));
818
819 tassert( msg->header(h_Contacts).size() == 3 );
820
821 resip::ParserContainer<resip::NameAddr>::iterator i = msg->header(h_Contacts).begin();
822 while ( i != msg->header(h_Contacts).end() )
823 {
824 DebugLog(<< "i=" << *i );
825 i++;
826 }
827 }
828 catch (ParseException& e)
829 {
830 }
831 tassert_verify(14);
832 }
833
834
835 void test15()
836 {
837 CritLog( << "2.15 Interesting bodies");
838
839 const char* txt = (
840 "NOTIFY sip:fluffy@212.157.205.40 SIP/2.0\r\n"
841 "Via: SIP/2.0/TCP 212.157.205.198:5060;branch=z9hG4bK2367411811584019109\r\n"
842 "To: sip:fluffy@212.157.205.40\r\n"
843 "From: sip:ntt2@h1.ntt2.sipit.net;tag=727823805122397238\r\n"
844 "Max-Forwards: 70\r\n"
845 "CSeq: 1 NOTIFY\r\n"
846 "Call-ID: 28067261571992032320\r\n"
847 "Contact: sip:ntt2@212.157.205.198:5060\r\n"
848 "Content-Length: 1929\r\n"
849 "Content-Type: multipart/signed;\r\n"
850 " protocol=\"application/pkcs7-signature\";\r\n"
851 " micalg=sha1; boundary=\"----YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\"\r\n"
852 "\r\n"
853 "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\r\n"
854 "Content-Type: multipart/mixed;boundary=\"----lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\"\r\n"
855 "Content-Length: 870\r\n"
856 "Content-Disposition: attachment;handling=required\r\n"
857 "\r\n"
858 "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\r\n"
859 "Content-Type: application/sipfrag\r\n"
860 "Content-Length: 320\r\n"
861 "\r\n"
862 "To: sip:fluffy@212.157.205.40\r\n"
863 "From: sip:ntt2@h1.ntt2.sipit.net;tag=727823805122397238\r\n"
864 "CSeq: 1 NOTIFY\r\n"
865 "Call-ID: 28067261571992032320\r\n"
866 "Contact: sip:ntt2@212.157.205.198:5060\r\n"
867 "Event: presence\r\n"
868 "Content-Length: 210\r\n"
869 "Content-Type: application/xpidf+xml\r\n"
870 "Subscription-State: active\r\n"
871 "User-Agent: NTT SecureSession User-Agent\r\n"
872 "\r\n"
873 "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\r\n"
874 "Content-Type: application/xpidf+xml\r\n"
875 "Content-Length: 210\r\n"
876 "\r\n"
877 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
878 "<presence xmlns:impp=\"urn:ietf:params:xml:ns:pidf\" entity=\"pres:someone@example.com\">\r\n"
879 "<tuple id=\"765\">\r\n"
880 "<status>\r\n"
881 "<basic>open</basic>\r\n"
882 "</status>\r\n"
883 "</tuple>\r\n"
884 "</presence>\r\n"
885 "\r\n"
886 "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY--\r\n"
887 "\r\n"
888 "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\r\n"
889 "Content-Type: application/pkcs7-signature; name=\"smime.p7s\"\r\n"
890 "Content-Transfer-Encoding: base64\r\n"
891 "Content-Disposition: attachment; filename=\"smime.p7s\"; handling=required\r\n"
892 "\r\n"
893 "MIIBVgYJKoZIhvcNAQcCoIIBRzCCAUMCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3\r\n"
894 "DQEHATGCASIwggEeAgEBMHwwcDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlm\r\n"
895 "b3JuaWExETAPBgNVBAcTCFNhbiBKb3NlMQ4wDAYDVQQKEwVzaXBpdDEpMCcGA1UE\r\n"
896 "CxMgU2lwaXQgVGVzdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkCCAIWABUCBgIVMAkG\r\n"
897 "BSsOAwIaBQAwDQYJKoZIhvcNAQEBBQAEgYAer8TPSMtA3ZqweGnXLUYKR51bp52N\r\n"
898 "oGBEqHZz7xR0Nhs6DsAOXiSFv19vTR//33u6Se3zpNNHP/zj7NRr+olimI2PeBNB\r\n"
899 "tczNdqexoN0pjRW7l7mHZ0e39pqZmI5bhFl+z9CJJu5xW0aSarw84CZxbh5RQaYr\r\n"
900 "zhSvTYdki20aiQ==\r\n"
901 "\r\n"
902 "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC--\r\n"
903 );
904
905 tassert_reset();
906 try
907 {
908 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt));
909
910 }
911 catch (ParseException& e)
912 {
913 }
914 tassert_verify(15);
915 }
916
917
918 int
919 main(int argc, const char*argv[])
920 {
921 Log::Level l = Log::Debug;
922
923 if (argc > 1)
924 {
925 switch(*argv[1])
926 {
927 case 'd': l = Log::Debug;
928 break;
929 case 'i': l = Log::Info;
930 break;
931 case 's': l = Log::Stack;
932 break;
933 case 'c': l = Log::Crit;
934 break;
935 }
936 }
937
938 Log::initialize(Log::Cout, l, argv[0]);
939 CritLog(<<"Test Driver Starting");
940 tassert_init(14);
941 test1();
942 test2();
943 test3();
944 test4();
945 test5();
946 test6();
947 test7();
948 test8();
949 test9();
950 test10();//this should fail as written
951 test11();
952 test12();
953 test13();
954 test14();
955
956
957 tassert_report();
958
959 CritLog(<<"Test Driver Done");
960 }
961
962 /* ====================================================================
963 * The Vovida Software License, Version 1.0
964 *
965 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
966 *
967 * Redistribution and use in source and binary forms, with or without
968 * modification, are permitted provided that the following conditions
969 * are met:
970 *
971 * 1. Redistributions of source code must retain the above copyright
972 * notice, this list of conditions and the following disclaimer.
973 *
974 * 2. Redistributions in binary form must reproduce the above copyright
975 * notice, this list of conditions and the following disclaimer in
976 * the documentation and/or other materials provided with the
977 * distribution.
978 *
979 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
980 * and "Vovida Open Communication Application Library (VOCAL)" must
981 * not be used to endorse or promote products derived from this
982 * software without prior written permission. For written
983 * permission, please contact vocal@vovida.org.
984 *
985 * 4. Products derived from this software may not be called "VOCAL", nor
986 * may "VOCAL" appear in their name, without prior written
987 * permission of Vovida Networks, Inc.
988 *
989 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
990 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
991 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
992 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
993 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
994 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
995 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
996 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
997 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
998 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
999 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
1000 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1001 * DAMAGE.
1002 *
1003 * ====================================================================
1004 *
1005 * This software consists of voluntary contributions made by Vovida
1006 * Networks, Inc. and many individuals on behalf of Vovida Networks,
1007 * Inc. For more information on Vovida Networks, Inc., please see
1008 * <http://www.vovida.org/>.
1009 *
1010 */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27