Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 5 commits
  • 9 files changed
  • 0 comments
  • 2 contributors
7 CHANGES
... ... @@ -1,6 +1,9 @@
1   -== 1.6.0 - ???
2   -* Split out the ldap portion of the code into its own library.
  1 +== 1.6.0 - 19-Mar-2013
  2 +* Split out the ldap portion of the code into its own branch.
3 3 * Don't require resolv-replace on Ruby 1.9.3 or later.
  4 +* Now gets proxy information from the http_proxy, https_proxy, and
  5 + no_proxy environment variables and uses that when making requests.
  6 + Thanks go to Kevin Olbrich for the patch.
4 7
5 8 == 1.5.3 - 29-Feb-2012
6 9 * Removed the Windows::Console dependency and replaced it with FFI since there
11 Rakefile
@@ -39,11 +39,6 @@ namespace 'example' do
39 39 task :udp do
40 40 ruby '-Ilib examples/example_pingudp.rb'
41 41 end
42   -
43   - desc 'Run the ldap ping example program'
44   - task :ldap do
45   - ruby '-Ilib examples/example_pingldap.rb'
46   - end
47 42 end
48 43
49 44 Rake::TestTask.new do |t|
@@ -89,12 +84,6 @@ namespace 'test' do
89 84 t.verbose = true
90 85 t.test_files = FileList['test/test_net_ping_wmi.rb']
91 86 end
92   -
93   - Rake::TestTask.new('ldap') do |t|
94   - t.warning = true
95   - t.verbose = true
96   - t.test_files = FileList['test/test_net_ping_ldap.rb']
97   - end
98 87 end
99 88
100 89 task :default => :test
22 examples/example_pingldap.rb
... ... @@ -1,22 +0,0 @@
1   -########################################################################
2   -# example_pingldap.rb
3   -#
4   -# A short sample program demonstrating an ldap ping. You can run
5   -# this program via the example:ldap task. Modify as you see fit.
6   -########################################################################
7   -require 'net/ping/ldap'
8   -
9   -good = 'ldap://localhost'
10   -bad = 'ldap://example.com'
11   -
12   -puts "== Good ping (if you have an ldap server at #{good})"
13   -
14   -p1 = Net::Ping::LDAP.new(good)
15   -p p1.ping?
16   -
17   -puts "== Bad ping"
18   -
19   -p2 = Net::Ping::LDAP.new(bad)
20   -p p2.ping?
21   -p p2.warning
22   -p p2.exception
3  lib/net/ping.rb
@@ -9,10 +9,9 @@
9 9 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   -require File.join(File.dirname(__FILE__), 'ping/ldap')
13 12
14 13 RbConfig = Config unless Object.const_defined?(:RbConfig)
15 14
16   -if RbConfig::CONFIG['host_os'] =~ /msdos|mswin|cygwin|mingw|win32|windows/i
  15 +if File::ALT_SEPARATOR
17 16 require File.join(File.dirname(__FILE__), 'ping/wmi')
18 17 end
107 lib/net/ping/ldap.rb
... ... @@ -1,107 +0,0 @@
1   -require File.join(File.dirname(__FILE__), 'ping')
2   -require 'net/ldap'
3   -require 'uri'
4   -
5   -
6   -# The Net module serves as a namespace only.
7   -module Net
8   -
9   - # The Ping::LDAP class encapsulates methods for LDAP pings.
10   - class Ping::LDAP < Ping
11   -
12   - # uri contains the URI object for the request
13   - #
14   - attr_accessor :uri
15   -
16   - # username and password may be set for ping using
17   - # an authenticated LDAP bind
18   - #
19   - attr_accessor :username
20   - attr_accessor :password
21   -
22   - # set/get the encryption method. By default nil,
23   - # but may be set to :simple_tls
24   - #
25   - attr_accessor :encryption
26   - def encryption=(value)
27   - @encryption = (value.is_a? Symbol) ? value : value.to_sym
28   - end
29   -
30   - # Creates and returns a new Ping::LDAP object.
31   - # The default +timeout+ is 5 seconds.
32   - #
33   - # +uri+ string is expected to be a full URI with scheme (ldap/ldaps)
34   - # and optionally the port (else default port is assumed) e.g.
35   - # ldap://my.ldap.host.com
36   - # ldap://my.ldap.host.com:1389
37   - # ldaps://my.ldap.host.com
38   - # ldaps://my.ldap.host.com:6636
39   - #
40   - # If a plain hostname is provided as the +uri+, a default port of 389 is assumed
41   - #
42   - def initialize(uri=nil, timeout=5)
43   - host, port = decode_uri(uri)
44   - super(host, port, timeout)
45   - end
46   -
47   - # method used to decode uri string
48   - #
49   - def decode_uri(value)
50   - @uri = URI.parse(value)
51   - if uri.scheme =~ /ldap/
52   - p = @port = uri.port
53   - h = @host = uri.host
54   - @encryption = uri.scheme=='ldaps' ? :simple_tls : nil
55   - else
56   - h = value
57   - p = 389
58   - end
59   - [h, p]
60   - end
61   -
62   - # constructs the LDAP configuration structure
63   - #
64   - def config
65   - {
66   - :host => uri.host,
67   - :port => uri.port,
68   - :encryption => encryption
69   - }.merge(
70   - (username && password) ?
71   - { :auth => {:method => :simple, :username => username, :password => password} } :
72   - { :auth => {:method => :anonymous} }
73   - )
74   - end
75   -
76   - # perform ping, optionally providing the ping destination uri
77   - #
78   - def ping(host = nil)
79   - decode_uri(host) if host
80   - super(@host)
81   -
82   - bool = false
83   -
84   - start_time = Time.now
85   -
86   - begin
87   - Timeout.timeout(@timeout) do
88   - Net::LDAP.new( config ).bind
89   - end
90   - rescue Net::LDAP::LdapError => e
91   - @exception = e.message
92   - rescue Exception => e
93   - @exception = e.message
94   - else
95   - bool = true
96   - end
97   -
98   - # There is no duration if the ping failed
99   - @duration = Time.now - start_time if bool
100   -
101   - bool
102   - end
103   -
104   - alias ping? ping
105   - alias pingecho ping
106   - end
107   -end
2  lib/net/ping/ping.rb
@@ -10,7 +10,7 @@ module Net
10 10 #
11 11 class Ping
12 12 # The version of the net-ping library.
13   - VERSION = '1.5.3'
  13 + VERSION = '1.6.0'
14 14
15 15 # The host to ping. In the case of Ping::HTTP, this is the URI.
16 16 attr_accessor :host
4 net-ping.gemspec
@@ -3,7 +3,7 @@ require 'rbconfig'
3 3
4 4 Gem::Specification.new do |spec|
5 5 spec.name = 'net-ping'
6   - spec.version = '1.5.3'
  6 + spec.version = '1.6.0'
7 7 spec.license = 'Artistic 2.0'
8 8 spec.author = 'Daniel J. Berger'
9 9 spec.email = 'djberg96@gmail.com'
@@ -15,12 +15,10 @@ Gem::Specification.new do |spec|
15 15 spec.rubyforge_project = 'shards'
16 16 spec.extra_rdoc_files = ['README', 'CHANGES', 'doc/ping.txt']
17 17
18   - spec.add_dependency('net-ldap', '~> 0.2.2')
19 18 spec.add_dependency('ffi', '>= 1.0.0')
20 19
21 20 spec.add_development_dependency('test-unit', '>= 2.5.0')
22 21 spec.add_development_dependency('fakeweb', '>= 1.3.0')
23   - spec.add_development_dependency('fakeldap', '~> 0.0.1')
24 22
25 23 if File::ALT_SEPARATOR && RUBY_PLATFORM != 'java'
26 24 spec.platform = Gem::Platform::CURRENT
2  test/test_net_ping.rb
@@ -28,7 +28,7 @@
28 28
29 29 class TC_Net_Ping < Test::Unit::TestCase
30 30 def test_net_ping_version
31   - assert_equal('1.5.3', Net::Ping::VERSION)
  31 + assert_equal('1.6.0', Net::Ping::VERSION)
32 32 end
33 33 end
34 34
197 test/test_net_ping_ldap.rb
... ... @@ -1,197 +0,0 @@
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 'test-unit'
8   -require 'net/ping/ldap'
9   -require 'fakeldap'
10   -
11   -class TC_Net_Ping_LDAP < Test::Unit::TestCase
12   - class << self
13   - def startup
14   - @@host = 'localhost'
15   - @@port = 2389
16   - @@uri = "ldap://#{@@host}:#{@@port}"
17   - @@timeout = 30
18   - @@cn = 'el.Daper'
19   - @@password = 'ldappassword'
20   -
21   - @@ldap_server = FakeLDAP::Server.new(:port => @@port)
22   - @@ldap_server.run_tcpserver
23   - @@ldap_server.add_user("cn=#{@@cn},ou=USERS,dc=example,dc=com", @@password)
24   - end
25   - def shutdown
26   - @@ldap_server.stop
27   - end
28   - end
29   - def setup
30   - @ldap = Net::Ping::LDAP.new(@@uri, @@timeout)
31   - @ldap.username = @@cn
32   - @ldap.password = @@password
33   - @bogus = 'ldap://blabfoobarurghxxxx.com' # One hopes so
34   - @bad = Net::Ping::LDAP.new(@bogus)
35   - end
36   -
37   - def teardown
38   - @ldap = nil
39   - end
40   -
41   - test 'ping basic functionality' do
42   - assert_respond_to(@ldap, :ping)
43   - assert_nothing_raised{ @ldap.ping }
44   - end
45   -
46   - test 'ping returns a boolean value' do
47   - assert_boolean(@ldap.ping?)
48   - assert_boolean(@bad.ping?)
49   - end
50   -
51   - test 'ping? is an alias for ping' do
52   - assert_alias_method(@ldap, :ping?, :ping)
53   - end
54   -
55   - test 'pingecho is an alias for ping' do
56   - assert_alias_method(@ldap, :pingecho, :ping)
57   - end
58   -
59   - test 'ping should succeed for a valid website' do
60   - assert_true(@ldap.ping?)
61   - end
62   -
63   - test 'ping should fail for an invalid website' do
64   - assert_false(@bad.ping?)
65   - end
66   -
67   - test 'duration basic functionality' do
68   - assert_respond_to(@ldap, :duration)
69   - assert_nothing_raised{ @ldap.ping }
70   - end
71   -
72   - test 'duration returns a float value on a successful ping' do
73   - assert_true(@ldap.ping)
74   - assert_kind_of(Float, @ldap.duration)
75   - end
76   -
77   - test 'duration is nil on an unsuccessful ping' do
78   - assert_false(@bad.ping)
79   - assert_nil(@ldap.duration)
80   - end
81   -
82   - test "duration is unset if a bad ping follows a good ping" do
83   - assert_true{ @ldap.ping }
84   - assert_not_nil(@ldap.duration)
85   - assert_false(@ldap.ping?(@bogus))
86   - assert_nil(@ldap.duration)
87   - end
88   -
89   - test 'host attribute basic functionality' do
90   - assert_respond_to(@ldap, :host)
91   - assert_respond_to(@ldap, :host=)
92   - assert_equal(@@host, @ldap.host)
93   - end
94   -
95   - test 'port attribute basic functionality' do
96   - assert_respond_to(@ldap, :port)
97   - assert_respond_to(@ldap, :port=)
98   - end
99   -
100   - test 'port attribute expected value' do
101   - assert_equal(@@port, @ldap.port)
102   - end
103   -
104   - test 'timeout attribute basic functionality' do
105   - assert_respond_to(@ldap, :timeout)
106   - assert_respond_to(@ldap, :timeout=)
107   - end
108   -
109   - test 'timeout attribute expected values' do
110   - assert_equal(@@timeout, @ldap.timeout)
111   - assert_equal(5, @bad.timeout)
112   - end
113   -
114   - test 'exception attribute basic functionality' do
115   - assert_respond_to(@ldap, :exception)
116   - assert_nil(@ldap.exception)
117   - end
118   -
119   - test 'exception attribute is nil if the ping is successful' do
120   - assert_true(@ldap.ping)
121   - assert_nil(@ldap.exception)
122   - end
123   -
124   - test 'exception attribute is not nil if the ping is unsuccessful' do
125   - assert_false(@bad.ping)
126   - assert_not_nil(@bad.exception)
127   - end
128   -
129   - test 'warning attribute basic functionality' do
130   - assert_respond_to(@ldap, :warning)
131   - assert_nil(@ldap.warning)
132   - end
133   -
134   - test 'uri attribute basic functionality' do
135   - assert_respond_to(@ldap, :uri)
136   - assert_respond_to(@ldap, :uri=)
137   - end
138   -
139   - test 'username attribute basic functionality' do
140   - assert_respond_to(@ldap, :username)
141   - assert_respond_to(@ldap, :username=)
142   - end
143   -
144   - test 'password attribute basic functionality' do
145   - assert_respond_to(@ldap, :password)
146   - assert_respond_to(@ldap, :password=)
147   - end
148   -
149   - test 'encryption attribute basic functionality' do
150   - assert_respond_to(@ldap, :encryption)
151   - assert_respond_to(@ldap, :encryption=)
152   - end
153   -
154   - test 'encryption defaults to nil for ldap' do
155   - assert_nil(Net::Ping::LDAP.new('ldap://somehost.example.net').encryption)
156   - end
157   -
158   - test 'encryption defaults to simple_tls for ldaps' do
159   - assert_equal(:simple_tls, Net::Ping::LDAP.new('ldaps://somehost.example.net').encryption)
160   - end
161   -
162   - test 'port defaults to 389 for ldap' do
163   - assert_equal(389, Net::Ping::LDAP.new('ldap://somehost.example.net').port)
164   - end
165   -
166   - test 'port defaults to 636 for ldaps' do
167   - assert_equal(636, Net::Ping::LDAP.new('ldaps://somehost.example.net').port)
168   - end
169   -
170   - test 'port extracted from uri if provided' do
171   - assert_equal(12345, Net::Ping::LDAP.new('ldap://somehost.example.net:12345').port)
172   - assert_equal(12345, Net::Ping::LDAP.new('ldaps://somehost.example.net:12345').port)
173   - end
174   -
175   - test 'encryption setting is forced to symbol' do
176   - @ldap.encryption = 'simple_tls'
177   - assert_true( @ldap.encryption.is_a? Symbol )
178   - assert_true( @ldap.config[:encryption].is_a? Symbol )
179   - end
180   -
181   - test 'username/password set in config auth section' do
182   - @ldap.username, @ldap.password = 'fred', 'derf'
183   - assert_equal('fred', @ldap.config[:auth][:username] )
184   - assert_equal('derf', @ldap.config[:auth][:password] )
185   - end
186   -
187   - test 'auth method defaults to simple if username/password set' do
188   - @ldap.username, @ldap.password = 'fred', 'derf'
189   - assert_equal(:simple, @ldap.config[:auth][:method] )
190   - end
191   -
192   - test 'if no username/password then defaults to auth anonymous' do
193   - @ldap.username = @ldap.password = nil
194   - assert_equal({:method => :anonymous}, @ldap.config[:auth] )
195   - end
196   -
197   -end

No commit comments for this range

Something went wrong with that request. Please try again.