proxy_pac_rb 0.3.4 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +0 -1
  3. data/.rubocop.yml +4 -0
  4. data/Gemfile +30 -19
  5. data/Gemfile.lock +220 -0
  6. data/README.md +3 -0
  7. data/Rakefile +49 -13
  8. data/bin/pprb +1 -116
  9. data/config/license_finder.yml +12 -0
  10. data/config/rubocop/exclude.yml +8 -0
  11. data/config/rubocop/include.yml +27 -0
  12. data/cucumber.yml +2 -0
  13. data/doc/dependencies/dependencies.db +0 -0
  14. data/features/resolve_proxy.feature +17 -0
  15. data/features/support/aruba.rb +13 -0
  16. data/features/support/env.rb +10 -1
  17. data/features/support/fixtures.rb +15 -0
  18. data/features/support/reporting.rb +2 -0
  19. data/lib/proxy_pac_rb/cli.rb +75 -0
  20. data/lib/proxy_pac_rb/cli_validator.rb +34 -0
  21. data/lib/proxy_pac_rb/encoding.rb +1 -1
  22. data/lib/proxy_pac_rb/environment.rb +10 -8
  23. data/lib/proxy_pac_rb/exceptions.rb +4 -4
  24. data/lib/proxy_pac_rb/file.rb +3 -3
  25. data/lib/proxy_pac_rb/parser.rb +11 -2
  26. data/lib/proxy_pac_rb/proxy_pac_js.rb +5 -5
  27. data/lib/proxy_pac_rb/runtime.rb +6 -5
  28. data/lib/proxy_pac_rb/runtimes/rubyracer.rb +42 -35
  29. data/lib/proxy_pac_rb/runtimes/rubyrhino.rb +27 -22
  30. data/lib/proxy_pac_rb/runtimes.rb +13 -15
  31. data/lib/proxy_pac_rb/version.rb +3 -2
  32. data/lib/proxy_pac_rb.rb +7 -3
  33. data/proxy_pac_rb.gemspec +1 -1
  34. data/script/ci +0 -4
  35. data/script/test_web +2 -1
  36. data/spec/environment_spec.rb +23 -23
  37. data/spec/file_spec.rb +5 -5
  38. data/spec/parser_spec.rb +16 -13
  39. data/spec/support/aruba.rb +50 -0
  40. data/spec/support/rspec.rb +18 -4
  41. data/spec/support/{string.rb → strip.rb} +0 -0
  42. data/tmp/script.rb +0 -2
  43. metadata +37 -29
  44. data/spec/support/environment.rb +0 -17
  45. data/spec/support/filesystem.rb +0 -20
data/lib/proxy_pac_rb.rb CHANGED
@@ -1,10 +1,12 @@
1
+ require 'active_support/core_ext/object/blank'
2
+ require 'active_support/core_ext/string/strip'
1
3
  require 'addressable/uri'
2
4
  require 'ipaddr'
5
+ require 'open-uri'
6
+ require 'optparse'
7
+ require 'ostruct'
3
8
  require 'resolv'
4
9
  require 'time'
5
- require 'open-uri'
6
- require 'active_support/core_ext/string/strip'
7
- require 'active_support/core_ext/object/blank'
8
10
 
9
11
  require 'proxy_pac_rb/version'
10
12
  require 'proxy_pac_rb/encoding'
@@ -17,3 +19,5 @@ require 'proxy_pac_rb/runtimes/rubyrhino'
17
19
  require 'proxy_pac_rb/runtimes'
18
20
  require 'proxy_pac_rb/parser'
19
21
  require 'proxy_pac_rb/proxy_pac_js'
22
+ require 'proxy_pac_rb/cli_validator'
23
+ require 'proxy_pac_rb/cli'
data/proxy_pac_rb.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Dennis Günnewig']
10
10
  spec.email = ['dg1@vrnetze.de']
11
11
  spec.homepage = 'https://github.com/dg-vrnetze/proxy_pac_rb'
12
- spec.summary = %q{gem to parse proxy auto-config files.}
12
+ spec.summary = 'gem to parse proxy auto-config files.'
13
13
  spec.description = <<-DESC
14
14
  This gem uses a JavaScript runtime to evaulate a proxy auto-config file the same way a browser does to determine what proxy (if
15
15
  any at all) should a program use to connect to a server. You must install on of the supported JavaScript runtimes:
data/script/ci CHANGED
@@ -1,7 +1,3 @@
1
1
  #!/bin/sh
2
2
 
3
- bundle exec script/test_web &
4
-
5
3
  bundle exec rake test:coveralls
6
-
7
- pkill -P $$
data/script/test_web CHANGED
@@ -5,9 +5,10 @@ Bundler.require :default, :test, :development
5
5
 
6
6
  require 'sinatra/base'
7
7
 
8
+ # Test server
8
9
  class Server < Sinatra::Base
9
10
  get '/:name' do
10
- root_directory = Pathname.new(File.expand_path('../../tmp/aruba', __FILE__))
11
+ root_directory = Pathname.new(File.expand_path('../../tmp/cucumber', __FILE__))
11
12
  File.read(File.join(root_directory, params[:name]))
12
13
  end
13
14
  end
@@ -6,66 +6,66 @@ describe ProxyPacRb::Environment do
6
6
  Environment.new(client_ip: '127.0.0.1', time: Time.now)
7
7
  end
8
8
 
9
- describe "#isResolvable()" do
10
- it "should return true for localhost" do
11
- expect(environment.isResolvable("localhost")).to be_true
9
+ describe '#isResolvable()' do
10
+ it 'should return true for localhost' do
11
+ expect(environment.isResolvable('localhost')).to be true
12
12
  end
13
13
 
14
- it "should return false for unexist.domain.localdomain" do
15
- expect(environment.isResolvable('unexist.domain.localdomain')).to be_false
14
+ it 'should return false for unexist.domain.localdomain' do
15
+ expect(environment.isResolvable('unexist.domain.localdomain')).to be false
16
16
  end
17
17
  end
18
18
 
19
19
  describe '#isPlainHostName' do
20
20
  it 'returns true for google' do
21
21
  result = environment.isPlainHostName('google')
22
- expect(result).to be_true
22
+ expect(result).to be true
23
23
  end
24
24
 
25
25
  it 'returns false for google.com' do
26
26
  result = environment.isPlainHostName('google.com')
27
- expect(result).to be_false
27
+ expect(result).to be false
28
28
  end
29
29
  end
30
30
 
31
31
  describe '#dnsDomainIs' do
32
32
  it 'returns true for maps.google.com' do
33
33
  result = environment.dnsDomainIs('maps.google.com', '.google.com')
34
- expect(result).to be_true
34
+ expect(result).to be true
35
35
  end
36
36
 
37
37
  it 'returns false for maps.ms.com' do
38
38
  result = environment.dnsDomainIs('maps.ms.com', '.google.com')
39
- expect(result).to be_false
39
+ expect(result).to be false
40
40
  end
41
41
  end
42
42
 
43
43
  describe '#localHostOrDomainIs' do
44
44
  it 'returns true for maps.google.com' do
45
45
  result = environment.localHostOrDomainIs('maps.google.com', 'maps.google.com')
46
- expect(result).to be_true
46
+ expect(result).to be true
47
47
  end
48
48
 
49
49
  it 'returns true for maps' do
50
50
  result = environment.localHostOrDomainIs('maps', 'maps.google.com')
51
- expect(result).to be_true
51
+ expect(result).to be true
52
52
  end
53
53
 
54
54
  it 'returns false for maps.ms.com' do
55
55
  result = environment.dnsDomainIs('maps.ms.com', '.google.com')
56
- expect(result).to be_false
56
+ expect(result).to be false
57
57
  end
58
58
  end
59
59
 
60
60
  describe '#isInNet' do
61
61
  it 'returns true for 127.0.0.1' do
62
62
  result = environment.isInNet('127.0.0.1', '127.0.0.0', '255.255.255.0')
63
- expect(result).to be_true
63
+ expect(result).to be true
64
64
  end
65
65
 
66
66
  it 'returns false for 10.0.0.1' do
67
67
  result = environment.isInNet('10.0.0.1', '127.0.0.0', '255.255.255.0')
68
- expect(result).to be_false
68
+ expect(result).to be false
69
69
  end
70
70
 
71
71
  it 'resolves host name' do
@@ -126,12 +126,12 @@ describe ProxyPacRb::Environment do
126
126
  describe '#shExpMatch' do
127
127
  it 'returns true for maps.google.com' do
128
128
  result = environment.shExpMatch('maps.google.com', '*.com')
129
- expect(result).to be_true
129
+ expect(result).to be true
130
130
  end
131
131
 
132
132
  it 'returns false for maps.ms.com' do
133
133
  result = environment.shExpMatch('maps.ms.com', '*.de')
134
- expect(result).to be_false
134
+ expect(result).to be false
135
135
  end
136
136
  end
137
137
 
@@ -150,13 +150,13 @@ describe ProxyPacRb::Environment do
150
150
  string = ''
151
151
  environment.prepare(string)
152
152
 
153
- %w[
154
- myIpAddress
155
- weekdayRange
156
- dateRange
157
- timeRange
158
- ].each { |f| expect(string).to include(f) }
159
-
153
+ %w(
154
+ myIpAddress
155
+ weekdayRange
156
+ dateRange
157
+ timeRange
158
+ ).each { |f| expect(string).to include(f) }
159
+
160
160
  end
161
161
  end
162
162
  end
data/spec/file_spec.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe File do
5
- let(:simple) do
5
+ let(:simple) do
6
6
  <<-EOS.strip_heredoc
7
7
  function FindProxyForURL(url, host) {
8
8
  return "DIRECT";
@@ -10,7 +10,7 @@ describe File do
10
10
  EOS
11
11
  end
12
12
 
13
- let(:client_ip_pac) do
13
+ let(:client_ip_pac) do
14
14
  <<-EOS.strip_heredoc
15
15
  function FindProxyForURL(url, host) {
16
16
  if ( myIpAddress() == '127.0.0.2' ) {
@@ -22,7 +22,7 @@ describe File do
22
22
  EOS
23
23
  end
24
24
 
25
- let(:time_pac) do
25
+ let(:time_pac) do
26
26
  <<-EOS.strip_heredoc
27
27
  function FindProxyForURL(url, host) {
28
28
  if ( timeRange(8, 18) ) {
@@ -37,9 +37,9 @@ describe File do
37
37
  context '#find' do
38
38
  it 'returns result of proxy.pac' do
39
39
  javascript = double('javascript')
40
- expect(javascript).to receive(:call).with("FindProxyForURL", "http://localhost", "localhost")
40
+ expect(javascript).to receive(:call).with('FindProxyForURL', 'http://localhost', 'localhost')
41
41
 
42
- ProxyPacRb::File.new(javascript).find("http://localhost")
42
+ ProxyPacRb::File.new(javascript).find('http://localhost')
43
43
  end
44
44
  end
45
45
  end
data/spec/parser_spec.rb CHANGED
@@ -2,30 +2,33 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe ProxyPacRb::Parser do
5
- let(:sample_pac) do
6
- create_file 'sample.pac', <<-EOS.strip_heredoc
5
+ before :each do
6
+ write_file 'sample.pac', <<-EOS.strip_heredoc
7
7
  function FindProxyForURL(url, host) {
8
8
  return "DIRECT";
9
9
  }
10
10
  EOS
11
11
  end
12
12
 
13
- context ".read" do
14
- it "should load a file from a path" do
13
+ let(:sample_pac) { absolute_path('sample.pac') }
14
+
15
+ context '.read' do
16
+ it 'should load a file from a path' do
15
17
  pac = ProxyPacRb::Parser.new.read(sample_pac)
16
18
  expect(pac).not_to be_nil
17
19
  end
18
20
  end
19
21
 
20
- context ".source" do
21
- let(:source) do <<-JS.strip_heredoc
22
+ context '.source' do
23
+ let(:source) do
24
+ <<-JS.strip_heredoc
22
25
  function FindProxyForURL(url, host) {
23
26
  return "DIRECT";
24
27
  }
25
28
  JS
26
29
  end
27
30
 
28
- it "should load source" do
31
+ it 'should load source' do
29
32
  pac = ProxyPacRb::Parser.new.source(source)
30
33
  expect(pac).not_to be_nil
31
34
  end
@@ -76,17 +79,17 @@ describe ProxyPacRb::Parser do
76
79
  string = <<-EOS
77
80
  function FindProxyForURL(url, host) {
78
81
  if (timeRange(8, 18)) {
79
- return "PROXY localhost:8080";
82
+ return "PROXY localhost:8080";
80
83
  } else {
81
84
  return "DIRECT";
82
85
  }
83
86
  }
84
87
  EOS
85
-
88
+
86
89
  environment = ProxyPacRb::Environment.new(time: Time.parse('2014-03-06 12:00'))
87
90
  file = ProxyPacRb::Parser.new(environment).source(string)
88
91
  expect(file.find('http://localhost')).to eq('PROXY localhost:8080')
89
-
92
+
90
93
  environment = ProxyPacRb::Environment.new(time: Time.parse('2014-03-08 6:00'))
91
94
  file = ProxyPacRb::Parser.new(environment).source(string)
92
95
  expect(file.find('http://localhost')).to eq('DIRECT')
@@ -96,17 +99,17 @@ describe ProxyPacRb::Parser do
96
99
  string = <<-EOS
97
100
  function FindProxyForURL(url, host) {
98
101
  if (dateRange("JUL", "SEP")) {
99
- return "PROXY localhost:8080";
102
+ return "PROXY localhost:8080";
100
103
  } else {
101
104
  return "DIRECT";
102
105
  }
103
106
  }
104
107
  EOS
105
-
108
+
106
109
  environment = ProxyPacRb::Environment.new(time: Time.parse('2014-07-06 12:00'))
107
110
  file = ProxyPacRb::Parser.new(environment).source(string)
108
111
  expect(file.find('http://localhost')).to eq('PROXY localhost:8080')
109
-
112
+
110
113
  environment = ProxyPacRb::Environment.new(time: Time.parse('2014-03-08 6:00'))
111
114
  file = ProxyPacRb::Parser.new(environment).source(string)
112
115
  expect(file.find('http://localhost')).to eq('DIRECT')
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+ require 'aruba/api'
3
+ require 'aruba/reporting'
4
+
5
+ # Spec Helpers
6
+ module SpecHelper
7
+ # Helpers for aruba
8
+ module Aruba
9
+ include ::Aruba::Api
10
+
11
+ def dirs
12
+ @dirs ||= %w(tmp rspec)
13
+ end
14
+
15
+ def absolute_path(*args)
16
+ in_current_dir { File.expand_path File.join(*args) }
17
+ end
18
+
19
+ def _create_file(*args)
20
+ super
21
+
22
+ self
23
+ end
24
+
25
+ def create_dir(*args)
26
+ super
27
+
28
+ self
29
+ end
30
+
31
+ def touch_file(file_name)
32
+ in_current_dir do
33
+ file_name = File.expand_path(file_name)
34
+ _mkdir(File.dirname(file_name))
35
+ FileUtils.touch file_name
36
+ end
37
+
38
+ self
39
+ end
40
+ end
41
+ end
42
+
43
+ RSpec.configure do |c|
44
+ c.include SpecHelper::Aruba
45
+
46
+ c.before :each do
47
+ clean_current_dir
48
+ restore_env
49
+ end
50
+ end
@@ -1,6 +1,20 @@
1
1
  # encoding: utf-8
2
- RSpec.configure do |c|
3
- c.filter_run_including :focus => true
4
- c.run_all_when_everything_filtered = true
5
- c.treat_symbols_as_metadata_keys_with_true_values = true
2
+ RSpec.configure do |config|
3
+ config.filter_run :focus
4
+ config.run_all_when_everything_filtered = true
5
+
6
+ config.default_formatter = 'doc' if config.files_to_run.one?
7
+
8
+ config.profile_examples = 10
9
+ config.order = :random
10
+ Kernel.srand config.seed
11
+
12
+ config.expect_with :rspec do |expectations|
13
+ expectations.syntax = :expect
14
+ end
15
+
16
+ config.mock_with :rspec do |mocks|
17
+ mocks.syntax = :expect
18
+ mocks.verify_partial_doubles = true
19
+ end
6
20
  end
File without changes
data/tmp/script.rb CHANGED
@@ -20,5 +20,3 @@ puts(file.find('http://localhost'))
20
20
  environment = ProxyPacRb::Environment.new(client_ip: '127.0.0.2')
21
21
  file = ProxyPacRb::Parser.new(environment).source(string)
22
22
  puts(file.find('http://localhost'))
23
-
24
-
metadata CHANGED
@@ -1,52 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxy_pac_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.6
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: 2014-04-11 00:00:00.000000000 Z
11
+ date: 2014-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: ! 'This gem uses a JavaScript runtime to evaulate a proxy auto-config
42
- file the same way a browser does to determine what proxy (if
43
-
44
- any at all) should a program use to connect to a server. You must install on of
45
- the supported JavaScript runtimes:
46
-
41
+ description: |
42
+ This gem uses a JavaScript runtime to evaulate a proxy auto-config file the same way a browser does to determine what proxy (if
43
+ any at all) should a program use to connect to a server. You must install on of the supported JavaScript runtimes:
47
44
  therubyracer, therubyrhino, johnson or mustang.
48
-
49
- '
50
45
  email:
51
46
  - dg1@vrnetze.de
52
47
  executables:
@@ -54,25 +49,37 @@ executables:
54
49
  extensions: []
55
50
  extra_rdoc_files: []
56
51
  files:
57
- - .gitignore
58
- - .rdebugrc
59
- - .rspec
60
- - .simplecov
61
- - .travis.yml
62
- - .yardopts
52
+ - ".gitignore"
53
+ - ".rdebugrc"
54
+ - ".rspec"
55
+ - ".rubocop.yml"
56
+ - ".simplecov"
57
+ - ".travis.yml"
58
+ - ".yardopts"
63
59
  - Gemfile
60
+ - Gemfile.lock
64
61
  - LICENSE.md
65
62
  - README.md
66
63
  - Rakefile
67
64
  - bin/pprb
65
+ - config/license_finder.yml
66
+ - config/rubocop/exclude.yml
67
+ - config/rubocop/include.yml
68
+ - cucumber.yml
69
+ - doc/dependencies/dependencies.db
68
70
  - features/.keep
69
71
  - features/resolve_proxy.feature
70
72
  - features/step_definitions.rb
73
+ - features/support/aruba.rb
71
74
  - features/support/env.rb
75
+ - features/support/fixtures.rb
76
+ - features/support/reporting.rb
72
77
  - files/sample.pac
73
78
  - files/sample2.pac
74
79
  - files/sample3.pac
75
80
  - lib/proxy_pac_rb.rb
81
+ - lib/proxy_pac_rb/cli.rb
82
+ - lib/proxy_pac_rb/cli_validator.rb
76
83
  - lib/proxy_pac_rb/encoding.rb
77
84
  - lib/proxy_pac_rb/environment.rb
78
85
  - lib/proxy_pac_rb/exceptions.rb
@@ -96,11 +103,10 @@ files:
96
103
  - spec/file_spec.rb
97
104
  - spec/parser_spec.rb
98
105
  - spec/spec_helper.rb
99
- - spec/support/environment.rb
100
- - spec/support/filesystem.rb
106
+ - spec/support/aruba.rb
101
107
  - spec/support/reporting.rb
102
108
  - spec/support/rspec.rb
103
- - spec/support/string.rb
109
+ - spec/support/strip.rb
104
110
  - tmp/functions.js
105
111
  - tmp/functions.rb
106
112
  - tmp/sample.pac
@@ -115,17 +121,17 @@ require_paths:
115
121
  - lib
116
122
  required_ruby_version: !ruby/object:Gem::Requirement
117
123
  requirements:
118
- - - ! '>='
124
+ - - ">="
119
125
  - !ruby/object:Gem::Version
120
126
  version: '0'
121
127
  required_rubygems_version: !ruby/object:Gem::Requirement
122
128
  requirements:
123
- - - ! '>='
129
+ - - ">="
124
130
  - !ruby/object:Gem::Version
125
131
  version: '0'
126
132
  requirements: []
127
133
  rubyforge_project:
128
- rubygems_version: 2.2.2
134
+ rubygems_version: 2.4.1
129
135
  signing_key:
130
136
  specification_version: 4
131
137
  summary: gem to parse proxy auto-config files.
@@ -133,14 +139,16 @@ test_files:
133
139
  - features/.keep
134
140
  - features/resolve_proxy.feature
135
141
  - features/step_definitions.rb
142
+ - features/support/aruba.rb
136
143
  - features/support/env.rb
144
+ - features/support/fixtures.rb
145
+ - features/support/reporting.rb
137
146
  - spec/environment_spec.rb
138
147
  - spec/file_spec.rb
139
148
  - spec/parser_spec.rb
140
149
  - spec/spec_helper.rb
141
- - spec/support/environment.rb
142
- - spec/support/filesystem.rb
150
+ - spec/support/aruba.rb
143
151
  - spec/support/reporting.rb
144
152
  - spec/support/rspec.rb
145
- - spec/support/string.rb
153
+ - spec/support/strip.rb
146
154
  has_rdoc: