net-ping 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,13 @@
1
+ == 1.4.1 - 17-Mar-2011
2
+ * Incorporated changes from Lukas Zapletal that alters the icmp tests to use
3
+ your localhost instead of going outside the network.
4
+ * The http tests were similarly modified courtesy of fakeweb, which is now a
5
+ development dependency. Again, change from Lukas Zapletal.
6
+ * The icmp tests were reworked for Windows Vista and later. This required the
7
+ addition of the win32-security library as a development dependency.
8
+ * The Net::Ping::WMI class is no longer skipped on require or in tests since
9
+ JRuby now supports win32ole.
10
+
1
11
  == 1.4.0 - 14-Feb-2011
2
12
  * Added the redirect_limit accessor for the Net::Ping::HTTP class. This caps
3
13
  the number of redirects that are allowed before a ping is considered a
@@ -45,7 +55,7 @@
45
55
  == 1.3.2 - 21-Sep-2009
46
56
  * Doing a 'require "net/ping"' was not automatically loading the
47
57
  Net::Ping::WMI class on MS Windows. This has been fixed. Thanks go to
48
- Joseph M. for the spot.
58
+ Joseph M. for the spot.
49
59
  * Removed all $LOAD_PATH mangling for both the library and tests.
50
60
  * Fixed a bug in the Net::Ping::HTTP class where a failed redirect did
51
61
  not set the @exception and @warning instance variables properly.
@@ -116,7 +126,7 @@
116
126
 
117
127
  == 1.2.0 - 5-Dec-2006
118
128
  * Internal reorganization - each class now lives in its own file.
119
- * Added the Ping::ICMP class. Thanks go to Jos Backus for contributing a
129
+ * Added the Ping::ICMP class. Thanks go to Jos Backus for contributing a
120
130
  large part of the code.
121
131
  * The host argument is now optional in the constructor. You can now specify
122
132
  it in the ping method instead. Note that it must be specified in one place
@@ -199,7 +209,7 @@
199
209
  * Doc updates
200
210
 
201
211
  == 0.2.0 - 14-Feb-2003
202
- * The default behavior of PingTCP with regards to ECONNREFUSED is now
212
+ * The default behavior of PingTCP with regards to ECONNREFUSED is now
203
213
  configurable
204
214
  * Added a VERSION constant and method (to the base class)
205
215
  * Added a test suite (for those with testunit installed)
data/lib/net/ping.rb CHANGED
@@ -10,8 +10,6 @@ require File.join(File.dirname(__FILE__), 'ping/icmp')
10
10
  require File.join(File.dirname(__FILE__), 'ping/external')
11
11
  require File.join(File.dirname(__FILE__), 'ping/http')
12
12
 
13
- if Config::CONFIG['host_os'] =~ /msdos|mswin|cygwin|mingw|win32|windows/i &&
14
- RUBY_PLATFORM != 'java'
15
- then
13
+ if Config::CONFIG['host_os'] =~ /msdos|mswin|cygwin|mingw|win32|windows/i
16
14
  require File.join(File.dirname(__FILE__), 'ping/wmi')
17
15
  end
data/lib/net/ping/ping.rb CHANGED
@@ -10,7 +10,7 @@ module Net
10
10
  #
11
11
  class Ping
12
12
  # The version of the net-ping library.
13
- VERSION = '1.4.0'
13
+ VERSION = '1.4.1'
14
14
 
15
15
  # The host to ping. In the case of Ping::HTTP, this is the URI.
16
16
  attr_accessor :host
data/net-ping.gemspec CHANGED
@@ -3,7 +3,7 @@ require 'rbconfig'
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = 'net-ping'
6
- gem.version = '1.4.0'
6
+ gem.version = '1.4.1'
7
7
  gem.license = 'Artistic 2.0'
8
8
  gem.author = 'Daniel J. Berger'
9
9
  gem.email = 'djberg96@gmail.com'
@@ -17,16 +17,16 @@ Gem::Specification.new do |gem|
17
17
  gem.extra_rdoc_files = ['README', 'CHANGES', 'doc/ping.txt']
18
18
 
19
19
  gem.add_development_dependency('test-unit', '>= 2.1.2')
20
+ gem.add_development_dependency('fakeweb', '>= 1.3.0')
20
21
 
21
22
  # These dependencies are for Net::Ping::External
22
- if Config::CONFIG['host_os'] =~ /mswin|dos|win32|windows|cygwin|mingw/i &&
23
- RUBY_PLATFORM != 'java'
24
- then
23
+ if File::ALT_SEPARATOR && RUBY_PLATFORM != 'java'
25
24
  gem.platform = Gem::Platform::CURRENT
26
25
  gem.add_dependency('windows-pr', '>= 1.0.8')
26
+ gem.add_development_dependency('win32-security', '>= 1.0.8')
27
27
 
28
28
  if RUBY_VERSION.to_f < 1.9
29
- gem.add_dependency('win32-open3', '>= 0.3.1')
29
+ gem.add_dependency('win32-open3', '>= 0.3.1')
30
30
  end
31
31
  end
32
32
 
@@ -8,19 +8,30 @@ require 'test_net_ping_external'
8
8
  require 'test_net_ping_http'
9
9
  require 'test_net_ping_tcp'
10
10
  require 'test_net_ping_udp'
11
+ require 'fakeweb'
11
12
 
12
- if Process.euid == 0
13
- require 'test_net_ping_icmp'
13
+ if File::ALT_SEPARATOR
14
+ require 'win32/security'
15
+ require 'windows/system_info'
16
+ include Windows::SystemInfo
17
+
18
+ if windows_version >= 6 && Win32::Security.elevated_security?
19
+ require 'test_net_ping_icmp'
20
+ end
21
+ else
22
+ if Process.euid == 0
23
+ require 'test_net_ping_icmp'
24
+ end
14
25
  end
15
26
 
16
- if Config::CONFIG['host_os'] =~ /mswin|win32|dos|cygwin|mingw/i &&
17
- RUBY_PLATFORM != 'java'
18
- then
27
+ if File::ALT_SEPARATOR
19
28
  require 'test_net_ping_wmi'
20
29
  end
21
30
 
22
31
  class TC_Net_Ping < Test::Unit::TestCase
23
32
  def test_net_ping_version
24
- assert_equal('1.4.0', Net::Ping::VERSION)
33
+ assert_equal('1.4.1', Net::Ping::VERSION)
25
34
  end
26
35
  end
36
+
37
+ FakeWeb.allow_net_connect = false
@@ -12,7 +12,16 @@ require 'net/ping/http'
12
12
 
13
13
  class TC_Net_Ping_HTTP < Test::Unit::TestCase
14
14
  def setup
15
- @uri = 'http://www.google.com/index.html'
15
+ @uri = 'http://www.google.com/index.html'
16
+ @uri_https = 'https://encrypted.google.com'
17
+
18
+ FakeWeb.register_uri(:get, @uri, :body => "PONG")
19
+ FakeWeb.register_uri(:get, @uri_https, :body => "PONG")
20
+ FakeWeb.register_uri(:get, "http://jigsaw.w3.org/HTTP/300/302.html",
21
+ :body => "PONG",
22
+ :location => "#{@uri}",
23
+ :status => ["302", "Found"])
24
+
16
25
  @http = Net::Ping::HTTP.new(@uri, 80, 30)
17
26
  @bad = Net::Ping::HTTP.new('http://www.blabfoobarurghxxxx.com') # One hopes not
18
27
  end
@@ -150,13 +159,13 @@ class TC_Net_Ping_HTTP < Test::Unit::TestCase
150
159
  end
151
160
 
152
161
  test 'ping against https site defaults to port 443' do
153
- @http = Net::Ping::HTTP.new("https://encrypted.google.com/")
162
+ @http = Net::Ping::HTTP.new(@uri_https)
154
163
  assert_equal(443, @http.port)
155
164
  end
156
165
 
157
166
  # This will generate a warning. Nothing I can do about it.
158
167
  test 'ping against https site works as expected' do
159
- @http = Net::Ping::HTTP.new("https://encrypted.google.com/")
168
+ @http = Net::Ping::HTTP.new(@uri_https)
160
169
  assert_true(@http.ping)
161
170
  end
162
171
 
@@ -12,115 +12,105 @@ require 'test/unit'
12
12
  require 'net/ping/icmp'
13
13
  include Net
14
14
 
15
- unless Process.euid == 0
16
- raise "The test:icmp task must be run with root privileges"
15
+ if File::ALT_SEPARATOR
16
+ require 'win32/security'
17
+ require 'windows/system_info'
18
+ include Windows::SystemInfo
19
+
20
+ if windows_version >= 6 && !Win32::Security.elevated_security?
21
+ raise "The test:icmp task must be run with elevated security rights"
22
+ end
23
+ else
24
+ unless Process.euid == 0
25
+ raise "The test:icmp task must be run with root privileges"
26
+ end
17
27
  end
18
28
 
19
29
  class TC_PingICMP < Test::Unit::TestCase
20
- def self.startup
21
- @@one_click = Config::CONFIG['host_os'] == 'mswin32'
22
- end
23
-
24
- def setup
25
- @host = "www.ruby-lang.org"
26
- @icmp = Ping::ICMP.new(@host)
27
- end
28
-
29
- def test_ping
30
- assert_respond_to(@icmp, :ping)
31
-
32
- omit_if(@@one_click, 'Unreliable socket library')
33
-
34
- assert_nothing_raised{ @icmp.ping }
35
- assert_nothing_raised{ @icmp.ping(@host) }
36
- end
37
-
38
- def test_ping_aliases_basic
39
- assert_respond_to(@icmp, :ping?)
40
- assert_respond_to(@icmp, :pingecho)
41
-
42
- omit_if(@@one_click, 'Unreliable socket library')
43
-
44
- assert_nothing_raised{ @icmp.ping? }
45
- assert_nothing_raised{ @icmp.ping?(@host) }
46
- end
47
-
48
- def test_ping_returns_boolean
49
- omit_if(@@one_click, 'Unreliable socket library')
50
- assert_boolean(@icmp.pingecho)
51
- assert_boolean(@icmp.pingecho(@host))
52
- end
53
-
54
- def test_ping_expected_failure
55
- omit_if(@@one_click, 'Unreliable socket library')
56
- assert_false(Ping::ICMP.new('bogus').ping?)
57
- assert_false(Ping::ICMP.new('http://www.asdfhjklasdfhlkj.com').ping?)
58
- end
59
-
60
- def test_bind
61
- omit_if(@@one_click, 'Unreliable socket library')
62
- assert_respond_to(@icmp, :bind)
63
- assert_nothing_raised{ @icmp.bind(Socket.gethostname) }
64
- assert_nothing_raised{ @icmp.bind(Socket.gethostname, 80) }
65
- end
66
-
67
- def test_duration
68
- omit_if(@@one_click, 'Unreliable socket library')
69
- assert_nothing_raised{ @icmp.ping }
70
- assert_respond_to(@icmp, :duration)
71
- assert_kind_of(Float, @icmp.duration)
72
- end
73
-
74
- def test_host
75
- assert_respond_to(@icmp, :host)
76
- assert_respond_to(@icmp, :host=)
77
- assert_equal('www.ruby-lang.org', @icmp.host)
78
- end
79
-
80
- def test_port
81
- assert_respond_to(@icmp, :port)
82
- assert_equal(nil, @icmp.port)
83
- end
84
-
85
- def test_timeout
86
- assert_respond_to(@icmp, :timeout)
87
- assert_respond_to(@icmp, :timeout=)
88
- assert_equal(5, @icmp.timeout)
89
- end
90
-
91
- def test_exception
92
- assert_respond_to(@icmp, :exception)
93
- omit_if(@@one_click, 'Unreliable socket library')
94
- assert_nothing_raised{ @icmp.ping }
95
- assert_nil(@icmp.exception)
96
- end
97
-
98
- def test_warning
99
- assert_respond_to(@icmp, :warning)
100
- end
101
-
102
- def test_data_size_get
103
- assert_respond_to(@icmp, :data_size)
104
- assert_equal(56, @icmp.data_size)
105
- end
106
-
107
- def test_data_size_set
108
- assert_respond_to(@icmp, :data_size=)
109
- assert_nothing_raised{ @icmp.data_size = 22 }
110
- end
111
-
112
- def test_odd_data_size_ok
113
- assert_nothing_raised{ @icmp.data_size = 57 }
114
- omit_if(@@one_click, 'Unreliable socket library')
115
- assert_boolean(@icmp.ping)
116
- end
117
-
118
- def teardown
119
- @host = nil
120
- @icmp = nil
121
- end
122
-
123
- def self.shutdown
124
- @@one_click = nil
125
- end
30
+ def setup
31
+ @host = 'localhost'
32
+ @icmp = Ping::ICMP.new(@host)
33
+ end
34
+
35
+ def test_ping
36
+ assert_respond_to(@icmp, :ping)
37
+ assert_nothing_raised{ @icmp.ping }
38
+ assert_nothing_raised{ @icmp.ping(@host) }
39
+ end
40
+
41
+ def test_ping_aliases_basic
42
+ assert_respond_to(@icmp, :ping?)
43
+ assert_respond_to(@icmp, :pingecho)
44
+ assert_nothing_raised{ @icmp.ping? }
45
+ assert_nothing_raised{ @icmp.ping?(@host) }
46
+ end
47
+
48
+ def test_ping_returns_boolean
49
+ assert_boolean(@icmp.pingecho)
50
+ assert_boolean(@icmp.pingecho(@host))
51
+ end
52
+
53
+ def test_ping_expected_failure
54
+ assert_false(Ping::ICMP.new('bogus').ping?)
55
+ assert_false(Ping::ICMP.new('http://www.asdfhjklasdfhlkj.com').ping?)
56
+ end
57
+
58
+ def test_bind
59
+ assert_respond_to(@icmp, :bind)
60
+ assert_nothing_raised{ @icmp.bind(Socket.gethostname) }
61
+ assert_nothing_raised{ @icmp.bind(Socket.gethostname, 80) }
62
+ end
63
+
64
+ def test_duration
65
+ assert_nothing_raised{ @icmp.ping }
66
+ assert_respond_to(@icmp, :duration)
67
+ assert_kind_of(Float, @icmp.duration)
68
+ end
69
+
70
+ def test_host
71
+ assert_respond_to(@icmp, :host)
72
+ assert_respond_to(@icmp, :host=)
73
+ assert_equal('localhost', @icmp.host)
74
+ end
75
+
76
+ def test_port
77
+ assert_respond_to(@icmp, :port)
78
+ assert_equal(nil, @icmp.port)
79
+ end
80
+
81
+ def test_timeout
82
+ assert_respond_to(@icmp, :timeout)
83
+ assert_respond_to(@icmp, :timeout=)
84
+ assert_equal(5, @icmp.timeout)
85
+ end
86
+
87
+ def test_exception
88
+ assert_respond_to(@icmp, :exception)
89
+ assert_nothing_raised{ @icmp.ping }
90
+ assert_nil(@icmp.exception)
91
+ end
92
+
93
+ def test_warning
94
+ assert_respond_to(@icmp, :warning)
95
+ end
96
+
97
+ def test_data_size_get
98
+ assert_respond_to(@icmp, :data_size)
99
+ assert_equal(56, @icmp.data_size)
100
+ end
101
+
102
+ def test_data_size_set
103
+ assert_respond_to(@icmp, :data_size=)
104
+ assert_nothing_raised{ @icmp.data_size = 22 }
105
+ end
106
+
107
+ def test_odd_data_size_ok
108
+ assert_nothing_raised{ @icmp.data_size = 57 }
109
+ assert_boolean(@icmp.ping)
110
+ end
111
+
112
+ def teardown
113
+ @host = nil
114
+ @icmp = nil
115
+ end
126
116
  end
@@ -13,8 +13,8 @@ include Net
13
13
 
14
14
  class TC_PingTCP < Test::Unit::TestCase
15
15
  def setup
16
- @host = 'www.ruby-lang.org'
17
- @port = 'ftp'
16
+ @host = 'localhost'
17
+ @port = 22
18
18
  @tcp = Ping::TCP.new(@host, @port)
19
19
  end
20
20
 
@@ -81,7 +81,7 @@ class TC_PingTCP < Test::Unit::TestCase
81
81
  def test_port
82
82
  assert_respond_to(@tcp, :port)
83
83
  assert_respond_to(@tcp, :port=)
84
- assert_equal('ftp', @tcp.port)
84
+ assert_equal(22, @tcp.port)
85
85
  end
86
86
 
87
87
  def test_timeout
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-ping
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 0
10
- version: 1.4.0
9
+ - 1
10
+ version: 1.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel J. Berger
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-15 00:00:00 -07:00
18
+ date: 2011-03-17 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -34,6 +34,22 @@ dependencies:
34
34
  version: 2.1.2
35
35
  type: :development
36
36
  version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: fakeweb
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 27
46
+ segments:
47
+ - 1
48
+ - 3
49
+ - 0
50
+ version: 1.3.0
51
+ type: :development
52
+ version_requirements: *id002
37
53
  description: " The net-ping library provides a ping interface for Ruby. It includes\n separate TCP, HTTP, ICMP, UDP, WMI (for Windows) and external ping\n classes.\n"
38
54
  email: djberg96@gmail.com
39
55
  executables: []