Skip to content

Commit

Permalink
fix raw_ssl_request method for ruby 3.2.1
Browse files Browse the repository at this point in the history
With ruby 3.2.1 upgrade depracated method for calling =~ on Object was removed
https://bugs.ruby-lang.org/issues/15231

This causes
`logger.warn "#{self.class} posting to plaintext endpoint, which is insecure" if logger unless endpoint =~ /^https:/` to throw an error.

Casting endpoint to string resolves this problem as all objects for handling uri
should respond to `to_s` method
  • Loading branch information
krzysztofbialek committed Mar 22, 2023
1 parent eb6d260 commit 63ec65a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/active_utils/posts_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def ssl_request(method, endpoint, data, headers)

def raw_ssl_request(method, endpoint, data, headers = {})
logger.warn "#{self.class} using ssl_strict=false, which is insecure" if logger unless ssl_strict
logger.warn "#{self.class} posting to plaintext endpoint, which is insecure" if logger unless endpoint =~ /^https:/
logger.warn "#{self.class} posting to plaintext endpoint, which is insecure" if logger unless endpoint.to_s =~ /^https:/

connection = new_connection(endpoint)
connection.open_timeout = open_timeout
Expand Down
9 changes: 9 additions & 0 deletions test/unit/posts_data_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ def test_logger_warns_if_ssl_strict_disabled
@poster.raw_ssl_request(:post, "https://shopify.com", "", {})
end

def test_logger_warns_can_handle_non_string_endpoints
@poster.logger = stub()
@poster.logger.expects(:warn).with("PostsDataTest::SSLPoster posting to plaintext endpoint, which is insecure")

Connection.any_instance.stubs(:request)

@poster.raw_ssl_request(:post, URI("http://shopify.com"), "", {})
end

def test_logger_no_warning_if_ssl_strict_enabled
@poster.logger = stub()
@poster.logger.stubs(:warn).never
Expand Down

0 comments on commit 63ec65a

Please sign in to comment.