Skip to content

Commit

Permalink
Merge pull request #151 from stefanmb/stefanmb/allow_false_verify_hos…
Browse files Browse the repository at this point in the history
…tname

Allow setting verify_hostname to false
  • Loading branch information
tenderlove authored Sep 9, 2024
2 parents 5c07962 + f9e3814 commit f99bcb2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/net/http/persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ def ssl connection
connection.verify_depth = @verify_depth
connection.verify_mode = @verify_mode
connection.verify_hostname = @verify_hostname if
@verify_hostname && connection.respond_to?(:verify_hostname=)
@verify_hostname != nil && connection.respond_to?(:verify_hostname=)

if OpenSSL::SSL::VERIFY_PEER == OpenSSL::SSL::VERIFY_NONE and
not Object.const_defined?(:I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG) then
Expand Down Expand Up @@ -1111,7 +1111,7 @@ def verify_mode= verify_mode
end

##
# Sets the HTTPS verify_hostname. Defaults to false.
# Sets the HTTPS verify_hostname.

def verify_hostname= verify_hostname
@verify_hostname = verify_hostname
Expand All @@ -1131,4 +1131,3 @@ def verify_callback= callback

require_relative 'persistent/connection'
require_relative 'persistent/pool'

19 changes: 17 additions & 2 deletions test/test_net_http_persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ def test_ssl_verify_mode
assert_equal OpenSSL::SSL::VERIFY_NONE, c.verify_mode
end

def test_ssl_verify_hostname
def test_ssl_enable_verify_hostname
skip 'OpenSSL is missing' unless HAVE_OPENSSL

@http.verify_hostname = true
Expand All @@ -1358,6 +1358,22 @@ def test_ssl_verify_hostname
assert c.verify_hostname
end

def test_ssl_disable_verify_hostname
skip 'OpenSSL is missing' unless HAVE_OPENSSL

@http.verify_hostname = false
c = Net::HTTP.new 'localhost', 80

skip 'net/http doesn\'t provide verify_hostname= method' unless
c.respond_to?(:verify_hostname=)

@http.ssl c

assert c.use_ssl?
assert c.verify_hostname == false
end


def test_ssl_warning
skip 'OpenSSL is missing' unless HAVE_OPENSSL

Expand Down Expand Up @@ -1474,4 +1490,3 @@ def test_connection_pool_after_fork
end
end
end

0 comments on commit f99bcb2

Please sign in to comment.