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,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Actions::InitializeApplication do
|
5
|
+
context '#run' do
|
6
|
+
it 'creates all files/directories neccessary to run local_pac' do
|
7
|
+
config_string = <<-EOS.strip_heredoc
|
8
|
+
:user_file: #{File.join(working_directory, 'config', 'user_file.csv')}
|
9
|
+
:config_file: #{File.join(working_directory, 'config', 'config.yaml')}
|
10
|
+
:test_cases_directory: #{File.join(working_directory, 'test_cases.d')}
|
11
|
+
:examples_directory: #{File.join(working_directory, 'test_cases.d/examples')}
|
12
|
+
EOS
|
13
|
+
|
14
|
+
config_file = create_file('config_spec.yaml', config_string)
|
15
|
+
|
16
|
+
config = ProxyTester::Config.new(config_file)
|
17
|
+
|
18
|
+
initializer = Actions::InitializeApplication.new({
|
19
|
+
create_user_file: true,
|
20
|
+
create_config_file: true,
|
21
|
+
create_test_cases_directory: true,
|
22
|
+
pre_seed: true
|
23
|
+
}, config)
|
24
|
+
|
25
|
+
result = capture(:stdout) do
|
26
|
+
silence(:stderr) do
|
27
|
+
initializer.run
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
expect(path_exists?('config/user_file.csv')).to be_true
|
32
|
+
expect(path_exists?('config/config.yaml')).to be_true
|
33
|
+
expect(path_exists?('test_cases.d')).to be_true
|
34
|
+
expect(path_exists?('test_cases.d/examples/support')).to be_true
|
35
|
+
expect(path_exists?('test_cases.d/examples/example_spec.rb')).to be_true
|
36
|
+
expect(path_exists?('test_cases.d/examples/spec_helper.rb')).to be_true
|
37
|
+
expect(result).to include('config_file:')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Actions::ShowConfig do
|
5
|
+
context '#initialize' do
|
6
|
+
it 'has no special requirements' do
|
7
|
+
expect {
|
8
|
+
Actions::ShowConfig.new
|
9
|
+
}.not_to raise_error
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context '#run' do
|
14
|
+
it 'gathers all relevant information and prints them to stdout' do
|
15
|
+
result = capture(:stdout) do
|
16
|
+
Actions::ShowConfig.new.run
|
17
|
+
end
|
18
|
+
|
19
|
+
expect(result).to include('user_file')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe CapybaraProxyPac do
|
5
|
+
let(:valid_pac_file1) do <<-EOS.strip_heredoc.chomp
|
6
|
+
function FindProxyForURL(url, host) {
|
7
|
+
return "PROXY localhost:3128";
|
8
|
+
}
|
9
|
+
EOS
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'all' do
|
13
|
+
it 'handles exceptions for file not found' do
|
14
|
+
pac = CapybaraProxyPac.new
|
15
|
+
expect { pac.pac_file = 'asdf' }.to raise_error Exceptions::PacFileNotFound
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context '#host' do
|
20
|
+
it 'returns host for url' do
|
21
|
+
file = create_file 'proxy.pac', valid_pac_file1
|
22
|
+
|
23
|
+
pac = CapybaraProxyPac.new
|
24
|
+
pac.pac_file = file
|
25
|
+
pac.url = 'http://www.heise.de'
|
26
|
+
|
27
|
+
expect(pac.host).to eq('localhost')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '#port' do
|
32
|
+
it 'returns port for url' do
|
33
|
+
file = create_file 'proxy.pac', valid_pac_file1
|
34
|
+
|
35
|
+
pac = CapybaraProxyPac.new
|
36
|
+
pac.pac_file = file
|
37
|
+
pac.url = 'http://www.heise.de'
|
38
|
+
|
39
|
+
expect(pac.port).to eq('3128')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe CapybaraProxy do
|
5
|
+
context '#initialize' do
|
6
|
+
it 'accepts no arguments' do
|
7
|
+
expect {
|
8
|
+
CapybaraProxy.new
|
9
|
+
}.not_to raise_error
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context '#type=' do
|
14
|
+
it 'sets the proxy type to none' do
|
15
|
+
proxy = CapybaraProxy.new
|
16
|
+
proxy.type = :none
|
17
|
+
|
18
|
+
expect(proxy.type).to eq 'none'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'sets the proxy type to http' do
|
22
|
+
proxy = CapybaraProxy.new
|
23
|
+
proxy.type = :http
|
24
|
+
|
25
|
+
expect(proxy.type).to eq 'http'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'sets the proxy type socks5' do
|
29
|
+
proxy = CapybaraProxy.new
|
30
|
+
proxy.type = :socks5
|
31
|
+
|
32
|
+
expect(proxy.type).to eq 'socks5'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'raises an exception for invalid proxy type' do
|
36
|
+
proxy = CapybaraProxy.new
|
37
|
+
expect {
|
38
|
+
proxy.type = :asdf
|
39
|
+
}.to raise_error Exceptions::ProxyTypeInvalid
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'results in an phantomjs argument' do
|
43
|
+
proxy = CapybaraProxy.new
|
44
|
+
proxy.host = 'host'
|
45
|
+
proxy.port = 3128
|
46
|
+
proxy.type = :socks5
|
47
|
+
|
48
|
+
expect(proxy.as_phantomjs_arguments).to eq(
|
49
|
+
[
|
50
|
+
'--proxy=host:3128',
|
51
|
+
'--proxy-type=socks5',
|
52
|
+
]
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context '#to_a' do
|
58
|
+
it 'accepts no arguments' do
|
59
|
+
proxy = CapybaraProxy.new
|
60
|
+
proxy.host = 'host'
|
61
|
+
proxy.port = 3128
|
62
|
+
|
63
|
+
proxy.user = double('user')
|
64
|
+
allow(proxy.user).to receive(:to_string).and_return('user:password')
|
65
|
+
|
66
|
+
expect(proxy.as_phantomjs_arguments).to eq(
|
67
|
+
[
|
68
|
+
'--proxy=host:3128',
|
69
|
+
'--proxy-auth=user:password',
|
70
|
+
]
|
71
|
+
)
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ProxyTester::Config do
|
5
|
+
let(:config_file) { create_file('config_.yaml') }
|
6
|
+
|
7
|
+
context '#initialize' do
|
8
|
+
it 'requires a file name' do
|
9
|
+
ProxyTester::Config.new(config_file)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context '#to_s' do
|
14
|
+
it 'outputs a nice config overview' do
|
15
|
+
config = ProxyTester::Config.new(config_file)
|
16
|
+
expect(config.to_s).to include ::File.join('.config', 'proxy_tester', 'config.yaml')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context '#lock' do
|
21
|
+
it 'raises and exception if changed afterward' do
|
22
|
+
config = ProxyTester::Config.new(config_file)
|
23
|
+
config.lock
|
24
|
+
|
25
|
+
expect {
|
26
|
+
config.config_file = 'asdf'
|
27
|
+
}.to raise_error Exceptions::ConfigLocked
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '#config_file' do
|
32
|
+
it 'returns value of config file' do
|
33
|
+
config_file = create_file 'config.yaml', <<-EOS.strip_heredoc
|
34
|
+
---
|
35
|
+
:config_file: '/asdf/config'
|
36
|
+
EOS
|
37
|
+
|
38
|
+
config = ProxyTester::Config.new(config_file)
|
39
|
+
expect(config.config_file).to eq('/asdf/config')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns default value if no config file is available' do
|
43
|
+
config = ProxyTester::Config.new(config_file)
|
44
|
+
file = ::File.join(ENV['HOME'], '.config', 'proxy_tester','config.yaml')
|
45
|
+
|
46
|
+
expect(config.config_file).to eq(file)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context '#user_file' do
|
51
|
+
it 'returns value of user file' do
|
52
|
+
config_file = create_file 'user.csv', <<-EOS.strip_heredoc
|
53
|
+
:user_file: '/asdf/user'
|
54
|
+
EOS
|
55
|
+
|
56
|
+
config = ProxyTester::Config.new(config_file)
|
57
|
+
expect(config.user_file).to eq('/asdf/user')
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns default value if no user file is available' do
|
61
|
+
config = ProxyTester::Config.new(config_file)
|
62
|
+
file = ::File.join(ENV['HOME'], '.config', 'proxy_tester','user.csv')
|
63
|
+
|
64
|
+
expect(config.user_file).to eq(file)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context '#test_cases_directory' do
|
69
|
+
it 'returns value of user file' do
|
70
|
+
config_file = create_file 'user.csv', <<-EOS.strip_heredoc
|
71
|
+
:test_cases_directory: '/asdf/cases'
|
72
|
+
EOS
|
73
|
+
|
74
|
+
config = ProxyTester::Config.new(config_file)
|
75
|
+
expect(config.test_cases_directory).to eq('/asdf/cases')
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'returns default value if no user file is available' do
|
79
|
+
config = ProxyTester::Config.new(config_file)
|
80
|
+
file = ::File.join(ENV['HOME'], '.config', 'proxy_tester','test_cases.d')
|
81
|
+
|
82
|
+
expect(config.test_cases_directory).to eq(file)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
data/spec/data_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ProxyTester::Data do
|
5
|
+
context '#instance_binding' do
|
6
|
+
it 'let you lookup variables' do
|
7
|
+
config = Class.new(Module) do
|
8
|
+
def pid_file
|
9
|
+
'/path/pid_file'
|
10
|
+
end
|
11
|
+
end.new
|
12
|
+
|
13
|
+
data = ProxyTester::Data.new(config)
|
14
|
+
# rubocop:disable Eval
|
15
|
+
result = eval('lookup("pid_file")', data.instance_binding)
|
16
|
+
# rubocop:enable Eval
|
17
|
+
expect(result).to eq('/path/pid_file')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context '#lookup' do
|
22
|
+
it 'let you lookup variables' do
|
23
|
+
config = Class.new(Module) do
|
24
|
+
def pid_file
|
25
|
+
'/path/pid_file'
|
26
|
+
end
|
27
|
+
end.new
|
28
|
+
|
29
|
+
data = ProxyTester::Data.new(config)
|
30
|
+
result = data.lookup('pid_file')
|
31
|
+
expect(result).to eq('/path/pid_file')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Environment do
|
5
|
+
context '#initialize' do
|
6
|
+
it 'requires no arguments' do
|
7
|
+
expect {
|
8
|
+
Environment.new
|
9
|
+
}.not_to raise_error
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context '#request_password' do
|
14
|
+
it 'asks for password' do
|
15
|
+
stderr = double(stderr)
|
16
|
+
expect(stderr).to receive(:printf).with('Please enter password: ')
|
17
|
+
|
18
|
+
stdin = double('stdin')
|
19
|
+
expect(stdin).to receive(:readline).and_return('passwd')
|
20
|
+
|
21
|
+
env = Environment.new(stdin, stderr)
|
22
|
+
expect(env.password).to eq('passwd')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ErbGenerator do
|
5
|
+
context '#compile' do
|
6
|
+
it 'needs a source and a target' do
|
7
|
+
data = double('binding')
|
8
|
+
allow(data).to receive(:instance_binding) do
|
9
|
+
Class.new do
|
10
|
+
def pid_file
|
11
|
+
'/path/pid_file'
|
12
|
+
end
|
13
|
+
|
14
|
+
def instance_binding
|
15
|
+
binding
|
16
|
+
end
|
17
|
+
end.new.instance_binding
|
18
|
+
end
|
19
|
+
|
20
|
+
source = double('source')
|
21
|
+
allow(source).to receive(:encoding)
|
22
|
+
allow(source).to receive(:read).and_return('Path <%= pid_file %>')
|
23
|
+
|
24
|
+
destination = double('destination')
|
25
|
+
expect(destination).to receive(:puts).with('Path /path/pid_file')
|
26
|
+
|
27
|
+
gen = ErbGenerator.new(data)
|
28
|
+
gen.compile(source, destination)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/factories.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe GitFile do
|
5
|
+
context 'initialize' do
|
6
|
+
it 'requires a path' do
|
7
|
+
expect {
|
8
|
+
GitFile.new('dir/path.txt')
|
9
|
+
}.not_to raise_error
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'accepts content' do
|
13
|
+
expect {
|
14
|
+
GitFile.new('dir/path.txt', 'content')
|
15
|
+
}.not_to raise_error
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context '#name' do
|
20
|
+
it 'has a name' do
|
21
|
+
file = GitFile.new('file.txt')
|
22
|
+
expect(file.name).to eq(:file)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context '#extension?' do
|
27
|
+
it 'checks if extension is the same' do
|
28
|
+
file = GitFile.new('path.txt')
|
29
|
+
expect(file).to be_extension('.txt')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context '#content' do
|
34
|
+
it 'returns the content of file' do
|
35
|
+
file = GitFile.new('file.txt', 'content')
|
36
|
+
expect(file.content).to eq('content')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context '#nil?' do
|
41
|
+
it 'is always false' do
|
42
|
+
file = GitFile.new('file.txt')
|
43
|
+
expect(file.nil?).to be_false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe GitRepository do
|
5
|
+
context '#initialize' do
|
6
|
+
it 'requires a storage path' do
|
7
|
+
file_creator = double('file_creator')
|
8
|
+
null_file = double('null_file')
|
9
|
+
|
10
|
+
Rugged::Repository.init_at(File.join(working_directory, 'git_repo'))
|
11
|
+
|
12
|
+
expect {
|
13
|
+
GitRepository.new(File.join(working_directory, 'git_repo'), file_creator, null_file)
|
14
|
+
}.not_to raise_error
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context '#find_file' do
|
19
|
+
it 'returns a file if exists in repository' do
|
20
|
+
repo_path = File.join(working_directory, 'git_repo')
|
21
|
+
Rugged::Repository.init_at(repo_path)
|
22
|
+
|
23
|
+
file = double('file')
|
24
|
+
allow(file).to receive(:name).and_return(:file)
|
25
|
+
|
26
|
+
file_creator = double('file_creator')
|
27
|
+
allow(file_creator).to receive(:new).with('file.txt', 'asdf').and_return(file)
|
28
|
+
|
29
|
+
null_file = double('null_file')
|
30
|
+
|
31
|
+
repo = GitRepository.new(repo_path, file_creator, null_file)
|
32
|
+
repo.add_content('file.txt', 'asdf')
|
33
|
+
f = repo.find_file(:file)
|
34
|
+
|
35
|
+
expect(f).to be(file)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns a null file if does not exist in repository' do
|
39
|
+
repo_path = File.join(working_directory, 'git_repo')
|
40
|
+
Rugged::Repository.init_at(repo_path)
|
41
|
+
|
42
|
+
file_creator = double('file_creator')
|
43
|
+
null_file = double('null_file')
|
44
|
+
|
45
|
+
repo = GitRepository.new(repo_path, file_creator, null_file)
|
46
|
+
f = repo.find_file(:file)
|
47
|
+
|
48
|
+
expect(f).to be(null_file)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'handles uninitialized repositories' do
|
52
|
+
repo_path = File.join(working_directory, 'git_repo')
|
53
|
+
Rugged::Repository.init_at(repo_path)
|
54
|
+
|
55
|
+
file_creator = double('file_creator')
|
56
|
+
null_file = double('null_file')
|
57
|
+
|
58
|
+
repo = GitRepository.new(repo_path, file_creator, null_file)
|
59
|
+
f = repo.find_file(:file)
|
60
|
+
|
61
|
+
expect(f).to be(null_file)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context '#each_file' do
|
66
|
+
it 'iterates over all found files' do
|
67
|
+
repo_path = File.join(working_directory, 'git_repo')
|
68
|
+
Rugged::Repository.init_at(repo_path)
|
69
|
+
|
70
|
+
file = double('file')
|
71
|
+
allow(file).to receive(:name).and_return(:file1)
|
72
|
+
|
73
|
+
file_creator = double('file_creator')
|
74
|
+
allow(file_creator).to receive(:new).with('file1.pac', 'asdf1').and_return(file)
|
75
|
+
|
76
|
+
null_file = double('null_file')
|
77
|
+
|
78
|
+
repo = GitRepository.new(repo_path, file_creator, null_file)
|
79
|
+
repo.add_content('file1.pac', 'asdf1')
|
80
|
+
|
81
|
+
result = []
|
82
|
+
repo.each_file { |f| result << f.name }
|
83
|
+
|
84
|
+
expect(result).to eq([:file1])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context '.clone' do
|
89
|
+
it 'clones existing repository' do
|
90
|
+
repo_path = File.join(working_directory, 'git_repo.git')
|
91
|
+
repo = GitRepository.create(repo_path)
|
92
|
+
repo.add_content('file1.pac', 'asdf1')
|
93
|
+
|
94
|
+
clone_path = File.join(working_directory, 'git_repo_clone')
|
95
|
+
|
96
|
+
clone = GitRepository.clone(repo_path, clone_path)
|
97
|
+
expect(clone.all_files.first.name).to eq(:file1)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'creates cloned bare repository' do
|
101
|
+
repo_path = File.join(working_directory, 'git_repo.git')
|
102
|
+
repo = GitRepository.create(repo_path)
|
103
|
+
repo.add_content('file1.pac', 'asdf1')
|
104
|
+
|
105
|
+
clone_path = File.join(working_directory, 'git_repo_clone')
|
106
|
+
GitRepository.clone(repo_path, clone_path, bare: true)
|
107
|
+
|
108
|
+
expect(Rugged::Repository.new(clone_path).bare?).to be true
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/spec/main_spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ProxyTester do
|
5
|
+
context '.load_user_database' do
|
6
|
+
it 'loads the database' do
|
7
|
+
user_file = create_file 'users.csv', <<-EOS.strip_heredoc
|
8
|
+
"name","password"
|
9
|
+
"user1","password1"
|
10
|
+
EOS
|
11
|
+
|
12
|
+
config_file = create_file 'config.yaml', <<-EOS.strip_heredoc
|
13
|
+
user_file: #{user_file}
|
14
|
+
EOS
|
15
|
+
|
16
|
+
ProxyTester.config = ProxyTester::Config.new(config_file)
|
17
|
+
ProxyTester.load_user_database
|
18
|
+
|
19
|
+
expect {
|
20
|
+
User.find_by!(name: 'user1')
|
21
|
+
}.not_to raise_error
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe PacResult do
|
5
|
+
it 'parses pac result' do
|
6
|
+
result = PacResult.new('PROXY localhost:3128')
|
7
|
+
|
8
|
+
expect(result.proxy).to eq('localhost')
|
9
|
+
expect(result.proxy_port).to eq('3128')
|
10
|
+
expect(result.request_type).to eq('PROXY')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'parses pac result' do
|
14
|
+
result = PacResult.new('DIRECT')
|
15
|
+
|
16
|
+
expect(result.proxy).to eq(nil)
|
17
|
+
expect(result.proxy_port).to eq(nil)
|
18
|
+
expect(result.request_type).to eq('DIRECT')
|
19
|
+
end
|
20
|
+
end
|