opensips-mi 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ccf5f5bbbc6e55802390c34cfc14d9786a3a66cae096150d2bf7ae9f58ca3bc6
4
- data.tar.gz: 2d2e16891fe1c6d0489c04df6a3ad03eb7971247f388cd19b29b456adb6cc34f
3
+ metadata.gz: 1956c21f6f508a1106aed87e99dbdc17925f529dc2d799554e6080a3ece2a23d
4
+ data.tar.gz: 0f2e9e1dbc906f5ed4fc92dd6cae377e1fd1e0d38866d66318258465832a9b54
5
5
  SHA512:
6
- metadata.gz: a31f00548de585c638296aa97b8fe4889c6d5d85deb7afe83be364a555941b476836f73d053516e05add7d8999f75fc0027a2008adbcdf1e8b2e57c12ae9fad1
7
- data.tar.gz: '028af90298a552a3bfff6054de1543acb519aeb846e78074e28b5c638d539a48734ef38eab3eb0cb2374e3b5f59167b655f7c32fa16b198cffff68c91c7fb689'
6
+ metadata.gz: 3c23130f92a3209b265ffe553fde481ae9c70897b1b13c31514358bdbfc6ed2329455ec3826fa4e99627498cd2a820a05a1e18c1ce51e22f4bb54b60e0c729e0
7
+ data.tar.gz: 5fa13a5dc0c8652625e1c1e14b740e816a8cdec36a2a32b50c688ffb8f642c4d92578a39a15da0d4e23a8dda6b152d669e65e5945fdd78fe862990a33f04fea6
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -1,3 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
3
+ - 2.3.8
data/Gemfile CHANGED
@@ -1,10 +1,7 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
- group :test do
4
- gem 'minitest'
5
- gem 'coveralls', require: false
6
- gem 'simplecov' #, :require => false
7
- gem 'mocha'
8
- end
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem 'simplecov', require: false, group: :test
9
6
 
10
7
  gemspec
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/clean"
3
3
  require 'opensips/mi/version'
4
+ require 'rspec/core/rake_task'
4
5
 
5
6
  require "rdoc/task"
6
7
  Rake::RDocTask.new do |rd|
@@ -10,11 +11,6 @@ Rake::RDocTask.new do |rd|
10
11
  rd.title = "OpenSIPs management interface " << Opensips::MI::VERSION
11
12
  end
12
13
 
13
- require 'rake/testtask'
14
- Rake::TestTask.new(:test) do |test|
15
- test.libs << 'lib' << 'test'
16
- test.pattern = 'test/**/test_*.rb'
17
- #test.verbose = true
18
- end
14
+ RSpec::Core::RakeTask.new(:spec)
19
15
 
20
- task :default => :test
16
+ task :default => :spec
@@ -83,7 +83,7 @@ module Opensips
83
83
  # compile headers to string
84
84
  headers = hf.map{|name,val| name.eql?("nl") ? "" : "#{name}: #{val}"}.join "\r\n"
85
85
  headers << "\r\n\r\n"
86
-
86
+
87
87
  # set_header is a hack for xmlrpc which fails if headers are quoted
88
88
  params = [method, ruri, next_hop, socket, set_header(headers)]
89
89
  params << body unless body.nil?
@@ -119,7 +119,7 @@ module Opensips
119
119
  hf['To'] = "<#{uri}>" unless hf.keys.map{|k|k.downcase}.include?('to')
120
120
  hf['From'] = "<#{uri}>;tag=#{SecureRandom.hex}" unless hf.keys.map{|k|k.downcase}.include?('from')
121
121
  hf['Event'] = EVENTNOTIFY[event]
122
-
122
+
123
123
  uac_dlg "NOTIFY", uri, hf
124
124
  end
125
125
 
@@ -168,7 +168,6 @@ module Opensips
168
168
  "Invalid port #{params[:port]}" unless (1..(2**16-1)).include?(params[:port])
169
169
  true
170
170
  end
171
-
172
171
  end
173
172
  end
174
173
  end
@@ -84,28 +84,22 @@ module Opensips
84
84
 
85
85
  # returns Array of registered contacts
86
86
  def ul_show_contact
87
- res = {}
88
- aor = nil
89
- contact = nil
90
-
87
+ result = []
91
88
  @rawdata.each do |r|
92
- r = r.strip
93
- key, val = r.split(":: ")
89
+ _, contact = r.strip.split("Contact:: ")
90
+ next unless contact
94
91
 
95
- if key == "AOR"
96
- aor = val
97
- res[aor] = []
98
- next
99
- elsif key == "Contact"
100
- contact = {}
101
- res[aor] << contact if res[aor]
102
- end
92
+ params = contact.split(';')
103
93
 
104
- contact[key.gsub(?-, ?_).downcase.to_sym] = val if key
105
- end
94
+ res = {contact: params.shift}
106
95
 
107
- @result = res
108
- self
96
+ params.each do |p|
97
+ key, val = p.split('=')
98
+ res[key.gsub(?-, ?_).downcase.to_sym] = val
99
+ end
100
+ result << res
101
+ end
102
+ @result = result
109
103
  end
110
104
 
111
105
  # returns hash of dialogs
@@ -146,7 +140,7 @@ module Opensips
146
140
  l.slice! "Process:: "
147
141
  h = {}
148
142
 
149
- l.split(" ", 3).each do |x|
143
+ l.split(" ", 3).each do |x|
150
144
  key, val = x.split("=", 2)
151
145
  h[key.downcase.to_sym] = val
152
146
  end
@@ -160,17 +154,18 @@ module Opensips
160
154
 
161
155
  private
162
156
  def dr_gws_hash
163
- Hash[
164
- @rawdata.map do |gw|
165
- if /\AID::\s+(?<id>[^\s]+)\s+IP=(?<ip>[^:\s]+):?(?<port>\d+)?\s+Enabled=(?<status>yes|no)/ =~ gw
166
- [id, {
167
- enabled: status.eql?('yes'),
168
- ipaddr: ip,
169
- port: port
170
- }]
171
- end
157
+ return nil if @rawdata.empty?
158
+ res = {}
159
+ @rawdata.map do |gw|
160
+ if /\AID::\s+(?<id>[^\s]+)\s+IP=(?<ip>[^:\s]+):?(?<port>\d+)?\s+Enabled=(?<status>yes|no)/ =~ gw
161
+ res[id] = {
162
+ enabled: status.eql?('yes'),
163
+ ipaddr: ip,
164
+ port: port
165
+ }
172
166
  end
173
- ]
167
+ end
168
+ res.empty? ? nil : res
174
169
  end
175
170
 
176
171
  end # END class
@@ -1,5 +1,5 @@
1
1
  module Opensips
2
2
  module MI
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  end
@@ -3,21 +3,23 @@ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'opensips/mi/version'
5
5
 
6
- Gem::Specification.new do |gem|
7
- gem.name = "opensips-mi"
8
- gem.version = Opensips::MI::VERSION
9
- gem.authors = ["Stas Kobzar"]
10
- gem.email = ["stas@modulis.ca"]
11
- gem.description = %q{Ruby module for interacting with OpenSIPs management interface}
12
- gem.summary = %q{OpenSIPs management interface}
13
- gem.homepage = "http://github.com/staskobzar/opensips-mi"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "opensips-mi"
8
+ spec.version = Opensips::MI::VERSION
9
+ spec.authors = ["Stas Kobzar"]
10
+ spec.email = ["stas@modulis.ca"]
11
+ spec.description = %q{Ruby module for interacting with OpenSIPs management interface}
12
+ spec.summary = %q{OpenSIPs management interface}
13
+ spec.homepage = "http://github.com/staskobzar/opensips-mi"
14
14
 
15
- gem.files = `git ls-files`.split($/).reject{|f| %r|^examples/.*|.match f}
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
15
+ spec.files = `git ls-files`.split($/).reject{|f| %r|^examples/.*|.match f}
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
19
18
 
20
- gem.add_development_dependency('bundler', '~> 1.3')
21
- gem.add_development_dependency('rdoc')
22
- gem.add_development_dependency('rake')
19
+ spec.add_dependency "xmlrpc", "~> 0.3"
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.16"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.8"
24
+ spec.add_development_dependency('rdoc')
23
25
  end
@@ -0,0 +1,4 @@
1
+ include Opensips::MI
2
+
3
+ describe Command do
4
+ end
File without changes
File without changes
@@ -0,0 +1,117 @@
1
+ include Opensips::MI
2
+
3
+ describe Response do
4
+ it "must raise if parameter is not Array" do
5
+ expect {Response.new "foo"}.to raise_error InvalidResponseData
6
+ end
7
+
8
+ it "must raise if response data id empty array" do
9
+ expect {Response.new Array[]}.to raise_error EmptyResponseData
10
+ end
11
+
12
+ it "must raise if invalid response data" do
13
+ expect {Response.new(["invalid param","343",222])}.
14
+ to raise_error InvalidResponseData
15
+ end
16
+
17
+ it "must parse successfull response" do
18
+ resp = Response.new ["200 it is OK", "data", ""]
19
+ expect(resp.success).to be_truthy
20
+ expect(resp.code).to be(200)
21
+ expect(resp.message).to match("it is OK")
22
+ end
23
+
24
+ it "must parse unsuccessfull response" do
25
+ resp = Response.new ["500 command 'unknown' not available"]
26
+ expect(resp.success).to be_falsey
27
+ expect(resp.code).to be(500)
28
+ expect(resp.message).to match("command 'unknown' not available")
29
+ end
30
+
31
+ it "parse ul dump response" do
32
+ res = Response.new(fixture('ul_dump'))
33
+ ul = res.ul_dump
34
+ expect(ul.result["7962"]).not_to be_nil
35
+ expect(ul.result["7962"][0][:callid]).to match("5e7a1e47da91c41c")
36
+ end
37
+
38
+ it "process uptime response" do
39
+ res = Response.new [
40
+ "200 OK",
41
+ "Now:: Fri Apr 12 22:04:27 2013",
42
+ "Up since:: Thu Apr 11 21:43:01 2013",
43
+ "Up time:: 87686 [sec]",
44
+ ""
45
+ ]
46
+ resp = res.uptime
47
+ expect(resp.result.uptime).to be(87686)
48
+ expect(resp.result.since.thursday?).to be_truthy
49
+ expect(resp.result.since.hour).to be(21)
50
+ expect(resp.result.since.mon).to be(4)
51
+ end
52
+
53
+ it "must fetch cache value" do
54
+ res = Response.new [
55
+ "200 OK",
56
+ "userdid = [18005552211]",
57
+ ""
58
+ ]
59
+ resp= res.cache_fetch
60
+ expect(resp.result.userdid).to match("18005552211")
61
+ end
62
+
63
+ it "must return userloc contacts" do
64
+ contacts = ["200 OK",
65
+ "Contact:: <sip:7747@10.132.113.198>;q=;expires=100;flags=0x0;cflags=0x0;socket=<udp:10.130.8.21:5060>;methods=0x1F7F;user_agent=<PolycomSoundStationIP-SSIP_6000-UA/3.3.5.0247_0004f2f18103>",
66
+ "Contact:: <sip:7747@10.130.8.100;line=628f4ffdfa7316e>;q=;expires=3593;flags=0x0;cflags=0x0;socket=<udp:10.130.8.21:5060>;methods=0xFFFFFFFF;user_agent=<Linphone/3.5.2 (eXosip2/3.6.0)>",
67
+ ""]
68
+ response = Response.new contacts
69
+ res = response.ul_show_contact
70
+ expect(res.size).to be(2)
71
+ expect(res.first[:socket]).to match("<udp:10.130.8.21:5060>")
72
+ expect(res.last[:expires]).to match("3593")
73
+ end
74
+
75
+ it "must process dialogs list" do
76
+ response = Response.new fixture('dlg_list')
77
+ res = response.dlg_list.result
78
+ expect(res.size).to be(1)
79
+ expect(res["3212:2099935485"][:callid]).to match("1854719653")
80
+ end
81
+
82
+ it "must process dr_gw_status response in hash" do
83
+ gw_list = [
84
+ "200 OK",
85
+ "ID:: gw1 IP=212.182.133.202:5060 Enabled=no ",
86
+ "ID:: gw2 IP=213.15.222.97:5060 Enabled=yes",
87
+ "ID:: gw3 IP=200.182.132.201:5060 Enabled=yes",
88
+ "ID:: gw4 IP=200.182.135.204:5060 Enabled=yes",
89
+ "ID:: pstn1 IP=199.18.14.101:5060 Enabled=yes",
90
+ "ID:: pstn2 IP=199.18.14.102:5060 Enabled=no",
91
+ "ID:: pstn3 IP=199.18.12.103:5060 Enabled=yes",
92
+ "ID:: pstn4 IP=199.18.12.104:5060 Enabled=yes",
93
+ ""
94
+ ]
95
+ response = Response.new gw_list
96
+ drgws = response.dr_gw_status
97
+ expect(drgws.result.size).to be(8)
98
+ expect(drgws.result["pstn4"][:ipaddr]).to match("199.18.12.104")
99
+ expect(drgws.result["pstn3"][:port]).to match("5060")
100
+ expect(drgws.result["gw1"][:enabled]).to be_falsey
101
+ expect(drgws.result["gw4"][:enabled]).to be_truthy
102
+ end
103
+
104
+ it "must return raw data if dr_gw_status is run with arguments" do
105
+ gw = [ "200 OK", "Enabled:: yes", "" ]
106
+ response = Response.new gw
107
+ drgws = response.dr_gw_status
108
+ expect(drgws.enabled).to be_truthy
109
+ end
110
+
111
+ it "result must be empty if command send to dr_gw_status" do
112
+ response = Response.new [ "200 OK", "" ]
113
+ drgws = response.dr_gw_status
114
+ expect(drgws.result).to be_nil
115
+ expect(drgws.success).to be_truthy
116
+ end
117
+ end
@@ -0,0 +1,112 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+
16
+ require 'simplecov'
17
+ SimpleCov.start
18
+
19
+ require 'opensips/mi'
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
46
+ # have no way to turn it off -- the option exists only for backwards
47
+ # compatibility in RSpec 3). It causes shared context metadata to be
48
+ # inherited by the metadata hash of host groups and examples, rather than
49
+ # triggering implicit auto-inclusion in groups with matching metadata.
50
+ config.shared_context_metadata_behavior = :apply_to_host_groups
51
+
52
+ # The settings below are suggested to provide a good initial experience
53
+ # with RSpec, but feel free to customize to your heart's content.
54
+ =begin
55
+ # This allows you to limit a spec run to individual examples or groups
56
+ # you care about by tagging them with `:focus` metadata. When nothing
57
+ # is tagged with `:focus`, all examples get run. RSpec also provides
58
+ # aliases for `it`, `describe`, and `context` that include `:focus`
59
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
60
+ config.filter_run_when_matching :focus
61
+
62
+ # Allows RSpec to persist some state between runs in order to support
63
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
64
+ # you configure your source control system to ignore this file.
65
+ config.example_status_persistence_file_path = "spec/examples.txt"
66
+
67
+ # Limits the available syntax to the non-monkey patched syntax that is
68
+ # recommended. For more details, see:
69
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
70
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
72
+ config.disable_monkey_patching!
73
+
74
+ # This setting enables warnings. It's recommended, but in some cases may
75
+ # be too noisy due to issues in dependencies.
76
+ config.warnings = true
77
+
78
+ # Many RSpec users commonly either run the entire suite or an individual
79
+ # file, and it's useful to allow more verbose output when running an
80
+ # individual spec file.
81
+ if config.files_to_run.one?
82
+ # Use the documentation formatter for detailed output,
83
+ # unless a formatter has already been configured
84
+ # (e.g. via a command-line flag).
85
+ config.default_formatter = "doc"
86
+ end
87
+
88
+ # Print the 10 slowest examples and example groups at the
89
+ # end of the spec run, to help surface which specs are running
90
+ # particularly slow.
91
+ config.profile_examples = 10
92
+
93
+ # Run specs in random order to surface order dependencies. If you find an
94
+ # order dependency and want to debug it, you can fix the order by providing
95
+ # the seed, which is printed after each run.
96
+ # --seed 1234
97
+ config.order = :random
98
+
99
+ # Seed global randomization in this process using the `--seed` CLI option.
100
+ # Setting this allows you to use `--seed` to deterministically reproduce
101
+ # test failures related to randomization by passing the same `--seed` value
102
+ # as the one that triggered the failure.
103
+ Kernel.srand config.seed
104
+ =end
105
+ end
106
+
107
+ def fixture(name)
108
+ path = File.expand_path('fixtures', File.dirname(__FILE__))
109
+ file = File.expand_path(name, path)
110
+ File.readlines(file).map{|l| l.chomp}
111
+ end
112
+
@@ -0,0 +1,102 @@
1
+ include Opensips::MI
2
+
3
+ describe Transport do
4
+ context "fifo" do
5
+ it "must raise when using unknown transport method" do
6
+ expect {
7
+ Opensips::MI.connect(:unknown_transport_method,{})
8
+ }.to raise_error NameError
9
+ end
10
+
11
+ it "must raise when no fifo_nameInstanceOf.new parameter passed" do
12
+ expect {
13
+ Opensips::MI.connect :fifo, {}
14
+ }.to raise_error ArgumentError
15
+ end
16
+
17
+ it "must raise when fifo_name file not exists" do
18
+ allow(File).to receive(:exists?).and_return(false)
19
+ expect {
20
+ Opensips::MI.connect :fifo, :fifo_name => '/file/not/exists'
21
+ }.to raise_error ArgumentError
22
+ end
23
+
24
+ it "must raise when fifo_name file is not pipe" do
25
+ allow(File).to receive(:exists?).and_return(true)
26
+ allow(File).to receive(:pipe?).and_return(false)
27
+ expect {
28
+ Opensips::MI.connect :fifo, :fifo_name => '/tmp/opensips_fifo'
29
+ }.to raise_error ArgumentError
30
+ end
31
+
32
+ it "must raise if fifo reply directory not exists" do
33
+ allow(Dir).to receive(:exists?).and_return(false)
34
+ expect {
35
+ Opensips::MI.connect :fifo, :fifo_name => '/tmp/opensips_fifo',
36
+ :reply_dir => '/tmp'
37
+ }.to raise_error ArgumentError
38
+ end
39
+ end
40
+
41
+ context "datagram" do
42
+ it "must raise if empty host" do
43
+ expect {
44
+ Opensips::MI.connect :datagram, {}
45
+ }.to raise_error ArgumentError
46
+ end
47
+
48
+ it "must raise if empty port" do
49
+ expect {
50
+ Opensips::MI.connect :datagram, {:host => "10.10.10.10"}
51
+ }.to raise_error ArgumentError
52
+ end
53
+
54
+ it "must raise if invalid host" do
55
+ host = "256.0.0.300"
56
+ expect {
57
+ Opensips::MI.connect :datagram, {:host => host, :port => 8088}
58
+ }.to raise_error(SocketError, /#{host}/)
59
+ end
60
+
61
+ it "must raise if invalid port" do
62
+ expect {
63
+ Opensips::MI.connect :datagram, {:host => "10.0.0.1", :port => (2**16 + 1)}
64
+ }.to raise_error SocketError
65
+
66
+ expect {
67
+ Opensips::MI.connect :datagram, {:host => "10.0.0.1", :port => 0}
68
+ }.to raise_error SocketError
69
+ end
70
+ end
71
+
72
+ context "datagram" do
73
+ it "must raise if empty host" do
74
+ expect {
75
+ Opensips::MI.connect :xmlrpc, {}
76
+ }.to raise_error ArgumentError
77
+ end
78
+
79
+ it "must raise if empty port" do
80
+ expect {
81
+ Opensips::MI.connect :xmlrpc, {:host => "10.10.10.10"}
82
+ }.to raise_error ArgumentError
83
+ end
84
+
85
+ it "must raise if invalid host" do
86
+ host = "256.0.0.300"
87
+ expect {
88
+ Opensips::MI.connect :xmlrpc, {:host => host, :port => 8088}
89
+ }.to raise_error(SocketError, /#{host}/)
90
+ end
91
+
92
+ it "must raise if invalid port" do
93
+ expect {
94
+ Opensips::MI.connect :xmlrpc, {:host => "10.0.0.1", :port => (2**16 + 1)}
95
+ }.to raise_error SocketError
96
+
97
+ expect {
98
+ Opensips::MI.connect :xmlrpc, {:host => "10.0.0.1", :port => 0}
99
+ }.to raise_error SocketError
100
+ end
101
+ end
102
+ end
metadata CHANGED
@@ -1,45 +1,73 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opensips-mi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stas Kobzar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-14 00:00:00.000000000 Z
11
+ date: 2018-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xmlrpc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.3'
33
+ version: '1.16'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '1.3'
40
+ version: '1.16'
27
41
  - !ruby/object:Gem::Dependency
28
- name: rdoc
42
+ name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">="
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: '10.0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">="
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '0'
54
+ version: '10.0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: rake
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - ">="
@@ -60,6 +88,7 @@ extensions: []
60
88
  extra_rdoc_files: []
61
89
  files:
62
90
  - ".gitignore"
91
+ - ".rspec"
63
92
  - ".travis.yml"
64
93
  - Gemfile
65
94
  - LICENSE.txt
@@ -75,13 +104,12 @@ files:
75
104
  - lib/opensips/mi/transport/xmlrpc.rb
76
105
  - lib/opensips/mi/version.rb
77
106
  - opensips-mi.gemspec
78
- - test/fifo/.keep
79
- - test/fixtures/dlg_list
80
- - test/fixtures/ul_dump
81
- - test/helper.rb
82
- - test/test_command.rb
83
- - test/test_response.rb
84
- - test/test_transport.rb
107
+ - spec/command_spec.rb
108
+ - spec/fixtures/dlg_list
109
+ - spec/fixtures/ul_dump
110
+ - spec/response_spec.rb
111
+ - spec/spec_helper.rb
112
+ - spec/transport_spec.rb
85
113
  homepage: http://github.com/staskobzar/opensips-mi
86
114
  licenses: []
87
115
  metadata: {}
@@ -101,15 +129,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
129
  version: '0'
102
130
  requirements: []
103
131
  rubyforge_project:
104
- rubygems_version: 2.7.8
132
+ rubygems_version: 2.7.6
105
133
  signing_key:
106
134
  specification_version: 4
107
135
  summary: OpenSIPs management interface
108
136
  test_files:
109
- - test/fifo/.keep
110
- - test/fixtures/dlg_list
111
- - test/fixtures/ul_dump
112
- - test/helper.rb
113
- - test/test_command.rb
114
- - test/test_response.rb
115
- - test/test_transport.rb
137
+ - spec/command_spec.rb
138
+ - spec/fixtures/dlg_list
139
+ - spec/fixtures/ul_dump
140
+ - spec/response_spec.rb
141
+ - spec/spec_helper.rb
142
+ - spec/transport_spec.rb
File without changes
@@ -1,85 +0,0 @@
1
- require 'simplecov'
2
- require 'coveralls'
3
- Coveralls.wear!
4
-
5
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
- SimpleCov::Formatter::HTMLFormatter,
7
- Coveralls::SimpleCov::Formatter
8
- ]
9
- SimpleCov.start
10
-
11
- require 'minitest/autorun'
12
- require 'mocha/setup'
13
- require 'stringio'
14
- require 'opensips/mi'
15
-
16
- def init_class_fifo
17
- Dir.stubs(:exists?).once.returns(true)
18
- File.stubs(:exists?).once.returns(true)
19
- File.stubs(:pipe?).once.returns(true)
20
- directory = File.expand_path 'test/fifo', Dir.pwd
21
- fifo_name = File.expand_path 'test/fifo/opensips_fifo', Dir.pwd
22
- replayfifo= 'fifo_reply_file_name'
23
- Opensips::MI::Transport::Fifo.new :fifo_name => fifo_name,
24
- :reply_dir => directory,
25
- :reply_fifo => replayfifo
26
- end
27
-
28
- def response_data_cmd_which
29
- Array[
30
- "200 OK", "get_statistics", "reset_statistics", "uptime", "version",
31
- "pwd", "arg", "which", "ps", "kill", "debug", "cache_store",
32
- "cache_fetch", "cache_remove", "event_subscribe", "help", "list_blacklists",
33
- "t_uac_dlg", "t_uac_cancel", "t_hash", "t_reply", "ul_rm", "ul_rm_contact",
34
- "ul_dump", "ul_flush", "ul_add", "ul_show_contact", "ul_sync", ""
35
- ]
36
- end
37
-
38
- def response_uldump
39
- fix = File.expand_path('fixtures/ul_dump',File.dirname(__FILE__))
40
- File.readlines(fix).map{|l| l.chomp}
41
- end
42
-
43
- def response_dr_gw_status_cmd
44
- Array[
45
- "200 OK",
46
- ""
47
- ]
48
- end
49
-
50
- def response_dr_gw_status_single
51
- Array[
52
- "200 OK",
53
- "Enabled:: yes",
54
- ""
55
- ]
56
- end
57
-
58
- def response_dr_gw_status_list
59
- Array[
60
- "200 OK",
61
- "ID:: gw1 IP=212.182.133.202:5060 Enabled=no ",
62
- "ID:: gw2 IP=213.15.222.97:5060 Enabled=yes",
63
- "ID:: gw3 IP=200.182.132.201:5060 Enabled=yes",
64
- "ID:: gw4 IP=200.182.135.204:5060 Enabled=yes",
65
- "ID:: pstn1 IP=199.18.14.101:5060 Enabled=yes",
66
- "ID:: pstn2 IP=199.18.14.102:5060 Enabled=no",
67
- "ID:: pstn3 IP=199.18.12.103:5060 Enabled=yes",
68
- "ID:: pstn4 IP=199.18.12.104:5060 Enabled=yes",
69
- ""
70
- ]
71
- end
72
-
73
- def response_contacts
74
- [
75
- "200 OK",
76
- "Contact:: <sip:7747@10.132.113.198>;q=;expires=100;flags=0x0;cflags=0x0;socket=<udp:10.130.8.21:5060>;methods=0x1F7F;user_agent=<PolycomSoundStationIP-SSIP_6000-UA/3.3.5.0247_0004f2f18103>",
77
- "Contact:: <sip:7747@10.130.8.100;line=628f4ffdfa7316e>;q=;expires=3593;flags=0x0;cflags=0x0;socket=<udp:10.130.8.21:5060>;methods=0xFFFFFFFF;user_agent=<Linphone/3.5.2 (eXosip2/3.6.0)>",
78
- "",
79
- ]
80
- end
81
-
82
- def response_dlg_list
83
- fix = File.expand_path('fixtures/dlg_list',File.dirname(__FILE__))
84
- File.readlines(fix).map{|l| l.chomp}
85
- end
@@ -1,97 +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
-
13
- it "must send command" do
14
- mi = init_class_fifo
15
- mi.expects(:command).with('ul_sync',[]).returns(Opensips::MI::Response.new(["200 OK",""]))
16
- mi.ul_sync.code.must_equal 200
17
- end
18
-
19
- it "must raise when missing basic mandatory headers" do
20
- mi = init_class_fifo
21
- ret = proc {
22
- mi.uac_dlg "NOTIFY",
23
- "sip:alice@wanderland.com",
24
- {"From" => "<sip:opensips@sipproxy.com>"}
25
- }.must_raise ArgumentError
26
- ret.message.must_match(/header To/)
27
-
28
- end
29
-
30
- it "must have good parameters" do
31
- mi = init_class_fifo
32
- mi.expects(:command).with('t_uac_dlg', [
33
- "NOTIFY",
34
- "sip:alice@wanderland.com",
35
- ".",
36
- ".",
37
- %Q/"From: <sip:opensips@sipproxy.com>\r\nTo: <sip:alice@wanderland.com>\r\n\r\n"/
38
- ])
39
- mi.uac_dlg "NOTIFY",
40
- "sip:alice@wanderland.com",
41
- {
42
- "From" => "<sip:opensips@sipproxy.com>",
43
- "To" => "<sip:alice@wanderland.com>"
44
- }
45
-
46
- end
47
-
48
- it "must raise when invalid event" do
49
- mi = init_class_fifo
50
- event = :unknown_event
51
- res = proc {
52
- mi.event_notify "sip:alice@proxy.com", event
53
- }.must_raise ArgumentError
54
- res.message.must_match(/#{event.to_s}/)
55
- end
56
-
57
- it "must send notify event" do
58
- mi = init_class_fifo
59
- tag = "123456"
60
- uri = "sip:alice@wanderland.com"
61
- SecureRandom.stubs(:hex).returns(tag)
62
- mi.expects(:uac_dlg).with("NOTIFY",
63
- uri,
64
- {
65
- "To" => "<#{uri}>",
66
- "From" => "<#{uri}>;tag=#{tag}",
67
- "Event" => "check-sync"
68
- }
69
- )
70
- mi.event_notify uri, :polycom_check_cfg
71
- end
72
-
73
- it "must send MWI notify" do
74
- mi = init_class_fifo
75
- tag = "123456"
76
- uri = "sip:alice@wanderland.com"
77
- new_vm = 5
78
- old_vm = 3
79
- SecureRandom.stubs(:hex).returns(tag)
80
- mi.expects(:uac_dlg).with("NOTIFY",
81
- uri,
82
- {
83
- 'To' => "<#{uri}>",
84
- 'From' => "<#{uri}>;tag=#{tag}",
85
- 'Event' => 'message-summary',
86
- 'Subscription-State' => 'active',
87
- 'Content-Type' => 'application/simple-message-summary',
88
- 'nl' => '',
89
- 'Messages-Waiting' => 'yes',
90
- 'Message-Account' => 'sip:*97@asterisk.com',
91
- 'Voice-Message' => "#{new_vm}/#{old_vm} (0/0)"
92
- })
93
- mi.mwi_update uri, 'sip:*97@asterisk.com', new_vm, old_vm
94
- end
95
-
96
- end
97
- end
@@ -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
@@ -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