Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
require "bundler/gem_tasks"
require 'bundler/gem_tasks'
require 'rake/testtask'

task default: :test

Rake::TestTask.new do |task|
task.libs << 'lib' << 'spec'
task.pattern = 'spec/**/*_spec.rb'
task.verbose = true
end
13 changes: 7 additions & 6 deletions lib/proxifier/proxies/socks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

module Proxifier
class SOCKSProxy < Proxy
VERSION = 0x05
VERSION = 0x05
SUBNEGOTIATION_VERSION = 0x01

def do_proxify(socket, host, port)
authenticaton_method = greet(socket)
Expand All @@ -26,12 +27,12 @@ def authenticate(socket, method)
case method
when 0x00 # NO AUTHENTICATION REQUIRED
when 0x02 # USERNAME/PASSWORD
user &&= user[0, 0xFF]
password &&= password[0, 0xFF]
_user = user ? user[0, 0xFF] : ''
_password = password ? password[0, 0xFF] : ''

socket << [user.size, user, password.size, password].pack("CA#{user.size}CA#{password.size}")
version, status = socket.read(2).unpack("CC")
check_version(version)
socket << [SUBNEGOTIATION_VERSION, _user.size, _user, _password.size, _password].pack("CCA#{_user.size}CA#{_password.size}")
version, status = socket.read(2).unpack('CC')
check_version(version, SUBNEGOTIATION_VERSION)

case status
when 0x00 # SUCCESS
Expand Down
2 changes: 1 addition & 1 deletion lib/proxifier/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def proxify?(host, no_proxy = nil)
attr_reader :url, :options

def initialize(url, options = {})
url = URI.parse(uri) unless url.is_a?(URI::Generic)
url = URI.parse(url) unless url.is_a?(URI::Generic)
@url, @options = url, options
end

Expand Down
2 changes: 1 addition & 1 deletion lib/proxifier/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Proxifier
VERSION = "1.0.3"
VERSION = '1.0.4'
end
2 changes: 2 additions & 0 deletions proxifier.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ Gem::Specification.new do |s|

s.files = Dir["bin/*", "lib/**/*"] + ["LICENSE", "README.md"]
s.executables = ["pirb", "pruby"]

s.add_development_dependency 'minitest', '>= 4.6.0'
end
30 changes: 30 additions & 0 deletions spec/proxifier/proxies/socks_spec.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions spec/proxifier/proxy_spec.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions spec/proxifier_spec.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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'