Skip to content

Commit

Permalink
fix test, rubocop, update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
MatzFan committed Aug 9, 2024
1 parent 94cff45 commit 41dd2a2
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 49 deletions.
42 changes: 24 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,44 @@ permissions:

jobs:
test:

runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.6', '2.7', '3.0', '3.1']
ruby: ['3.1', '3.2', '3.3', head]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Act dependencies
if: ${{ env.ACT }}
run: |
apt-get update && apt-get install sudo -y # https://github.com/nektos/act/issues/107
- name: Install and setup tor
run: |
sudo apt-get update
sudo apt-get install -y tor
tor --version
sudo sh -c 'echo SOCKSPort 9050 > /etc/tor/torrc'
sudo sh -c 'echo SocksPort 9050 > /etc/tor/torrc'
sudo sh -c 'echo ControlPort 9051 >> /etc/tor/torrc'
export HashedControlPassword=$(tor --quiet --hash-password "")
sudo sh -c 'echo "HashedControlPassword $HashedControlPassword" >> /etc/tor/torrc'
sudo sh -c "echo HashedControlPassword $HashedControlPassword >> /etc/tor/torrc"
sudo sh -c 'cat /etc/tor/torrc'
sudo service tor start
pidof tor
- name: Install gems
run: |
sudo gem install rubocop
sudo gem install rubocop-minitest
tor --verify-config
# sudo service tor start
# pidof tor
- name: Set up Ruby
# Automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@2b019609e2b0f1ea1a2bc8ca11cb82ab46ada124
uses: ruby/setup-ruby@v1 # https://github.com/ruby/setup-ruby
with:
ruby-version: ${{ matrix.ruby-version }}
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Install gems
run: |
bundle install
- name: Run tests
run: |
ruby test/test_socksify.rb
rubocop
bundle exec ruby test/test_socksify.rb
bundle exec rubocop
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ require: 'rubocop-minitest'
AllCops:
NewCops: enable
TargetRubyVersion: 2.0

Gemspec/RequireMFA:
Enabled: false
11 changes: 11 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
source 'https://rubygems.org'

group :test do
gem 'minitest', '~> 5.16'
end

group :development, :test do
gem 'rubocop', '~> 1.31'
gem 'rubocop-minitest', '~> 0.20'
gem 'rubocop-performance', '~> 1.21'
end
51 changes: 51 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
json (2.7.2)
language_server-protocol (3.17.0.3)
minitest (5.24.1)
parallel (1.26.1)
parser (3.3.4.2)
ast (~> 2.4.1)
racc
racc (1.8.1)
rainbow (3.1.1)
regexp_parser (2.9.2)
rexml (3.3.4)
strscan
rubocop (1.65.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.0)
parser (>= 3.3.1.0)
rubocop-minitest (0.35.1)
rubocop (>= 1.61, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-performance (1.21.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (1.13.0)
strscan (3.1.0)
unicode-display_width (2.5.0)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
minitest (~> 5.16)
rubocop (~> 1.31)
rubocop-minitest (~> 0.20)
rubocop-performance (~> 1.21)

BUNDLED WITH
2.5.17
2 changes: 1 addition & 1 deletion lib/socksify/tcpsocket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SOCKSConnectionPeerAddress < String
def initialize(socks_server, socks_port, peer_host)
@socks_server = socks_server
@socks_port = socks_port
super peer_host
super(peer_host)
end

def inspect
Expand Down
5 changes: 0 additions & 5 deletions socksify.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'rubygems'

# rubocop:disable Gemspec/RequireMFA
Gem::Specification.new do |s|
s.name = 'socksify'
s.version = '1.7.2'
Expand All @@ -20,8 +19,4 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.executables = %w[socksify_ruby]
s.extra_rdoc_files = Dir.glob('doc/**/*') + %w[COPYING]
s.add_development_dependency 'minitest', '~> 5.16'
s.add_development_dependency 'rubocop', '~> 1.31'
s.add_development_dependency 'rubocop-minitest', '~> 0.20'
end
# rubocop:enable Gemspec/RequireMFA
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def check_tor_with_service_as_string(http_klass = Net::HTTP)

module YandexHelperMethods
def internet_yandex_com_ip(http_klass = Net::HTTP)
parse_internet_yandex_com_response get_http(http_klass, 'https://213.180.204.62/internet', 'yandex.com') # "http://yandex.com/internet"
parse_internet_yandex_com_response get_http(http_klass, 'https://5.255.255.77/internet', 'yandex.com') # "http://yandex.com/internet"
end

def parse_internet_yandex_com_response(body)
Expand Down
32 changes: 8 additions & 24 deletions test/test_socksify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,34 @@ def self.test_order
if RUBY_VERSION.to_f < 3.1 # test legacy methods TCPSocket.socks_server= and TCPSocket.socks_port=
def test_check_tor
disable_socks

is_tor_direct, ip_direct = check_tor

refute is_tor_direct

enable_socks

is_tor_socks, ip_socks = check_tor
assert is_tor_socks

assert is_tor_socks
refute_equal ip_direct, ip_socks
end

def test_check_tor_with_service_as_a_string
disable_socks

is_tor_direct, ip_direct = check_tor_with_service_as_string
refute is_tor_direct

refute is_tor_direct
enable_socks

is_tor_socks, ip_socks = check_tor_with_service_as_string

assert is_tor_socks

refute_equal ip_direct, ip_socks
end

def test_connect_to_ip
disable_socks

ip_direct = internet_yandex_com_ip

enable_socks

ip_socks = internet_yandex_com_ip

refute_equal ip_direct, ip_socks
Expand All @@ -57,19 +52,17 @@ def test_connect_to_ip

def test_check_tor_via_net_http
disable_socks

tor_direct, ip_direct = check_tor
refute tor_direct

refute tor_direct
tor_socks, ip_socks = check_tor(http_tor_proxy)
assert tor_socks

assert tor_socks
refute_equal ip_direct, ip_socks
end

def test_connect_to_ip_via_net_http
disable_socks

ip_direct = internet_yandex_com_ip
ip_socks = internet_yandex_com_ip(http_tor_proxy)

Expand All @@ -78,24 +71,21 @@ def test_connect_to_ip_via_net_http

def test_ignores
disable_socks

tor_direct, ip_direct = check_tor
refute tor_direct

refute tor_direct
enable_socks
TCPSocket.socks_ignores << 'check.torproject.org'

tor_socks_ignored, ip_socks_ignored = check_tor
refute tor_socks_ignored

refute tor_socks_ignored
assert_equal ip_direct, ip_socks_ignored
end

def test_resolve
enable_socks

assert_includes ['8.8.8.8', '8.8.4.4'], Socksify.resolve('dns.google.com')

assert_raises SOCKSError::HostUnreachable do
Socksify.resolve('nonexistent.spaceboyz.net')
end
Expand All @@ -105,29 +95,24 @@ def test_resolve_reverse
enable_socks

assert_equal('dns.google', Socksify.resolve('8.8.8.8'))

assert_raises SOCKSError::HostUnreachable do
Socksify.resolve('0.0.0.0')
end
end

def test_proxy
enable_socks

default_server = TCPSocket.socks_server
default_port = TCPSocket.socks_port

Socksify.proxy('localhost.example.com', 60_001) do
assert_equal 'localhost.example.com', TCPSocket.socks_server
assert_equal 60_001, TCPSocket.socks_port
end

assert_equal [TCPSocket.socks_server, TCPSocket.socks_port], [default_server, default_port]
end

def test_proxy_failback
enable_socks

default_server = TCPSocket.socks_server
default_port = TCPSocket.socks_port

Expand All @@ -136,7 +121,6 @@ def test_proxy_failback
raise StandardError, 'error'
end
end

assert_equal TCPSocket.socks_server, default_server
assert_equal TCPSocket.socks_port, default_port
end
Expand Down

0 comments on commit 41dd2a2

Please sign in to comment.