-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from adfoster-r7/expose-supported-proxies
Expose supported proxies
- Loading branch information
Showing
4 changed files
with
60 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: binary -*- | ||
|
||
module Rex | ||
module Socket | ||
module Proxies | ||
module ProxyType | ||
SAPNI = 'sapni' | ||
HTTP = 'http' | ||
SOCKS4 = 'socks4' | ||
SOCKS5 = 'socks5' | ||
end | ||
|
||
# @param [String,nil] value A proxy chain of format {type:host:port[,type:host:port][...]} | ||
# @return [Array] The array of proxies, i.e. {[['type', 'host', 'port']]} | ||
def self.parse(value) | ||
value.to_s.strip.split(',').map { |a| a.strip }.map { |a| a.split(':').map { |b| b.strip } } | ||
end | ||
|
||
def self.supported_types | ||
ProxyType.constants.map { |c| ProxyType.const_get(c) } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding:binary -*- | ||
require 'rex/socket/proxies' | ||
|
||
RSpec.describe Rex::Socket::Proxies do | ||
describe '.supported_types' do | ||
it 'should equal the array of available proxies' do | ||
expected = %w[ | ||
sapni | ||
socks4 | ||
http | ||
socks5 | ||
] | ||
expect(subject.supported_types).to match_array expected | ||
end | ||
end | ||
|
||
describe '.parse' do | ||
[ | ||
{ value: nil, expected: [] }, | ||
{ value: '', expected: [] }, | ||
{ value: ' ', expected: [] }, | ||
{ value: 'sapni:198.51.100.1:8080, socks4:198.51.100.1:1080 ', expected: [['sapni', '198.51.100.1', '8080'], ['socks4', '198.51.100.1', '1080']] }, | ||
].each do |test| | ||
it "correctly parses #{test[:value]} as #{test[:expected]}" do | ||
expect(described_class.parse(test[:value])).to eq test[:expected] | ||
end | ||
end | ||
end | ||
end |