proxy_pac_rb 0.3.6 → 0.3.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ff197d6ab742c5e43e2a6ca3b5d9ed6e482ef3d
4
- data.tar.gz: e25cecd2819edc2431a0011516cbf96a81204b50
3
+ metadata.gz: 7951ec8d15a5a0f666378a7a9f438a2aeb299b63
4
+ data.tar.gz: ba584acd74dbac98965d4fb0adc80909ec0358e8
5
5
  SHA512:
6
- metadata.gz: a4eec5297aef87e2bd79f5d9028210d42beb05171babd1fb0b970131397761d06963bdb323c88f15ac4a12fcedd12a876e585a3e57d70de7ca49d93bbd06df7a
7
- data.tar.gz: ef7aec25f1e9bdf60636b05b93a49c61fd5c8483ea7e2cc027c216189b20e6f3465b3d29b5eaeb13d94f95b87f0febdbb09b2ae212c81633237b2fabfe4f3cd3
6
+ metadata.gz: d7dde2bb7a4a6f00fdd07cf966320b4da7d502ec0c781c960e8c734030c97483850df044701bdbdd239672d9229b0217a58e42eab67c9444a2237f5b8ba806df
7
+ data.tar.gz: 150272872cd8ce67c6d6b31b660029d327ac9198348e3877dbad47bc1889ee933fce3dcefdcd95597b6a5a4c949b3ee57aaedbfdfa997620882360642e780c54
data/.rubocop.yml CHANGED
@@ -1,4 +1,39 @@
1
- inherit_from:
2
- - config/rubocop/include.yml
3
- - config/rubocop/exclude.yml
4
- - .rubocop_todo.yml
1
+ AllCops:
2
+ Exclude:
3
+ - 'tmp/**/*'
4
+
5
+ Metrics/AbcSize:
6
+ Max: 38
7
+
8
+ # Configuration parameters: AllowURI.
9
+ Metrics/LineLength:
10
+ Max: 225
11
+
12
+ # Configuration parameters: CountKeywordArgs.
13
+ Metrics/ParameterLists:
14
+ Max: 6
15
+
16
+ Metrics/BlockNesting:
17
+ Max: 4
18
+
19
+ # Configuration parameters: CountComments.
20
+ Metrics/ClassLength:
21
+ Max: 174
22
+
23
+ Metrics/CyclomaticComplexity:
24
+ Max: 7
25
+
26
+ # Configuration parameters: CountComments.
27
+ Metrics/MethodLength:
28
+ Max: 76
29
+
30
+ Metrics/PerceivedComplexity:
31
+ Max: 8
32
+
33
+ Style/RegexpLiteral:
34
+ MaxSlashes: 0
35
+
36
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
37
+ Style/MethodName:
38
+ Exclude:
39
+ - lib/proxy_pac_rb/environment.rb
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
+ env:
2
+ - CI=1
1
3
  language: ruby
2
4
  bundler_args: --without development
3
5
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.0
6
+ - 2.1.5
7
7
  script: script/ci
data/Gemfile CHANGED
@@ -3,16 +3,6 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in local_pac.gemspec
4
4
  gemspec
5
5
 
6
- group :test do
7
- gem 'rspec', require: false
8
- gem 'fuubar', require: false
9
- gem 'simplecov', require: false
10
- gem 'rubocop', require: false
11
- gem 'coveralls', require: false
12
- gem 'cucumber', require: false
13
- gem 'aruba', require: false
14
- end
15
-
16
6
  group :development, :test do
17
7
  if !ENV.key?('CI') && !ENV.key?('TRAVIS')
18
8
  gem 'pry'
@@ -28,13 +18,17 @@ group :development, :test do
28
18
  end
29
19
 
30
20
  gem 'activesupport', '~> 4.0.0', require: false
21
+ gem 'aruba', require: false
31
22
  gem 'awesome_print', require: 'ap'
32
23
  gem 'bundler', '~> 1.3', require: false
33
24
  gem 'command_exec', require: false
25
+ gem 'coveralls', require: false
26
+ gem 'cucumber', require: false
34
27
  gem 'erubis'
35
28
  gem 'fedux_org-stdlib', '~>0.7.25', require: false
36
29
  gem 'filegen'
37
30
  gem 'foreman', require: false
31
+ gem 'fuubar', require: false
38
32
  gem 'github-markup'
39
33
  gem 'inch', require: false
40
34
  gem 'launchy', require: false
@@ -42,6 +36,9 @@ group :development, :test do
42
36
  gem 'rack'
43
37
  gem 'rake', require: false
44
38
  gem 'redcarpet', require: false
39
+ gem 'rspec', require: false
40
+ gem 'rubocop', require: false
41
+ gem 'simplecov', require: false
45
42
  gem 'sinatra', require: 'sinatra/base'
46
43
  gem 'tmrb', require: false
47
44
  gem 'travis-lint', require: false
data/Gemfile.lock CHANGED
@@ -1,49 +1,50 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- proxy_pac_rb (0.3.5)
4
+ proxy_pac_rb (0.3.6)
5
5
  activesupport
6
6
  addressable
7
+ uglifier
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
- activesupport (4.0.9)
12
+ activesupport (4.0.13)
12
13
  i18n (~> 0.6, >= 0.6.9)
13
14
  minitest (~> 4.2)
14
15
  multi_json (~> 1.3)
15
16
  thread_safe (~> 0.1)
16
17
  tzinfo (~> 0.3.37)
17
18
  addressable (2.3.6)
18
- aruba (0.6.1)
19
+ aruba (0.6.2)
19
20
  childprocess (>= 0.3.6)
20
21
  cucumber (>= 1.1.1)
21
22
  rspec-expectations (>= 2.7.0)
22
23
  ast (2.0.0)
23
24
  astrolabe (1.3.0)
24
25
  parser (>= 2.2.0.pre.3, < 3.0)
25
- awesome_print (1.2.0)
26
+ awesome_print (1.6.1)
26
27
  blockenspiel (0.4.5)
27
28
  builder (3.2.2)
28
- byebug (3.4.0)
29
+ byebug (3.5.1)
29
30
  columnize (~> 0.8)
30
31
  debugger-linecache (~> 1.2)
31
32
  slop (~> 3.6)
32
- childprocess (0.5.3)
33
+ childprocess (0.5.5)
33
34
  ffi (~> 1.0, >= 1.0.11)
34
35
  coderay (1.1.0)
35
- columnize (0.8.9)
36
+ columnize (0.9.0)
36
37
  command_exec (0.2.0)
37
38
  activesupport
38
39
  smart_colored
39
40
  xml-simple
40
- coveralls (0.7.1)
41
- multi_json (~> 1.3)
42
- rest-client
43
- simplecov (>= 0.7)
44
- term-ansicolor
45
- thor
46
- cucumber (1.3.16)
41
+ coveralls (0.7.8)
42
+ multi_json (~> 1.10)
43
+ rest-client (~> 1.7)
44
+ simplecov (~> 0.9.1)
45
+ term-ansicolor (~> 1.3)
46
+ thor (~> 0.19.1)
47
+ cucumber (1.3.18)
47
48
  builder (>= 2.1.2)
48
49
  diff-lcs (>= 1.1.3)
49
50
  gherkin (~> 2.12)
@@ -52,39 +53,38 @@ GEM
52
53
  debugger-linecache (1.2.0)
53
54
  diff-lcs (1.2.5)
54
55
  docile (1.1.5)
55
- dotenv (0.11.1)
56
- dotenv-deployment (~> 0.0.2)
57
- dotenv-deployment (0.0.2)
56
+ dotenv (1.0.2)
58
57
  erubis (2.7.0)
59
- fedux_org-stdlib (0.7.25)
58
+ execjs (2.2.2)
59
+ fedux_org-stdlib (0.7.33)
60
60
  activesupport
61
- ffi (1.9.3)
61
+ ffi (1.9.6)
62
62
  filegen (0.4.3)
63
63
  activesupport
64
- foreman (0.75.0)
65
- dotenv (~> 0.11.1)
64
+ foreman (0.77.0)
65
+ dotenv (~> 1.0.2)
66
66
  thor (~> 0.19.1)
67
67
  fuubar (2.0.0)
68
68
  rspec (~> 3.0)
69
69
  ruby-progressbar (~> 1.4)
70
70
  gherkin (2.12.2)
71
71
  multi_json (~> 1.3)
72
- github-markup (1.2.1)
72
+ github-markup (1.3.1)
73
73
  posix-spawn (~> 0.3.8)
74
- httparty (0.13.1)
74
+ httparty (0.13.3)
75
75
  json (~> 1.8)
76
76
  multi_xml (>= 0.5.2)
77
- i18n (0.6.11)
78
- inch (0.4.10)
77
+ i18n (0.7.0)
78
+ inch (0.5.10)
79
79
  pry
80
80
  sparkr (>= 0.2.0)
81
81
  term-ansicolor
82
- yard (~> 0.8.7)
83
- json (1.8.1)
84
- launchy (2.4.2)
82
+ yard (~> 0.8.7.5)
83
+ json (1.8.2)
84
+ launchy (2.4.3)
85
85
  addressable (~> 2.3)
86
- libv8 (3.16.14.5)
87
- license_finder (1.1.1)
86
+ libv8 (3.16.14.7)
87
+ license_finder (1.2)
88
88
  bundler
89
89
  httparty
90
90
  sequel
@@ -92,33 +92,32 @@ GEM
92
92
  thor
93
93
  xml-simple
94
94
  method_source (0.8.2)
95
- mime-types (2.3)
95
+ mime-types (2.4.3)
96
96
  minitest (4.7.5)
97
97
  multi_json (1.10.1)
98
98
  multi_test (0.1.1)
99
99
  multi_xml (0.5.5)
100
- netrc (0.7.7)
101
- parser (2.2.0.pre.4)
100
+ netrc (0.10.2)
101
+ parser (2.2.0.2)
102
102
  ast (>= 1.1, < 3.0)
103
- slop (~> 3.4, >= 3.4.5)
104
103
  posix-spawn (0.3.9)
105
104
  powerpack (0.0.9)
106
105
  pry (0.10.1)
107
106
  coderay (~> 1.1.0)
108
107
  method_source (~> 0.8.1)
109
108
  slop (~> 3.4)
110
- pry-byebug (2.0.0)
109
+ pry-byebug (3.0.0)
111
110
  byebug (~> 3.4)
112
111
  pry (~> 0.10)
113
112
  pry-doc (0.6.0)
114
113
  pry (~> 0.9)
115
114
  yard (~> 0.8)
116
- rack (1.5.2)
115
+ rack (1.6.0)
117
116
  rack-protection (1.5.3)
118
117
  rack
119
118
  rainbow (2.0.0)
120
- rake (10.3.2)
121
- redcarpet (3.1.2)
119
+ rake (10.4.2)
120
+ redcarpet (3.2.2)
122
121
  ref (1.0.5)
123
122
  rest-client (1.7.2)
124
123
  mime-types (>= 1.16, < 3.0)
@@ -127,26 +126,26 @@ GEM
127
126
  rspec-core (~> 3.1.0)
128
127
  rspec-expectations (~> 3.1.0)
129
128
  rspec-mocks (~> 3.1.0)
130
- rspec-core (3.1.2)
129
+ rspec-core (3.1.7)
131
130
  rspec-support (~> 3.1.0)
132
- rspec-expectations (3.1.0)
131
+ rspec-expectations (3.1.2)
133
132
  diff-lcs (>= 1.2.0, < 2.0)
134
133
  rspec-support (~> 3.1.0)
135
- rspec-mocks (3.1.0)
134
+ rspec-mocks (3.1.3)
136
135
  rspec-support (~> 3.1.0)
137
- rspec-support (3.1.0)
138
- rubocop (0.26.0)
136
+ rspec-support (3.1.2)
137
+ rubocop (0.28.0)
139
138
  astrolabe (~> 1.3)
140
- parser (>= 2.2.0.pre.4, < 3.0)
139
+ parser (>= 2.2.0.pre.7, < 3.0)
141
140
  powerpack (~> 0.0.6)
142
141
  rainbow (>= 1.99.1, < 3.0)
143
142
  ruby-progressbar (~> 1.4)
144
- ruby-prof (0.15.1)
145
- ruby-progressbar (1.5.1)
146
- sequel (4.14.0)
147
- simplecov (0.9.0)
143
+ ruby-prof (0.15.3)
144
+ ruby-progressbar (1.7.1)
145
+ sequel (4.19.0)
146
+ simplecov (0.9.1)
148
147
  docile (~> 1.1.0)
149
- multi_json
148
+ multi_json (~> 1.0)
150
149
  simplecov-html (~> 0.8.0)
151
150
  simplecov-html (0.8.0)
152
151
  sinatra (1.4.5)
@@ -156,7 +155,7 @@ GEM
156
155
  slop (3.6.0)
157
156
  smart_colored (1.1.1)
158
157
  sparkr (0.4.1)
159
- sqlite3 (1.3.9)
158
+ sqlite3 (1.3.10)
160
159
  term-ansicolor (1.3.0)
161
160
  tins (~> 1.0)
162
161
  therubyracer (0.12.1)
@@ -168,16 +167,19 @@ GEM
168
167
  thor (0.19.1)
169
168
  thread_safe (0.3.4)
170
169
  tilt (1.4.1)
171
- tins (1.3.2)
170
+ tins (1.3.3)
172
171
  tmrb (1.2.7)
173
172
  thor
174
173
  travis-lint (2.0.0)
175
174
  json
176
- tzinfo (0.3.41)
175
+ tzinfo (0.3.43)
176
+ uglifier (2.7.0)
177
+ execjs (>= 0.3.0)
178
+ json (>= 1.8.0)
177
179
  versionomy (0.4.4)
178
180
  blockenspiel (>= 0.4.5)
179
181
  xml-simple (1.1.4)
180
- yard (0.8.7.4)
182
+ yard (0.8.7.6)
181
183
 
182
184
  PLATFORMS
183
185
  ruby
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Proxy Pac Rb
2
2
 
3
- [![Build Status](https://travis-ci.org/dg-vrnetze/proxy_pac_rb.png?branch=master)](https://travis-ci.org/dg-vrnetze/proxy_pac_rb)
4
- [![Code Climate](https://codeclimate.com/github/dg-vrnetze/proxy_pac_rb.png)](https://codeclimate.com/github/dg-vrnetze/proxy_pac_rb)
5
- [![Coverage Status](https://coveralls.io/repos/dg-vrnetze/proxy_pac_rb/badge.png?branch=master)](https://coveralls.io/r/dg-vrnetze/proxy_pac_rb?branch=master)
3
+ [![Build Status](https://travis-ci.org/dg-ratiodata/proxy_pac_rb.png?branch=master)](https://travis-ci.org/dg-ratiodata/proxy_pac_rb)
4
+ [![Code Climate](https://codeclimate.com/github/dg-ratiodata/proxy_pac_rb.png)](https://codeclimate.com/github/dg-ratiodata/proxy_pac_rb)
5
+ [![Coverage Status](https://coveralls.io/repos/dg-ratiodata/proxy_pac_rb/badge.png?branch=master)](https://coveralls.io/r/dg-ratiodata/proxy_pac_rb?branch=master)
6
6
  [![Gem Version](https://badge.fury.io/rb/proxy_pac_rb.png)](http://badge.fury.io/rb/proxy_pac_rb)
7
7
 
8
8
  `proxy_pac_rb` is a gem to parse [proxy auto-config](http://en.wikipedia.org/wiki/Proxy_auto-config) files.
@@ -41,6 +41,8 @@ After installing the `proxy_pac_rb` gem you must install a JavaScript runtime. C
41
41
 
42
42
  ### Command Line
43
43
 
44
+ #### Find proxy for url
45
+
44
46
  *Arguments*
45
47
 
46
48
  * `-p|--proxy-pac FILE`: Path to proxy pac file
@@ -55,7 +57,23 @@ After installing the `proxy_pac_rb` gem you must install a JavaScript runtime. C
55
57
  curl -L -o sample.pac https://github.com/dg-vrnetze/proxy_pac_rb/raw/master/files/sample.pac
56
58
 
57
59
  # Parse pac
58
- pprb -c 127.0.0.1 -t "2014-03-09 12:00:00" -p sample.pac https://github.com
60
+ pprb find proxy -c 127.0.0.1 -t "2014-03-09 12:00:00" -p sample.pac -u https://github.com
61
+
62
+ # => url: result
63
+ # => https://github.com: DIRECT
64
+ ```
65
+
66
+ #### Compress proxy.pac-file
67
+
68
+ You can compress a proxy.pac with `pprb` to reduce the amount of data
69
+ transferred to download the proxy.pac.
70
+
71
+ ```
72
+ # Download pac
73
+ curl -L -o sample.pac https://github.com/dg-vrnetze/proxy_pac_rb/raw/master/files/sample.pac
74
+
75
+ # Parse pac
76
+ pprb compress proxy_pac -p sample.pac
59
77
 
60
78
  # => url: result
61
79
  # => https://github.com: DIRECT
data/bin/pprb CHANGED
@@ -4,6 +4,6 @@ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
4
4
 
5
5
  require 'proxy_pac_rb'
6
6
 
7
- ProxyPacRb::Cli.start
7
+ ProxyPacRb::Cli::Runner.start
8
8
 
9
9
  exit 0
Binary file
@@ -0,0 +1,91 @@
1
+ Feature: Compress proxy pac
2
+
3
+ As a proxy administrator
4
+ I want to compress a proxy pac
5
+ In order to save some bandwidth
6
+
7
+ Scenario: Existing proxy.pac.in
8
+ Given a file named "proxy.pac.in" with:
9
+ """
10
+ function FindProxyForURL(url, host) {
11
+ return 'PROXY localhost:3128';
12
+ }
13
+ """
14
+ When I successfully run `pprb compress pac_file -p proxy.pac`
15
+ Then the file "proxy.pac" should contain:
16
+ """
17
+ function FindProxyForURL(){return"PROXY localhost:3128"}
18
+ """
19
+
20
+ Scenario: Existing proxy.pac
21
+ Given a file named "proxy.pac" with:
22
+ """
23
+ function FindProxyForURL(url, host) {
24
+ return 'PROXY localhost:3128';
25
+ }
26
+ """
27
+ When I successfully run `pprb compress pac_file -p proxy.pac`
28
+ Then the file "proxy.pac.out" should contain:
29
+ """
30
+ function FindProxyForURL(){return"PROXY localhost:3128"}
31
+ """
32
+
33
+ Scenario: Use proxy.pac.in as filename
34
+ Given a file named "proxy.pac.in" with:
35
+ """
36
+ function FindProxyForURL(url, host) {
37
+ return 'PROXY localhost:3128';
38
+ }
39
+ """
40
+ When I successfully run `pprb compress pac_file -p proxy.pac.in`
41
+ Then the file "proxy.pac" should contain:
42
+ """
43
+ function FindProxyForURL(){return"PROXY localhost:3128"}
44
+ """
45
+
46
+ Scenario: Checks for valid proxy pac
47
+ Given a file named "proxy.pac.in" with:
48
+ """
49
+ $"§$"
50
+ function FindProxyForURL(url, host) {
51
+ return 'PROXY localhost:3128';
52
+ }
53
+ """
54
+ When I run `pprb compress pac_file -p proxy.pac.in`
55
+ Then the output should contain:
56
+ """
57
+ Proxy.pac-file "proxy.pac.in" is invalid. I ignore that file
58
+ """
59
+
60
+ Scenario: Use multiple proxy.pac.in
61
+ Given a file named "proxy1.pac.in" with:
62
+ """
63
+ function FindProxyForURL(url, host) {
64
+ return 'PROXY localhost:3128';
65
+ }
66
+ """
67
+ And a file named "proxy2.pac.in" with:
68
+ """
69
+ function FindProxyForURL(url, host) {
70
+ return 'PROXY localhost:3128';
71
+ }
72
+ """
73
+ And a file named "proxy3.pac" with:
74
+ """
75
+ function FindProxyForURL(url, host) {
76
+ return 'PROXY localhost:3128';
77
+ }
78
+ """
79
+ When I successfully run `pprb compress pac_file -p proxy1.pac proxy2.pac proxy3.pac`
80
+ Then the file "proxy1.pac" should contain:
81
+ """
82
+ function FindProxyForURL(){return"PROXY localhost:3128"}
83
+ """
84
+ And the file "proxy2.pac" should contain:
85
+ """
86
+ function FindProxyForURL(){return"PROXY localhost:3128"}
87
+ """
88
+ And the file "proxy3.pac.out" should contain:
89
+ """
90
+ function FindProxyForURL(){return"PROXY localhost:3128"}
91
+ """
@@ -11,7 +11,18 @@ Feature: Resolve proxy
11
11
  return 'PROXY localhost:3128';
12
12
  }
13
13
  """
14
- When I successfully run `pprb -p proxy.pac www.example.org`
14
+ When I successfully run `pprb find proxy -p proxy.pac -u www.example.org`
15
+ Then the output should contain:
16
+ """
17
+ PROXY localhost:3128
18
+ """
19
+
20
+ Scenario: Existing proxy.pac with compressed content
21
+ Given a file named "proxy.pac" with:
22
+ """
23
+ function FindProxyForURL(){return"PROXY localhost:3128"}
24
+ """
25
+ When I successfully run `pprb find proxy -p proxy.pac -u www.example.org`
15
26
  Then the output should contain:
16
27
  """
17
28
  PROXY localhost:3128
@@ -24,7 +35,7 @@ Feature: Resolve proxy
24
35
  return 'PROXY localhost:3128';
25
36
  }
26
37
  """
27
- When I successfully run `pprb -p ./proxy.pac www.example.org`
38
+ When I successfully run `pprb find proxy -p ./proxy.pac -u www.example.org`
28
39
  Then the output should contain:
29
40
  """
30
41
  PROXY localhost:3128
@@ -37,14 +48,14 @@ Feature: Resolve proxy
37
48
  return 'PROXY localhost:3128';
38
49
  }
39
50
  """
40
- When I successfully run `pprb -p http://127.0.0.1:4567/proxy.pac www.example.org`
51
+ When I successfully run `pprb find proxy -p http://127.0.0.1:4567/proxy.pac -u www.example.org`
41
52
  Then the output should contain:
42
53
  """
43
54
  PROXY localhost:3128
44
55
  """
45
56
 
46
57
  Scenario: Non-Existing proxy.pac
47
- When I run `pprb -p proxy.pac www.example.org`
58
+ When I run `pprb find proxy -p proxy.pac -u www.example.org`
48
59
  Then the output should contain:
49
60
  """
50
61
  No such file or directory
@@ -57,10 +68,10 @@ Feature: Resolve proxy
57
68
  return 'PROXY localhost:3128';
58
69
  }
59
70
  """
60
- When I run `pprb -p proxy.pac`
71
+ When I run `pprb find proxy -p proxy.pac`
61
72
  Then the output should contain:
62
73
  """
63
- You need to provide at least one url
74
+ No value provided for required options '--urls'
64
75
  """
65
76
 
66
77
  Scenario: Missing proxy parameter
@@ -70,10 +81,10 @@ Feature: Resolve proxy
70
81
  return 'PROXY localhost:3128';
71
82
  }
72
83
  """
73
- When I run `pprb www.example.org`
84
+ When I run `pprb find proxy -u www.example.org`
74
85
  Then the output should contain:
75
86
  """
76
- You need to provide a proxy pac file
87
+ No value provided for required options '--proxy-pac'
77
88
  """
78
89
 
79
90
  Scenario: Use client ip
@@ -87,12 +98,12 @@ Feature: Resolve proxy
87
98
  }
88
99
  }
89
100
  """
90
- When I successfully run `pprb -p proxy.pac -c 10.0.0.1 www.example.org`
101
+ When I successfully run `pprb find proxy -p proxy.pac -c 10.0.0.1 -u www.example.org`
91
102
  Then the output should contain:
92
103
  """
93
104
  PROXY localhost:3128
94
105
  """
95
- When I successfully run `pprb -p proxy.pac -c 192.0.0.1 www.example.org`
106
+ When I successfully run `pprb find proxy -p proxy.pac -c 192.0.0.1 -u www.example.org`
96
107
  Then the output should contain:
97
108
  """
98
109
  DIRECT
@@ -109,12 +120,12 @@ Feature: Resolve proxy
109
120
  }
110
121
  }
111
122
  """
112
- When I successfully run `pprb -p proxy.pac -t 2014-04-09 www.example.org`
123
+ When I successfully run `pprb find proxy -p proxy.pac -t 2014-04-09 -u www.example.org`
113
124
  Then the output should contain:
114
125
  """
115
126
  PROXY localhost:3128
116
127
  """
117
- When I successfully run `pprb -p proxy.pac -t 2014-12-07 www.example.org`
128
+ When I successfully run `pprb find proxy -p proxy.pac -t 2014-12-07 -u www.example.org`
118
129
  Then the output should contain:
119
130
  """
120
131
  DIRECT
@@ -131,7 +142,7 @@ Feature: Resolve proxy
131
142
  }
132
143
  }
133
144
  """
134
- When I successfully run `pprb -p proxy.pac unexist.localhost.localdomain`
145
+ When I successfully run `pprb find proxy -p proxy.pac -u unexist.localhost.localdomain`
135
146
  Then the output should contain:
136
147
  """
137
148
  DIRECT
@@ -148,7 +159,7 @@ Feature: Resolve proxy
148
159
  isInNet(hostip, "127.0.0.1", "255.255.255.255")) return 'proxy.example.com';
149
160
  }
150
161
  """
151
- When I successfully run `pprb -p proxy.pac http://localhost`
162
+ When I successfully run `pprb find proxy -p proxy.pac -u http://localhost`
152
163
  Then the output should contain:
153
164
  """
154
165
  proxy.example.com
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ module ProxyPacRb
3
+ module Cli
4
+ # Compress things
5
+ class Compress < Thor
6
+ register(CompressProxyPac, 'proxy_pac', 'proxy_pac', 'Compress proxy pac')
7
+
8
+ default_command :proxy_pac
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ module ProxyPacRb
3
+ module Cli
4
+ # Find proxy for url
5
+ class CompressProxyPac < Thor::Group
6
+ include Shared
7
+
8
+ class_option :proxy_pac, type: :array, desc: 'Proxy.pac-file(s)', aliases: '-p', required: true
9
+
10
+ def set_variables
11
+ @proxy_pacs = options[:proxy_pac].map { |p| ProxyPacTemplate.new(p) }
12
+ @compressor = JavascriptCompressor.new
13
+ end
14
+
15
+ def test_proxy_pac
16
+ @proxy_pacs.each do |p|
17
+ begin
18
+ file = ProxyPacRb::Parser.new.source(p.raw_content)
19
+ file.find('http://example.org')
20
+ rescue V8::Error => e
21
+ $stderr.puts "Proxy.pac-file \"#{p.input_path}\" is invalid. I ignore that file: #{e.message}"
22
+ end
23
+ end
24
+ end
25
+
26
+ def compress_proxy_pac
27
+ @proxy_pacs.each do |p|
28
+ p.compress_me(@compressor)
29
+ p.write
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ module ProxyPacRb
3
+ module Cli
4
+ # Find things
5
+ class Find < Thor
6
+ register(FindProxy, 'proxy', 'find_proxy', 'Find proxy for URL(s)')
7
+
8
+ default_command :proxy
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+ module ProxyPacRb
3
+ module Cli
4
+ # Find proxy for url
5
+ class FindProxy < Thor::Group
6
+ include Shared
7
+
8
+ class_option :client_ip, default: '127.0.0.1', desc: 'Client IP-address', aliases: '-c'
9
+ class_option :time, default: Time.now.to_s, desc: 'Time to use during lookup url', aliases: '-t'
10
+ class_option :proxy_pac, desc: 'Proxy.pac-file', aliases: '-p', required: true
11
+ class_option :urls, type: :array, desc: 'URLs to check against proxy pac', aliases: '-u', required: true
12
+
13
+ def find_proxy
14
+ CliValidator.new(options).validate
15
+
16
+ client_ip = IPAddr.new(options[:client_ip])
17
+ time = Time.parse(options[:time])
18
+ proxy_pac = ProxyPacFile.new(options[:proxy_pac])
19
+ urls = options[:urls]
20
+
21
+ environment = ProxyPacRb::Environment.new(client_ip: client_ip, time: time)
22
+ file = ProxyPacRb::Parser.new(environment).source(proxy_pac.content)
23
+
24
+ $stderr.printf("%30s: %-s\n", 'url', 'result')
25
+ urls.each do |u|
26
+ begin
27
+ $stderr.printf("%30s: %-s\n", u, file.find(u))
28
+ rescue Exceptions::UrlInvalid
29
+ $stderr.puts "You provide an invalid url \"#{u}\". Please use a correct one."
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ module ProxyPacRb
3
+ # Commandline parsing
4
+ module Cli
5
+ # Run command
6
+ class Runner < Thor
7
+ map '-v' => :version
8
+ map '--version' => :version
9
+
10
+ desc 'find', 'Find something'
11
+ subcommand 'find', Find
12
+
13
+ desc 'compress', 'Compress something'
14
+ subcommand 'compress', Compress
15
+
16
+ desc 'show', 'Show something'
17
+ subcommand 'show', Show
18
+
19
+ desc 'version', 'version', hide: true
20
+ def version
21
+ invoke 'proxy_pac_rb:cli:show:version'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+ module ProxyPacRb
3
+ module Cli
4
+ # Shared methods for all cli commands
5
+ module Shared
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ module ProxyPacRb
3
+ module Cli
4
+ # Show things
5
+ class Show < Thor
6
+ desc 'version', 'Show version'
7
+ def version
8
+ $stderr.puts ProxyPacRb::VERSION
9
+ end
10
+
11
+ default_command :version
12
+ end
13
+ end
14
+ end
@@ -19,11 +19,11 @@ module ProxyPacRb
19
19
  private
20
20
 
21
21
  def empty_url?
22
- options.urls.blank?
22
+ options[:urls].blank?
23
23
  end
24
24
 
25
25
  def empty_pac_file?
26
- options.proxy_pac_file.blank?
26
+ options[:proxy_pac].blank?
27
27
  end
28
28
 
29
29
  def exit_with_message(msg)
@@ -0,0 +1,9 @@
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
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ module ProxyPacRb
3
+ # ProxyPac
4
+ class ProxyPac
5
+ private
6
+
7
+ attr_reader :path
8
+
9
+ public
10
+
11
+ def initialize(path)
12
+ @path = path
13
+ end
14
+
15
+ def content
16
+ fail
17
+ end
18
+
19
+ private
20
+
21
+ def read_proxy_pac(path)
22
+ uri = Addressable::URI.parse(path)
23
+
24
+ uri.path = ::File.expand_path(uri.path) if uri.host.nil?
25
+
26
+ ENV.delete 'HTTP_PROXY'
27
+ ENV.delete 'HTTPS_PROXY'
28
+ ENV.delete 'http_proxy'
29
+ ENV.delete 'https_proxy'
30
+
31
+ open(uri, proxy: false).read
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+ module ProxyPacRb
3
+ # Pac file not for parsing
4
+ class ProxyPacFile < ProxyPac
5
+ def content
6
+ read_proxy_pac(path)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,39 @@
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
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+ module ProxyPacRb
3
+ # Template for proxy pac
4
+ class ProxyPacTemplate
5
+ private
6
+
7
+ attr_reader :path, :compressed_content
8
+
9
+ public
10
+
11
+ attr_writer :compressed_content
12
+
13
+ def initialize(path)
14
+ @path = path
15
+ end
16
+
17
+ def write
18
+ ::File.write(output_path, compressed_content)
19
+ end
20
+
21
+ def compress_me(compressor)
22
+ compressor.compress(self)
23
+ end
24
+
25
+ def raw_content
26
+ read_proxy_pac(input_path)
27
+ end
28
+
29
+ def input_path
30
+ if ::File.exist?(path.gsub(/#{in_extension}*$/, '') + in_extension)
31
+ return path.gsub(/#{in_extension}*$/, '') + in_extension
32
+ elsif ::File.exist? path
33
+ return path
34
+ else
35
+ fail Errno::ENOENT, "Both paths \"#{path.gsub(/#{in_extension}*$/, '') + in_extension}\" and \"#{path}\" do not exist."
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def in_extension
42
+ '.in'
43
+ end
44
+
45
+ def out_extension
46
+ '.out'
47
+ end
48
+
49
+ def output_path
50
+ if ::File.exist?(path.gsub(/#{in_extension}*$/, '') + in_extension)
51
+ return path.gsub(/#{in_extension}*$/, '')
52
+ elsif ::File.exist? path
53
+ return path + out_extension
54
+ else
55
+ fail Errno::ENOENT, "Both paths \"#{path.gsub(/#{in_extension}*$/, '') + in_extension}\" and \"#{path}\" do not exist."
56
+ end
57
+ end
58
+
59
+ def read_proxy_pac(path)
60
+ uri = Addressable::URI.parse(path)
61
+
62
+ uri.path = ::File.expand_path(uri.path) if uri.host.nil?
63
+
64
+ ENV.delete 'HTTP_PROXY'
65
+ ENV.delete 'HTTPS_PROXY'
66
+ ENV.delete 'http_proxy'
67
+ ENV.delete 'https_proxy'
68
+
69
+ open(uri, proxy: false).read
70
+ end
71
+ end
72
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # ProxyPacRb
3
3
  module ProxyPacRb
4
- VERSION = '0.3.6'
4
+ VERSION = '0.3.7'
5
5
  end
data/lib/proxy_pac_rb.rb CHANGED
@@ -2,6 +2,8 @@ require 'active_support/core_ext/object/blank'
2
2
  require 'active_support/core_ext/string/strip'
3
3
  require 'addressable/uri'
4
4
  require 'ipaddr'
5
+ require 'thor'
6
+ require 'uglifier'
5
7
  require 'open-uri'
6
8
  require 'optparse'
7
9
  require 'ostruct'
@@ -19,5 +21,17 @@ require 'proxy_pac_rb/runtimes/rubyrhino'
19
21
  require 'proxy_pac_rb/runtimes'
20
22
  require 'proxy_pac_rb/parser'
21
23
  require 'proxy_pac_rb/proxy_pac_js'
24
+ require 'proxy_pac_rb/proxy_pac'
25
+ require 'proxy_pac_rb/proxy_pac_file'
26
+ require 'proxy_pac_rb/proxy_pac_template'
27
+ require 'proxy_pac_rb/javascript_compressor'
28
+
22
29
  require 'proxy_pac_rb/cli_validator'
23
- require 'proxy_pac_rb/cli'
30
+
31
+ require 'proxy_pac_rb/cli/shared'
32
+ require 'proxy_pac_rb/cli/find_proxy'
33
+ require 'proxy_pac_rb/cli/compress_proxy_pac'
34
+ require 'proxy_pac_rb/cli/compress'
35
+ require 'proxy_pac_rb/cli/show'
36
+ require 'proxy_pac_rb/cli/find'
37
+ require 'proxy_pac_rb/cli/runner'
data/proxy_pac_rb.gemspec CHANGED
@@ -25,4 +25,5 @@ DESC
25
25
 
26
26
  spec.add_runtime_dependency 'addressable'
27
27
  spec.add_runtime_dependency 'activesupport'
28
+ spec.add_runtime_dependency 'uglifier'
28
29
  end
@@ -156,7 +156,6 @@ describe ProxyPacRb::Environment do
156
156
  dateRange
157
157
  timeRange
158
158
  ).each { |f| expect(string).to include(f) }
159
-
160
159
  end
161
160
  end
162
161
  end
data/spec/parser_spec.rb CHANGED
@@ -114,6 +114,5 @@ describe ProxyPacRb::Parser do
114
114
  file = ProxyPacRb::Parser.new(environment).source(string)
115
115
  expect(file.find('http://localhost')).to eq('DIRECT')
116
116
  end
117
-
118
117
  end
119
118
  end
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.6
4
+ version: 0.3.7
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-09-10 00:00:00.000000000 Z
11
+ date: 2015-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: uglifier
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: |
42
56
  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
57
  any at all) should a program use to connect to a server. You must install on of the supported JavaScript runtimes:
@@ -63,11 +77,10 @@ files:
63
77
  - Rakefile
64
78
  - bin/pprb
65
79
  - config/license_finder.yml
66
- - config/rubocop/exclude.yml
67
- - config/rubocop/include.yml
68
80
  - cucumber.yml
69
81
  - doc/dependencies/dependencies.db
70
82
  - features/.keep
83
+ - features/compress_proxy_pac.feature
71
84
  - features/resolve_proxy.feature
72
85
  - features/step_definitions.rb
73
86
  - features/support/aruba.rb
@@ -79,13 +92,25 @@ files:
79
92
  - files/sample3.pac
80
93
  - lib/proxy_pac_rb.rb
81
94
  - lib/proxy_pac_rb/cli.rb
95
+ - lib/proxy_pac_rb/cli/compress.rb
96
+ - lib/proxy_pac_rb/cli/compress_proxy_pac.rb
97
+ - lib/proxy_pac_rb/cli/find.rb
98
+ - lib/proxy_pac_rb/cli/find_proxy.rb
99
+ - lib/proxy_pac_rb/cli/runner.rb
100
+ - lib/proxy_pac_rb/cli/shared.rb
101
+ - lib/proxy_pac_rb/cli/show.rb
82
102
  - lib/proxy_pac_rb/cli_validator.rb
83
103
  - lib/proxy_pac_rb/encoding.rb
84
104
  - lib/proxy_pac_rb/environment.rb
85
105
  - lib/proxy_pac_rb/exceptions.rb
86
106
  - lib/proxy_pac_rb/file.rb
107
+ - lib/proxy_pac_rb/javascript_compressor.rb
87
108
  - lib/proxy_pac_rb/parser.rb
109
+ - lib/proxy_pac_rb/proxy_pac.rb
110
+ - lib/proxy_pac_rb/proxy_pac_file.rb
88
111
  - lib/proxy_pac_rb/proxy_pac_js.rb
112
+ - lib/proxy_pac_rb/proxy_pac_template
113
+ - lib/proxy_pac_rb/proxy_pac_template.rb
89
114
  - lib/proxy_pac_rb/runtime.rb
90
115
  - lib/proxy_pac_rb/runtimes.rb
91
116
  - lib/proxy_pac_rb/runtimes/rubyracer.rb
@@ -131,12 +156,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
156
  version: '0'
132
157
  requirements: []
133
158
  rubyforge_project:
134
- rubygems_version: 2.4.1
159
+ rubygems_version: 2.4.5
135
160
  signing_key:
136
161
  specification_version: 4
137
162
  summary: gem to parse proxy auto-config files.
138
163
  test_files:
139
164
  - features/.keep
165
+ - features/compress_proxy_pac.feature
140
166
  - features/resolve_proxy.feature
141
167
  - features/step_definitions.rb
142
168
  - features/support/aruba.rb
@@ -1,8 +0,0 @@
1
- AllCops:
2
- Exclude:
3
- - 'tmp/**/*'
4
-
5
- # Configuration parameters: EnforcedStyle, SupportedStyles.
6
- Style/MethodName:
7
- Exclude:
8
- - lib/proxy_pac_rb/environment.rb
@@ -1,27 +0,0 @@
1
- # Configuration parameters: AllowURI.
2
- Metrics/LineLength:
3
- Max: 225
4
-
5
- # Configuration parameters: CountKeywordArgs.
6
- Metrics/ParameterLists:
7
- Max: 6
8
-
9
- Metrics/BlockNesting:
10
- Max: 4
11
-
12
- # Configuration parameters: CountComments.
13
- Metrics/ClassLength:
14
- Max: 174
15
-
16
- Metrics/CyclomaticComplexity:
17
- Max: 7
18
-
19
- # Configuration parameters: CountComments.
20
- Metrics/MethodLength:
21
- Max: 76
22
-
23
- Metrics/PerceivedComplexity:
24
- Max: 8
25
-
26
- Style/RegexpLiteral:
27
- MaxSlashes: 0