local_pac 0.1.11 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +13 -0
- data/README.DEVELOPER.md +18 -0
- data/README.md +9 -1
- data/app/assets/fonts/open-sans/Apache License Version 2.txt +53 -0
- data/app/assets/fonts/open-sans/OpenSans-Bold-webfont.eot +0 -0
- data/app/assets/fonts/open-sans/OpenSans-Bold-webfont.svg +251 -0
- data/app/assets/fonts/open-sans/OpenSans-Bold-webfont.ttf +0 -0
- data/app/assets/fonts/open-sans/OpenSans-Bold-webfont.woff +0 -0
- data/app/assets/fonts/open-sans/OpenSans-BoldItalic-webfont.eot +0 -0
- data/app/assets/fonts/open-sans/OpenSans-BoldItalic-webfont.svg +251 -0
- data/app/assets/fonts/open-sans/OpenSans-BoldItalic-webfont.ttf +0 -0
- data/app/assets/fonts/open-sans/OpenSans-BoldItalic-webfont.woff +0 -0
- data/app/assets/fonts/open-sans/OpenSans-ExtraBold-webfont.eot +0 -0
- data/app/assets/fonts/open-sans/OpenSans-ExtraBold-webfont.svg +251 -0
- data/app/assets/fonts/open-sans/OpenSans-ExtraBold-webfont.ttf +0 -0
- data/app/assets/fonts/open-sans/OpenSans-ExtraBold-webfont.woff +0 -0
- data/app/assets/fonts/open-sans/OpenSans-ExtraBoldItalic-webfont.eot +0 -0
- data/app/assets/fonts/open-sans/OpenSans-ExtraBoldItalic-webfont.svg +251 -0
- data/app/assets/fonts/open-sans/OpenSans-ExtraBoldItalic-webfont.ttf +0 -0
- data/app/assets/fonts/open-sans/OpenSans-ExtraBoldItalic-webfont.woff +0 -0
- data/app/assets/fonts/open-sans/OpenSans-Italic-webfont.eot +0 -0
- data/app/assets/fonts/open-sans/OpenSans-Italic-webfont.svg +251 -0
- data/app/assets/fonts/open-sans/OpenSans-Italic-webfont.ttf +0 -0
- data/app/assets/fonts/open-sans/OpenSans-Italic-webfont.woff +0 -0
- data/app/assets/fonts/open-sans/OpenSans-Light-webfont.eot +0 -0
- data/app/assets/fonts/open-sans/OpenSans-Light-webfont.svg +252 -0
- data/app/assets/fonts/open-sans/OpenSans-Light-webfont.ttf +0 -0
- data/app/assets/fonts/open-sans/OpenSans-Light-webfont.woff +0 -0
- data/app/assets/fonts/open-sans/OpenSans-LightItalic-webfont.eot +0 -0
- data/app/assets/fonts/open-sans/OpenSans-LightItalic-webfont.svg +252 -0
- data/app/assets/fonts/open-sans/OpenSans-LightItalic-webfont.ttf +0 -0
- data/app/assets/fonts/open-sans/OpenSans-LightItalic-webfont.woff +0 -0
- data/app/assets/fonts/open-sans/OpenSans-Regular-webfont.eot +0 -0
- data/app/assets/fonts/open-sans/OpenSans-Regular-webfont.svg +252 -0
- data/app/assets/fonts/open-sans/OpenSans-Regular-webfont.ttf +0 -0
- data/app/assets/fonts/open-sans/OpenSans-Regular-webfont.woff +0 -0
- data/app/assets/fonts/open-sans/OpenSans-Semibold-webfont.eot +0 -0
- data/app/assets/fonts/open-sans/OpenSans-Semibold-webfont.svg +251 -0
- data/app/assets/fonts/open-sans/OpenSans-Semibold-webfont.ttf +0 -0
- data/app/assets/fonts/open-sans/OpenSans-Semibold-webfont.woff +0 -0
- data/app/assets/fonts/open-sans/OpenSans-SemiboldItalic-webfont.eot +0 -0
- data/app/assets/fonts/open-sans/OpenSans-SemiboldItalic-webfont.svg +251 -0
- data/app/assets/fonts/open-sans/OpenSans-SemiboldItalic-webfont.ttf +0 -0
- data/app/assets/fonts/open-sans/OpenSans-SemiboldItalic-webfont.woff +0 -0
- data/app/assets/javascripts/application.js +17 -0
- data/app/assets/javascripts/jquery-min.js +4 -0
- data/app/assets/stylesheets/application.css.scss +139 -0
- data/app/assets/stylesheets/open-sans.css.scss +109 -0
- data/app/controllers/application_controller.rb +90 -0
- data/app/controllers/assets_controller.rb +64 -0
- data/app/controllers/file_serve_controller.rb +22 -0
- data/app/controllers/lookup_controller.rb +34 -0
- data/app/locales/de.yml +2 -0
- data/app/locales/en.yml +31 -0
- data/{features/show_known_pacfiles.feature → app/public/favicon.ico} +0 -0
- data/app/views/application.haml +10 -0
- data/app/views/error.haml +6 -0
- data/app/views/form.haml +11 -0
- data/app/views/lookup.haml +3 -0
- data/app/views/lookup_result.haml +19 -0
- data/bin/local_pac +47 -27
- data/config.ru +24 -3
- data/features/fetch_proxy_pac.feature +1 -1
- data/features/initializer.feature +0 -1
- data/features/{show_config.feature → show_status.feature} +2 -2
- data/features/step_definitions.rb +14 -0
- data/features/support/env.rb +1 -0
- data/files/config.yaml +1 -0
- data/files/example-config.erb +16 -0
- data/lib/local_pac/{logger.rb → access_logger.rb} +1 -1
- data/lib/local_pac/actions/create_directory.rb +2 -2
- data/lib/local_pac/actions/create_file.rb +2 -2
- data/lib/local_pac/actions/create_output.rb +36 -0
- data/lib/local_pac/config.rb +15 -5
- data/lib/local_pac/exceptions.rb +12 -0
- data/lib/local_pac/initializer.rb +10 -1
- data/lib/local_pac/main.rb +39 -2
- data/lib/local_pac/null_access_logger.rb +6 -0
- data/lib/local_pac/proxy_pac/html_data.rb +17 -0
- data/lib/local_pac/proxy_pac/html_div_style.rb +48 -0
- data/lib/local_pac/proxy_pac/html_table_style.rb +57 -0
- data/lib/local_pac/proxy_pac/pac_engine.rb +28 -0
- data/lib/local_pac/proxy_pac/pac_parser.rb +33 -0
- data/lib/local_pac/proxy_pac/pac_result.rb +49 -0
- data/lib/local_pac/proxy_pac/pac_result_html_stylist.rb +34 -0
- data/lib/local_pac/proxy_pac/result.rb +40 -0
- data/lib/local_pac/proxy_pac/result_parser.rb +49 -0
- data/lib/local_pac/router.rb +7 -0
- data/lib/local_pac/server.rb +28 -0
- data/lib/local_pac/spec_helper_file_server.rb +1 -1
- data/lib/local_pac/ui_logger.rb +0 -1
- data/lib/local_pac/version.rb +1 -1
- data/lib/local_pac.rb +15 -4
- data/local_pac.gemspec +10 -0
- data/script/console +14 -0
- data/share/archlinux/PKGBUILD +4 -4
- data/spec/actions/create_directory_spec.rb +1 -1
- data/spec/actions/create_file_spec.rb +0 -2
- data/spec/actions/create_output_spec.rb +46 -0
- data/spec/config_spec.rb +11 -0
- data/spec/features/fetch_proxy_pac_spec.rb +49 -14
- data/spec/features/lookup_proxy_spec.rb +102 -0
- data/spec/initializer_spec.rb +7 -2
- data/spec/proxy_pac/html_div_style_spec.rb +45 -0
- data/spec/proxy_pac/html_table_style_spec.rb +54 -0
- data/spec/proxy_pac/pac_engine_spec.rb +33 -0
- data/spec/proxy_pac/pac_parser_spec.rb +32 -0
- data/spec/proxy_pac/pac_result_html_stylist_spec.rb +36 -0
- data/spec/proxy_pac/pac_result_spec.rb +54 -0
- data/spec/proxy_pac_result_parser_spec.rb +15 -0
- data/spec/server_spec.rb +18 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/spec_helper_features.rb +3 -0
- data/spec/support/capybara.rb +6 -0
- metadata +264 -8
- data/lib/local_pac/file_server.rb +0 -37
@@ -0,0 +1,102 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'spec_helper_features'
|
4
|
+
|
5
|
+
describe 'Fetch proxy pac' do
|
6
|
+
context '/v1/pac' do
|
7
|
+
let(:valid_pac_file) do <<-EOS.strip_heredoc.chomp
|
8
|
+
function FindProxyForURL(url, host) {
|
9
|
+
return "DIRECT";
|
10
|
+
}
|
11
|
+
EOS
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:pac_file_return_nil) do <<-EOS.strip_heredoc.chomp
|
15
|
+
function FindProxyForURL(url, host) {
|
16
|
+
return "";
|
17
|
+
}
|
18
|
+
EOS
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:invalid_pac_file) do <<-EOS.strip_heredoc.chomp
|
22
|
+
function FindProxyForURL(url, host) {
|
23
|
+
asdfasdf();
|
24
|
+
}
|
25
|
+
EOS
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:git_repo) { 'git_repo' }
|
29
|
+
|
30
|
+
before(:each) do
|
31
|
+
git_init(git_repo)
|
32
|
+
create_file(File.join(git_repo, 'file.pac'), valid_pac_file)
|
33
|
+
git_add(git_repo, 'file.pac')
|
34
|
+
git_commit(git_repo)
|
35
|
+
end
|
36
|
+
|
37
|
+
before :each do
|
38
|
+
config = Class.new do
|
39
|
+
include FeduxOrg::Stdlib::Filesystem
|
40
|
+
|
41
|
+
def root_directory
|
42
|
+
File.expand_path('../../../', __FILE__)
|
43
|
+
end
|
44
|
+
|
45
|
+
def local_storage
|
46
|
+
File.join(working_directory, 'git_repo', '.git')
|
47
|
+
end
|
48
|
+
end.new
|
49
|
+
|
50
|
+
LocalPac.config = config
|
51
|
+
Capybara.app = LocalPac::App::LookupController
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'looks up proxy', :focus do
|
55
|
+
visit('/file.pac')
|
56
|
+
within('#search') do
|
57
|
+
fill_in 'url', :with => 'http://www.example.org'
|
58
|
+
end
|
59
|
+
expect(page).to have_content('asdf')
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'shows a result output' do
|
63
|
+
rendered_view = <<-EOS.strip_heredoc
|
64
|
+
EOS
|
65
|
+
response = post('/file.pac', {:url => 'http://example.org'})
|
66
|
+
expect(last_response).to be_ok
|
67
|
+
expect(response.body).to eq('Please enter fully quallified url')
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'handles a nil file as well' do
|
71
|
+
create_file(File.join(git_repo, 'file_nil.pac'), pac_file_return_nil)
|
72
|
+
git_add(git_repo, 'file_nil.pac')
|
73
|
+
git_commit(git_repo)
|
74
|
+
|
75
|
+
rendered_view = <<-EOS.strip_heredoc
|
76
|
+
EOS
|
77
|
+
|
78
|
+
response = post('/file_nil.pac', {:url => 'http://example.org'})
|
79
|
+
|
80
|
+
expect(last_response).to be_ok
|
81
|
+
expect(response.body).to eq(rendered_view)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'raises an exception on invalid pac file' do
|
85
|
+
create_file(File.join(git_repo, 'invalid.pac'), invalid_pac_file)
|
86
|
+
git_add(git_repo, 'invalid.pac')
|
87
|
+
git_commit(git_repo)
|
88
|
+
|
89
|
+
expect {
|
90
|
+
response = post('/invalid.pac', {:url => 'http://example.org'})
|
91
|
+
}.to raise_error RuntimeError
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'returns a result for an existing proxy pac' do
|
95
|
+
pending
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'returns a error if file does not exist' do
|
99
|
+
pending
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/spec/initializer_spec.rb
CHANGED
@@ -10,20 +10,25 @@ describe Initializer do
|
|
10
10
|
:local_storage: #{File.join(working_directory, 'storage', 'cache.git')}
|
11
11
|
:executable: #{File.join(working_directory, 'bin', 'local_pac')}
|
12
12
|
:pid_file: #{File.join(working_directory, 'run', 'pid')}
|
13
|
+
:sass_cache: #{File.join(working_directory, 'cache', 'sass')}
|
13
14
|
:gem_path: []
|
14
15
|
EOS
|
15
16
|
config_file = create_file('config.yaml', config_string)
|
16
17
|
|
17
18
|
config = LocalPac::Config.new(config_file)
|
18
19
|
initializer = Initializer.new({}, config)
|
19
|
-
|
20
|
-
|
20
|
+
result = capture(:stdout) do
|
21
|
+
silence(:stderr) do
|
22
|
+
initializer.run
|
23
|
+
end
|
21
24
|
end
|
22
25
|
|
23
26
|
expect(path_exists?('log')).to be_true
|
27
|
+
expect(path_exists?('cache/sass')).to be_true
|
24
28
|
expect(path_exists?('storage/cache.git')).to be_true
|
25
29
|
expect(path_exists?(File.join('storage', 'cache.git', 'hooks', 'pre-receive'))).to be_true
|
26
30
|
expect(path_exists?('run')).to be_true
|
31
|
+
expect(result).to include("log_sink: #{File.expand_path(File.join(ENV['HOME'], '.local', 'share', 'local_pac', 'log'))}")
|
27
32
|
end
|
28
33
|
end
|
29
34
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ProxyPac::HTMLDivStyle do
|
5
|
+
it 'produces a table' do
|
6
|
+
data1 = double('DataHTML')
|
7
|
+
allow(data1).to receive(:element).and_return('1st data')
|
8
|
+
allow(data1).to receive(:header).and_return('1st header')
|
9
|
+
allow(data1).to receive(:header_css_class).and_return('header')
|
10
|
+
allow(data1).to receive(:element_css_class).and_return('element')
|
11
|
+
|
12
|
+
data2 = double('DataHTML')
|
13
|
+
allow(data2).to receive(:element).and_return('2nd data')
|
14
|
+
allow(data2).to receive(:header).and_return('2nd header')
|
15
|
+
allow(data2).to receive(:header_css_class).and_return('header')
|
16
|
+
allow(data2).to receive(:element_css_class).and_return('element')
|
17
|
+
|
18
|
+
style = ProxyPac::HTMLDivStyle.new(main_container_css_class: 'main_container', element_container_css_class: 'element_container')
|
19
|
+
style.add_data(data1)
|
20
|
+
style.add_data(data2)
|
21
|
+
|
22
|
+
expected_result = <<-EOS.strip_heredoc.chomp
|
23
|
+
<div class="main_container">
|
24
|
+
<div class="element_container">
|
25
|
+
<div class="header">
|
26
|
+
1st header
|
27
|
+
</div>
|
28
|
+
<div class="element">
|
29
|
+
1st data
|
30
|
+
</div>
|
31
|
+
</div>
|
32
|
+
<div class="element_container">
|
33
|
+
<div class="header">
|
34
|
+
2nd header
|
35
|
+
</div>
|
36
|
+
<div class="element">
|
37
|
+
2nd data
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
</div>
|
41
|
+
EOS
|
42
|
+
|
43
|
+
expect(style.to_s).to eq(expected_result)
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ProxyPac::HTMLTableStyle do
|
5
|
+
it 'produces a table' do
|
6
|
+
data1 = double('DataHTML')
|
7
|
+
allow(data1).to receive(:element).and_return('1st data')
|
8
|
+
allow(data1).to receive(:header).and_return('1st header')
|
9
|
+
allow(data1).to receive(:header_css_class).and_return('header')
|
10
|
+
allow(data1).to receive(:element_css_class).and_return('element')
|
11
|
+
|
12
|
+
data2 = double('DataHTML')
|
13
|
+
allow(data2).to receive(:element).and_return('2nd data')
|
14
|
+
allow(data2).to receive(:header).and_return('2nd header')
|
15
|
+
allow(data2).to receive(:header_css_class).and_return('header')
|
16
|
+
allow(data2).to receive(:element_css_class).and_return('element')
|
17
|
+
|
18
|
+
style = ProxyPac::HTMLTableStyle.new(main_container_css_class: 'main_container', element_container_css_class: 'element_container')
|
19
|
+
style.add_data(data1)
|
20
|
+
style.add_data(data2)
|
21
|
+
|
22
|
+
expected_result = <<-EOS.strip_heredoc.chomp
|
23
|
+
<table class="main_container">
|
24
|
+
<tr class="element_container">
|
25
|
+
<th>
|
26
|
+
<span class="header">
|
27
|
+
1st header
|
28
|
+
</span>
|
29
|
+
</th>
|
30
|
+
<th>
|
31
|
+
<span class="header">
|
32
|
+
2nd header
|
33
|
+
</span>
|
34
|
+
</th>
|
35
|
+
</tr>
|
36
|
+
<tr class="element_container">
|
37
|
+
<td>
|
38
|
+
<span class="element">
|
39
|
+
1st data
|
40
|
+
</span>
|
41
|
+
</td>
|
42
|
+
<td>
|
43
|
+
<span class="element">
|
44
|
+
2nd data
|
45
|
+
</span>
|
46
|
+
</td>
|
47
|
+
</tr>
|
48
|
+
</table>
|
49
|
+
EOS
|
50
|
+
|
51
|
+
|
52
|
+
expect(style.to_s).to eq(expected_result)
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ProxyPac::PACEngine do
|
5
|
+
let(:valid_pac_file) do <<-EOS.strip_heredoc
|
6
|
+
function FindProxyForURL(url, host) {
|
7
|
+
return "DIRECT"
|
8
|
+
}
|
9
|
+
EOS
|
10
|
+
end
|
11
|
+
|
12
|
+
context '#find' do
|
13
|
+
it 'returns a result' do
|
14
|
+
file = double('PacFile')
|
15
|
+
expect(file).to receive(:content).and_return(valid_pac_file)
|
16
|
+
|
17
|
+
parser = ProxyPac::PACEngine.new(file: file)
|
18
|
+
result = parser.find(Addressable::URI.parse('http://example.org'))
|
19
|
+
expect(result).to eq('DIRECT')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'raises an error if pac file is invalid' do
|
23
|
+
file = double('PacFile')
|
24
|
+
allow(file).to receive(:content).and_return('asdfasdf()')
|
25
|
+
|
26
|
+
parser = ProxyPac::PACEngine.new(file: file)
|
27
|
+
|
28
|
+
expect do
|
29
|
+
parser.find(Addressable::URI.parse('http://example.org'))
|
30
|
+
end.to raise_error Exceptions::PacFileInvalid
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ProxyPac::PacParser do
|
5
|
+
context '#initialize' do
|
6
|
+
it 'fails if file is missing' do
|
7
|
+
engine = double('pac_engine')
|
8
|
+
|
9
|
+
expect {
|
10
|
+
ProxyPac::PacParser.new(engine: engine)
|
11
|
+
}.to raise_error ArgumentError
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context '#find' do
|
16
|
+
it 'finds a proxy for url' do
|
17
|
+
engine = double('pac_engine')
|
18
|
+
expect(engine).to receive(:find).and_return('DIRECT')
|
19
|
+
|
20
|
+
file = double('PacFile')
|
21
|
+
|
22
|
+
stylist = double('Stylist')
|
23
|
+
allow(stylist).to receive(:style_me)
|
24
|
+
|
25
|
+
result_generator = double('PacResult')
|
26
|
+
allow(result_generator).to receive(:new).and_return { result_generator }
|
27
|
+
|
28
|
+
parser = ProxyPac::PacParser.new(file: file, engine: engine, result_generator: result_generator, stylist: stylist)
|
29
|
+
result = parser.find('http://example.org')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ProxyPac::PacResultHtmlStylist do
|
5
|
+
context '#initialize' do
|
6
|
+
it 'does not require anything' do
|
7
|
+
expect {
|
8
|
+
ProxyPac::PacResultHtmlStylist.new
|
9
|
+
}.not_to raise_error
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context '#style_me' do
|
14
|
+
it 'builds html for full string' do
|
15
|
+
result = double('PacResult')
|
16
|
+
allow(result).to receive(:proxy_port).and_return('8080')
|
17
|
+
allow(result).to receive(:proxy).and_return('127.0.0.1')
|
18
|
+
allow(result).to receive(:request_type).and_return('PROXY')
|
19
|
+
allow(result).to receive(:styled_content=).with("<span class=\"lp_request_type\">PROXY</span> <span class=\"lp_proxy\">127.0.0.1</span>:<span class=\"lp_proxy_port\">8080</span>")
|
20
|
+
|
21
|
+
stylist = ProxyPac::PacResultHtmlStylist.new
|
22
|
+
stylist.style_me(result)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'builds html for string without port' do
|
26
|
+
result = double('PacResult')
|
27
|
+
allow(result).to receive(:proxy_port).and_return(nil)
|
28
|
+
allow(result).to receive(:proxy).and_return('127.0.0.1')
|
29
|
+
allow(result).to receive(:request_type).and_return('PROXY')
|
30
|
+
allow(result).to receive(:styled_content=).with("<span class=\"lp_request_type\">PROXY</span> <span class=\"lp_proxy\">127.0.0.1</span>")
|
31
|
+
|
32
|
+
stylist = ProxyPac::PacResultHtmlStylist.new
|
33
|
+
stylist.style_me(result)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ProxyPac::PacResult do
|
5
|
+
context '#initialize' do
|
6
|
+
it 'requires a pac parser result' do
|
7
|
+
ProxyPac::PacResult.new('"DIRECT"')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'handles a empty string' do
|
11
|
+
expect {
|
12
|
+
ProxyPac::PacResult.new('')
|
13
|
+
}.not_to raise_error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context '#verbatim_content' do
|
18
|
+
it 'returns the verbatim content' do
|
19
|
+
result = ProxyPac::PacResult.new('"DIRECT"')
|
20
|
+
expect(result.verbatim_content).to eq('"DIRECT"')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context '#proxy' do
|
25
|
+
it 'extracts proxy-hostname from string' do
|
26
|
+
result = ProxyPac::PacResult.new('"PROXY 127.0.0.1:8080"')
|
27
|
+
expect(result.proxy).to eq('127.0.0.1')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'extracts proxy-hostname from short string' do
|
31
|
+
result = ProxyPac::PacResult.new('"PROXY 127.0.0.1"')
|
32
|
+
expect(result.proxy).to eq('127.0.0.1')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context '#proxy_port' do
|
37
|
+
it 'extracts proxy-port from string' do
|
38
|
+
result = ProxyPac::PacResult.new('"PROXY 127.0.0.1:8080"')
|
39
|
+
expect(result.proxy_port).to eq('8080')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context '#request_type' do
|
44
|
+
it 'extracts request type from string' do
|
45
|
+
result = ProxyPac::PacResult.new('"PROXY 127.0.0.1:8080"')
|
46
|
+
expect(result.request_type).to eq('PROXY')
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'extracts request type from short string' do
|
50
|
+
result = ProxyPac::PacResult.new('"DIRECT"')
|
51
|
+
expect(result.request_type).to eq('DIRECT')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
## encoding: utf-8
|
2
|
+
#require 'spec_helper'
|
3
|
+
#
|
4
|
+
#describe ProxyPacResultParser do
|
5
|
+
# context '#parse' do
|
6
|
+
# it 'parses string and returns html' do
|
7
|
+
# string = 'PROXY 127.0.0.1:3128'
|
8
|
+
# string = '<span class="lp_request_type">PROXY</span> <span class="lp_proxy">127.0.0.1</span>:<span class="lp_proxy_port">3128</span>'
|
9
|
+
#
|
10
|
+
# parser = ProxyPacResultParser.new
|
11
|
+
# result = parser.parse string
|
12
|
+
# expect(result).to eq(string)
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
#end
|
data/spec/server_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Server do
|
5
|
+
context '#initialize' do
|
6
|
+
it 'requires listen statement' do
|
7
|
+
expect {
|
8
|
+
Server.new('tcp://locahost:8000')
|
9
|
+
}.not_to raise_error
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'fails on invalid listen statement' do
|
13
|
+
expect {
|
14
|
+
Server.new(nil)
|
15
|
+
}.to raise_error Exceptions::ServerListenStatementInvalid
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -14,6 +14,8 @@ Bundler.require :default, :test, :development
|
|
14
14
|
|
15
15
|
require 'local_pac/spec_helper'
|
16
16
|
|
17
|
+
# Loading support files
|
17
18
|
Dir.glob(File.expand_path('../support/*.rb', __FILE__)).each { |f| require_relative f }
|
18
19
|
|
20
|
+
# Avoid writing "describe LocalPac::MyClass do [..]" but "describe MyClass do [..]"
|
19
21
|
include LocalPac
|