proxy_tester 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +22 -0
- data/.rdebugrc +7 -0
- data/.rspec +3 -0
- data/.simplecov +8 -0
- data/Gemfile +37 -0
- data/Gemfile.lock +199 -0
- data/LICENSE.txt +22 -0
- data/Procfile +1 -0
- data/README.md +582 -0
- data/Rakefile +64 -0
- data/bin/proxy_tester +11 -0
- data/db/migrate/20140314_create_environment.rb +8 -0
- data/files/config.yaml +1 -0
- data/files/example-config.erb +12 -0
- data/files/example-spec_helper.rb.erb +23 -0
- data/files/example-test_case.rb.erb +27 -0
- data/files/example-test_cases-gemfile.rb.erb +9 -0
- data/files/example-user_file.erb +4 -0
- data/lib/proxy_tester/actions/add_examples_to_test_cases_directory.rb +125 -0
- data/lib/proxy_tester/actions/clone_repository.rb +39 -0
- data/lib/proxy_tester/actions/create_directory.rb +33 -0
- data/lib/proxy_tester/actions/create_file.rb +55 -0
- data/lib/proxy_tester/actions/create_output.rb +36 -0
- data/lib/proxy_tester/actions/handle_error.rb +37 -0
- data/lib/proxy_tester/actions/initialize_application.rb +70 -0
- data/lib/proxy_tester/actions/show_config.rb +10 -0
- data/lib/proxy_tester/capybara_proxy.rb +54 -0
- data/lib/proxy_tester/capybara_proxy_pac.rb +62 -0
- data/lib/proxy_tester/cli/main.rb +59 -0
- data/lib/proxy_tester/config.rb +100 -0
- data/lib/proxy_tester/data.rb +23 -0
- data/lib/proxy_tester/database_session.rb +15 -0
- data/lib/proxy_tester/environment.rb +21 -0
- data/lib/proxy_tester/erb_generator.rb +34 -0
- data/lib/proxy_tester/error_handler.rb +107 -0
- data/lib/proxy_tester/error_messages.rb +82 -0
- data/lib/proxy_tester/exceptions.rb +53 -0
- data/lib/proxy_tester/git_file.rb +31 -0
- data/lib/proxy_tester/git_null_file.rb +32 -0
- data/lib/proxy_tester/git_repository.rb +120 -0
- data/lib/proxy_tester/handle_error.rb +37 -0
- data/lib/proxy_tester/locales/en-rails.yml +205 -0
- data/lib/proxy_tester/locales/en.yml +42 -0
- data/lib/proxy_tester/main.rb +46 -0
- data/lib/proxy_tester/models/user.rb +17 -0
- data/lib/proxy_tester/pac_result.rb +50 -0
- data/lib/proxy_tester/rspec/helper.rb +211 -0
- data/lib/proxy_tester/rspec_runner.rb +43 -0
- data/lib/proxy_tester/template_file.rb +19 -0
- data/lib/proxy_tester/template_repository.rb +22 -0
- data/lib/proxy_tester/ui_logger.rb +30 -0
- data/lib/proxy_tester/user_database.rb +24 -0
- data/lib/proxy_tester/version.rb +3 -0
- data/lib/proxy_tester.rb +54 -0
- data/proxy_tester.gemspec +34 -0
- data/script/acceptance_test +4 -0
- data/script/bootstrap +56 -0
- data/script/ci +3 -0
- data/script/console +14 -0
- data/script/release +3 -0
- data/script/test_web +22 -0
- data/script/unit_test +3 -0
- data/spec/actions/add_examples_to_test_cases_directory_spec.rb +52 -0
- data/spec/actions/clone_repository_spec.rb +83 -0
- data/spec/actions/create_directory_spec.rb +59 -0
- data/spec/actions/create_file_spec.rb +139 -0
- data/spec/actions/create_output_spec.rb +46 -0
- data/spec/actions/handle_error_spec.rb +74 -0
- data/spec/actions/initialize_application_spec.rb +40 -0
- data/spec/actions/show_config_spec.rb +22 -0
- data/spec/capybara_proxy_pac_spec.rb +42 -0
- data/spec/capybara_proxy_spec.rb +76 -0
- data/spec/config_spec.rb +86 -0
- data/spec/data_spec.rb +34 -0
- data/spec/environment_spec.rb +25 -0
- data/spec/erb_generator_spec.rb +31 -0
- data/spec/examples/proxy.pac +7 -0
- data/spec/factories.rb +8 -0
- data/spec/features/check_ssl_sites_spec.rb +8 -0
- data/spec/git_file_spec.rb +46 -0
- data/spec/git_repository_spec.rb +111 -0
- data/spec/main_spec.rb +25 -0
- data/spec/pac_result_spec.rb +20 -0
- data/spec/proxy_tester_spec_helper_spec.rb +137 -0
- data/spec/rspec_runner_spec.rb +29 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/capybara.rb +11 -0
- data/spec/support/database_cleaner.rb +14 -0
- data/spec/support/debugging.rb +3 -0
- data/spec/support/environment.rb +33 -0
- data/spec/support/example.rb +16 -0
- data/spec/support/factory_girl.rb +15 -0
- data/spec/support/filesystem.rb +19 -0
- data/spec/support/helper_features.rb +31 -0
- data/spec/support/matcher.rb +17 -0
- data/spec/support/reporting.rb +1 -0
- data/spec/support/rspec.rb +5 -0
- data/spec/support/string.rb +2 -0
- data/spec/template_file_spec.rb +25 -0
- data/spec/template_repository_spec.rb +44 -0
- data/spec/user_database_spec.rb +63 -0
- data/spec/user_spec.rb +62 -0
- metadata +398 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# You can place files in "<%= lookup('example_directory') %>" and require them here.
|
3
|
+
#
|
4
|
+
# File "file.rb" in "<%= lookup('example_directory') %>" becomes
|
5
|
+
#
|
6
|
+
# require 'examples/file'
|
7
|
+
#
|
8
|
+
# in your spec.
|
9
|
+
#
|
10
|
+
describe '<%= lookup('description') %>' do
|
11
|
+
<% Array(lookup('proxies')).each do |p| -%>
|
12
|
+
context '<%= p[:host] %>:<%= p[:port] %>' do
|
13
|
+
before :each do
|
14
|
+
use_proxy host: '<%= p[:host] %>', port: <%= p[:port] %>
|
15
|
+
end
|
16
|
+
|
17
|
+
<% Array(lookup('urls')).each do |url| -%>
|
18
|
+
it 'works with <%= url[:uri] %>' do
|
19
|
+
visit '<%= url[:uri] %>'
|
20
|
+
expect(page).to have_content('<%= url[:content] %>')
|
21
|
+
end
|
22
|
+
|
23
|
+
<% end -%>
|
24
|
+
end
|
25
|
+
|
26
|
+
<% end -%>
|
27
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
<% Array(lookup('gems')).each do |l| -%>
|
4
|
+
# *<%= l[:name] %>*
|
5
|
+
# <%= l[:description] %>
|
6
|
+
# Please see "<%= l[:url] %>" for further information
|
7
|
+
gem '<%= l[:name] %>'<%- if l[:require] == false %>, require: false<% elsif l[:require] %>, require: '<%= l[:require] %>'<% end %>
|
8
|
+
|
9
|
+
<% end -%>
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ProxyTester
|
3
|
+
module Actions
|
4
|
+
class AddExamplesToTestCasesDirectory
|
5
|
+
private
|
6
|
+
|
7
|
+
attr_reader :examples_directory, :options
|
8
|
+
|
9
|
+
public
|
10
|
+
|
11
|
+
def initialize(examples_directory, options = {})
|
12
|
+
@examples_directory = examples_directory
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
if need_to_run? || options[:force] == true
|
18
|
+
Actions::CreateDirectory.new(File.join(examples_directory, 'support'), force: options[:force]).run
|
19
|
+
Actions::CreateFile.new(:'example-test_case.rb', File.join(examples_directory, 'example_spec.rb'), test_case_data, force: options[:force], create_directories: true).run
|
20
|
+
Actions::CreateFile.new(:'example-test_cases-gemfile.rb', File.join(examples_directory, 'Gemfile'), test_spec_helper_data, force: options[:force], create_directories: true).run
|
21
|
+
Actions::CreateFile.new(:'example-spec_helper.rb', File.join(examples_directory, 'spec_helper.rb'), test_spec_helper_data, force: options[:force], create_directories: true).run
|
22
|
+
else
|
23
|
+
ProxyTester.ui_logger.warn "Directory with examples already exists at \"#{examples_directory}\" . Do not create it again!."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def test_spec_helper_data
|
30
|
+
Data.new(
|
31
|
+
OpenStruct.new(
|
32
|
+
libraries: [
|
33
|
+
{
|
34
|
+
name: 'open-uri',
|
35
|
+
require: 'open-uri',
|
36
|
+
description: 'Easier use of urls in scripts',
|
37
|
+
url: 'http://www.ruby-doc.org/stdlib-2.1.1/libdoc/open-uri/rdoc/OpenURI.html',
|
38
|
+
},
|
39
|
+
],
|
40
|
+
gems: [
|
41
|
+
{
|
42
|
+
name: 'pry',
|
43
|
+
description: 'REPL shell with completion to make writing specs easier',
|
44
|
+
url: 'http://pryrepl.org/',
|
45
|
+
},
|
46
|
+
{
|
47
|
+
name: 'pry-debugger',
|
48
|
+
description: 'Integration debugger into pry',
|
49
|
+
require: false,
|
50
|
+
url: 'https://github.com/nixme/pry-debugger',
|
51
|
+
},
|
52
|
+
{
|
53
|
+
name: 'pry-doc',
|
54
|
+
description: 'Documentation for pry',
|
55
|
+
require: false,
|
56
|
+
url: 'http://pryrepl.org/',
|
57
|
+
},
|
58
|
+
{
|
59
|
+
name: 'debugger',
|
60
|
+
description: 'The debugger for ruby. Please install the ruby gem "pry-debugger" for integration with pry.',
|
61
|
+
url: 'http://pryrepl.org/',
|
62
|
+
},
|
63
|
+
{
|
64
|
+
name: 'debugger-completion',
|
65
|
+
require: 'debugger/completion',
|
66
|
+
description: 'Completion for debugger shell',
|
67
|
+
url: 'https://github.com/cldwalker/debugger-completion',
|
68
|
+
},
|
69
|
+
{
|
70
|
+
name: 'nokogiri',
|
71
|
+
description: 'HTML parser to make writing tests easier.',
|
72
|
+
url: 'http://nokogiri.org/',
|
73
|
+
},
|
74
|
+
{
|
75
|
+
name: 'excon',
|
76
|
+
description: 'HTTP library with proxy support',
|
77
|
+
url: 'https://github.com/geemus/excon',
|
78
|
+
},
|
79
|
+
{
|
80
|
+
name: 'awesome_print',
|
81
|
+
require: 'ap',
|
82
|
+
description: 'Output data in repl shell',
|
83
|
+
url: 'https://github.com/michaeldv/awesome_print',
|
84
|
+
},
|
85
|
+
],
|
86
|
+
)
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_case_data
|
91
|
+
Data.new(
|
92
|
+
OpenStruct.new(
|
93
|
+
example_directory: examples_directory,
|
94
|
+
description: 'This is an example test case',
|
95
|
+
proxies: [
|
96
|
+
{
|
97
|
+
host: 'proxy.example.org',
|
98
|
+
port: 8080,
|
99
|
+
},
|
100
|
+
{
|
101
|
+
host: 'proxy2.example.org',
|
102
|
+
port: 3128,
|
103
|
+
},
|
104
|
+
],
|
105
|
+
urls: [
|
106
|
+
{
|
107
|
+
uri: 'http://www.example.org',
|
108
|
+
content: 'Example Domain',
|
109
|
+
},
|
110
|
+
{
|
111
|
+
uri: 'http://www.example.net',
|
112
|
+
content: 'Example Domain',
|
113
|
+
}
|
114
|
+
]
|
115
|
+
)
|
116
|
+
)
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
def need_to_run?
|
121
|
+
!::File.exists? examples_directory
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ProxyTester
|
3
|
+
module Actions
|
4
|
+
class CloneRepository
|
5
|
+
private
|
6
|
+
|
7
|
+
attr_reader :source, :destination, :options
|
8
|
+
|
9
|
+
public
|
10
|
+
|
11
|
+
def initialize(source, destination, options = {})
|
12
|
+
@source = ::File.expand_path(source)
|
13
|
+
@destination = ::File.expand_path(destination)
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
if need_to_run? || options[:force] == true
|
19
|
+
ProxyTester.ui_logger.warn "Cloning repository from \"#{source}\" to \"#{destination}\"."
|
20
|
+
|
21
|
+
if !need_to_run? && options[:force] == true
|
22
|
+
ProxyTester.ui_logger.warn "This action does not support \":force\"-flag. Please move away the destination repository yourself."
|
23
|
+
return
|
24
|
+
end
|
25
|
+
|
26
|
+
GitRepository.clone(source, destination, bare: options.fetch(:bare, false))
|
27
|
+
else
|
28
|
+
ProxyTester.ui_logger.warn "Destination \"#{destination}\" already exists. Do not create it again!"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def need_to_run?
|
35
|
+
!::File.exists? destination
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ProxyTester
|
3
|
+
module Actions
|
4
|
+
class CreateDirectory
|
5
|
+
private
|
6
|
+
|
7
|
+
attr_reader :fs_engine, :path, :options
|
8
|
+
|
9
|
+
public
|
10
|
+
|
11
|
+
def initialize(path, options = {}, fs_engine = FileUtils)
|
12
|
+
@path =::File.expand_path(path)
|
13
|
+
@options = options
|
14
|
+
@fs_engine = fs_engine
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
if need_to_run? || options[:force] == true
|
19
|
+
ProxyTester.ui_logger.warn "Creating directory \"#{path}\"."
|
20
|
+
fs_engine.mkdir_p(path)
|
21
|
+
else
|
22
|
+
ProxyTester.ui_logger.warn "Directory \"#{path}\" already exists. Do not create it again!."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def need_to_run?
|
29
|
+
!::File.exists?(path)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ProxyTester
|
3
|
+
module Actions
|
4
|
+
class CreateFile
|
5
|
+
private
|
6
|
+
|
7
|
+
attr_reader :name, :destination, :data, :options, :engine, :repository
|
8
|
+
|
9
|
+
public
|
10
|
+
|
11
|
+
def initialize(name, destination, data, options = {}, engine = ErbGenerator, repository = TemplateRepository.new)
|
12
|
+
@name = name
|
13
|
+
@destination =::File.expand_path(destination)
|
14
|
+
@data = data
|
15
|
+
@options = options
|
16
|
+
@engine = engine
|
17
|
+
@repository = repository
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
if need_to_run? || options[:force] == true
|
22
|
+
ProxyTester.ui_logger.warn "Creating file \"#{destination}\"."
|
23
|
+
|
24
|
+
create_directories if options[:create_directories] == true
|
25
|
+
|
26
|
+
file = template(name, ::File.new(destination, 'w'), data)
|
27
|
+
FileUtils.chmod('+x', file) if options[:executable] == true
|
28
|
+
else
|
29
|
+
ProxyTester.ui_logger.warn "File \"#{destination}\" already exists. Do not create it again!."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def create_directories
|
36
|
+
FileUtils.mkdir_p(::File.dirname(destination))
|
37
|
+
end
|
38
|
+
|
39
|
+
def template(local_name, local_destination, local_data)
|
40
|
+
template = repository.find(local_name)
|
41
|
+
|
42
|
+
generator = engine.new(local_data)
|
43
|
+
generator.compile(template, local_destination)
|
44
|
+
|
45
|
+
local_destination
|
46
|
+
rescue Errno::ENOENT
|
47
|
+
fail Exceptions::ErbTemplateIsUnknown, JSON.dump(message: "Unknown erb template \"#{template_path}\".")
|
48
|
+
end
|
49
|
+
|
50
|
+
def need_to_run?
|
51
|
+
!::File.exists?(destination)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ProxyTester
|
3
|
+
module Actions
|
4
|
+
class CreateOutput
|
5
|
+
private
|
6
|
+
|
7
|
+
attr_reader :name, :output, :engine, :repository, :data
|
8
|
+
|
9
|
+
public
|
10
|
+
|
11
|
+
def initialize(name, output, data, engine = ErbGenerator, repository = TemplateRepository.new)
|
12
|
+
@name = name
|
13
|
+
@output = output
|
14
|
+
@data = data
|
15
|
+
@engine = engine
|
16
|
+
@repository = repository
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
ProxyTester.ui_logger.info "Creating example configuration:"
|
21
|
+
template(name, output, data)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def template(local_name, local_destination, local_data)
|
27
|
+
template = repository.find(local_name)
|
28
|
+
|
29
|
+
generator = engine.new(local_data)
|
30
|
+
generator.compile(template, local_destination)
|
31
|
+
rescue Errno::ENOENT
|
32
|
+
fail Exceptions::ErbTemplateIsUnknown, JSON.dump(message: "Unknown erb template \"#{template_path}\".")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ProxyTester
|
3
|
+
module Actions
|
4
|
+
class HandleError
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
attr_reader :exception, :original_message, :handler_klass
|
9
|
+
|
10
|
+
public
|
11
|
+
|
12
|
+
def initialize(exception, handler_klass = ErrorHandler)
|
13
|
+
@exception = exception.class
|
14
|
+
@original_message = exception.message
|
15
|
+
@handler_klass = handler_klass
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
handler = handler_klass.find exception
|
20
|
+
handler.original_message = original_message
|
21
|
+
|
22
|
+
handler.execute(parsed_message)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def parsed_message
|
28
|
+
result = JSON.parse(original_message)
|
29
|
+
return {} unless result.kind_of? Hash
|
30
|
+
|
31
|
+
result
|
32
|
+
rescue JSON::ParserError
|
33
|
+
{}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module ProxyTester
|
2
|
+
module Actions
|
3
|
+
class InitializeApplication
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
attr_reader :config, :options
|
8
|
+
|
9
|
+
public
|
10
|
+
|
11
|
+
def initialize(options = {}, config = ProxyTester.config)
|
12
|
+
@options = options
|
13
|
+
@config = config
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
create_test_cases_directory if options[:create_test_cases_directory]
|
18
|
+
create_user_file if options[:create_user_file]
|
19
|
+
create_config_file if options[:create_config_file]
|
20
|
+
|
21
|
+
pre_seed if options[:pre_seed]
|
22
|
+
|
23
|
+
show_example_config
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def create_test_cases_directory
|
29
|
+
ProxyTester.ui_logger.info "Creating test case directory : #{config.test_cases_directory}"
|
30
|
+
Actions::CreateDirectory.new(config.test_cases_directory, force: options[:force]).run
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_config_file
|
34
|
+
ProxyTester.ui_logger.info "Creating config file at \"#{config.config_file}\"."
|
35
|
+
Actions::CreateFile.new(:'example-config', config.config_file, Data.new(config), force: options[:force], create_directories: true).run
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_user_file
|
39
|
+
ProxyTester.ui_logger.info "Creating user file at \"#{config.user_file}\"."
|
40
|
+
|
41
|
+
data = OpenStruct.new(
|
42
|
+
users: [
|
43
|
+
{
|
44
|
+
name: 'user1',
|
45
|
+
password: 'password1',
|
46
|
+
description: 'description',
|
47
|
+
},
|
48
|
+
{
|
49
|
+
name: 'user2',
|
50
|
+
password: 'password2',
|
51
|
+
description: 'description',
|
52
|
+
},
|
53
|
+
]
|
54
|
+
)
|
55
|
+
|
56
|
+
Actions::CreateFile.new(:'example-user_file', config.user_file, Data.new(data), force: options[:force], create_directories: true).run
|
57
|
+
end
|
58
|
+
|
59
|
+
def show_example_config
|
60
|
+
ProxyTester.ui_logger.info "Showing the configuration of proxy_tester on your system."
|
61
|
+
Actions::CreateOutput.new(:'example-config', $stdout, Data.new(config)).run
|
62
|
+
end
|
63
|
+
|
64
|
+
def pre_seed
|
65
|
+
ProxyTester.ui_logger.info "Adding examples to at #{config.examples_directory}"
|
66
|
+
Actions::AddExamplesToTestCasesDirectory.new(config.examples_directory, force: options[:force]).run
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ProxyTester
|
3
|
+
class CapybaraProxy
|
4
|
+
|
5
|
+
attr_accessor :host, :user
|
6
|
+
attr_reader :port, :type
|
7
|
+
|
8
|
+
def port=(value)
|
9
|
+
@port = value.to_i
|
10
|
+
end
|
11
|
+
|
12
|
+
def type=(value)
|
13
|
+
case value
|
14
|
+
when :none
|
15
|
+
@type = 'none'
|
16
|
+
when :socks5
|
17
|
+
@type = 'socks5'
|
18
|
+
when :http
|
19
|
+
@type = 'http'
|
20
|
+
else
|
21
|
+
raise Exceptions::ProxyTypeInvalid, JSON.dump(type: value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_sym
|
26
|
+
return :no_proxy if host.blank? or port.blank?
|
27
|
+
|
28
|
+
"#{host}_#{port}".to_sym
|
29
|
+
end
|
30
|
+
|
31
|
+
def as_phantomjs_arguments
|
32
|
+
result = []
|
33
|
+
result << "--proxy=#{proxy_string}" if host || port
|
34
|
+
result << "--proxy-type=#{type}" if type
|
35
|
+
result << "--proxy-auth=#{user_string}" if user
|
36
|
+
|
37
|
+
result
|
38
|
+
end
|
39
|
+
|
40
|
+
def blank?
|
41
|
+
host.blank? and port.blank?
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def proxy_string
|
47
|
+
"#{host}:#{port}".shellescape
|
48
|
+
end
|
49
|
+
|
50
|
+
def user_string
|
51
|
+
user.to_string.shellescape
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ProxyTester
|
3
|
+
class CapybaraProxyPac
|
4
|
+
|
5
|
+
attr_accessor :client_ip, :time, :pac_file, :url, :resul
|
6
|
+
|
7
|
+
def host
|
8
|
+
@result ||= result
|
9
|
+
|
10
|
+
result.proxy
|
11
|
+
end
|
12
|
+
|
13
|
+
def port
|
14
|
+
@result ||= result
|
15
|
+
|
16
|
+
result.proxy_port
|
17
|
+
end
|
18
|
+
|
19
|
+
def blank?
|
20
|
+
host.blank? or port.blank?
|
21
|
+
end
|
22
|
+
|
23
|
+
def direct?
|
24
|
+
@result ||= result
|
25
|
+
|
26
|
+
result.request_type == 'DIRECT'
|
27
|
+
end
|
28
|
+
|
29
|
+
def pac_file=(source)
|
30
|
+
uri = Addressable::URI.heuristic_parse(source)
|
31
|
+
|
32
|
+
if uri.host.blank?
|
33
|
+
@pac_file = File.read(source)
|
34
|
+
else
|
35
|
+
@pac_file = open(uri, { proxy: false })
|
36
|
+
end
|
37
|
+
|
38
|
+
@pac_file
|
39
|
+
rescue Errno::ENOENT
|
40
|
+
raise Exceptions::PacFileNotFound, JSON.dump(file: pac_file)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def result
|
46
|
+
return PacResult.new if pac_file.blank?
|
47
|
+
|
48
|
+
env_hash = {}
|
49
|
+
env_hash[:client_ip] = client_ip if client_ip
|
50
|
+
env_hash[:time] = time if time
|
51
|
+
|
52
|
+
parser = ProxyPacRb::Parser.new(ProxyPacRb::Environment.new(env_hash))
|
53
|
+
|
54
|
+
file = parser.source(pac_file)
|
55
|
+
result = PacResult.new(file.find(url))
|
56
|
+
|
57
|
+
raise Exceptions::PacResultResult, JSON.dump(file: pac_file, result: result) if result.blank?
|
58
|
+
|
59
|
+
result
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding
|
2
|
+
module ProxyTester
|
3
|
+
module Cli
|
4
|
+
class Main < Thor
|
5
|
+
class_option :config_file, type: :string, desc: 'Config file'
|
6
|
+
class_option :log_level, type: :string, desc: 'Log level for ui logging'
|
7
|
+
class_option :debug_mode, type: :boolean, desc: 'Run application in debug mode'
|
8
|
+
|
9
|
+
desc 'test', 'Run tests'
|
10
|
+
option :test_cases_directory, type: :string, desc: 'Directory with test cases'
|
11
|
+
option :tags, type: :array, desc: 'Filter tests based on tags'
|
12
|
+
def test
|
13
|
+
ProxyTester.config = ProxyTester::Config.new(options[:config_file]) if options[:config_file]
|
14
|
+
ProxyTester.config.log_level = options[:log_level] if options[:log_level]
|
15
|
+
ProxyTester.config.debug_mode = options[:debug_mode] if options[:debug_mode]
|
16
|
+
ProxyTester.config.test_cases_directory = options[:test_cases_directory] if options[:test_cases_directory]
|
17
|
+
ProxyTester.config.lock
|
18
|
+
|
19
|
+
ProxyTester.ui_logger.level = ProxyTester.config.log_level
|
20
|
+
ProxyTester.enable_debug_mode if ProxyTester.config.debug_mode
|
21
|
+
|
22
|
+
ProxyTester::RspecRunner.new.run(options[:tags])
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'init', 'Create files/directories to use proxy_tester'
|
26
|
+
option :force, type: :boolean, default: false, desc: 'Overwrite existing files?'
|
27
|
+
option :pre_seed, type: :boolean, default: false, desc: 'Add examples to test cases directory'
|
28
|
+
option :test_cases_directory, type: :string, desc: 'Directory with test cases'
|
29
|
+
option :user_file, type: :string, desc: 'Path to user file'
|
30
|
+
|
31
|
+
option :create_config_file, type: :boolean, desc: 'Create config file', default: true
|
32
|
+
option :create_user_file, type: :boolean, desc: 'Create user file', default: true
|
33
|
+
option :create_test_cases_directory, type: :boolean, desc: 'Create directory to store test cases', default: true
|
34
|
+
def init
|
35
|
+
ProxyTester.config = ProxyTester::Config.new(options[:config_file]) if options[:config_file]
|
36
|
+
|
37
|
+
ProxyTester.config.log_level = options[:log_level] if options[:log_level]
|
38
|
+
ProxyTester.config.debug_mode = options[:debug_mode] if options[:debug_mode]
|
39
|
+
ProxyTester.config.test_cases_directory = options[:test_cases_directory] if options[:test_cases_directory]
|
40
|
+
ProxyTester.config.user_file = options[:user_file] if options[:user_file]
|
41
|
+
ProxyTester.config.lock
|
42
|
+
|
43
|
+
ProxyTester.ui_logger.level = ProxyTester.config.log_level
|
44
|
+
ProxyTester.enable_debug_mode if ProxyTester.config.debug_mode
|
45
|
+
|
46
|
+
ProxyTester.ui_logger.debug('Options: ' + options.to_s)
|
47
|
+
ProxyTester.ui_logger.debug("Config:\n" + ProxyTester.config.to_s)
|
48
|
+
|
49
|
+
Actions::InitializeApplication.new(
|
50
|
+
force: options[:force],
|
51
|
+
pre_seed: options[:pre_seed],
|
52
|
+
create_config_file: options[:create_config_file],
|
53
|
+
create_user_file: options[:create_user_file],
|
54
|
+
create_test_cases_directory: options[:create_test_cases_directory],
|
55
|
+
).run
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|