From 63ec65a2628cddac9b2434835439818b0ba09f20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Bia=C5=82ek?= Date: Wed, 22 Mar 2023 09:35:26 +0100 Subject: [PATCH 1/2] fix raw_ssl_request method for ruby 3.2.1 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 --- lib/active_utils/posts_data.rb | 2 +- test/unit/posts_data_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/active_utils/posts_data.rb b/lib/active_utils/posts_data.rb index 53ab31f..48d8200 100644 --- a/lib/active_utils/posts_data.rb +++ b/lib/active_utils/posts_data.rb @@ -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 diff --git a/test/unit/posts_data_test.rb b/test/unit/posts_data_test.rb index f42d16c..4cade9a 100644 --- a/test/unit/posts_data_test.rb +++ b/test/unit/posts_data_test.rb @@ -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 From 75380e15dae2251b2fd8fa6dc7800e725fdfef44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Bia=C5=82ek?= Date: Wed, 22 Mar 2023 10:03:36 +0100 Subject: [PATCH 2/2] replace mocha/setup with moca/minitest --- test/test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 60cc8cc..984b405 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,6 @@ require 'active_utils' require 'minitest/autorun' -require 'mocha/setup' +require 'mocha/minitest' include ActiveUtils