net-ping 1.3.4-x86-mingw32 → 1.4.0-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +30 -0
- data/README +2 -4
- data/Rakefile +6 -1
- data/lib/net/ping.rb +1 -1
- data/lib/net/ping/external.rb +12 -12
- data/lib/net/ping/http.rb +43 -21
- data/lib/net/ping/icmp.rb +30 -27
- data/lib/net/ping/ping.rb +5 -5
- data/net-ping.gemspec +3 -3
- data/test/test_net_ping.rb +1 -1
- data/test/test_net_ping_external.rb +56 -22
- data/test/test_net_ping_http.rb +53 -1
- metadata +18 -7
data/CHANGES
CHANGED
@@ -1,3 +1,33 @@
|
|
1
|
+
== 1.4.0 - 14-Feb-2011
|
2
|
+
* Added the redirect_limit accessor for the Net::Ping::HTTP class. This caps
|
3
|
+
the number of redirects that are allowed before a ping is considered a
|
4
|
+
failure. The default is 5.
|
5
|
+
* Changed the way in which redirects are detected. Previously I was checking
|
6
|
+
against the response class, but decided this was unreliable. I now check the
|
7
|
+
response code itself. Any code in the 300 range is considered a redirect.
|
8
|
+
* The default port for the Net::Ping::HTTP class is no longer explicitly set
|
9
|
+
to 80, but instead uses the result of the URI.parse(uri).port method by
|
10
|
+
default. Note that you can still override the port if you explicitly provide
|
11
|
+
one in the constructor.
|
12
|
+
* The Net::Ping::HTTP class now handles https URI's properly. Note that you may
|
13
|
+
get a warning about peer certificates.
|
14
|
+
|
15
|
+
== 1.3.7 - 14-Oct-2010
|
16
|
+
* Wrapped the ICMP ping in a while loop that breaks on success to prevent
|
17
|
+
the ping from failing too early. Thanks go to Benny Holmgren for the
|
18
|
+
spot and the patch.
|
19
|
+
|
20
|
+
== 1.3.6 - 4-Sep-2010
|
21
|
+
* Fixed variable naming issue in Net::Ping::External. Thanks go to taw
|
22
|
+
for the spot.
|
23
|
+
* Added a default Rake task.
|
24
|
+
* Refactored the tests for Net::Ping::External to take advantage of the
|
25
|
+
features of test-unit 2.x.
|
26
|
+
|
27
|
+
== 1.3.5 - 3-Sep-2010
|
28
|
+
* Allow for custom user agent in Net::Ping::HTTP. Thanks go to Michael
|
29
|
+
Reinsch for the patch.
|
30
|
+
|
1
31
|
== 1.3.4 - 25-Jun-2010
|
2
32
|
* Fixed a dumb platform bug. Thanks go to Jason Frey for the spot.
|
3
33
|
|
data/README
CHANGED
@@ -2,11 +2,9 @@
|
|
2
2
|
A collection of classes that provide different ways to ping computers.
|
3
3
|
|
4
4
|
== Prerequisites
|
5
|
-
* Ruby 1.8.0 or later
|
6
5
|
* The win32-open3 (1.8.x) and windows-pr libraries are required on
|
7
6
|
MS Windows when using the Net::Ping::External class unless you're
|
8
7
|
using JRuby.
|
9
|
-
* Windows 2000 or later is required to use the Ping::WMI class.
|
10
8
|
|
11
9
|
== Installation
|
12
10
|
gem install net-ping
|
@@ -36,8 +34,8 @@
|
|
36
34
|
|
37
35
|
== Known Issues
|
38
36
|
Older versions of Ruby 1.9.x may not work with UDP pings.
|
39
|
-
|
40
|
-
incorrect error class being raised. See JRuby-4896.
|
37
|
+
Older versions of JRuby will return false positives in UDP pings
|
38
|
+
because of an incorrect error class being raised. See JRuby-4896.
|
41
39
|
|
42
40
|
== License
|
43
41
|
Artistic 2.0
|
data/Rakefile
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'rake'
|
2
|
+
require 'rake/clean'
|
2
3
|
require 'rake/testtask'
|
3
4
|
include Config
|
4
5
|
|
6
|
+
CLEAN.include("**/*.gem", "**/*.rbc")
|
7
|
+
|
5
8
|
namespace 'gem' do
|
6
9
|
desc 'Create the net-ping gem'
|
7
|
-
task :create do
|
10
|
+
task :create => [:clean] do
|
8
11
|
spec = eval(IO.read('net-ping.gemspec'))
|
9
12
|
Gem::Builder.new(spec).build
|
10
13
|
end
|
@@ -82,3 +85,5 @@ namespace 'test' do
|
|
82
85
|
t.test_files = FileList['test/test_net_ping_wmi.rb']
|
83
86
|
end
|
84
87
|
end
|
88
|
+
|
89
|
+
task :default => :test
|
data/lib/net/ping.rb
CHANGED
@@ -10,7 +10,7 @@ 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/i &&
|
13
|
+
if Config::CONFIG['host_os'] =~ /msdos|mswin|cygwin|mingw|win32|windows/i &&
|
14
14
|
RUBY_PLATFORM != 'java'
|
15
15
|
then
|
16
16
|
require File.join(File.dirname(__FILE__), 'ping/wmi')
|
data/lib/net/ping/external.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rbconfig'
|
2
2
|
require File.join(File.dirname(__FILE__), 'ping')
|
3
3
|
|
4
|
-
if Config::CONFIG['host_os'] =~ /mswin|win32|msdos|cygwin|mingw/i &&
|
4
|
+
if Config::CONFIG['host_os'] =~ /mswin|win32|msdos|cygwin|mingw|windows/i &&
|
5
5
|
RUBY_PLATFORM != 'java'
|
6
6
|
then
|
7
7
|
if RUBY_VERSION.to_f < 1.9
|
@@ -18,7 +18,7 @@ module Net
|
|
18
18
|
# The Ping::External class encapsulates methods for external (system) pings.
|
19
19
|
class Ping::External < Ping
|
20
20
|
|
21
|
-
CWINDOWS = Config::CONFIG['host_os'] =~ /mswin|win32|msdos|cygwin|mingw/i &&
|
21
|
+
CWINDOWS = Config::CONFIG['host_os'] =~ /mswin|win32|msdos|cygwin|mingw|windows/i &&
|
22
22
|
RUBY_PLATFORM != 'java'
|
23
23
|
|
24
24
|
if CWINDOWS
|
@@ -35,7 +35,7 @@ module Net
|
|
35
35
|
def ping(host = @host)
|
36
36
|
super(host)
|
37
37
|
|
38
|
-
|
38
|
+
stdin, stdout, stderr = ""
|
39
39
|
pstring = "ping "
|
40
40
|
bool = false
|
41
41
|
orig_cp = nil
|
@@ -63,12 +63,12 @@ module Net
|
|
63
63
|
err = nil
|
64
64
|
|
65
65
|
Timeout.timeout(@timeout){
|
66
|
-
|
67
|
-
err =
|
66
|
+
stdin, stdout, stderr = Open3.popen3(pstring)
|
67
|
+
err = stderr.gets # Can't chomp yet, might be nil
|
68
68
|
}
|
69
69
|
|
70
|
-
|
71
|
-
|
70
|
+
stdin.close
|
71
|
+
stderr.close
|
72
72
|
|
73
73
|
if CWINDOWS && GetConsoleCP() != orig_cp
|
74
74
|
SetConsoleCP(orig_cp)
|
@@ -83,8 +83,8 @@ module Net
|
|
83
83
|
end
|
84
84
|
# The "no answer" response goes to stdout, not stderr, so check it
|
85
85
|
else
|
86
|
-
lines =
|
87
|
-
|
86
|
+
lines = stdout.readlines
|
87
|
+
stdout.close
|
88
88
|
if lines.nil? || lines.empty?
|
89
89
|
bool = true
|
90
90
|
else
|
@@ -109,9 +109,9 @@ module Net
|
|
109
109
|
rescue Exception => error
|
110
110
|
@exception = error.message
|
111
111
|
ensure
|
112
|
-
|
113
|
-
|
114
|
-
|
112
|
+
stdin.close if stdin && !stdin.closed?
|
113
|
+
stdout.close if stdout && !stdout.closed?
|
114
|
+
stderr.close if stderr && !stderr.closed?
|
115
115
|
end
|
116
116
|
|
117
117
|
# There is no duration if the ping failed
|
data/lib/net/ping/http.rb
CHANGED
@@ -1,31 +1,41 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'ping')
|
2
2
|
require 'net/http'
|
3
|
+
require 'net/https'
|
3
4
|
require 'uri'
|
4
|
-
require 'rbconfig'
|
5
5
|
|
6
6
|
# Force non-blocking Socket.getaddrinfo on Unix systems. Do not use on
|
7
7
|
# Windows because it (ironically) causes blocking problems.
|
8
|
-
unless
|
8
|
+
unless File::ALT_SEPARATOR
|
9
9
|
require 'resolv-replace'
|
10
10
|
end
|
11
11
|
|
12
12
|
# The Net module serves as a namespace only.
|
13
13
|
module Net
|
14
|
-
|
14
|
+
|
15
15
|
# The Ping::HTTP class encapsulates methods for HTTP pings.
|
16
16
|
class Ping::HTTP < Ping
|
17
|
-
|
17
|
+
|
18
18
|
# By default an http ping will follow a redirect and give you the result
|
19
19
|
# of the final URI. If this value is set to false, then it will not
|
20
20
|
# follow a redirect and will return false immediately on a redirect.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
attr_accessor :follow_redirect
|
23
|
-
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
|
24
|
+
# The maximum number of redirects allowed. The default is 5.
|
25
|
+
attr_accessor :redirect_limit
|
26
|
+
|
27
|
+
# The user agent used for the HTTP request. The default is nil.
|
28
|
+
attr_accessor :user_agent
|
29
|
+
|
30
|
+
# Creates and returns a new Ping::HTTP object. The default port is the
|
31
|
+
# port associated with the URI. The default timeout is 5 seconds.
|
32
|
+
#
|
33
|
+
def initialize(uri=nil, port=nil, timeout=5)
|
28
34
|
@follow_redirect = true
|
35
|
+
@redirect_limit = 5
|
36
|
+
|
37
|
+
port ||= URI.parse(uri).port if uri
|
38
|
+
|
29
39
|
super(uri, port, timeout)
|
30
40
|
end
|
31
41
|
|
@@ -34,7 +44,7 @@ module Net
|
|
34
44
|
# successful and true is returned. Otherwise, false is returned
|
35
45
|
# and the Ping::HTTP#exception method should contain a string
|
36
46
|
# indicating what went wrong.
|
37
|
-
#
|
47
|
+
#
|
38
48
|
# If the HTTP#follow_redirect accessor is set to true (which it is
|
39
49
|
# by default) and a redirect occurs during the ping, then the
|
40
50
|
# HTTP#warning attribute is set to the redirect message, but the
|
@@ -42,7 +52,7 @@ module Net
|
|
42
52
|
# response is considered a failed ping.
|
43
53
|
#
|
44
54
|
# If no file or path is specified in the URI, then '/' is assumed.
|
45
|
-
#
|
55
|
+
#
|
46
56
|
def ping(host = @host)
|
47
57
|
super(host)
|
48
58
|
bool = false
|
@@ -53,9 +63,14 @@ module Net
|
|
53
63
|
begin
|
54
64
|
response = nil
|
55
65
|
uri_path = uri.path.empty? ? '/' : uri.path
|
56
|
-
|
57
|
-
|
58
|
-
|
66
|
+
headers = { }
|
67
|
+
headers["User-Agent"] = user_agent unless user_agent.nil?
|
68
|
+
Timeout.timeout(@timeout) do
|
69
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
70
|
+
http.use_ssl = (uri.scheme == 'https')
|
71
|
+
request = Net::HTTP::Get.new(uri_path)
|
72
|
+
response = http.start{ |h| h.request(request) }
|
73
|
+
end
|
59
74
|
rescue Exception => err
|
60
75
|
@exception = err.message
|
61
76
|
else
|
@@ -64,18 +79,25 @@ module Net
|
|
64
79
|
else
|
65
80
|
if @follow_redirect
|
66
81
|
@warning = response.message
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
82
|
+
rlimit = 0
|
83
|
+
|
84
|
+
# Any response code in the 300 range is a redirect
|
85
|
+
while response.code.to_i >= 300 && response.code.to_i < 400
|
86
|
+
if rlimit >= redirect_limit
|
87
|
+
@exception = "Redirect limit exceeded"
|
88
|
+
break
|
89
|
+
end
|
90
|
+
redirect = URI.parse(response['location'])
|
91
|
+
redirect = uri + redirect if redirect.relative?
|
71
92
|
response = Net::HTTP.get_response(redirect.host, redirect.path, @port)
|
93
|
+
rlimit += 1
|
72
94
|
end
|
73
|
-
|
95
|
+
|
74
96
|
if response.is_a?(Net::HTTPSuccess)
|
75
97
|
bool = true
|
76
98
|
else
|
77
99
|
@warning = nil
|
78
|
-
@exception
|
100
|
+
@exception ||= response.message
|
79
101
|
end
|
80
102
|
else
|
81
103
|
@exception = response.message
|
data/lib/net/ping/icmp.rb
CHANGED
@@ -97,33 +97,36 @@ module Net
|
|
97
97
|
|
98
98
|
begin
|
99
99
|
Timeout.timeout(@timeout){
|
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
|
-
|
125
|
-
|
126
|
-
|
100
|
+
while true
|
101
|
+
io_array = select([socket], nil, nil, timeout)
|
102
|
+
|
103
|
+
if io_array.nil? || io_array[0].empty?
|
104
|
+
return false
|
105
|
+
end
|
106
|
+
|
107
|
+
pid = nil
|
108
|
+
seq = nil
|
109
|
+
|
110
|
+
data, sender = socket.recvfrom(1500)
|
111
|
+
port, host = Socket.unpack_sockaddr_in(sender)
|
112
|
+
type, subcode = data[20, 2].unpack('C2')
|
113
|
+
|
114
|
+
case type
|
115
|
+
when ICMP_ECHOREPLY
|
116
|
+
if data.length >= 28
|
117
|
+
pid, seq = data[24, 4].unpack('n3')
|
118
|
+
end
|
119
|
+
else
|
120
|
+
if data.length > 56
|
121
|
+
pid, seq = data[52, 4].unpack('n3')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
if pid == @pid && seq == @seq && type == ICMP_ECHOREPLY
|
126
|
+
bool = true
|
127
|
+
break
|
128
|
+
end
|
129
|
+
end
|
127
130
|
}
|
128
131
|
rescue Exception => err
|
129
132
|
@exception = err
|
data/lib/net/ping/ping.rb
CHANGED
@@ -4,13 +4,13 @@ require 'timeout'
|
|
4
4
|
# The Net module serves as a namespace only.
|
5
5
|
#
|
6
6
|
module Net
|
7
|
-
|
7
|
+
|
8
8
|
# The Ping class serves as an abstract base class for all other Ping class
|
9
9
|
# types. You should not instantiate this class directly.
|
10
10
|
#
|
11
11
|
class Ping
|
12
12
|
# The version of the net-ping library.
|
13
|
-
VERSION = '1.
|
13
|
+
VERSION = '1.4.0'
|
14
14
|
|
15
15
|
# The host to ping. In the case of Ping::HTTP, this is the URI.
|
16
16
|
attr_accessor :host
|
@@ -44,7 +44,7 @@ module Net
|
|
44
44
|
# The default constructor for the Net::Ping class. Accepts an optional
|
45
45
|
# +host+, +port+ and +timeout+. The port defaults to your echo port, or
|
46
46
|
# 7 if that happens to be undefined. The default timeout is 5 seconds.
|
47
|
-
#
|
47
|
+
#
|
48
48
|
# The host, although optional in the constructor, must be specified at
|
49
49
|
# some point before the Net::Ping#ping method is called, or else an
|
50
50
|
# ArgumentError will be raised.
|
@@ -64,7 +64,7 @@ module Net
|
|
64
64
|
|
65
65
|
yield self if block_given?
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
# The default interface for the Net::Ping#ping method. Each subclass
|
69
69
|
# should call super() before continuing with their own implementation in
|
70
70
|
# order to ensure that the @exception and @warning instance variables
|
@@ -81,7 +81,7 @@ module Net
|
|
81
81
|
@exception = nil
|
82
82
|
@warning = nil
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
alias ping? ping
|
86
86
|
alias pingecho ping
|
87
87
|
end
|
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.
|
6
|
+
gem.version = '1.4.0'
|
7
7
|
gem.license = 'Artistic 2.0'
|
8
8
|
gem.author = 'Daniel J. Berger'
|
9
9
|
gem.email = 'djberg96@gmail.com'
|
@@ -16,10 +16,10 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.rubyforge_project = 'shards'
|
17
17
|
gem.extra_rdoc_files = ['README', 'CHANGES', 'doc/ping.txt']
|
18
18
|
|
19
|
-
gem.add_development_dependency('test-unit', '>= 2.
|
19
|
+
gem.add_development_dependency('test-unit', '>= 2.1.2')
|
20
20
|
|
21
21
|
# These dependencies are for Net::Ping::External
|
22
|
-
if Config::CONFIG['host_os'] =~ /mswin|dos|win32|cygwin|mingw/i &&
|
22
|
+
if Config::CONFIG['host_os'] =~ /mswin|dos|win32|windows|cygwin|mingw/i &&
|
23
23
|
RUBY_PLATFORM != 'java'
|
24
24
|
then
|
25
25
|
gem.platform = Gem::Platform::CURRENT
|
data/test/test_net_ping.rb
CHANGED
@@ -18,64 +18,98 @@ class TC_Net_Ping_External < Test::Unit::TestCase
|
|
18
18
|
@bad = Net::Ping::External.new(@bogus)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
test "ping basic functionality" do
|
22
22
|
assert_respond_to(@pe, :ping)
|
23
|
+
end
|
24
|
+
|
25
|
+
test "ping with no arguments" do
|
23
26
|
assert_nothing_raised{ @pe.ping }
|
27
|
+
end
|
28
|
+
|
29
|
+
test "ping accepts a hostname" do
|
24
30
|
assert_nothing_raised{ @pe.ping(@host) }
|
25
31
|
end
|
26
32
|
|
27
|
-
|
33
|
+
test "ping returns a boolean" do
|
34
|
+
assert_boolean(@pe.ping)
|
35
|
+
assert_boolean(@bad.ping)
|
36
|
+
end
|
37
|
+
|
38
|
+
test "ping? alias" do
|
28
39
|
assert_respond_to(@pe, :ping?)
|
29
|
-
|
30
|
-
|
31
|
-
|
40
|
+
assert_alias_method(@pe, :ping?, :ping)
|
41
|
+
end
|
42
|
+
|
43
|
+
test "pingecho alias" do
|
32
44
|
assert_nothing_raised{ @pe.pingecho }
|
33
|
-
|
45
|
+
assert_alias_method(@pe, :pingecho, :ping)
|
34
46
|
end
|
35
47
|
|
36
|
-
|
37
|
-
|
48
|
+
test "pinging a good host returns true" do
|
49
|
+
assert_true(@pe.ping?)
|
38
50
|
end
|
39
51
|
|
40
|
-
|
41
|
-
|
42
|
-
assert_equal(false, @bad.exception.nil?, "Bad exception data")
|
52
|
+
test "pinging a bogus host returns false" do
|
53
|
+
assert_false(@bad.ping?)
|
43
54
|
end
|
44
55
|
|
45
|
-
|
56
|
+
test "duration basic functionality" do
|
46
57
|
assert_nothing_raised{ @pe.ping }
|
47
58
|
assert_respond_to(@pe, :duration)
|
48
59
|
assert_kind_of(Float, @pe.duration)
|
49
60
|
end
|
50
61
|
|
51
|
-
|
62
|
+
test "host getter basic functionality" do
|
52
63
|
assert_respond_to(@pe, :host)
|
53
|
-
assert_respond_to(@pe, :host=)
|
54
64
|
assert_equal('www.ruby-lang.org', @pe.host)
|
55
65
|
end
|
56
66
|
|
57
|
-
|
67
|
+
test "host setter basic functionality" do
|
68
|
+
assert_respond_to(@pe, :host=)
|
69
|
+
assert_nothing_raised{ @pe.host = @bad }
|
70
|
+
assert_equal(@bad, @pe.host)
|
71
|
+
end
|
72
|
+
|
73
|
+
test "port getter basic functionality" do
|
58
74
|
assert_respond_to(@pe, :port)
|
59
|
-
assert_respond_to(@pe, :port=)
|
60
75
|
assert_equal(7, @pe.port)
|
61
76
|
end
|
62
77
|
|
63
|
-
|
78
|
+
test "port setter basic functionality" do
|
79
|
+
assert_respond_to(@pe, :port=)
|
80
|
+
assert_nothing_raised{ @pe.port = 90 }
|
81
|
+
assert_equal(90, @pe.port)
|
82
|
+
end
|
83
|
+
|
84
|
+
test "timeout getter basic functionality" do
|
64
85
|
assert_respond_to(@pe, :timeout)
|
65
|
-
assert_respond_to(@pe, :timeout=)
|
66
86
|
assert_equal(5, @pe.timeout)
|
67
87
|
end
|
68
88
|
|
69
|
-
|
89
|
+
test "timeout setter basic functionality" do
|
90
|
+
assert_respond_to(@pe, :timeout=)
|
91
|
+
assert_nothing_raised{ @pe.timeout = 30 }
|
92
|
+
assert_equal(30, @pe.timeout)
|
93
|
+
end
|
94
|
+
|
95
|
+
test "exception method basic functionality" do
|
70
96
|
assert_respond_to(@pe, :exception)
|
71
|
-
assert_nothing_raised{ @pe.ping }
|
72
|
-
assert_nothing_raised{ @bad.ping }
|
73
97
|
assert_nil(@pe.exception)
|
98
|
+
end
|
99
|
+
|
100
|
+
test "pinging a bogus host stores exception data" do
|
101
|
+
assert_nothing_raised{ @bad.ping? }
|
74
102
|
assert_not_nil(@bad.exception)
|
75
103
|
end
|
76
104
|
|
77
|
-
|
105
|
+
test "pinging a good host results in no exception data" do
|
106
|
+
assert_nothing_raised{ @pe.ping }
|
107
|
+
assert_nil(@pe.exception)
|
108
|
+
end
|
109
|
+
|
110
|
+
test "warning basic functionality" do
|
78
111
|
assert_respond_to(@pe, :warning)
|
112
|
+
assert_nil(@pe.warning)
|
79
113
|
end
|
80
114
|
|
81
115
|
def teardown
|
data/test/test_net_ping_http.rb
CHANGED
@@ -13,7 +13,7 @@ require 'net/ping/http'
|
|
13
13
|
class TC_Net_Ping_HTTP < Test::Unit::TestCase
|
14
14
|
def setup
|
15
15
|
@uri = 'http://www.google.com/index.html'
|
16
|
-
@http = Net::Ping::HTTP.new(@uri, 80, 30)
|
16
|
+
@http = Net::Ping::HTTP.new(@uri, 80, 30)
|
17
17
|
@bad = Net::Ping::HTTP.new('http://www.blabfoobarurghxxxx.com') # One hopes not
|
18
18
|
end
|
19
19
|
|
@@ -108,6 +108,58 @@ class TC_Net_Ping_HTTP < Test::Unit::TestCase
|
|
108
108
|
assert_nil(@http.warning)
|
109
109
|
end
|
110
110
|
|
111
|
+
test 'user_agent accessor is defined' do
|
112
|
+
assert_respond_to(@http, :user_agent)
|
113
|
+
assert_respond_to(@http, :user_agent=)
|
114
|
+
end
|
115
|
+
|
116
|
+
test 'user_agent defaults to nil' do
|
117
|
+
assert_nil(@http.user_agent)
|
118
|
+
end
|
119
|
+
|
120
|
+
test 'ping with user agent' do
|
121
|
+
@http.user_agent = "KDDI-CA32"
|
122
|
+
assert_true(@http.ping)
|
123
|
+
end
|
124
|
+
|
125
|
+
test 'redirect_limit accessor is defined' do
|
126
|
+
assert_respond_to(@http, :redirect_limit)
|
127
|
+
assert_respond_to(@http, :redirect_limit=)
|
128
|
+
end
|
129
|
+
|
130
|
+
test 'redirect_limit defaults to 5' do
|
131
|
+
assert_equal(5, @http.redirect_limit)
|
132
|
+
end
|
133
|
+
|
134
|
+
test 'redirects succeed by default' do
|
135
|
+
@http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
|
136
|
+
assert_true(@http.ping)
|
137
|
+
end
|
138
|
+
|
139
|
+
test 'redirect fail if follow_redirect is set to false' do
|
140
|
+
@http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
|
141
|
+
@http.follow_redirect = false
|
142
|
+
assert_false(@http.ping)
|
143
|
+
end
|
144
|
+
|
145
|
+
test 'ping with redirect limit set to zero fails' do
|
146
|
+
@http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
|
147
|
+
@http.redirect_limit = 0
|
148
|
+
assert_false(@http.ping)
|
149
|
+
assert_equal("Redirect limit exceeded", @http.exception)
|
150
|
+
end
|
151
|
+
|
152
|
+
test 'ping against https site defaults to port 443' do
|
153
|
+
@http = Net::Ping::HTTP.new("https://encrypted.google.com/")
|
154
|
+
assert_equal(443, @http.port)
|
155
|
+
end
|
156
|
+
|
157
|
+
# This will generate a warning. Nothing I can do about it.
|
158
|
+
test 'ping against https site works as expected' do
|
159
|
+
@http = Net::Ping::HTTP.new("https://encrypted.google.com/")
|
160
|
+
assert_true(@http.ping)
|
161
|
+
end
|
162
|
+
|
111
163
|
def teardown
|
112
164
|
@uri = nil
|
113
165
|
@http = nil
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-ping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 7
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
7
|
-
- 3
|
8
8
|
- 4
|
9
|
-
|
9
|
+
- 0
|
10
|
+
version: 1.4.0
|
10
11
|
platform: x86-mingw32
|
11
12
|
authors:
|
12
13
|
- Daniel J. Berger
|
@@ -14,30 +15,34 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-02-15 00:00:00 -07:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: test-unit
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
27
30
|
segments:
|
28
31
|
- 2
|
29
|
-
-
|
30
|
-
-
|
31
|
-
version: 2.
|
32
|
+
- 1
|
33
|
+
- 2
|
34
|
+
version: 2.1.2
|
32
35
|
type: :development
|
33
36
|
version_requirements: *id001
|
34
37
|
- !ruby/object:Gem::Dependency
|
35
38
|
name: windows-pr
|
36
39
|
prerelease: false
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 7
|
41
46
|
segments:
|
42
47
|
- 1
|
43
48
|
- 0
|
@@ -49,9 +54,11 @@ dependencies:
|
|
49
54
|
name: win32-open3
|
50
55
|
prerelease: false
|
51
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
52
58
|
requirements:
|
53
59
|
- - ">="
|
54
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 17
|
55
62
|
segments:
|
56
63
|
- 0
|
57
64
|
- 3
|
@@ -105,23 +112,27 @@ rdoc_options: []
|
|
105
112
|
require_paths:
|
106
113
|
- lib
|
107
114
|
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
108
116
|
requirements:
|
109
117
|
- - ">="
|
110
118
|
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
111
120
|
segments:
|
112
121
|
- 0
|
113
122
|
version: "0"
|
114
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
115
125
|
requirements:
|
116
126
|
- - ">="
|
117
127
|
- !ruby/object:Gem::Version
|
128
|
+
hash: 3
|
118
129
|
segments:
|
119
130
|
- 0
|
120
131
|
version: "0"
|
121
132
|
requirements: []
|
122
133
|
|
123
134
|
rubyforge_project: shards
|
124
|
-
rubygems_version: 1.3.
|
135
|
+
rubygems_version: 1.3.7
|
125
136
|
signing_key:
|
126
137
|
specification_version: 3
|
127
138
|
summary: A ping interface for Ruby.
|