opensips-mi 0.0.5 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.travis.yml +1 -1
- data/Gemfile +4 -6
- data/README.md +4 -1
- data/Rakefile +3 -7
- data/lib/opensips/mi/command.rb +4 -9
- data/lib/opensips/mi/response.rb +65 -36
- data/lib/opensips/mi/transport/datagram.rb +14 -2
- data/lib/opensips/mi/transport/fifo.rb +4 -4
- data/lib/opensips/mi/version.rb +1 -1
- data/opensips-mi.gemspec +17 -15
- data/spec/command_spec.rb +4 -0
- data/{test → spec}/fixtures/dlg_list +0 -0
- data/{test → spec}/fixtures/ul_dump +0 -0
- data/spec/response_spec.rb +117 -0
- data/spec/spec_helper.rb +112 -0
- data/spec/transport_spec.rb +119 -0
- metadata +54 -40
- data/test/helper.rb +0 -89
- data/test/test_command.rb +0 -118
- data/test/test_response.rb +0 -124
- data/test/test_transport.rb +0 -209
data/test/test_command.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
include Opensips::MI
|
3
|
-
|
4
|
-
describe Command, "commands for transport classes" do
|
5
|
-
before do
|
6
|
-
end
|
7
|
-
|
8
|
-
after do
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "missing methods" do
|
12
|
-
it "must raise if parameter is not Array" do
|
13
|
-
mi = init_class_fifo
|
14
|
-
mi.expects(:command).with('which').returns(mock(:rawdata => ['meth1', 'meth2']))
|
15
|
-
proc {
|
16
|
-
mi.unknown_command
|
17
|
-
}.must_raise NoMethodError
|
18
|
-
end
|
19
|
-
|
20
|
-
it "must send command" do
|
21
|
-
mi = init_class_fifo
|
22
|
-
mi.expects(:command).with('which').returns(Opensips::MI::Response.new(response_data_cmd_which))
|
23
|
-
mi.expects(:command).with('ul_sync',[]).returns(Opensips::MI::Response.new(["200 OK",""]))
|
24
|
-
mi.ul_sync.code.must_equal 200
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
it "must raise when missing basic mandatory headers" do
|
29
|
-
mi = init_class_fifo
|
30
|
-
ret = proc {
|
31
|
-
mi.uac_dlg "NOTIFY",
|
32
|
-
"sip:alice@wanderland.com",
|
33
|
-
{"From" => "<sip:opensips@sipproxy.com>"}
|
34
|
-
}.must_raise ArgumentError
|
35
|
-
ret.message.must_match(/header To/)
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
it "must raise when missing body mandatory headers" do
|
40
|
-
mi = init_class_fifo
|
41
|
-
ret = proc {
|
42
|
-
mi.uac_dlg "NOTIFY",
|
43
|
-
"sip:alice@wanderland.com",
|
44
|
-
{"From" => "<sip:opensips>", "To" => "<sip:bob>", "content-type" => "xml"},
|
45
|
-
?., ?., "<body>Hello</body>"
|
46
|
-
}.must_raise ArgumentError
|
47
|
-
ret.message.must_match(/header Content-length/)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "must have good parameters" do
|
51
|
-
mi = init_class_fifo
|
52
|
-
mi.expects(:command).with('t_uac_dlg', [
|
53
|
-
"NOTIFY",
|
54
|
-
"sip:alice@wanderland.com",
|
55
|
-
".",
|
56
|
-
".",
|
57
|
-
%Q/"From: <sip:opensips@sipproxy.com>\r\nTo: <sip:alice@wanderland.com>\r\n"/
|
58
|
-
])
|
59
|
-
mi.uac_dlg "NOTIFY",
|
60
|
-
"sip:alice@wanderland.com",
|
61
|
-
{
|
62
|
-
"From" => "<sip:opensips@sipproxy.com>",
|
63
|
-
"To" => "<sip:alice@wanderland.com>"
|
64
|
-
}
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
it "must raise when invalid event" do
|
69
|
-
mi = init_class_fifo
|
70
|
-
event = :unknown_event
|
71
|
-
res = proc {
|
72
|
-
mi.event_notify "sip:alice@proxy.com", event
|
73
|
-
}.must_raise ArgumentError
|
74
|
-
res.message.must_match(/#{event.to_s}/)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "must send notify event" do
|
78
|
-
mi = init_class_fifo
|
79
|
-
tag = "123456"
|
80
|
-
uri = "sip:alice@wanderland.com"
|
81
|
-
SecureRandom.stubs(:hex).returns(tag)
|
82
|
-
mi.expects(:uac_dlg).with("NOTIFY",
|
83
|
-
uri,
|
84
|
-
{
|
85
|
-
"To" => "<#{uri}>",
|
86
|
-
"From" => "<#{uri}>;tag=#{tag}",
|
87
|
-
"Event" => "check-sync"
|
88
|
-
}
|
89
|
-
)
|
90
|
-
mi.event_notify uri, :polycom_check_cfg
|
91
|
-
end
|
92
|
-
|
93
|
-
it "must send MWI notify" do
|
94
|
-
mi = init_class_fifo
|
95
|
-
tag = "123456"
|
96
|
-
uri = "sip:alice@wanderland.com"
|
97
|
-
new_vm = 5
|
98
|
-
old_vm = 3
|
99
|
-
SecureRandom.stubs(:hex).returns(tag)
|
100
|
-
mi.expects(:uac_dlg).with("NOTIFY",
|
101
|
-
uri,
|
102
|
-
{
|
103
|
-
'To' => "<#{uri}>",
|
104
|
-
'From' => "<#{uri}>;tag=#{tag}",
|
105
|
-
'Event' => 'message-summary',
|
106
|
-
'Subscription-State' => 'active',
|
107
|
-
'Content-Type' => 'application/simple-message-summary',
|
108
|
-
'Content-Length' => 86,
|
109
|
-
'nl' => '',
|
110
|
-
'Messages-Waiting' => 'yes',
|
111
|
-
'Message-Account' => 'sip:*97@asterisk.com',
|
112
|
-
'Voice-Message' => "#{new_vm}/#{old_vm} (0/0)"
|
113
|
-
})
|
114
|
-
mi.mwi_update uri, 'sip:*97@asterisk.com', new_vm, old_vm
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
118
|
-
end
|
data/test/test_response.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
include Opensips::MI
|
3
|
-
|
4
|
-
describe Response, "response class" do
|
5
|
-
before do
|
6
|
-
@which = response_data_cmd_which
|
7
|
-
@data_ok = ["200 it is OK", "data", ""]
|
8
|
-
@data_nok = ["500 command 'unknown' not available"]
|
9
|
-
end
|
10
|
-
|
11
|
-
after do
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "processing response" do
|
15
|
-
it "must raise if parameter is not Array" do
|
16
|
-
proc {
|
17
|
-
Response.new "String"
|
18
|
-
}.must_raise InvalidResponseData
|
19
|
-
end
|
20
|
-
|
21
|
-
it "must raise if response data id empty array" do
|
22
|
-
proc {
|
23
|
-
Response.new Array[]
|
24
|
-
}.must_raise EmptyResponseData
|
25
|
-
end
|
26
|
-
|
27
|
-
it "must return Response class" do
|
28
|
-
r = Response.new(@data_ok)
|
29
|
-
r.must_be_instance_of Response
|
30
|
-
end
|
31
|
-
|
32
|
-
it "must raise if invalid response data" do
|
33
|
-
proc {
|
34
|
-
Response.new(["invalid param","343",222])
|
35
|
-
}.must_raise InvalidResponseData
|
36
|
-
end
|
37
|
-
|
38
|
-
it "must parse successfull response" do
|
39
|
-
r = Response.new(@data_ok)
|
40
|
-
r.success.must_equal true
|
41
|
-
r.code.must_equal 200
|
42
|
-
r.message.must_equal "it is OK"
|
43
|
-
end
|
44
|
-
|
45
|
-
it "must parse unsuccessfull response" do
|
46
|
-
r = Response.new(@data_nok)
|
47
|
-
r.success.must_equal false
|
48
|
-
r.code.must_equal 500
|
49
|
-
r.message.must_equal "command 'unknown' not available"
|
50
|
-
end
|
51
|
-
|
52
|
-
it "parse ul dump response" do
|
53
|
-
res = Response.new(response_uldump)
|
54
|
-
ul = res.ul_dump
|
55
|
-
ul.result["7962"].wont_equal nil
|
56
|
-
ul.result["7962"]['Callid'].must_equal "5e7a1e47da91c41c"
|
57
|
-
end
|
58
|
-
|
59
|
-
it "process uptime response" do
|
60
|
-
res = Response.new [
|
61
|
-
"200 OK",
|
62
|
-
"Now:: Fri Apr 12 22:04:27 2013",
|
63
|
-
"Up since:: Thu Apr 11 21:43:01 2013",
|
64
|
-
"Up time:: 87686 [sec]",
|
65
|
-
""
|
66
|
-
]
|
67
|
-
response = res.uptime
|
68
|
-
response.result.uptime.must_equal 87686
|
69
|
-
response.result.since.thursday?.must_equal true
|
70
|
-
response.result.since.hour.must_equal 21
|
71
|
-
response.result.since.mon.must_equal 4
|
72
|
-
end
|
73
|
-
|
74
|
-
it "must fetch cache value" do
|
75
|
-
res = Response.new [
|
76
|
-
"200 OK",
|
77
|
-
"userdid = [18005552211]",
|
78
|
-
""
|
79
|
-
]
|
80
|
-
response = res.cache_fetch
|
81
|
-
response.result.userdid.must_equal "18005552211"
|
82
|
-
end
|
83
|
-
|
84
|
-
it "must return userloc contacts" do
|
85
|
-
response = Response.new response_contacts
|
86
|
-
res = response.ul_show_contact.result
|
87
|
-
res.must_be_instance_of Array
|
88
|
-
res.size.must_equal 2
|
89
|
-
res.first[:socket].must_equal "<udp:10.130.8.21:5060>"
|
90
|
-
res.last[:expires].must_equal "3593"
|
91
|
-
end
|
92
|
-
|
93
|
-
it "must process dialogs list" do
|
94
|
-
response = Response.new response_dlg_list
|
95
|
-
res = response.dlg_list.result
|
96
|
-
res.size.must_equal 1
|
97
|
-
res["3212:2099935485"][:callid].must_equal "1854719653"
|
98
|
-
end
|
99
|
-
|
100
|
-
it "must process dr_gw_status response in hash" do
|
101
|
-
response = Response.new response_dr_gw_status_list
|
102
|
-
drgws = response.dr_gw_status
|
103
|
-
drgws.result.size.must_equal 8
|
104
|
-
drgws.result["pstn4"][:ipaddr].must_equal "199.18.12.104"
|
105
|
-
drgws.result["pstn3"][:port].must_equal "5060"
|
106
|
-
drgws.result["gw1"][:enabled].must_equal false
|
107
|
-
drgws.result["gw4"][:enabled].must_equal true
|
108
|
-
end
|
109
|
-
|
110
|
-
it "must return raw data if dr_gw_status is run with arguments" do
|
111
|
-
response = Response.new response_dr_gw_status_single
|
112
|
-
drgws = response.dr_gw_status
|
113
|
-
drgws.enabled.must_equal true
|
114
|
-
end
|
115
|
-
|
116
|
-
it "result must be empty if command send to dr_gw_status" do
|
117
|
-
response = Response.new response_dr_gw_status_cmd
|
118
|
-
drgws = response.dr_gw_status
|
119
|
-
drgws.result.must_equal nil
|
120
|
-
drgws.success.must_equal true
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
data/test/test_transport.rb
DELETED
@@ -1,209 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Opensips::MI::Transport, "testing MI transport layers" do
|
4
|
-
before do
|
5
|
-
@fifo_params = {:fifo_name => '/tmp/opensips_fifo'}
|
6
|
-
end
|
7
|
-
|
8
|
-
after do
|
9
|
-
end
|
10
|
-
|
11
|
-
# Fifo
|
12
|
-
describe "test fifo transport layer" do
|
13
|
-
it "must retrun fifo class instance" do
|
14
|
-
File.stubs(:exists?).once.returns(true)
|
15
|
-
File.stubs(:pipe?).twice.returns(true)
|
16
|
-
Kernel.stubs(:system).returns(true)
|
17
|
-
Opensips::MI.connect(:fifo,@fifo_params).must_be_instance_of Opensips::MI::Transport::Fifo
|
18
|
-
end
|
19
|
-
|
20
|
-
it "must raise when using unknown transport method" do
|
21
|
-
proc {
|
22
|
-
Opensips::MI.connect(:unknown_transport_method,{})
|
23
|
-
}.must_raise NameError
|
24
|
-
end
|
25
|
-
|
26
|
-
it "must raise when no fifo_nameInstanceOf.new parameter passed" do
|
27
|
-
proc {
|
28
|
-
Opensips::MI.connect :fifo, {}
|
29
|
-
}.must_raise ArgumentError
|
30
|
-
end
|
31
|
-
|
32
|
-
it "must raise when fifo_name file not exists" do
|
33
|
-
File.stubs(:exists?).once.returns(false)
|
34
|
-
proc {
|
35
|
-
Opensips::MI.connect :fifo, :fifo_name => '/file/not/exists'
|
36
|
-
}.must_raise ArgumentError
|
37
|
-
end
|
38
|
-
|
39
|
-
it "must raise when fifo_name file is not pipe" do
|
40
|
-
File.stubs(:exists?).once.returns(true)
|
41
|
-
File.stubs(:pipe?).once.returns(false)
|
42
|
-
proc {
|
43
|
-
Opensips::MI.connect :fifo, :fifo_name => '/tmp/opensips_fifo'
|
44
|
-
}.must_raise ArgumentError
|
45
|
-
end
|
46
|
-
|
47
|
-
it "must raise if fifo reply directory not exists" do
|
48
|
-
Dir.stubs(:exists?).once.returns false
|
49
|
-
proc {
|
50
|
-
Opensips::MI.connect :fifo, :fifo_name => '/tmp/opensips_fifo',
|
51
|
-
:reply_dir => '/tmp'
|
52
|
-
}.must_raise ArgumentError
|
53
|
-
end
|
54
|
-
|
55
|
-
it "must set attributes for class instance" do
|
56
|
-
Dir.stubs(:exists?).once.returns(true)
|
57
|
-
File.stubs(:exists?).once.returns(true)
|
58
|
-
File.stubs(:pipe?).once.returns(true)
|
59
|
-
directory = '/tmp/opensips/fifo'
|
60
|
-
fifo_name = '/tmp/opensips_fifo'
|
61
|
-
replayfifo= 'fifo_reply_file_name'
|
62
|
-
fifo = Opensips::MI::Transport::Fifo.new :fifo_name => fifo_name,
|
63
|
-
:reply_dir => directory,
|
64
|
-
:reply_fifo => replayfifo
|
65
|
-
fifo.reply_dir.must_equal directory
|
66
|
-
fifo.fifo_name.must_equal fifo_name
|
67
|
-
fifo.reply_dir.must_equal directory
|
68
|
-
end
|
69
|
-
|
70
|
-
it "must create temporary fifo reply file" do
|
71
|
-
fifo = init_class_fifo
|
72
|
-
Kernel.stubs(:system).returns(true)
|
73
|
-
File.stubs(:pipe?).returns(true)
|
74
|
-
fifo.open
|
75
|
-
end
|
76
|
-
|
77
|
-
it "must raise if can not create reply fifo" do
|
78
|
-
fifo = init_class_fifo
|
79
|
-
Kernel.stubs(:system).returns(true)
|
80
|
-
File.stubs(:pipe?).returns(false)
|
81
|
-
proc { fifo.open }.must_raise SystemCallError
|
82
|
-
end
|
83
|
-
|
84
|
-
it "must send command to fifo" do
|
85
|
-
File.stubs(:exists?).returns(true)
|
86
|
-
File.stubs(:pipe?).returns(true)
|
87
|
-
IO.stubs(:sysopen).returns(5)
|
88
|
-
io_obj = mock()
|
89
|
-
io_obj.expects(:close).twice()
|
90
|
-
io_obj.expects(:syswrite)
|
91
|
-
io_obj.expects(:gets).returns(nil)
|
92
|
-
IO.stubs(:open).twice().returns(io_obj)
|
93
|
-
Opensips::MI::Response.expects(:new).returns(true)
|
94
|
-
|
95
|
-
fifo = Opensips::MI.connect(:fifo,@fifo_params)
|
96
|
-
fifo.command('which')
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
100
|
-
# Datagram
|
101
|
-
describe "test datagram transport layer" do
|
102
|
-
it "must raise if empty host" do
|
103
|
-
proc {
|
104
|
-
Opensips::MI.connect :datagram, {}
|
105
|
-
}.must_raise ArgumentError
|
106
|
-
end
|
107
|
-
|
108
|
-
it "must raise if empty port" do
|
109
|
-
proc {
|
110
|
-
Opensips::MI.connect :datagram, {:host => "10.10.10.10"}
|
111
|
-
}.must_raise ArgumentError
|
112
|
-
end
|
113
|
-
|
114
|
-
it "must raise if invalid host" do
|
115
|
-
host = "256.0.0.300"
|
116
|
-
res = proc {
|
117
|
-
Opensips::MI.connect :datagram, {:host => host, :port => 8088}
|
118
|
-
}.must_raise SocketError
|
119
|
-
res.message.must_match(/#{host}/)
|
120
|
-
end
|
121
|
-
|
122
|
-
it "must raise if invalid port" do
|
123
|
-
proc {
|
124
|
-
Opensips::MI.connect :datagram, {:host => "10.0.0.1", :port => (2**16 + 1)}
|
125
|
-
}.must_raise SocketError
|
126
|
-
|
127
|
-
proc {
|
128
|
-
Opensips::MI.connect :datagram, {:host => "10.0.0.1", :port => 0}
|
129
|
-
}.must_raise SocketError
|
130
|
-
end
|
131
|
-
|
132
|
-
it "must connect to socket" do
|
133
|
-
UDPSocket.expects(:new).returns(mock(:connect => true))
|
134
|
-
res = Opensips::MI.connect :datagram,
|
135
|
-
:host => "192.168.122.128",
|
136
|
-
:port => 8809
|
137
|
-
res.respond_to?(:uac_dlg).must_equal true
|
138
|
-
end
|
139
|
-
|
140
|
-
it "must send valid command to socket" do
|
141
|
-
cmd = 'command'
|
142
|
-
params = ["aaa","bbb","ccc"]
|
143
|
-
|
144
|
-
sock = mock('UDPSocket')
|
145
|
-
sock.stubs(:connect)
|
146
|
-
sock.stubs(:send).with([":#{cmd}:", *params].join(?\n) + ?\n, 0)
|
147
|
-
sock.stubs(:recvfrom).returns( response_data_cmd_which )
|
148
|
-
UDPSocket.expects(:new).returns(sock)
|
149
|
-
res = Opensips::MI.connect :datagram,
|
150
|
-
:host => "192.168.122.128",
|
151
|
-
:port => 8809
|
152
|
-
res.command(cmd, params).code.must_equal 200
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
# XMLRPC
|
158
|
-
describe "test xmlrpc transport layer" do
|
159
|
-
it "must raise if empty host" do
|
160
|
-
proc {
|
161
|
-
Opensips::MI.connect :xmlrpc, {}
|
162
|
-
}.must_raise ArgumentError
|
163
|
-
end
|
164
|
-
|
165
|
-
it "must raise if empty port" do
|
166
|
-
proc {
|
167
|
-
Opensips::MI.connect :xmlrpc, {:host => "10.10.10.10"}
|
168
|
-
}.must_raise ArgumentError
|
169
|
-
end
|
170
|
-
|
171
|
-
it "must raise if invalid host" do
|
172
|
-
host = "256.0.0.300"
|
173
|
-
res = proc {
|
174
|
-
Opensips::MI.connect :xmlrpc, {:host => host, :port => 8088}
|
175
|
-
}.must_raise SocketError
|
176
|
-
res.message.must_match(/#{host}/)
|
177
|
-
end
|
178
|
-
|
179
|
-
it "must raise if invalid port" do
|
180
|
-
proc {
|
181
|
-
Opensips::MI.connect :xmlrpc, {:host => "10.0.0.1", :port => (2**16 + 1)}
|
182
|
-
}.must_raise SocketError
|
183
|
-
|
184
|
-
proc {
|
185
|
-
Opensips::MI.connect :xmlrpc, {:host => "10.0.0.1", :port => 0}
|
186
|
-
}.must_raise SocketError
|
187
|
-
end
|
188
|
-
|
189
|
-
it "must connect to xmlrpc server" do
|
190
|
-
host = "192.168.122.128"
|
191
|
-
port = 8080
|
192
|
-
rpc = mock('XMLRPC::Client')
|
193
|
-
rpc.stubs(:new_from_uri).
|
194
|
-
with("http://#{host}:#{port}/#{Opensips::MI::Transport::Xmlrpc::RPCSEG}",nil,3)
|
195
|
-
res = Opensips::MI.connect :xmlrpc,
|
196
|
-
:host => host,
|
197
|
-
:port => port
|
198
|
-
|
199
|
-
res.respond_to?(:uac_dlg).must_equal true
|
200
|
-
|
201
|
-
params = ["aaa","bbb"]
|
202
|
-
cmd = "command"
|
203
|
-
rpc.stubs(:call).with(cmd, *params).returns( response_data_cmd_which )
|
204
|
-
res.command(cmd, params) #.must_be_instance_of Opensips::MI::Response
|
205
|
-
end
|
206
|
-
|
207
|
-
end
|
208
|
-
|
209
|
-
end
|