Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

sync with upstream #1

Merged
merged 4 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 28, 2013
  1. @djberg96

    Merge pull request #15 from 6fusion/master

    djberg96 authored
    add support for proxies to Net::Ping::HTTP
Commits on Mar 19, 2013
  1. @djberg96
  2. @djberg96
  3. @djberg96
This page is out of date. Refresh to see the latest.
View
7 CHANGES
@@ -1,6 +1,9 @@
-== 1.6.0 - ???
-* Split out the ldap portion of the code into its own library.
+== 1.6.0 - 19-Mar-2013
+* Split out the ldap portion of the code into its own branch.
* Don't require resolv-replace on Ruby 1.9.3 or later.
+* Now gets proxy information from the http_proxy, https_proxy, and
+ no_proxy environment variables and uses that when making requests.
+ Thanks go to Kevin Olbrich for the patch.
== 1.5.3 - 29-Feb-2012
* Removed the Windows::Console dependency and replaced it with FFI since there
View
11 Rakefile
@@ -39,11 +39,6 @@ namespace 'example' do
task :udp do
ruby '-Ilib examples/example_pingudp.rb'
end
-
- desc 'Run the ldap ping example program'
- task :ldap do
- ruby '-Ilib examples/example_pingldap.rb'
- end
end
Rake::TestTask.new do |t|
@@ -89,12 +84,6 @@ namespace 'test' do
t.verbose = true
t.test_files = FileList['test/test_net_ping_wmi.rb']
end
-
- Rake::TestTask.new('ldap') do |t|
- t.warning = true
- t.verbose = true
- t.test_files = FileList['test/test_net_ping_ldap.rb']
- end
end
task :default => :test
View
22 examples/example_pingldap.rb
@@ -1,22 +0,0 @@
-########################################################################
-# example_pingldap.rb
-#
-# A short sample program demonstrating an ldap ping. You can run
-# this program via the example:ldap task. Modify as you see fit.
-########################################################################
-require 'net/ping/ldap'
-
-good = 'ldap://localhost'
-bad = 'ldap://example.com'
-
-puts "== Good ping (if you have an ldap server at #{good})"
-
-p1 = Net::Ping::LDAP.new(good)
-p p1.ping?
-
-puts "== Bad ping"
-
-p2 = Net::Ping::LDAP.new(bad)
-p p2.ping?
-p p2.warning
-p p2.exception
View
3  lib/net/ping.rb
@@ -9,10 +9,9 @@
require File.join(File.dirname(__FILE__), 'ping/icmp')
require File.join(File.dirname(__FILE__), 'ping/external')
require File.join(File.dirname(__FILE__), 'ping/http')
-require File.join(File.dirname(__FILE__), 'ping/ldap')
RbConfig = Config unless Object.const_defined?(:RbConfig)
-if RbConfig::CONFIG['host_os'] =~ /msdos|mswin|cygwin|mingw|win32|windows/i
+if File::ALT_SEPARATOR
require File.join(File.dirname(__FILE__), 'ping/wmi')
end
View
107 lib/net/ping/ldap.rb
@@ -1,107 +0,0 @@
-require File.join(File.dirname(__FILE__), 'ping')
-require 'net/ldap'
-require 'uri'
-
-
-# The Net module serves as a namespace only.
-module Net
-
- # The Ping::LDAP class encapsulates methods for LDAP pings.
- class Ping::LDAP < Ping
-
- # uri contains the URI object for the request
- #
- attr_accessor :uri
-
- # username and password may be set for ping using
- # an authenticated LDAP bind
- #
- attr_accessor :username
- attr_accessor :password
-
- # set/get the encryption method. By default nil,
- # but may be set to :simple_tls
- #
- attr_accessor :encryption
- def encryption=(value)
- @encryption = (value.is_a? Symbol) ? value : value.to_sym
- end
-
- # Creates and returns a new Ping::LDAP object.
- # The default +timeout+ is 5 seconds.
- #
- # +uri+ string is expected to be a full URI with scheme (ldap/ldaps)
- # and optionally the port (else default port is assumed) e.g.
- # ldap://my.ldap.host.com
- # ldap://my.ldap.host.com:1389
- # ldaps://my.ldap.host.com
- # ldaps://my.ldap.host.com:6636
- #
- # If a plain hostname is provided as the +uri+, a default port of 389 is assumed
- #
- def initialize(uri=nil, timeout=5)
- host, port = decode_uri(uri)
- super(host, port, timeout)
- end
-
- # method used to decode uri string
- #
- def decode_uri(value)
- @uri = URI.parse(value)
- if uri.scheme =~ /ldap/
- p = @port = uri.port
- h = @host = uri.host
- @encryption = uri.scheme=='ldaps' ? :simple_tls : nil
- else
- h = value
- p = 389
- end
- [h, p]
- end
-
- # constructs the LDAP configuration structure
- #
- def config
- {
- :host => uri.host,
- :port => uri.port,
- :encryption => encryption
- }.merge(
- (username && password) ?
- { :auth => {:method => :simple, :username => username, :password => password} } :
- { :auth => {:method => :anonymous} }
- )
- end
-
- # perform ping, optionally providing the ping destination uri
- #
- def ping(host = nil)
- decode_uri(host) if host
- super(@host)
-
- bool = false
-
- start_time = Time.now
-
- begin
- Timeout.timeout(@timeout) do
- Net::LDAP.new( config ).bind
- end
- rescue Net::LDAP::LdapError => e
- @exception = e.message
- rescue Exception => e
- @exception = e.message
- else
- bool = true
- end
-
- # There is no duration if the ping failed
- @duration = Time.now - start_time if bool
-
- bool
- end
-
- alias ping? ping
- alias pingecho ping
- end
-end
View
2  lib/net/ping/ping.rb
@@ -10,7 +10,7 @@ module Net
#
class Ping
# The version of the net-ping library.
- VERSION = '1.5.3'
+ VERSION = '1.6.0'
# The host to ping. In the case of Ping::HTTP, this is the URI.
attr_accessor :host
View
4 net-ping.gemspec
@@ -3,7 +3,7 @@ require 'rbconfig'
Gem::Specification.new do |spec|
spec.name = 'net-ping'
- spec.version = '1.5.3'
+ spec.version = '1.6.0'
spec.license = 'Artistic 2.0'
spec.author = 'Daniel J. Berger'
spec.email = 'djberg96@gmail.com'
@@ -15,12 +15,10 @@ Gem::Specification.new do |spec|
spec.rubyforge_project = 'shards'
spec.extra_rdoc_files = ['README', 'CHANGES', 'doc/ping.txt']
- spec.add_dependency('net-ldap', '~> 0.2.2')
spec.add_dependency('ffi', '>= 1.0.0')
spec.add_development_dependency('test-unit', '>= 2.5.0')
spec.add_development_dependency('fakeweb', '>= 1.3.0')
- spec.add_development_dependency('fakeldap', '~> 0.0.1')
if File::ALT_SEPARATOR && RUBY_PLATFORM != 'java'
spec.platform = Gem::Platform::CURRENT
View
2  test/test_net_ping.rb
@@ -28,7 +28,7 @@
class TC_Net_Ping < Test::Unit::TestCase
def test_net_ping_version
- assert_equal('1.5.3', Net::Ping::VERSION)
+ assert_equal('1.6.0', Net::Ping::VERSION)
end
end
View
197 test/test_net_ping_ldap.rb
@@ -1,197 +0,0 @@
-#################################################################################
-# test_net_ping_http.rb
-#
-# Test case for the Net::PingHTTP class. This should be run via the 'test' or
-# 'test:http' Rake task.
-#################################################################################
-require 'test-unit'
-require 'net/ping/ldap'
-require 'fakeldap'
-
-class TC_Net_Ping_LDAP < Test::Unit::TestCase
- class << self
- def startup
- @@host = 'localhost'
- @@port = 2389
- @@uri = "ldap://#{@@host}:#{@@port}"
- @@timeout = 30
- @@cn = 'el.Daper'
- @@password = 'ldappassword'
-
- @@ldap_server = FakeLDAP::Server.new(:port => @@port)
- @@ldap_server.run_tcpserver
- @@ldap_server.add_user("cn=#{@@cn},ou=USERS,dc=example,dc=com", @@password)
- end
- def shutdown
- @@ldap_server.stop
- end
- end
- def setup
- @ldap = Net::Ping::LDAP.new(@@uri, @@timeout)
- @ldap.username = @@cn
- @ldap.password = @@password
- @bogus = 'ldap://blabfoobarurghxxxx.com' # One hopes so
- @bad = Net::Ping::LDAP.new(@bogus)
- end
-
- def teardown
- @ldap = nil
- end
-
- test 'ping basic functionality' do
- assert_respond_to(@ldap, :ping)
- assert_nothing_raised{ @ldap.ping }
- end
-
- test 'ping returns a boolean value' do
- assert_boolean(@ldap.ping?)
- assert_boolean(@bad.ping?)
- end
-
- test 'ping? is an alias for ping' do
- assert_alias_method(@ldap, :ping?, :ping)
- end
-
- test 'pingecho is an alias for ping' do
- assert_alias_method(@ldap, :pingecho, :ping)
- end
-
- test 'ping should succeed for a valid website' do
- assert_true(@ldap.ping?)
- end
-
- test 'ping should fail for an invalid website' do
- assert_false(@bad.ping?)
- end
-
- test 'duration basic functionality' do
- assert_respond_to(@ldap, :duration)
- assert_nothing_raised{ @ldap.ping }
- end
-
- test 'duration returns a float value on a successful ping' do
- assert_true(@ldap.ping)
- assert_kind_of(Float, @ldap.duration)
- end
-
- test 'duration is nil on an unsuccessful ping' do
- assert_false(@bad.ping)
- assert_nil(@ldap.duration)
- end
-
- test "duration is unset if a bad ping follows a good ping" do
- assert_true{ @ldap.ping }
- assert_not_nil(@ldap.duration)
- assert_false(@ldap.ping?(@bogus))
- assert_nil(@ldap.duration)
- end
-
- test 'host attribute basic functionality' do
- assert_respond_to(@ldap, :host)
- assert_respond_to(@ldap, :host=)
- assert_equal(@@host, @ldap.host)
- end
-
- test 'port attribute basic functionality' do
- assert_respond_to(@ldap, :port)
- assert_respond_to(@ldap, :port=)
- end
-
- test 'port attribute expected value' do
- assert_equal(@@port, @ldap.port)
- end
-
- test 'timeout attribute basic functionality' do
- assert_respond_to(@ldap, :timeout)
- assert_respond_to(@ldap, :timeout=)
- end
-
- test 'timeout attribute expected values' do
- assert_equal(@@timeout, @ldap.timeout)
- assert_equal(5, @bad.timeout)
- end
-
- test 'exception attribute basic functionality' do
- assert_respond_to(@ldap, :exception)
- assert_nil(@ldap.exception)
- end
-
- test 'exception attribute is nil if the ping is successful' do
- assert_true(@ldap.ping)
- assert_nil(@ldap.exception)
- end
-
- test 'exception attribute is not nil if the ping is unsuccessful' do
- assert_false(@bad.ping)
- assert_not_nil(@bad.exception)
- end
-
- test 'warning attribute basic functionality' do
- assert_respond_to(@ldap, :warning)
- assert_nil(@ldap.warning)
- end
-
- test 'uri attribute basic functionality' do
- assert_respond_to(@ldap, :uri)
- assert_respond_to(@ldap, :uri=)
- end
-
- test 'username attribute basic functionality' do
- assert_respond_to(@ldap, :username)
- assert_respond_to(@ldap, :username=)
- end
-
- test 'password attribute basic functionality' do
- assert_respond_to(@ldap, :password)
- assert_respond_to(@ldap, :password=)
- end
-
- test 'encryption attribute basic functionality' do
- assert_respond_to(@ldap, :encryption)
- assert_respond_to(@ldap, :encryption=)
- end
-
- test 'encryption defaults to nil for ldap' do
- assert_nil(Net::Ping::LDAP.new('ldap://somehost.example.net').encryption)
- end
-
- test 'encryption defaults to simple_tls for ldaps' do
- assert_equal(:simple_tls, Net::Ping::LDAP.new('ldaps://somehost.example.net').encryption)
- end
-
- test 'port defaults to 389 for ldap' do
- assert_equal(389, Net::Ping::LDAP.new('ldap://somehost.example.net').port)
- end
-
- test 'port defaults to 636 for ldaps' do
- assert_equal(636, Net::Ping::LDAP.new('ldaps://somehost.example.net').port)
- end
-
- test 'port extracted from uri if provided' do
- assert_equal(12345, Net::Ping::LDAP.new('ldap://somehost.example.net:12345').port)
- assert_equal(12345, Net::Ping::LDAP.new('ldaps://somehost.example.net:12345').port)
- end
-
- test 'encryption setting is forced to symbol' do
- @ldap.encryption = 'simple_tls'
- assert_true( @ldap.encryption.is_a? Symbol )
- assert_true( @ldap.config[:encryption].is_a? Symbol )
- end
-
- test 'username/password set in config auth section' do
- @ldap.username, @ldap.password = 'fred', 'derf'
- assert_equal('fred', @ldap.config[:auth][:username] )
- assert_equal('derf', @ldap.config[:auth][:password] )
- end
-
- test 'auth method defaults to simple if username/password set' do
- @ldap.username, @ldap.password = 'fred', 'derf'
- assert_equal(:simple, @ldap.config[:auth][:method] )
- end
-
- test 'if no username/password then defaults to auth anonymous' do
- @ldap.username = @ldap.password = nil
- assert_equal({:method => :anonymous}, @ldap.config[:auth] )
- end
-
-end
Something went wrong with that request. Please try again.