Skip to content

Commit 41dd2a2

Browse files
author
MatzFan
committed
fix test, rubocop, update workflow
1 parent 94cff45 commit 41dd2a2

File tree

8 files changed

+99
-49
lines changed

8 files changed

+99
-49
lines changed

.github/workflows/test.yml

+24-18
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,44 @@ permissions:
1212

1313
jobs:
1414
test:
15-
1615
runs-on: ubuntu-latest
1716
strategy:
1817
matrix:
19-
ruby-version: ['2.6', '2.7', '3.0', '3.1']
18+
ruby: ['3.1', '3.2', '3.3', head]
2019

2120
steps:
22-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
22+
23+
- name: Install Act dependencies
24+
if: ${{ env.ACT }}
25+
run: |
26+
apt-get update && apt-get install sudo -y # https://github.com/nektos/act/issues/107
27+
2328
- name: Install and setup tor
2429
run: |
30+
sudo apt-get update
2531
sudo apt-get install -y tor
2632
tor --version
27-
sudo sh -c 'echo SOCKSPort 9050 > /etc/tor/torrc'
33+
sudo sh -c 'echo SocksPort 9050 > /etc/tor/torrc'
2834
sudo sh -c 'echo ControlPort 9051 >> /etc/tor/torrc'
2935
export HashedControlPassword=$(tor --quiet --hash-password "")
30-
sudo sh -c 'echo "HashedControlPassword $HashedControlPassword" >> /etc/tor/torrc'
36+
sudo sh -c "echo HashedControlPassword $HashedControlPassword >> /etc/tor/torrc"
3137
sudo sh -c 'cat /etc/tor/torrc'
32-
sudo service tor start
33-
pidof tor
34-
- name: Install gems
35-
run: |
36-
sudo gem install rubocop
37-
sudo gem install rubocop-minitest
38+
tor --verify-config
39+
# sudo service tor start
40+
# pidof tor
3841
3942
- name: Set up Ruby
40-
# Automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
41-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
42-
# uses: ruby/setup-ruby@v1
43-
uses: ruby/setup-ruby@2b019609e2b0f1ea1a2bc8ca11cb82ab46ada124
43+
uses: ruby/setup-ruby@v1 # https://github.com/ruby/setup-ruby
4444
with:
45-
ruby-version: ${{ matrix.ruby-version }}
45+
ruby-version: ${{ matrix.ruby }}
46+
bundler-cache: true
47+
48+
- name: Install gems
49+
run: |
50+
bundle install
51+
4652
- name: Run tests
4753
run: |
48-
ruby test/test_socksify.rb
49-
rubocop
54+
bundle exec ruby test/test_socksify.rb
55+
bundle exec rubocop

.rubocop.yml

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ require: 'rubocop-minitest'
44
AllCops:
55
NewCops: enable
66
TargetRubyVersion: 2.0
7+
8+
Gemspec/RequireMFA:
9+
Enabled: false

Gemfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
source 'https://rubygems.org'
2+
3+
group :test do
4+
gem 'minitest', '~> 5.16'
5+
end
6+
7+
group :development, :test do
8+
gem 'rubocop', '~> 1.31'
9+
gem 'rubocop-minitest', '~> 0.20'
10+
gem 'rubocop-performance', '~> 1.21'
11+
end

Gemfile.lock

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
ast (2.4.2)
5+
json (2.7.2)
6+
language_server-protocol (3.17.0.3)
7+
minitest (5.24.1)
8+
parallel (1.26.1)
9+
parser (3.3.4.2)
10+
ast (~> 2.4.1)
11+
racc
12+
racc (1.8.1)
13+
rainbow (3.1.1)
14+
regexp_parser (2.9.2)
15+
rexml (3.3.4)
16+
strscan
17+
rubocop (1.65.1)
18+
json (~> 2.3)
19+
language_server-protocol (>= 3.17.0)
20+
parallel (~> 1.10)
21+
parser (>= 3.3.0.2)
22+
rainbow (>= 2.2.2, < 4.0)
23+
regexp_parser (>= 2.4, < 3.0)
24+
rexml (>= 3.2.5, < 4.0)
25+
rubocop-ast (>= 1.31.1, < 2.0)
26+
ruby-progressbar (~> 1.7)
27+
unicode-display_width (>= 2.4.0, < 3.0)
28+
rubocop-ast (1.32.0)
29+
parser (>= 3.3.1.0)
30+
rubocop-minitest (0.35.1)
31+
rubocop (>= 1.61, < 2.0)
32+
rubocop-ast (>= 1.31.1, < 2.0)
33+
rubocop-performance (1.21.1)
34+
rubocop (>= 1.48.1, < 2.0)
35+
rubocop-ast (>= 1.31.1, < 2.0)
36+
ruby-progressbar (1.13.0)
37+
strscan (3.1.0)
38+
unicode-display_width (2.5.0)
39+
40+
PLATFORMS
41+
ruby
42+
x86_64-linux
43+
44+
DEPENDENCIES
45+
minitest (~> 5.16)
46+
rubocop (~> 1.31)
47+
rubocop-minitest (~> 0.20)
48+
rubocop-performance (~> 1.21)
49+
50+
BUNDLED WITH
51+
2.5.17

lib/socksify/tcpsocket.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SOCKSConnectionPeerAddress < String
3131
def initialize(socks_server, socks_port, peer_host)
3232
@socks_server = socks_server
3333
@socks_port = socks_port
34-
super peer_host
34+
super(peer_host)
3535
end
3636

3737
def inspect

socksify.gemspec

-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
require 'rubygems'
44

5-
# rubocop:disable Gemspec/RequireMFA
65
Gem::Specification.new do |s|
76
s.name = 'socksify'
87
s.version = '1.7.2'
@@ -20,8 +19,4 @@ Gem::Specification.new do |s|
2019
s.require_path = 'lib'
2120
s.executables = %w[socksify_ruby]
2221
s.extra_rdoc_files = Dir.glob('doc/**/*') + %w[COPYING]
23-
s.add_development_dependency 'minitest', '~> 5.16'
24-
s.add_development_dependency 'rubocop', '~> 1.31'
25-
s.add_development_dependency 'rubocop-minitest', '~> 0.20'
2622
end
27-
# rubocop:enable Gemspec/RequireMFA

test/test_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def check_tor_with_service_as_string(http_klass = Net::HTTP)
6969

7070
module YandexHelperMethods
7171
def internet_yandex_com_ip(http_klass = Net::HTTP)
72-
parse_internet_yandex_com_response get_http(http_klass, 'https://213.180.204.62/internet', 'yandex.com') # "http://yandex.com/internet"
72+
parse_internet_yandex_com_response get_http(http_klass, 'https://5.255.255.77/internet', 'yandex.com') # "http://yandex.com/internet"
7373
end
7474

7575
def parse_internet_yandex_com_response(body)

test/test_socksify.rb

+8-24
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,34 @@ def self.test_order
1515
if RUBY_VERSION.to_f < 3.1 # test legacy methods TCPSocket.socks_server= and TCPSocket.socks_port=
1616
def test_check_tor
1717
disable_socks
18-
1918
is_tor_direct, ip_direct = check_tor
19+
2020
refute is_tor_direct
2121

2222
enable_socks
23-
2423
is_tor_socks, ip_socks = check_tor
25-
assert is_tor_socks
2624

25+
assert is_tor_socks
2726
refute_equal ip_direct, ip_socks
2827
end
2928

3029
def test_check_tor_with_service_as_a_string
3130
disable_socks
32-
3331
is_tor_direct, ip_direct = check_tor_with_service_as_string
34-
refute is_tor_direct
3532

33+
refute is_tor_direct
3634
enable_socks
37-
3835
is_tor_socks, ip_socks = check_tor_with_service_as_string
36+
3937
assert is_tor_socks
4038

4139
refute_equal ip_direct, ip_socks
4240
end
4341

4442
def test_connect_to_ip
4543
disable_socks
46-
4744
ip_direct = internet_yandex_com_ip
48-
4945
enable_socks
50-
5146
ip_socks = internet_yandex_com_ip
5247

5348
refute_equal ip_direct, ip_socks
@@ -57,19 +52,17 @@ def test_connect_to_ip
5752

5853
def test_check_tor_via_net_http
5954
disable_socks
60-
6155
tor_direct, ip_direct = check_tor
62-
refute tor_direct
6356

57+
refute tor_direct
6458
tor_socks, ip_socks = check_tor(http_tor_proxy)
65-
assert tor_socks
6659

60+
assert tor_socks
6761
refute_equal ip_direct, ip_socks
6862
end
6963

7064
def test_connect_to_ip_via_net_http
7165
disable_socks
72-
7366
ip_direct = internet_yandex_com_ip
7467
ip_socks = internet_yandex_com_ip(http_tor_proxy)
7568

@@ -78,24 +71,21 @@ def test_connect_to_ip_via_net_http
7871

7972
def test_ignores
8073
disable_socks
81-
8274
tor_direct, ip_direct = check_tor
83-
refute tor_direct
8475

76+
refute tor_direct
8577
enable_socks
8678
TCPSocket.socks_ignores << 'check.torproject.org'
87-
8879
tor_socks_ignored, ip_socks_ignored = check_tor
89-
refute tor_socks_ignored
9080

81+
refute tor_socks_ignored
9182
assert_equal ip_direct, ip_socks_ignored
9283
end
9384

9485
def test_resolve
9586
enable_socks
9687

9788
assert_includes ['8.8.8.8', '8.8.4.4'], Socksify.resolve('dns.google.com')
98-
9989
assert_raises SOCKSError::HostUnreachable do
10090
Socksify.resolve('nonexistent.spaceboyz.net')
10191
end
@@ -105,29 +95,24 @@ def test_resolve_reverse
10595
enable_socks
10696

10797
assert_equal('dns.google', Socksify.resolve('8.8.8.8'))
108-
10998
assert_raises SOCKSError::HostUnreachable do
11099
Socksify.resolve('0.0.0.0')
111100
end
112101
end
113102

114103
def test_proxy
115104
enable_socks
116-
117105
default_server = TCPSocket.socks_server
118106
default_port = TCPSocket.socks_port
119-
120107
Socksify.proxy('localhost.example.com', 60_001) do
121108
assert_equal 'localhost.example.com', TCPSocket.socks_server
122109
assert_equal 60_001, TCPSocket.socks_port
123110
end
124-
125111
assert_equal [TCPSocket.socks_server, TCPSocket.socks_port], [default_server, default_port]
126112
end
127113

128114
def test_proxy_failback
129115
enable_socks
130-
131116
default_server = TCPSocket.socks_server
132117
default_port = TCPSocket.socks_port
133118

@@ -136,7 +121,6 @@ def test_proxy_failback
136121
raise StandardError, 'error'
137122
end
138123
end
139-
140124
assert_equal TCPSocket.socks_server, default_server
141125
assert_equal TCPSocket.socks_port, default_port
142126
end

0 commit comments

Comments
 (0)