net-ping 1.4.1-x86-mingw32 → 1.5.3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +258 -232
- data/MANIFEST +25 -23
- data/README +52 -46
- data/Rakefile +100 -89
- data/doc/ping.txt +274 -249
- data/examples/example_pingexternal.rb +16 -16
- data/examples/example_pinghttp.rb +22 -22
- data/examples/example_pingldap.rb +22 -0
- data/examples/example_pingtcp.rb +16 -16
- data/examples/example_pingudp.rb +12 -12
- data/lib/net/ping.rb +18 -15
- data/lib/net/ping/external.rb +122 -126
- data/lib/net/ping/http.rb +149 -120
- data/lib/net/ping/icmp.rb +180 -168
- data/lib/net/ping/ldap.rb +107 -0
- data/lib/net/ping/ping.rb +89 -88
- data/lib/net/ping/tcp.rb +83 -83
- data/lib/net/ping/udp.rb +119 -119
- data/lib/net/ping/wmi.rb +118 -118
- data/net-ping.gemspec +43 -38
- data/test/test_net_ping.rb +37 -37
- data/test/test_net_ping_external.rb +128 -121
- data/test/test_net_ping_http.rb +182 -176
- data/test/test_net_ping_icmp.rb +120 -116
- data/test/test_net_ping_ldap.rb +200 -0
- data/test/test_net_ping_tcp.rb +108 -108
- data/test/test_net_ping_udp.rb +122 -122
- data/test/test_net_ping_wmi.rb +84 -84
- metadata +59 -26
data/test/test_net_ping_http.rb
CHANGED
@@ -1,176 +1,182 @@
|
|
1
|
-
#################################################################################
|
2
|
-
# test_net_ping_http.rb
|
3
|
-
#
|
4
|
-
# Test case for the Net::PingHTTP class. This should be run via the 'test' or
|
5
|
-
# 'test:http' Rake task.
|
6
|
-
#################################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'net/ping/http'
|
12
|
-
|
13
|
-
class TC_Net_Ping_HTTP < Test::Unit::TestCase
|
14
|
-
def setup
|
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(:
|
20
|
-
FakeWeb.register_uri(:
|
21
|
-
|
22
|
-
:
|
23
|
-
:
|
24
|
-
|
25
|
-
|
26
|
-
@
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
assert_boolean(@
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
assert_respond_to(@http, :host
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
assert_alias_method(@http, :uri
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
assert_respond_to(@http, :port
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
assert_respond_to(@http, :timeout
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
assert_equal(
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
assert_respond_to(@http, :user_agent
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
assert_respond_to(@http, :redirect_limit
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
@http
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
@http
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
test 'ping against https site works as expected' do
|
168
|
-
@http = Net::Ping::HTTP.new(@uri_https)
|
169
|
-
assert_true(@http.ping)
|
170
|
-
end
|
171
|
-
|
172
|
-
|
173
|
-
@
|
174
|
-
@http =
|
175
|
-
|
176
|
-
end
|
1
|
+
#################################################################################
|
2
|
+
# test_net_ping_http.rb
|
3
|
+
#
|
4
|
+
# Test case for the Net::PingHTTP class. This should be run via the 'test' or
|
5
|
+
# 'test:http' Rake task.
|
6
|
+
#################################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'net/ping/http'
|
12
|
+
|
13
|
+
class TC_Net_Ping_HTTP < Test::Unit::TestCase
|
14
|
+
def setup
|
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(:head, @uri, :body => "PONG")
|
20
|
+
FakeWeb.register_uri(:head, @uri_https, :body => "PONG")
|
21
|
+
FakeWeb.register_uri(:head, "http://jigsaw.w3.org/HTTP/300/302.html",
|
22
|
+
:body => "PONG",
|
23
|
+
:location => "#{@uri}",
|
24
|
+
:status => ["302", "Found"])
|
25
|
+
|
26
|
+
@http = Net::Ping::HTTP.new(@uri, 80, 30)
|
27
|
+
@bad = Net::Ping::HTTP.new('http://www.blabfoobarurghxxxx.com') # One hopes not
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'ping basic functionality' do
|
31
|
+
assert_respond_to(@http, :ping)
|
32
|
+
assert_nothing_raised{ @http.ping }
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'ping returns a boolean value' do
|
36
|
+
assert_boolean(@http.ping?)
|
37
|
+
assert_boolean(@bad.ping?)
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'ping? is an alias for ping' do
|
41
|
+
assert_alias_method(@http, :ping?, :ping)
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'pingecho is an alias for ping' do
|
45
|
+
assert_alias_method(@http, :pingecho, :ping)
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'ping should succeed for a valid website' do
|
49
|
+
assert_true(@http.ping?)
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'ping should fail for an invalid website' do
|
53
|
+
assert_false(@bad.ping?)
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'duration basic functionality' do
|
57
|
+
assert_respond_to(@http, :duration)
|
58
|
+
assert_nothing_raised{ @http.ping }
|
59
|
+
end
|
60
|
+
|
61
|
+
test 'duration returns a float value on a successful ping' do
|
62
|
+
assert_true(@http.ping)
|
63
|
+
assert_kind_of(Float, @http.duration)
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'duration is nil on an unsuccessful ping' do
|
67
|
+
assert_false(@bad.ping)
|
68
|
+
assert_nil(@http.duration)
|
69
|
+
end
|
70
|
+
|
71
|
+
test 'host attribute basic functionality' do
|
72
|
+
assert_respond_to(@http, :host)
|
73
|
+
assert_respond_to(@http, :host=)
|
74
|
+
assert_equal('http://www.google.com/index.html', @http.host)
|
75
|
+
end
|
76
|
+
|
77
|
+
test 'uri is an alias for host' do
|
78
|
+
assert_alias_method(@http, :uri, :host)
|
79
|
+
assert_alias_method(@http, :uri=, :host=)
|
80
|
+
end
|
81
|
+
|
82
|
+
test 'port attribute basic functionality' do
|
83
|
+
assert_respond_to(@http, :port)
|
84
|
+
assert_respond_to(@http, :port=)
|
85
|
+
end
|
86
|
+
|
87
|
+
test 'port attribute expected value' do
|
88
|
+
assert_equal(80, @http.port)
|
89
|
+
end
|
90
|
+
|
91
|
+
test 'timeout attribute basic functionality' do
|
92
|
+
assert_respond_to(@http, :timeout)
|
93
|
+
assert_respond_to(@http, :timeout=)
|
94
|
+
end
|
95
|
+
|
96
|
+
test 'timeout attribute expected values' do
|
97
|
+
assert_equal(30, @http.timeout)
|
98
|
+
assert_equal(5, @bad.timeout)
|
99
|
+
end
|
100
|
+
|
101
|
+
test 'exception attribute basic functionality' do
|
102
|
+
assert_respond_to(@http, :exception)
|
103
|
+
assert_nil(@http.exception)
|
104
|
+
end
|
105
|
+
|
106
|
+
test 'exception attribute is nil if the ping is successful' do
|
107
|
+
assert_true(@http.ping)
|
108
|
+
assert_nil(@http.exception)
|
109
|
+
end
|
110
|
+
|
111
|
+
test 'exception attribute is not nil if the ping is unsuccessful' do
|
112
|
+
assert_false(@bad.ping)
|
113
|
+
assert_not_nil(@bad.exception)
|
114
|
+
end
|
115
|
+
|
116
|
+
test 'warning attribute basic functionality' do
|
117
|
+
assert_respond_to(@http, :warning)
|
118
|
+
assert_nil(@http.warning)
|
119
|
+
end
|
120
|
+
|
121
|
+
test 'user_agent accessor is defined' do
|
122
|
+
assert_respond_to(@http, :user_agent)
|
123
|
+
assert_respond_to(@http, :user_agent=)
|
124
|
+
end
|
125
|
+
|
126
|
+
test 'user_agent defaults to nil' do
|
127
|
+
assert_nil(@http.user_agent)
|
128
|
+
end
|
129
|
+
|
130
|
+
test 'ping with user agent' do
|
131
|
+
@http.user_agent = "KDDI-CA32"
|
132
|
+
assert_true(@http.ping)
|
133
|
+
end
|
134
|
+
|
135
|
+
test 'redirect_limit accessor is defined' do
|
136
|
+
assert_respond_to(@http, :redirect_limit)
|
137
|
+
assert_respond_to(@http, :redirect_limit=)
|
138
|
+
end
|
139
|
+
|
140
|
+
test 'redirect_limit defaults to 5' do
|
141
|
+
assert_equal(5, @http.redirect_limit)
|
142
|
+
end
|
143
|
+
|
144
|
+
test 'redirects succeed by default' do
|
145
|
+
@http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
|
146
|
+
assert_true(@http.ping)
|
147
|
+
end
|
148
|
+
|
149
|
+
test 'redirect fail if follow_redirect is set to false' do
|
150
|
+
@http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
|
151
|
+
@http.follow_redirect = false
|
152
|
+
assert_false(@http.ping)
|
153
|
+
end
|
154
|
+
|
155
|
+
test 'ping with redirect limit set to zero fails' do
|
156
|
+
@http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
|
157
|
+
@http.redirect_limit = 0
|
158
|
+
assert_false(@http.ping)
|
159
|
+
assert_equal("Redirect limit exceeded", @http.exception)
|
160
|
+
end
|
161
|
+
|
162
|
+
test 'ping against https site defaults to port 443' do
|
163
|
+
@http = Net::Ping::HTTP.new(@uri_https)
|
164
|
+
assert_equal(443, @http.port)
|
165
|
+
end
|
166
|
+
|
167
|
+
test 'ping against https site works as expected' do
|
168
|
+
@http = Net::Ping::HTTP.new(@uri_https)
|
169
|
+
assert_true(@http.ping)
|
170
|
+
end
|
171
|
+
|
172
|
+
test 'ping with get option' do
|
173
|
+
@http = Net::Ping::HTTP.new(@uri)
|
174
|
+
@http.get_request = true
|
175
|
+
assert_true(@http.ping)
|
176
|
+
end
|
177
|
+
|
178
|
+
def teardown
|
179
|
+
@uri = nil
|
180
|
+
@http = nil
|
181
|
+
end
|
182
|
+
end
|
data/test/test_net_ping_icmp.rb
CHANGED
@@ -1,116 +1,120 @@
|
|
1
|
-
#######################################################################
|
2
|
-
# test_net_ping_icmp.rb
|
3
|
-
#
|
4
|
-
# Test case for the Net::PingICMP class. You must run this test case
|
5
|
-
# with root privileges on UNIX systems. This should be run via the
|
6
|
-
# 'test' or 'test:icmp' Rake task.
|
7
|
-
#######################################################################
|
8
|
-
require 'rubygems'
|
9
|
-
gem 'test-unit'
|
10
|
-
|
11
|
-
require 'test/unit'
|
12
|
-
require 'net/ping/icmp'
|
13
|
-
include Net
|
14
|
-
|
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
|
27
|
-
end
|
28
|
-
|
29
|
-
class TC_PingICMP < Test::Unit::TestCase
|
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
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
assert_nothing_raised{ @icmp.
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
def
|
98
|
-
assert_respond_to(@icmp, :
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
assert_nothing_raised{ @icmp.data_size =
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
@
|
114
|
-
|
115
|
-
|
116
|
-
|
1
|
+
#######################################################################
|
2
|
+
# test_net_ping_icmp.rb
|
3
|
+
#
|
4
|
+
# Test case for the Net::PingICMP class. You must run this test case
|
5
|
+
# with root privileges on UNIX systems. This should be run via the
|
6
|
+
# 'test' or 'test:icmp' Rake task.
|
7
|
+
#######################################################################
|
8
|
+
require 'rubygems'
|
9
|
+
gem 'test-unit'
|
10
|
+
|
11
|
+
require 'test/unit'
|
12
|
+
require 'net/ping/icmp'
|
13
|
+
include Net
|
14
|
+
|
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
|
27
|
+
end
|
28
|
+
|
29
|
+
class TC_PingICMP < Test::Unit::TestCase
|
30
|
+
def setup
|
31
|
+
@host = '127.0.0.1' # '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_success
|
54
|
+
assert_true(Ping::ICMP.new(@host).ping?)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_ping_expected_failure
|
58
|
+
assert_false(Ping::ICMP.new('bogus').ping?)
|
59
|
+
assert_false(Ping::ICMP.new('http://www.asdfhjklasdfhlkj.com').ping?)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_bind
|
63
|
+
assert_respond_to(@icmp, :bind)
|
64
|
+
assert_nothing_raised{ @icmp.bind(Socket.gethostname) }
|
65
|
+
assert_nothing_raised{ @icmp.bind(Socket.gethostname, 80) }
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_duration
|
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(@host, @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
|
+
assert_nothing_raised{ @icmp.ping }
|
94
|
+
assert_nil(@icmp.exception)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_warning
|
98
|
+
assert_respond_to(@icmp, :warning)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_data_size_get
|
102
|
+
assert_respond_to(@icmp, :data_size)
|
103
|
+
assert_equal(56, @icmp.data_size)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_data_size_set
|
107
|
+
assert_respond_to(@icmp, :data_size=)
|
108
|
+
assert_nothing_raised{ @icmp.data_size = 22 }
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_odd_data_size_ok
|
112
|
+
assert_nothing_raised{ @icmp.data_size = 57 }
|
113
|
+
assert_boolean(@icmp.ping)
|
114
|
+
end
|
115
|
+
|
116
|
+
def teardown
|
117
|
+
@host = nil
|
118
|
+
@icmp = nil
|
119
|
+
end
|
120
|
+
end
|