From b0055e5905200e51e9b253bd9c16d51ff3be5363 Mon Sep 17 00:00:00 2001 From: MatzFan Date: Sun, 20 Jul 2025 11:29:28 +0100 Subject: [PATCH] bump required_ruby_version to 2.7 (fixes #64); rubocop --- .github/workflows/test.yml | 2 +- .rubocop.yml | 2 +- ChangeLog | 7 ++++++- Gemfile | 2 ++ Gemfile.lock | 7 +++---- Rakefile | 2 ++ bin/socksify_ruby | 1 + lib/socksify.rb | 3 ++- lib/socksify/debug.rb | 2 ++ lib/socksify/http.rb | 2 ++ lib/socksify/socksproxyable.rb | 8 ++++---- lib/socksify/tcpsocket.rb | 4 +++- lib/socksify/version.rb | 2 +- socksify.gemspec | 2 +- test/test_socksify_legacy.rb | 2 ++ 15 files changed, 33 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index de66a0e..f1edc5b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,7 +25,7 @@ jobs: strategy: matrix: - ruby: ['3.2', '3.3', '3.4', head] + ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4', head] steps: - uses: actions/checkout@v4 diff --git a/.rubocop.yml b/.rubocop.yml index bb838fb..b7f343f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,7 +6,7 @@ plugins: AllCops: NewCops: enable - TargetRubyVersion: 2.0 + TargetRubyVersion: 2.7 Gemspec/RequireMFA: Enabled: false diff --git a/ChangeLog b/ChangeLog index 908cc39..385555f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -82,8 +82,13 @@ SOCKSify Ruby 1.7.3 * add Rakefile * fix missing :timeout kwarg in TCPSocket class (thanks @lizzypy) -unreleased +2025-07-17 SOCKSify Ruby 1.8.0 =================== * Authentication support added to Net::HTTP.socks_proxy (thanks to @ojab and @anton-smagin) + +unreleased +SOCKSify Ruby 1.8.1 +=================== +* clarify required ruby version >= 2.7 diff --git a/Gemfile b/Gemfile index 01e2bff..90f1027 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 599155b..eb7845f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ GEM remote: https://rubygems.org/ specs: ast (2.4.3) - json (2.12.2) + json (2.13.0) language_server-protocol (3.17.0.5) lint_roller (1.1.0) minitest (5.25.5) @@ -26,7 +26,7 @@ GEM rubocop-ast (>= 1.45.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 4.0) - rubocop-ast (1.45.1) + rubocop-ast (1.46.0) parser (>= 3.3.7.2) prism (~> 1.4) rubocop-minitest (0.38.1) @@ -46,7 +46,6 @@ GEM unicode-emoji (4.0.4) PLATFORMS - ruby x86_64-linux DEPENDENCIES @@ -58,4 +57,4 @@ DEPENDENCIES rubocop-rake (~> 0.7) BUNDLED WITH - 2.6.9 + 2.4.22 diff --git a/Rakefile b/Rakefile index c58fc43..d021ae2 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' require 'rake/testtask' diff --git a/bin/socksify_ruby b/bin/socksify_ruby index 8fb4ece..b7c9a15 100755 --- a/bin/socksify_ruby +++ b/bin/socksify_ruby @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true if ARGV.size < 2 puts "Usage: #{$PROGRAM_NAME} [script args ...]" diff --git a/lib/socksify.rb b/lib/socksify.rb index b248be2..bc01f4b 100644 --- a/lib/socksify.rb +++ b/lib/socksify.rb @@ -1,4 +1,5 @@ # encoding: us-ascii +# frozen_string_literal: true # Copyright (C) 2007 Stephan Maka # @@ -119,7 +120,7 @@ def self.proxy(server, port) end def self.request(host) - req = String.new << "\005" + req = (+'') << "\005" case host when /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ # to IPv4 address req << "\xF1\000\001#{(1..4).map { |i| Regexp.last_match(i).to_i }.pack('CCCC')}" diff --git a/lib/socksify/debug.rb b/lib/socksify/debug.rb index 43d56cd..3d4462a 100644 --- a/lib/socksify/debug.rb +++ b/lib/socksify/debug.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # namespace module Socksify # rubocop:disable Style/Documentation diff --git a/lib/socksify/http.rb b/lib/socksify/http.rb index 1373a49..1ecf569 100644 --- a/lib/socksify/http.rb +++ b/lib/socksify/http.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright (C) 2007 Stephan Maka # Copyright (C) 2011 Musy Bite # diff --git a/lib/socksify/socksproxyable.rb b/lib/socksify/socksproxyable.rb index f0e83c2..b5e5b27 100644 --- a/lib/socksify/socksproxyable.rb +++ b/lib/socksify/socksproxyable.rb @@ -69,20 +69,20 @@ module InstanceMethodsConnect # rubocop:disable Metrics def socks_connect(host, port) port = Socket.getservbyname(port) if port.is_a?(String) - req = String.new + req = +'' Socksify.debug_debug 'Sending destination address' req << TCPSocket.socks_version_hex Socksify.debug_debug TCPSocket.socks_version_hex.unpack 'H*' req << "\001" req << "\000" if self.class.socks_version == '5' - req << [port].pack('n') if self.class.socks_version =~ /^4/ + req << [port].pack('n') if /^4/.match?(self.class.socks_version) host = Resolv::DNS.new.getaddress(host).to_s if self.class.socks_version == '4' Socksify.debug_debug host if host =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ # to IPv4 address req << "\001" if self.class.socks_version == '5' ip = (1..4).map { |i| Regexp.last_match(i).to_i }.pack('CCCC') req << ip - elsif host =~ /^[:0-9a-f]+$/ # to IPv6 address + elsif /^[:0-9a-f]+$/.match?(host) # to IPv6 address raise 'TCP/IPv6 over SOCKS is not yet supported (inet_pton missing in Ruby & not supported by Tor' # req << "\004" # UNREACHABLE elsif self.class.socks_version == '5' # to hostname @@ -133,7 +133,7 @@ def socks_receive_reply i = 0 ip6 = '' bind_addr_s.each_byte do |b| - ip6 += ':' if i > 0 && i.even? + ip6 += ':' if i.positive? && i.even? i += 1 ip6 += b.to_s(16).rjust(2, '0') end diff --git a/lib/socksify/tcpsocket.rb b/lib/socksify/tcpsocket.rb index f62ab99..d358073 100644 --- a/lib/socksify/tcpsocket.rb +++ b/lib/socksify/tcpsocket.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'socksproxyable' # monkey patch @@ -70,7 +72,7 @@ def socks_ignores def make_socks_connection(host, port, **kwargs) Socksify.debug_notice "Connecting to SOCKS server #{socks_server}:#{socks_port}" initialize_tcp socks_server, socks_port, **kwargs - socks_authenticate(socks_username, socks_password) unless @socks_version =~ /^4/ + socks_authenticate(socks_username, socks_password) unless /^4/.match?(@socks_version) socks_connect(host, port) if host end diff --git a/lib/socksify/version.rb b/lib/socksify/version.rb index 647c1c1..eb302f9 100644 --- a/lib/socksify/version.rb +++ b/lib/socksify/version.rb @@ -2,5 +2,5 @@ # namespace module Socksify - VERSION = '1.8.0' + VERSION = '1.8.1' end diff --git a/socksify.gemspec b/socksify.gemspec index 5a2af51..1833b44 100644 --- a/socksify.gemspec +++ b/socksify.gemspec @@ -8,7 +8,7 @@ Gem::Specification.new do |s| s.summary = 'Redirect all TCPSockets through a SOCKS5 proxy' s.authors = ['Stephan Maka', 'Andrey Kouznetsov', 'Christopher Thorpe', 'Musy Bite', 'Yuichi Tateno', 'David Dollar'] s.licenses = ['Ruby', 'GPL-3.0'] - s.required_ruby_version = '>= 2.0' + s.required_ruby_version = '>= 2.7' s.email = 'stephan@spaceboyz.net' s.homepage = 'https://github.com/astro/socksify-ruby' s.files = %w[COPYING] diff --git a/test/test_socksify_legacy.rb b/test/test_socksify_legacy.rb index 3ba7541..fc66ef9 100644 --- a/test/test_socksify_legacy.rb +++ b/test/test_socksify_legacy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module TestSocksifyLegacy if RUBY_VERSION.to_f < 3.1 # test legacy methods TCPSocket.socks_server= and TCPSocket.socks_port= def test_check_tor