Skip to content

Commit f99bcb2

Browse files
authored
Merge pull request #151 from stefanmb/stefanmb/allow_false_verify_hostname
Allow setting verify_hostname to false
2 parents 5c07962 + f9e3814 commit f99bcb2

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

lib/net/http/persistent.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ def ssl connection
10011001
connection.verify_depth = @verify_depth
10021002
connection.verify_mode = @verify_mode
10031003
connection.verify_hostname = @verify_hostname if
1004-
@verify_hostname && connection.respond_to?(:verify_hostname=)
1004+
@verify_hostname != nil && connection.respond_to?(:verify_hostname=)
10051005

10061006
if OpenSSL::SSL::VERIFY_PEER == OpenSSL::SSL::VERIFY_NONE and
10071007
not Object.const_defined?(:I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG) then
@@ -1111,7 +1111,7 @@ def verify_mode= verify_mode
11111111
end
11121112

11131113
##
1114-
# Sets the HTTPS verify_hostname. Defaults to false.
1114+
# Sets the HTTPS verify_hostname.
11151115

11161116
def verify_hostname= verify_hostname
11171117
@verify_hostname = verify_hostname
@@ -1131,4 +1131,3 @@ def verify_callback= callback
11311131

11321132
require_relative 'persistent/connection'
11331133
require_relative 'persistent/pool'
1134-

test/test_net_http_persistent.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ def test_ssl_verify_mode
13431343
assert_equal OpenSSL::SSL::VERIFY_NONE, c.verify_mode
13441344
end
13451345

1346-
def test_ssl_verify_hostname
1346+
def test_ssl_enable_verify_hostname
13471347
skip 'OpenSSL is missing' unless HAVE_OPENSSL
13481348

13491349
@http.verify_hostname = true
@@ -1358,6 +1358,22 @@ def test_ssl_verify_hostname
13581358
assert c.verify_hostname
13591359
end
13601360

1361+
def test_ssl_disable_verify_hostname
1362+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
1363+
1364+
@http.verify_hostname = false
1365+
c = Net::HTTP.new 'localhost', 80
1366+
1367+
skip 'net/http doesn\'t provide verify_hostname= method' unless
1368+
c.respond_to?(:verify_hostname=)
1369+
1370+
@http.ssl c
1371+
1372+
assert c.use_ssl?
1373+
assert c.verify_hostname == false
1374+
end
1375+
1376+
13611377
def test_ssl_warning
13621378
skip 'OpenSSL is missing' unless HAVE_OPENSSL
13631379

@@ -1474,4 +1490,3 @@ def test_connection_pool_after_fork
14741490
end
14751491
end
14761492
end
1477-

0 commit comments

Comments
 (0)