Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix that setting a https:// site but not setting ssl_options would re…

…sult in a non-SSL http instance. Clean up syntax and clarify tests.
  • Loading branch information...
commit 08baa3b0c2dd9e6ebf0d1d62bbaa495d029d2f28 1 parent df43ecd
@jeremy jeremy authored
View
4 lib/active_resource/base.rb
@@ -568,9 +568,9 @@ def timeout
# * <tt>:verify_depth</tt> - The maximum depth for the certificate chain verification.
# * <tt>:cert_store</tt> - OpenSSL::X509::Store to verify peer certificate.
# * <tt>:ssl_timeout</tt> -The SSL timeout in seconds.
- def ssl_options=(opts={})
+ def ssl_options=(options)
@connection = nil
- @ssl_options = opts
+ @ssl_options = options
end
# Returns the SSL options hash.
View
5 lib/active_resource/connection.rb
@@ -41,6 +41,7 @@ def initialize(site, format = ActiveResource::Formats::JsonFormat)
# Set URI for remote service.
def site=(site)
@site = site.is_a?(URI) ? site : URI.parse(site)
+ @ssl_options ||= {} if @site.is_a?(URI::HTTPS)
@user = URI.parser.unescape(@site.user) if @site.user
@password = URI.parser.unescape(@site.password) if @site.password
end
@@ -71,8 +72,8 @@ def timeout=(timeout)
end
# Hash of options applied to Net::HTTP instance when +site+ protocol is 'https'.
- def ssl_options=(opts={})
- @ssl_options = opts
+ def ssl_options=(options)
+ @ssl_options = options
end
# Executes a GET request.
View
16 test/cases/base_test.rb
@@ -135,13 +135,23 @@ def test_timeout_variable_can_be_reset
end
def test_ssl_options_hash_can_be_reset
+ # SSL options are nil, resulting in an empty hash on the connection.
actor = Class.new(ActiveResource::Base)
actor.site = 'https://cinema'
assert_nil actor.ssl_options
- actor.ssl_options = {:foo => 5}
+ connection = actor.connection
+ assert_equal Hash.new, connection.ssl_options
+
+ # Setting SSL options wipes the connection.
+ actor.ssl_options = { :foo => 5 }
+ assert_not_equal connection, actor.connection
+ connection = actor.connection
+ assert_equal 5, connection.ssl_options[:foo]
+
+ # Setting SSL options to nil also wipes the connection.
actor.ssl_options = nil
- assert_nil actor.ssl_options
- assert_nil actor.connection.ssl_options
+ assert_not_equal connection, actor.connection
+ assert_equal Hash.new, actor.connection.ssl_options
end
def test_credentials_from_site_are_decoded
View
10 test/cases/connection_test.rb
@@ -222,14 +222,20 @@ def test_accept_http_header
def test_ssl_options_get_applied_to_http
http = Net::HTTP.new('')
- @conn.site="https://secure"
- @conn.ssl_options={:verify_mode => OpenSSL::SSL::VERIFY_PEER}
+ @conn.site = 'https://secure'
+ @conn.ssl_options = { :verify_mode => OpenSSL::SSL::VERIFY_PEER }
@conn.send(:configure_http, http)
assert http.use_ssl?
assert_equal http.verify_mode, OpenSSL::SSL::VERIFY_PEER
end
+ def test_ssl_options_get_applied_to_https_urls_without_explicitly_setting_ssl_options
+ http = Net::HTTP.new('')
+ @conn.site = 'https://secure'
+ assert @conn.send(:configure_http, http).use_ssl?
+ end
+
def test_ssl_error
http = Net::HTTP.new('')
@conn.expects(:http).returns(http)

2 comments on commit 08baa3b

@gtd

Wow thanks for fixing this at the drop of a hat.

@jeremy
Owner

No problem. My bad ;)

Please sign in to comment.
Something went wrong with that request. Please try again.