File: 23_valid_message.t

package info (click to toggle)
libnet-sip-perl 0.838-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,132 kB
  • sloc: perl: 11,988; makefile: 6
file content (124 lines) | stat: -rw-r--r-- 2,570 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/perl

use strict;
use warnings;
use Test::More;

use Net::SIP::Packet;
use Net::SIP::Request;
use Net::SIP::Response;

check(undef, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 10 INVITE
Content-length: 0

REQ

check(qr/method in cseq does not match method of request/, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 10 BYE
Content-length: 0

REQ

check(qr/conflicting definition of cseq/, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 10 INVITE
Cseq: 20 INVITE
Content-length: 0

REQ

check(qr/conflicting definition of call-id/, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 20 INVITE
Call-Id: barfoot@example.com
Content-length: 0

REQ

check(qr/conflicting definition of content-length/, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 20 INVITE
Content-length: 0
Content-length: 10

REQ

check(qr/conflicting definition of from/, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 20 INVITE
Content-length: 0
From: <sip:foo@example.com>

REQ

check(qr/conflicting definition of to/, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 20 INVITE
Content-length: 0
To: <sip:foo@example.com>

REQ

check(undef, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 20 INVITE
Content-length: 0
Contact: <sip:foo@example.com>
Contact: <sip:bar@example.com>

REQ

check(undef, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com[123]
Cseq: 20 INVITE
Content-length: 0
Contact: <sip:foo@example.com>

REQ

# Don't try to parse a headers keepalive packet of null chars
check(qr/empty packet/, "\r\n\r\n" . (chr(hex('00')) x 12));

done_testing();

sub check {
    my ($expect_err,$string) = @_;
    my $pkt = eval { Net::SIP::Packet->new($string) };
    # diag($@ ? "error: $@": "no error");
    if (! $expect_err) {
	ok($pkt,'valid message');
    } else {
	like($@, $expect_err, "expected error: $expect_err");
    }
    # diag($pkt->as_string) if $pkt;
}