proxy_pac_rb 0.3.8 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.travis.yml +2 -1
  4. data/Gemfile +13 -13
  5. data/Gemfile.lock +84 -58
  6. data/README.md +40 -13
  7. data/features/check_proxy_pac.feature +31 -0
  8. data/features/compress_proxy_pac.feature +3 -16
  9. data/features/resolve_proxy.feature +1 -1
  10. data/lib/proxy_pac_rb/cli/compress_proxy_pac.rb +25 -11
  11. data/lib/proxy_pac_rb/cli/find_proxy.rb +13 -8
  12. data/lib/proxy_pac_rb/cli/lint.rb +11 -0
  13. data/lib/proxy_pac_rb/cli/lint_proxy_pac.rb +37 -0
  14. data/lib/proxy_pac_rb/cli/runner.rb +5 -0
  15. data/lib/proxy_pac_rb/cli/shared.rb +4 -0
  16. data/lib/proxy_pac_rb/cli_validator.rb +14 -0
  17. data/lib/proxy_pac_rb/errors.rb +19 -0
  18. data/lib/proxy_pac_rb/javascript.rb +19 -0
  19. data/lib/proxy_pac_rb/main.rb +22 -0
  20. data/lib/proxy_pac_rb/parser.rb +32 -21
  21. data/lib/proxy_pac_rb/proxy_pac.rb +10 -20
  22. data/lib/proxy_pac_rb/proxy_pac_compressor.rb +9 -0
  23. data/lib/proxy_pac_rb/proxy_pac_dumper.rb +65 -0
  24. data/lib/proxy_pac_rb/proxy_pac_file.rb +20 -3
  25. data/lib/proxy_pac_rb/proxy_pac_linter.rb +82 -0
  26. data/lib/proxy_pac_rb/proxy_pac_loader.rb +98 -0
  27. data/lib/proxy_pac_rb/proxy_pac_parser.rb +41 -0
  28. data/lib/proxy_pac_rb/rack/proxy_pac_compressor.rb +68 -0
  29. data/lib/proxy_pac_rb/rack/proxy_pac_linter.rb +66 -0
  30. data/lib/proxy_pac_rb/runtimes/rubyracer.rb +2 -2
  31. data/lib/proxy_pac_rb/runtimes/rubyrhino.rb +2 -2
  32. data/lib/proxy_pac_rb/runtimes.rb +3 -3
  33. data/lib/proxy_pac_rb/version.rb +1 -1
  34. data/lib/proxy_pac_rb.rb +10 -3
  35. data/proxy_pac_rb.gemspec +2 -0
  36. data/spec/api_spec.rb +207 -0
  37. data/spec/parser_spec.rb +66 -53
  38. data/spec/rack/proxy_pac_compressor_spec.rb +59 -0
  39. data/spec/rack/proxy_pac_linter_spec.rb +65 -0
  40. data/spec/spec_helper.rb +1 -0
  41. data/spec/support/matchers/file.rb +23 -0
  42. data/spec/support/rack_test.rb +1 -0
  43. data/spec/support/rspec.rb +3 -1
  44. data/spec/support/webmock.rb +1 -0
  45. metadata +30 -12
  46. data/features/support/fixtures.rb +0 -15
  47. data/lib/proxy_pac_rb/cli.rb +0 -75
  48. data/lib/proxy_pac_rb/file.rb +0 -21
  49. data/lib/proxy_pac_rb/javascript_compressor.rb +0 -9
  50. data/lib/proxy_pac_rb/proxy_pac_template +0 -39
  51. data/spec/file_spec.rb +0 -45
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+ require 'proxy_pac_rb/rack/proxy_pac_linter'
3
+
4
+ RSpec.describe ProxyPacRb::Rack::ProxyPacLinter, type: :rack_test do
5
+ let(:content) do
6
+ <<-EOS.strip_heredoc.chomp
7
+ function FindProxyForURL(url, host) {
8
+ return "DIRECT";
9
+ }
10
+ EOS
11
+ end
12
+
13
+ before(:each) { get '/' }
14
+ subject(:body) { last_response.body }
15
+
16
+ context 'when valid proxy pac is given' do
17
+ let(:app) do
18
+ a = Class.new(Sinatra::Base) do
19
+ before do
20
+ content_type 'application/x-ns-proxy-autoconfig'
21
+ end
22
+
23
+ get '/' do
24
+ <<-EOS.strip_heredoc.chomp
25
+ function FindProxyForURL(url, host) {
26
+ return "DIRECT";
27
+ }
28
+ EOS
29
+ end
30
+ end
31
+
32
+ a.use ProxyPacRb::Rack::ProxyPacLinter
33
+
34
+ a.new
35
+ end
36
+
37
+ it { expect(body).to include content }
38
+ end
39
+
40
+ context 'when invalid proxy pac is given' do
41
+ let(:content) { 'Unexpected string' }
42
+
43
+ let(:app) do
44
+ a = Class.new(Sinatra::Base) do
45
+ before do
46
+ content_type 'application/x-ns-proxy-autoconfig'
47
+ end
48
+
49
+ get '/' do
50
+ <<-EOS.strip_heredoc.chomp
51
+ function FindProxyForURL(url, host) {
52
+ return $"§$ "DIRECT";
53
+ }
54
+ EOS
55
+ end
56
+ end
57
+
58
+ a.use ProxyPacRb::Rack::ProxyPacLinter
59
+
60
+ a.new
61
+ end
62
+
63
+ it { expect(body).to include content }
64
+ end
65
+ end
data/spec/spec_helper.rb CHANGED
@@ -12,6 +12,7 @@ Bundler.require :default, :test, :development
12
12
 
13
13
  # Loading support files
14
14
  Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require_relative f }
15
+ Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require_relative f }
15
16
 
16
17
  # Avoid writing "describe LocalPac::MyClass do [..]" but "describe MyClass do [..]"
17
18
  include ProxyPacRb
@@ -0,0 +1,23 @@
1
+ RSpec::Matchers.define :be_existing_file do |_|
2
+ match { |actual| File.file?(actual) }
3
+
4
+ failure_message do |actual|
5
+ format("expected that file \"%s\" exists", actual)
6
+ end
7
+
8
+ failure_message_when_negated do |actual|
9
+ format("expected that file \"%s\" does not exist", actual)
10
+ end
11
+ end
12
+
13
+ RSpec::Matchers.define :have_content do |expected|
14
+ match { |actual| File.read(actual).chomp == expected.chomp }
15
+
16
+ failure_message do |actual|
17
+ format("expected that file \"%s\" contains:\n%s", actual, expected)
18
+ end
19
+
20
+ failure_message_when_negated do |actual|
21
+ format("expected that file \"%s\" does not contain:\n%s", actual, expected)
22
+ end
23
+ end
@@ -0,0 +1 @@
1
+ require 'rack/test'
@@ -5,7 +5,7 @@ RSpec.configure do |config|
5
5
 
6
6
  config.default_formatter = 'doc' if config.files_to_run.one?
7
7
 
8
- config.profile_examples = 10
8
+ # config.profile_examples = 10
9
9
  config.order = :random
10
10
  Kernel.srand config.seed
11
11
 
@@ -17,4 +17,6 @@ RSpec.configure do |config|
17
17
  mocks.syntax = :expect
18
18
  mocks.verify_partial_doubles = true
19
19
  end
20
+
21
+ config.include Rack::Test::Methods, type: :rack_test
20
22
  end
@@ -0,0 +1 @@
1
+ require 'webmock/rspec'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxy_pac_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Günnewig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-02 00:00:00.000000000 Z
11
+ date: 2015-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -80,37 +80,45 @@ files:
80
80
  - cucumber.yml
81
81
  - doc/dependencies/dependencies.db
82
82
  - features/.keep
83
+ - features/check_proxy_pac.feature
83
84
  - features/compress_proxy_pac.feature
84
85
  - features/resolve_proxy.feature
85
86
  - features/step_definitions.rb
86
87
  - features/support/aruba.rb
87
88
  - features/support/env.rb
88
- - features/support/fixtures.rb
89
89
  - features/support/reporting.rb
90
90
  - files/sample.pac
91
91
  - files/sample2.pac
92
92
  - files/sample3.pac
93
93
  - lib/proxy_pac_rb.rb
94
- - lib/proxy_pac_rb/cli.rb
95
94
  - lib/proxy_pac_rb/cli/compress.rb
96
95
  - lib/proxy_pac_rb/cli/compress_proxy_pac.rb
97
96
  - lib/proxy_pac_rb/cli/find.rb
98
97
  - lib/proxy_pac_rb/cli/find_proxy.rb
98
+ - lib/proxy_pac_rb/cli/lint.rb
99
+ - lib/proxy_pac_rb/cli/lint_proxy_pac.rb
99
100
  - lib/proxy_pac_rb/cli/runner.rb
100
101
  - lib/proxy_pac_rb/cli/shared.rb
101
102
  - lib/proxy_pac_rb/cli/show.rb
102
103
  - lib/proxy_pac_rb/cli_validator.rb
103
104
  - lib/proxy_pac_rb/encoding.rb
104
105
  - lib/proxy_pac_rb/environment.rb
106
+ - lib/proxy_pac_rb/errors.rb
105
107
  - lib/proxy_pac_rb/exceptions.rb
106
- - lib/proxy_pac_rb/file.rb
107
- - lib/proxy_pac_rb/javascript_compressor.rb
108
+ - lib/proxy_pac_rb/javascript.rb
109
+ - lib/proxy_pac_rb/main.rb
108
110
  - lib/proxy_pac_rb/parser.rb
109
111
  - lib/proxy_pac_rb/proxy_pac.rb
112
+ - lib/proxy_pac_rb/proxy_pac_compressor.rb
113
+ - lib/proxy_pac_rb/proxy_pac_dumper.rb
110
114
  - lib/proxy_pac_rb/proxy_pac_file.rb
111
115
  - lib/proxy_pac_rb/proxy_pac_js.rb
112
- - lib/proxy_pac_rb/proxy_pac_template
116
+ - lib/proxy_pac_rb/proxy_pac_linter.rb
117
+ - lib/proxy_pac_rb/proxy_pac_loader.rb
118
+ - lib/proxy_pac_rb/proxy_pac_parser.rb
113
119
  - lib/proxy_pac_rb/proxy_pac_template.rb
120
+ - lib/proxy_pac_rb/rack/proxy_pac_compressor.rb
121
+ - lib/proxy_pac_rb/rack/proxy_pac_linter.rb
114
122
  - lib/proxy_pac_rb/runtime.rb
115
123
  - lib/proxy_pac_rb/runtimes.rb
116
124
  - lib/proxy_pac_rb/runtimes/rubyracer.rb
@@ -124,14 +132,19 @@ files:
124
132
  - script/release
125
133
  - script/test_web
126
134
  - script/unit_test
135
+ - spec/api_spec.rb
127
136
  - spec/environment_spec.rb
128
- - spec/file_spec.rb
129
137
  - spec/parser_spec.rb
138
+ - spec/rack/proxy_pac_compressor_spec.rb
139
+ - spec/rack/proxy_pac_linter_spec.rb
130
140
  - spec/spec_helper.rb
131
141
  - spec/support/aruba.rb
142
+ - spec/support/matchers/file.rb
143
+ - spec/support/rack_test.rb
132
144
  - spec/support/reporting.rb
133
145
  - spec/support/rspec.rb
134
146
  - spec/support/strip.rb
147
+ - spec/support/webmock.rb
135
148
  - tmp/functions.js
136
149
  - tmp/functions.rb
137
150
  - tmp/sample.pac
@@ -146,9 +159,9 @@ require_paths:
146
159
  - lib
147
160
  required_ruby_version: !ruby/object:Gem::Requirement
148
161
  requirements:
149
- - - ">="
162
+ - - "~>"
150
163
  - !ruby/object:Gem::Version
151
- version: '0'
164
+ version: '2.0'
152
165
  required_rubygems_version: !ruby/object:Gem::Requirement
153
166
  requirements:
154
167
  - - ">="
@@ -162,19 +175,24 @@ specification_version: 4
162
175
  summary: gem to parse proxy auto-config files.
163
176
  test_files:
164
177
  - features/.keep
178
+ - features/check_proxy_pac.feature
165
179
  - features/compress_proxy_pac.feature
166
180
  - features/resolve_proxy.feature
167
181
  - features/step_definitions.rb
168
182
  - features/support/aruba.rb
169
183
  - features/support/env.rb
170
- - features/support/fixtures.rb
171
184
  - features/support/reporting.rb
185
+ - spec/api_spec.rb
172
186
  - spec/environment_spec.rb
173
- - spec/file_spec.rb
174
187
  - spec/parser_spec.rb
188
+ - spec/rack/proxy_pac_compressor_spec.rb
189
+ - spec/rack/proxy_pac_linter_spec.rb
175
190
  - spec/spec_helper.rb
176
191
  - spec/support/aruba.rb
192
+ - spec/support/matchers/file.rb
193
+ - spec/support/rack_test.rb
177
194
  - spec/support/reporting.rb
178
195
  - spec/support/rspec.rb
179
196
  - spec/support/strip.rb
197
+ - spec/support/webmock.rb
180
198
  has_rdoc:
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
- module FeatureHelper
3
- # Helper for fixtures
4
- module Fixtures
5
- def fixtures_manager
6
- @fixtures_manager ||= FeduxOrgStdlib::FixturesManagement::FixturesManager.new
7
-
8
- @fixtures_manager.load_fixtures(File.expand_path('../../../fixtures', __FILE__))
9
-
10
- @fixtures_manager
11
- end
12
- end
13
- end
14
-
15
- World(FeatureHelper::Fixtures)
@@ -1,75 +0,0 @@
1
- # encoding: utf-8
2
- module ProxyPacRb
3
- # Command line interface
4
- class Cli
5
- attr_accessor :options
6
-
7
- def self.start(argv = ARGV)
8
- cli = new
9
- cli.parse(argv)
10
-
11
- CliValidator.new(cli.options).validate
12
-
13
- environment = ProxyPacRb::Environment.new(client_ip: cli.options.client_ip, time: cli.options.time)
14
- file = ProxyPacRb::Parser.new(environment).source(cli.options.proxy_pac_file)
15
-
16
- $stderr.printf("%30s: %-s\n", 'url', 'result')
17
- cli.options.urls.each do |u|
18
- begin
19
- $stderr.printf("%30s: %-s\n", u, file.find(u))
20
- rescue Exceptions::UrlInvalid
21
- $stderr.puts "You provide an invalid url \"#{u}\". Please use a correct one."
22
- end
23
- end
24
- end
25
-
26
- def initialize
27
- @options = OpenStruct.new
28
-
29
- @options.client_ip = IPAddr.new('127.0.0.1')
30
- @options.time = Time.now
31
- end
32
-
33
- def parse(argv)
34
- parser = OptionParser.new do |opts|
35
- opts.banner = 'Usage: pprb [options] url1 [url2..urln]'
36
-
37
- opts.on('-c', '--client-ip IP', 'Client ip address') do |i|
38
- options.client_ip = IPAddr.new(i)
39
- end
40
-
41
- opts.on('-t', '--time YYYY-MM-DD HH:MM:SS', 'Time to use during lookup url') do |t|
42
- options.time = Time.parse(t)
43
- end
44
-
45
- opts.on('-p', '--proxy-pac FILE|URL', 'Proxy.pac-file') do |f|
46
- uri = Addressable::URI.parse(f)
47
-
48
- uri.path = ::File.expand_path(uri.path) if uri.host.nil?
49
-
50
- ENV.delete 'HTTP_PROXY'
51
- ENV.delete 'HTTPS_PROXY'
52
- ENV.delete 'http_proxy'
53
- ENV.delete 'https_proxy'
54
-
55
- options.proxy_pac_file = open(uri, proxy: false).read
56
- end
57
-
58
- opts.on_tail('-h', '--help', 'Show this message') do
59
- $stderr.puts opts
60
- exit
61
- end
62
-
63
- opts.on_tail('--version', 'Show version') do
64
- $stderr.puts ProxyPacRb::VERSION
65
- exit
66
- end
67
- end
68
-
69
- $stderr.puts parser.help if argv.blank?
70
-
71
- parser.parse!(argv)
72
- options.urls = argv
73
- end
74
- end
75
- end
@@ -1,21 +0,0 @@
1
- module ProxyPacRb
2
- # Proxy pac file
3
- class File
4
- private
5
-
6
- attr_reader :javascript
7
-
8
- public
9
-
10
- def initialize(javascript)
11
- @javascript = javascript
12
- end
13
-
14
- def find(url)
15
- uri = Addressable::URI.heuristic_parse(url)
16
- fail Exceptions::UrlInvalid, 'url is missing host' unless uri.host
17
-
18
- javascript.call('FindProxyForURL', url, uri.host)
19
- end
20
- end
21
- end
@@ -1,9 +0,0 @@
1
- # encoding: utf-8
2
- module ProxyPacRb
3
- # Compress javascript files
4
- class JavascriptCompressor
5
- def compress(proxy_pac_template)
6
- proxy_pac_template.compressed_content = Uglifier.new.compile(proxy_pac_template.raw_content)
7
- end
8
- end
9
- end
@@ -1,39 +0,0 @@
1
- # encoding: utf-8
2
- module ProxyPacRb
3
- class ProxyPacTemplate
4
-
5
- private
6
-
7
- attr_reader :path
8
-
9
- public
10
-
11
- def initialize(path)
12
- @path = path
13
- end
14
-
15
- def path
16
- @path + '.in'
17
- end
18
-
19
- def content
20
- read_proxy_pac(path)
21
- end
22
-
23
- private
24
-
25
- def read_proxy_pac(path)
26
- uri = Addressable::URI.parse(path)
27
-
28
- uri.path = ::File.expand_path(uri.path) if uri.host.nil?
29
-
30
- ENV.delete 'HTTP_PROXY'
31
- ENV.delete 'HTTPS_PROXY'
32
- ENV.delete 'http_proxy'
33
- ENV.delete 'https_proxy'
34
-
35
- open(uri, proxy: false).read
36
- end
37
-
38
- end
39
- end
data/spec/file_spec.rb DELETED
@@ -1,45 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe File do
5
- let(:simple) do
6
- <<-EOS.strip_heredoc
7
- function FindProxyForURL(url, host) {
8
- return "DIRECT";
9
- }
10
- EOS
11
- end
12
-
13
- let(:client_ip_pac) do
14
- <<-EOS.strip_heredoc
15
- function FindProxyForURL(url, host) {
16
- if ( myIpAddress() == '127.0.0.2' ) {
17
- return "DIRECT";
18
- } else {
19
- return "PROXY localhost:8080";
20
- }
21
- }
22
- EOS
23
- end
24
-
25
- let(:time_pac) do
26
- <<-EOS.strip_heredoc
27
- function FindProxyForURL(url, host) {
28
- if ( timeRange(8, 18) ) {
29
- return "PROXY localhost:8080";
30
- } else {
31
- return "DIRECT";
32
- }
33
- }
34
- EOS
35
- end
36
-
37
- context '#find' do
38
- it 'returns result of proxy.pac' do
39
- javascript = double('javascript')
40
- expect(javascript).to receive(:call).with('FindProxyForURL', 'http://localhost', 'localhost')
41
-
42
- ProxyPacRb::File.new(javascript).find('http://localhost')
43
- end
44
- end
45
- end