Skip to content

Commit 28b1fbd

Browse files
authored
Merge pull request #63 from MatzFan/master
Completed auth functionality
2 parents ca69e45 + f766793 commit 28b1fbd

12 files changed

Lines changed: 93 additions & 60 deletions

File tree

.github/workflows/test.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
services:
18-
services:
19-
socks5:
20-
image: serjs/go-socks5-proxy
21-
env:
22-
PROXY_USER: user
23-
PROXY_PASSWORD: password
24-
ports:
25-
- 1080:1080
18+
socks5:
19+
image: serjs/go-socks5-proxy
20+
env:
21+
PROXY_USER: user
22+
PROXY_PASSWORD: password
23+
ports:
24+
- 1080:1080
2625

2726
strategy:
2827
matrix:
29-
ruby: ['3.1', '3.2', '3.3', head]
28+
ruby: ['3.2', '3.3', '3.4', head]
3029

3130
steps:
3231
- uses: actions/checkout@v4

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/pkg/
2+
.ruby-version

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
require:
2+
plugins:
33
- rubocop-minitest
44
- rubocop-performance
55
- rubocop-rake

ChangeLog

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,9 @@ SOCKSify Ruby 1.7.3
8181
===================
8282
* add Rakefile
8383
* fix missing :timeout kwarg in TCPSocket class (thanks @lizzypy)
84-
* Authentication support added to Net::HTTP.SOCKSProxy
84+
85+
unreleased
86+
SOCKSify Ruby 1.8.0
87+
===================
88+
* Authentication support added to Net::HTTP.socks_proxy
8589
(thanks to @ojab and @anton-smagin)

Gemfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
source 'https://rubygems.org'
22

33
group :test do
4-
gem 'minitest', '~> 5.16'
4+
gem 'minitest', '~> 5.25'
55
end
66

77
group :development, :test do
8-
gem 'rake', '~> 13.2'
9-
gem 'rubocop', '~> 1.31'
10-
gem 'rubocop-minitest', '~> 0.20'
11-
gem 'rubocop-performance', '~> 1.21'
12-
gem 'rubocop-rake', '~> 0.6'
8+
gem 'rake', '~> 13.3'
9+
gem 'rubocop', '~> 1.78'
10+
gem 'rubocop-minitest', '~> 0.38'
11+
gem 'rubocop-performance', '~> 1.25'
12+
gem 'rubocop-rake', '~> 0.7'
1313
end

Gemfile.lock

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,61 @@
11
GEM
22
remote: https://rubygems.org/
33
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)
4+
ast (2.4.3)
5+
json (2.12.2)
6+
language_server-protocol (3.17.0.5)
7+
lint_roller (1.1.0)
8+
minitest (5.25.5)
9+
parallel (1.27.0)
10+
parser (3.3.8.0)
1011
ast (~> 2.4.1)
1112
racc
13+
prism (1.4.0)
1214
racc (1.8.1)
1315
rainbow (3.1.1)
14-
rake (13.2.1)
15-
regexp_parser (2.9.2)
16-
rexml (3.3.4)
17-
strscan
18-
rubocop (1.65.1)
16+
rake (13.3.0)
17+
regexp_parser (2.10.0)
18+
rubocop (1.78.0)
1919
json (~> 2.3)
20-
language_server-protocol (>= 3.17.0)
20+
language_server-protocol (~> 3.17.0.2)
21+
lint_roller (~> 1.1.0)
2122
parallel (~> 1.10)
2223
parser (>= 3.3.0.2)
2324
rainbow (>= 2.2.2, < 4.0)
24-
regexp_parser (>= 2.4, < 3.0)
25-
rexml (>= 3.2.5, < 4.0)
26-
rubocop-ast (>= 1.31.1, < 2.0)
25+
regexp_parser (>= 2.9.3, < 3.0)
26+
rubocop-ast (>= 1.45.1, < 2.0)
2727
ruby-progressbar (~> 1.7)
28-
unicode-display_width (>= 2.4.0, < 3.0)
29-
rubocop-ast (1.32.0)
30-
parser (>= 3.3.1.0)
31-
rubocop-minitest (0.35.1)
32-
rubocop (>= 1.61, < 2.0)
33-
rubocop-ast (>= 1.31.1, < 2.0)
34-
rubocop-performance (1.21.1)
35-
rubocop (>= 1.48.1, < 2.0)
36-
rubocop-ast (>= 1.31.1, < 2.0)
37-
rubocop-rake (0.6.0)
38-
rubocop (~> 1.0)
28+
unicode-display_width (>= 2.4.0, < 4.0)
29+
rubocop-ast (1.45.1)
30+
parser (>= 3.3.7.2)
31+
prism (~> 1.4)
32+
rubocop-minitest (0.38.1)
33+
lint_roller (~> 1.1)
34+
rubocop (>= 1.75.0, < 2.0)
35+
rubocop-ast (>= 1.38.0, < 2.0)
36+
rubocop-performance (1.25.0)
37+
lint_roller (~> 1.1)
38+
rubocop (>= 1.75.0, < 2.0)
39+
rubocop-ast (>= 1.38.0, < 2.0)
40+
rubocop-rake (0.7.1)
41+
lint_roller (~> 1.1)
42+
rubocop (>= 1.72.1)
3943
ruby-progressbar (1.13.0)
40-
strscan (3.1.0)
41-
unicode-display_width (2.5.0)
44+
unicode-display_width (3.1.4)
45+
unicode-emoji (~> 4.0, >= 4.0.4)
46+
unicode-emoji (4.0.4)
4247

4348
PLATFORMS
4449
ruby
4550
x86_64-linux
4651

4752
DEPENDENCIES
48-
minitest (~> 5.16)
49-
rake (~> 13.2)
50-
rubocop (~> 1.31)
51-
rubocop-minitest (~> 0.20)
52-
rubocop-performance (~> 1.21)
53-
rubocop-rake (~> 0.6)
53+
minitest (~> 5.25)
54+
rake (~> 13.3)
55+
rubocop (~> 1.78)
56+
rubocop-minitest (~> 0.38)
57+
rubocop-performance (~> 1.25)
58+
rubocop-rake (~> 0.7)
5459

5560
BUNDLED WITH
56-
2.5.17
61+
2.6.9

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,32 @@ end
6363
```
6464
Note that `Net::HTTP.socks_proxy` never relies on `TCPSocket.socks_server`/`socks_port`. You should either set `socks_proxy` arguments explicitly or use `Net::HTTP` directly.
6565

66+
### Authentication
67+
```rb
68+
require 'socksify/http'
69+
70+
uri = URI.parse('http://ipecho.net/plain')
71+
Net::HTTP.socks_proxy('127.0.0.1', 1080, username: 'my_username', password: 'my_pwd').start(uri.host, uri.port) do |http|
72+
req = Net::HTTP::Get.new uri
73+
resp = http.request(req)
74+
puts resp.inspect
75+
puts resp.body
76+
end
77+
```
78+
6679
### Resolve addresses via SOCKS
6780
```rb
6881
Socksify.resolve("spaceboyz.net")
6982
# => "87.106.131.203"
7083
```
84+
7185
### Testing and Debugging
7286

7387
A tor proxy and socks5 proxy with auth is required before running the tests.
74-
* Install tor from your usual package manager, check it is running with `pidof tor` then run the tests with:
88+
* Install tor from your usual package manager, check it is running with `pidof tor`
7589
* Start a SOCKS5 proxy using Docker `docker run -d --name socks5 -p 1080:1080 -e PROXY_USER=user -e PROXY_PASSWORD=password serjs/go-socks5-proxy`
7690

91+
Then run the tests with:
7792
`bundle exec rake`
7893

7994
Colorful diagnostic messages are enabled by default via:

lib/socksify/http.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
module Net
2222
# patched class
2323
class HTTP
24-
def self.socks_proxy(p_host, p_port, p_username = nil, p_password = nil)
24+
def self.socks_proxy(p_host, p_port, username: nil, password: nil)
2525
proxyclass.module_eval do
2626
include Ruby3NetHTTPConnectable if RUBY_VERSION.to_f > 3.0 # patch #connect method
2727
include SOCKSProxyDelta::InstanceMethods
2828
extend SOCKSProxyDelta::ClassMethods
2929

3030
@socks_server = p_host
3131
@socks_port = p_port
32-
@socks_username = p_username
33-
@socks_password = p_password
32+
@socks_username = username
33+
@socks_password = password
3434
end
3535

3636
proxyclass

lib/socksify/socksproxyable.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
module Socksproxyable
55
# class methods
66
module ClassMethods
7+
SOCKS4_VERSIONS = %w[4 4a].freeze
8+
79
attr_accessor :socks_server, :socks_port, :socks_username, :socks_password
810

911
def socks_version
@@ -19,7 +21,7 @@ def socks_ignores=(*hosts)
1921
end
2022

2123
def socks_version_hex
22-
socks_version == '4a' || socks_version == '4' ? "\004" : "\005"
24+
SOCKS4_VERSIONS.include?(socks_version) ? "\004" : "\005"
2325
end
2426
end
2527

lib/socksify/version.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
# namespace
4+
module Socksify
5+
VERSION = '1.8.0'
6+
end

0 commit comments

Comments
 (0)