Fixes for Proxy creation from URL String and SOCKS5 authentication. Bump version number to 1.0.4.

This commit is contained in:
rulingcom committed 2024-02-24 11:58:46 +08:00
1 parent 41ead73b21
commit bf1f0bee18
9 files changed
+107 -9

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
require 'spec_helper'
require 'uri'
require 'proxifier/proxies/socks'
describe Proxifier::SOCKSProxy do
before do
@socket = MiniTest::Mock.new
end
it 'should comply with SOCKS5 authentication specification' do
proxy = Proxifier::Proxy('socks://joe:sekret@myproxy:60123')
proxy.must_be_instance_of Proxifier::SOCKSProxy
TCPSocket.stub :new, @socket do
@socket.expect :<<, nil, ["\x05\x02\x00\x02"]
@socket.expect :read, "\x05\x02", [2]
@socket.expect :<<, nil, ["\x01\x03joe\x06sekret"]
@socket.expect :read, "\x01\x00", [2]
@socket.expect :<<, nil, ["\x05\x01\x00\x03\tlocalhost\x048"]
@socket.expect :read, "\x05\x00\x00\x01", [4]
@socket.expect :read, "\x7F\x00\x00\x01", [4]
@socket.expect :read, "\x08", [2]
proxy.open('localhost', 1080)
end
end
end
+28
View File
@@ -0,0 +1,28 @@
require 'spec_helper'
require 'uri'
require 'proxifier/proxy'
describe Proxifier::Proxy do
it 'should create proxy from URL String' do
proxy = Proxifier::Proxy.new('socks://joe:sekret@myproxy:60123')
proxy.url.scheme.must_equal 'socks'
proxy.user.must_equal 'joe'
proxy.password.must_equal 'sekret'
proxy.host.must_equal 'myproxy'
proxy.port.must_equal 60123
end
it 'should create proxy from generic URI' do
uri = URI::Generic.new('socks', 'joe:sekret', 'myproxy', 60123, nil, nil, nil, nil, nil)
proxy = Proxifier::Proxy.new(uri)
proxy.url.scheme.must_equal 'socks'
proxy.user.must_equal 'joe'
proxy.password.must_equal 'sekret'
proxy.host.must_equal 'myproxy'
proxy.port.must_equal 60123
end
end
+20
View File
@@ -0,0 +1,20 @@
require 'spec_helper'
require 'proxifier/proxies/socks'
describe Proxifier do
it 'should have a version number' do
Proxifier::VERSION.wont_be_nil
end
it 'should create Proxy from URL String' do
proxy = Proxifier::Proxy('socks://joe:sekret@myproxy:60123')
proxy.must_be_instance_of Proxifier::SOCKSProxy
proxy.user.must_equal 'joe'
proxy.password.must_equal 'sekret'
proxy.host.must_equal 'myproxy'
proxy.port.must_equal 60123
end
end
+8
View File
@@ -0,0 +1,8 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'rubygems'
gem 'minitest' # ensure we are using the gem version
require 'minitest/spec'
require 'minitest/autorun'
require 'proxifier'