proxy_pac_rb 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -3
- data/CONTRIBUTING.md +61 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +6 -14
- data/README.md +319 -14
- data/Rakefile +2 -96
- data/features/init_proxy_pac.feature +47 -0
- data/features/resolve_proxy.feature +1 -1
- data/features/step_definitions.rb +11 -0
- data/lib/proxy_pac_rb/cli/compress_proxy_pac.rb +1 -1
- data/lib/proxy_pac_rb/cli/find_proxy.rb +2 -0
- data/lib/proxy_pac_rb/cli/init.rb +10 -0
- data/lib/proxy_pac_rb/cli/init_proxy_pac.rb +98 -0
- data/lib/proxy_pac_rb/cli/lint.rb +0 -1
- data/lib/proxy_pac_rb/cli/lint_proxy_pac.rb +0 -1
- data/lib/proxy_pac_rb/cli/runner.rb +3 -0
- data/lib/proxy_pac_rb/environment.rb +13 -10
- data/lib/proxy_pac_rb/errors.rb +4 -0
- data/lib/proxy_pac_rb/javascript_compiler.rb +29 -0
- data/lib/proxy_pac_rb/main.rb +6 -0
- data/lib/proxy_pac_rb/parser.rb +2 -7
- data/lib/proxy_pac_rb/proxy_pac_file.rb +53 -5
- data/lib/proxy_pac_rb/proxy_pac_linter.rb +11 -5
- data/lib/proxy_pac_rb/proxy_pac_loader.rb +38 -5
- data/lib/proxy_pac_rb/proxy_pac_parser.rb +9 -21
- data/lib/proxy_pac_rb/rack/proxy_pac_compressor.rb +3 -3
- data/lib/proxy_pac_rb/rack/proxy_pac_linter.rb +3 -3
- data/lib/proxy_pac_rb/rspec/helpers/.keep +0 -0
- data/lib/proxy_pac_rb/rspec/helpers.rb +52 -0
- data/lib/proxy_pac_rb/rspec/matchers/.keep +0 -0
- data/lib/proxy_pac_rb/rspec/matchers/proxy.rb +23 -0
- data/lib/proxy_pac_rb/rspec/matchers/url.rb +13 -0
- data/lib/proxy_pac_rb/rspec/shared_contexts/.keep +0 -0
- data/lib/proxy_pac_rb/rspec/shared_examples/.keep +0 -0
- data/lib/proxy_pac_rb/rspec.rb +18 -0
- data/lib/proxy_pac_rb/version.rb +1 -1
- data/lib/proxy_pac_rb.rb +5 -1
- data/script/config.ru +8 -0
- data/spec/api/proxy_pac_compressor_spec.rb +31 -0
- data/spec/api/proxy_pac_dumper_spec.rb +67 -0
- data/spec/api/proxy_pac_file_spec.rb +90 -0
- data/spec/api/proxy_pac_linter_spec.rb +61 -0
- data/spec/api/proxy_pac_loader_spec.rb +88 -0
- data/spec/api/proxy_pac_parser_spec.rb +56 -0
- data/spec/environment_spec.rb +121 -78
- data/spec/parser_spec.rb +1 -1
- data/spec/rspec/compare_proxy_pac_files_spec.rb +62 -0
- data/spec/rspec/parse_proxy_pac_spec.rb +88 -0
- data/spec/rspec/readability_spec.rb +57 -0
- data/spec/rspec/rspec_spec.rb +7 -0
- data/spec/rspec/validitiy_spec.rb +48 -0
- data/spec/support/aruba.rb +0 -27
- data/spec/support/shared_examples/loader.rb +27 -0
- data/templates/build/middleman/config.rb +12 -0
- data/templates/build/middleman/script/build +2 -0
- data/templates/build/middleman/source/.keep +0 -0
- data/templates/default/.gitignore +24 -0
- data/templates/default/Gemfile +3 -0
- data/templates/default/Rakefile +1 -0
- data/templates/default/script/bootstrap +22 -0
- data/templates/new_proxy_pac.pac.erb +3 -0
- data/templates/test_framework/rspec/spec_helper.rb +9 -0
- data/templates/test_framework/rspec/support/aruba.rb +23 -0
- data/templates/test_framework/rspec/support/matchers/shared_contexts/.keep +0 -0
- data/templates/test_framework/rspec/support/proxy_pac_rb.rb +1 -0
- data/templates/test_framework/rspec/support/rspec.rb +20 -0
- data/templates/test_framework/rspec/support/shared_contexts/.keep +0 -0
- data/templates/test_framework/rspec/support/shared_examples/.keep +0 -0
- metadata +56 -6
- data/lib/proxy_pac_rb/proxy_pac.rb +0 -24
- data/script/test_web +0 -16
- data/spec/api_spec.rb +0 -207
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af8baea71f58817f9cdb5f272ee6c185562b178f
|
4
|
+
data.tar.gz: 7ead5006f6d5957b9fa9dd1c317d7668daec7e69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa68a759f58f146e000ed26a9778bccdac7dc31787ec1e101152dab623050ffc211bfb7342347b48ef51ec8b3a26b6dc40323d82811f27852f1e25f06ba2c633
|
7
|
+
data.tar.gz: fc862d9c7899ad8d9bf4c756895df016f3a16990e71d99a758fc5df1b20d15496b3bb036b7fd03859818f5f26b2153e4b494e6f66c4d0f63588a3921bf7426c3
|
data/.rubocop.yml
CHANGED
@@ -14,6 +14,9 @@ Metrics/LineLength:
|
|
14
14
|
Metrics/ParameterLists:
|
15
15
|
Max: 6
|
16
16
|
|
17
|
+
Style/CaseEquality:
|
18
|
+
Enabled: false
|
19
|
+
|
17
20
|
Metrics/BlockNesting:
|
18
21
|
Max: 4
|
19
22
|
|
@@ -31,9 +34,6 @@ Metrics/MethodLength:
|
|
31
34
|
Metrics/PerceivedComplexity:
|
32
35
|
Max: 8
|
33
36
|
|
34
|
-
Style/RegexpLiteral:
|
35
|
-
MaxSlashes: 0
|
36
|
-
|
37
37
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
38
38
|
Style/MethodName:
|
39
39
|
Exclude:
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
In the spirit of [free software][free-sw], **everyone** is encouraged to help
|
4
|
+
improve this project.
|
5
|
+
|
6
|
+
[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
|
7
|
+
|
8
|
+
Here are some ways *you* can contribute:
|
9
|
+
|
10
|
+
* by using alpha, beta, and prerelease versions
|
11
|
+
* by reporting bugs
|
12
|
+
* by suggesting new features
|
13
|
+
* by writing or editing documentation
|
14
|
+
* by writing specifications
|
15
|
+
* by writing code ( **no patch is too small** : fix typos, add comments, clean up inconsistent whitespace )
|
16
|
+
* by refactoring code
|
17
|
+
* by closing [issues][]
|
18
|
+
* by reviewing patches
|
19
|
+
|
20
|
+
[issues]: https://github.com/fedux-org/proxy_pac_rb/issues
|
21
|
+
|
22
|
+
## Submitting an Issue
|
23
|
+
|
24
|
+
We use the [GitHub issue tracker][issues] to track bugs and features. Before
|
25
|
+
submitting a bug report or feature request, check to make sure it hasn't
|
26
|
+
already been submitted.
|
27
|
+
|
28
|
+
When submitting a bug report, please include a [Gist][] that includes a *stack
|
29
|
+
trace* and any details that may be necessary to reproduce the bug, including
|
30
|
+
your *gem version*, *Ruby version*, and *operating system*. Ideally, a bug report
|
31
|
+
should include a pull request with failing specs.
|
32
|
+
|
33
|
+
[gist]: https://gist.github.com/
|
34
|
+
|
35
|
+
## Submitting a Pull Request
|
36
|
+
|
37
|
+
1. [Fork the repository.][fork]
|
38
|
+
2. Create a topic [branch]. `git checkout -b local_topic_branch`
|
39
|
+
3. Add specs for your unimplemented feature or bug fix.
|
40
|
+
4. Run `bundle exec rake test`. If your specs pass, return to step 3.
|
41
|
+
5. Implement your feature or bug fix.
|
42
|
+
6. Run `bundle exec rake test`. If your specs fail, return to step 5.
|
43
|
+
7. Add, commit, and push your changes. To push your topic branch use `git push -u origin local_topic_branch`.
|
44
|
+
8. [Submit a pull request.][pr]
|
45
|
+
|
46
|
+
Here are some reasons why a pull request may not be merged:
|
47
|
+
|
48
|
+
1. It hasn’t been reviewed.
|
49
|
+
2. It doesn’t include specs for new functionality.
|
50
|
+
3. It doesn’t include documentation for new functionality.
|
51
|
+
4. It changes behavior without changing the relevant documentation, comments, or specs.
|
52
|
+
5. It changes behavior of an existing public API, breaking backward compatibility.
|
53
|
+
6. It breaks the tests on a supported platform.
|
54
|
+
7. It doesn’t merge cleanly (requiring Git rebasing and conflict resolution).
|
55
|
+
|
56
|
+
Include this emoji in the top of your ticket to signal to us that you read this
|
57
|
+
file: :memo:
|
58
|
+
|
59
|
+
[fork]: http://help.github.com/fork-a-repo/
|
60
|
+
[branch]: https://help.github.com/articles/fork-a-repo#create-branches
|
61
|
+
[pr]: http://help.github.com/send-pull-requests/
|
data/Gemfile
CHANGED
@@ -9,8 +9,8 @@ group :debug do
|
|
9
9
|
|
10
10
|
gem 'pry-doc', require: false
|
11
11
|
gem 'pry-stack_explorer', require: false
|
12
|
-
gem 'pry-exception_explorer', require: false
|
13
|
-
gem 'pry-rescue', require: false
|
12
|
+
# gem 'pry-exception_explorer', require: false
|
13
|
+
# gem 'pry-rescue', require: false
|
14
14
|
gem 'pry-byebug', require: false
|
15
15
|
end
|
16
16
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
proxy_pac_rb (0.4.
|
4
|
+
proxy_pac_rb (0.4.2)
|
5
5
|
activesupport
|
6
6
|
addressable
|
7
7
|
uglifier
|
@@ -28,7 +28,7 @@ GEM
|
|
28
28
|
debug_inspector (>= 0.0.1)
|
29
29
|
blockenspiel (0.4.5)
|
30
30
|
builder (3.2.2)
|
31
|
-
byebug (4.0.
|
31
|
+
byebug (4.0.5)
|
32
32
|
columnize (= 0.9.0)
|
33
33
|
childprocess (0.5.5)
|
34
34
|
ffi (~> 1.0, >= 1.0.11)
|
@@ -38,7 +38,7 @@ GEM
|
|
38
38
|
activesupport
|
39
39
|
smart_colored
|
40
40
|
xml-simple
|
41
|
-
coveralls (0.
|
41
|
+
coveralls (0.8.0)
|
42
42
|
multi_json (~> 1.10)
|
43
43
|
rest-client (>= 1.6.8, < 2)
|
44
44
|
simplecov (~> 0.9.1)
|
@@ -61,7 +61,7 @@ GEM
|
|
61
61
|
domain_name (0.5.23)
|
62
62
|
unf (>= 0.0.5, < 1.0.0)
|
63
63
|
erubis (2.7.0)
|
64
|
-
execjs (2.
|
64
|
+
execjs (2.5.0)
|
65
65
|
fedux_org-stdlib (0.7.33)
|
66
66
|
activesupport
|
67
67
|
ffi (1.9.8)
|
@@ -86,7 +86,6 @@ GEM
|
|
86
86
|
sparkr (>= 0.2.0)
|
87
87
|
term-ansicolor
|
88
88
|
yard (~> 0.8.7.5)
|
89
|
-
interception (0.5)
|
90
89
|
json (1.8.2)
|
91
90
|
launchy (2.4.3)
|
92
91
|
addressable (~> 2.3)
|
@@ -116,11 +115,6 @@ GEM
|
|
116
115
|
pry-doc (0.6.0)
|
117
116
|
pry (~> 0.9)
|
118
117
|
yard (~> 0.8)
|
119
|
-
pry-exception_explorer (0.2.3)
|
120
|
-
pry-stack_explorer (>= 0.4.6)
|
121
|
-
pry-rescue (1.4.1)
|
122
|
-
interception (>= 0.5)
|
123
|
-
pry
|
124
118
|
pry-stack_explorer (0.4.9.2)
|
125
119
|
binding_of_caller (>= 0.7)
|
126
120
|
pry (>= 0.9.11)
|
@@ -150,7 +144,7 @@ GEM
|
|
150
144
|
diff-lcs (>= 1.2.0, < 2.0)
|
151
145
|
rspec-support (~> 3.2.0)
|
152
146
|
rspec-support (3.2.2)
|
153
|
-
rubocop (0.
|
147
|
+
rubocop (0.30.0)
|
154
148
|
astrolabe (~> 1.3)
|
155
149
|
parser (>= 2.2.0.1, < 3.0)
|
156
150
|
powerpack (~> 0.1)
|
@@ -196,7 +190,7 @@ GEM
|
|
196
190
|
unf_ext (0.0.6)
|
197
191
|
versionomy (0.4.4)
|
198
192
|
blockenspiel (>= 0.4.5)
|
199
|
-
webmock (1.
|
193
|
+
webmock (1.21.0)
|
200
194
|
addressable (>= 2.3.6)
|
201
195
|
crack (>= 0.3.2)
|
202
196
|
xml-simple (1.1.5)
|
@@ -227,8 +221,6 @@ DEPENDENCIES
|
|
227
221
|
pry
|
228
222
|
pry-byebug
|
229
223
|
pry-doc
|
230
|
-
pry-exception_explorer
|
231
|
-
pry-rescue
|
232
224
|
pry-stack_explorer
|
233
225
|
rack
|
234
226
|
rack-test
|
data/README.md
CHANGED
@@ -70,7 +70,7 @@ pprb find proxy -c 127.0.0.1 -t "2014-03-09 12:00:00" -p sample.pac -u https://g
|
|
70
70
|
You can compress a proxy.pac with `pprb` to reduce the amount of data
|
71
71
|
transferred to download the proxy.pac.
|
72
72
|
|
73
|
-
```
|
73
|
+
```bash
|
74
74
|
# Download pac
|
75
75
|
curl -L -o sample.pac https://github.com/fedux-org/proxy_pac_rb/raw/master/files/sample.pac
|
76
76
|
|
@@ -82,7 +82,7 @@ pprb compress proxy_pac -p sample.pac
|
|
82
82
|
|
83
83
|
You can lint a proxy.pac with `pprb` to check a proxy.pac before deploying it.
|
84
84
|
|
85
|
-
```
|
85
|
+
```bash
|
86
86
|
# Download pac
|
87
87
|
curl -L -o sample.pac https://github.com/fedux-org/proxy_pac_rb/raw/master/files/sample.pac
|
88
88
|
|
@@ -90,10 +90,46 @@ curl -L -o sample.pac https://github.com/fedux-org/proxy_pac_rb/raw/master/files
|
|
90
90
|
pprb lint proxy_pac -p sample.pac
|
91
91
|
```
|
92
92
|
|
93
|
-
|
93
|
+
#### Init new proxy.pac
|
94
|
+
|
95
|
+
You can use the following command to start a new proxy.pac:
|
96
|
+
|
97
|
+
*Plain*
|
98
|
+
|
99
|
+
```bash
|
100
|
+
pprb init proxy_pac
|
101
|
+
```
|
102
|
+
|
103
|
+
*Add rspec*
|
104
|
+
|
105
|
+
To test your proxy.pac you can use `rspec`.
|
106
|
+
|
107
|
+
```bash
|
108
|
+
pprb init proxy_pac --test rspec
|
94
109
|
```
|
95
110
|
|
96
|
-
*
|
111
|
+
*Add middleman*
|
112
|
+
|
113
|
+
To build your proxy.pac you can use `middleman`.
|
114
|
+
|
115
|
+
```bash
|
116
|
+
pprb init proxy_pac --build middleman
|
117
|
+
```
|
118
|
+
|
119
|
+
### "rack"-middleware
|
120
|
+
|
121
|
+
The middleware which comes with `proxy_pac_rb` is compliant with the
|
122
|
+
`rack`-specification - tested via
|
123
|
+
[`rack/lint`](https://github.com/rack/rack/blob/master/lib/rack/lint.rb) and
|
124
|
+
should work with every `rack`-compliant-server.
|
125
|
+
|
126
|
+
#### Prerequisites
|
127
|
+
|
128
|
+
Make sure the content is served with `"Content-Type":
|
129
|
+
'application/x-ns-proxy-autoconfig'`. Otherwise the content is ignored by both
|
130
|
+
middlewares.
|
131
|
+
|
132
|
+
#### Warning
|
97
133
|
|
98
134
|
The linter-`rack`-middleware needs to be activated before ANY other
|
99
135
|
middleman-extension, `rack`-middleware or whatever framework you are using
|
@@ -122,18 +158,52 @@ Error
|
|
122
158
|
There were errors during this build
|
123
159
|
```
|
124
160
|
|
125
|
-
|
161
|
+
|
162
|
+
#### Linter Middleware
|
126
163
|
|
127
164
|
```ruby
|
128
165
|
require 'proxy_pac_rb/rack/proxy_pac_linter'
|
129
166
|
use ProxyPacRb::Rack::ProxyPacLinter
|
130
167
|
```
|
131
168
|
|
132
|
-
|
169
|
+
#### Compressor Middleware
|
133
170
|
|
134
171
|
```ruby
|
135
172
|
require 'proxy_pac_rb/rack/proxy_pac_compressor'
|
136
173
|
use ProxyPacRb::Rack::ProxyPacCompressor
|
174
|
+
```
|
175
|
+
|
176
|
+
#### Using "rack"-middleware with "middleman"
|
177
|
+
|
178
|
+
If you want to use the `rack`-middleware with `middleman` look at the following
|
179
|
+
code snippet captured from the `middleman`-configuration file `config.rb`:
|
180
|
+
|
181
|
+
* `config.rb`:
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
# Important needs to come first
|
185
|
+
# See Warning above for a full explanation
|
186
|
+
require 'proxy_pac_rb/rack/proxy_pac_linter'
|
187
|
+
use ProxyPacRb::Rack::ProxyPacLinter
|
188
|
+
|
189
|
+
require 'proxy_pac_rb/rack/proxy_pac_compressor'
|
190
|
+
use ProxyPacRb::Rack::ProxyPacCompressor
|
191
|
+
|
192
|
+
# The middleware works on content served with
|
193
|
+
# "Content-Type" 'application/x-ns-proxy-autoconfig'
|
194
|
+
page "*.pac", content_type: 'application/x-ns-proxy-autoconfig'
|
195
|
+
|
196
|
+
# This provides an uncompressed copy of the proxy.pac to make it
|
197
|
+
# possible for your support to review it by hand
|
198
|
+
Dir.glob(File.join(source_dir, '**', '*.pac')).each do |f|
|
199
|
+
# Path should be relative to source dir
|
200
|
+
relative_path = Pathname.new(f).relative_path_from(Pathname.new(source_dir))
|
201
|
+
|
202
|
+
# "text/plain" prevents the middlewares to handle it
|
203
|
+
proxy(format('%s.raw', relative_path), relative_path.to_s, content_type: 'text/plain')
|
204
|
+
end
|
205
|
+
|
206
|
+
```
|
137
207
|
|
138
208
|
### Ruby
|
139
209
|
|
@@ -142,7 +212,7 @@ use ProxyPacRb::Rack::ProxyPacCompressor
|
|
142
212
|
```ruby
|
143
213
|
require 'proxy_pac_rb'
|
144
214
|
|
145
|
-
file = ProxyPacRb::Parser.new.
|
215
|
+
file = ProxyPacRb::Parser.new.parse('https://github.com/fedux-org/proxy_pac_rb/raw/master/files/sample.pac')
|
146
216
|
file.find('https://github.com') # => "DIRECT"
|
147
217
|
```
|
148
218
|
|
@@ -155,7 +225,7 @@ curl -L -o sample.pac https://github.com/fedux-org/proxy_pac_rb/raw/master/files
|
|
155
225
|
```ruby
|
156
226
|
require 'proxy_pac_rb'
|
157
227
|
|
158
|
-
file = ProxyPacRb::Parser.new.
|
228
|
+
file = ProxyPacRb::Parser.new.parse("sample.pac")
|
159
229
|
file.find('https://github.com') # => "DIRECT"
|
160
230
|
```
|
161
231
|
|
@@ -164,7 +234,7 @@ file.find('https://github.com') # => "DIRECT"
|
|
164
234
|
```ruby
|
165
235
|
require 'proxy_pac_rb'
|
166
236
|
|
167
|
-
file = ProxyPacRb::Parser.new.
|
237
|
+
file = ProxyPacRb::Parser.new.parse <<-JS
|
168
238
|
function FindProxyForURL(url, host) {
|
169
239
|
return "DIRECT";
|
170
240
|
}
|
@@ -179,11 +249,11 @@ file.find('http://localhost') # => "DIRECT"
|
|
179
249
|
require 'proxy_pac_rb'
|
180
250
|
|
181
251
|
environment = ProxyPacRb::Environment.new(client_ip: '127.0.0.1')
|
182
|
-
file = ProxyPacRb::Parser.new(environment).
|
252
|
+
file = ProxyPacRb::Parser.new(environment).parse('https://github.com/fedux-org/proxy_pac_rb/raw/master/files/sample2.pac')
|
183
253
|
file.find('https://github.com') # => "PROXY localhost:8080"
|
184
254
|
|
185
255
|
environment = ProxyPacRb::Environment.new(client_ip: '127.0.0.2')
|
186
|
-
file = ProxyPacRb::Parser.new(environment).
|
256
|
+
file = ProxyPacRb::Parser.new(environment).parse('https://github.com/fedux-org/proxy_pac_rb/raw/master/files/sample2.pac')
|
187
257
|
file.find('https://github.com') # => "DIRECT"
|
188
258
|
```
|
189
259
|
|
@@ -203,11 +273,11 @@ function FindProxyForURL(url, host) {
|
|
203
273
|
EOS
|
204
274
|
|
205
275
|
environment = ProxyPacRb::Environment.new(time: Time.parse('2014-07-06 12:00'))
|
206
|
-
file = ProxyPacRb::Parser.new(environment).
|
276
|
+
file = ProxyPacRb::Parser.new(environment).parse(string)
|
207
277
|
file.find('http://localhost') # => 'PROXY localhost:8080'
|
208
278
|
|
209
279
|
environment = ProxyPacRb::Environment.new(time: Time.parse('2014-03-08 6:00'))
|
210
|
-
file = ProxyPacRb::Parser.new(environment).
|
280
|
+
file = ProxyPacRb::Parser.new(environment).parse(string)
|
211
281
|
file.find('http://localhost') # => 'DIRECT'
|
212
282
|
```
|
213
283
|
|
@@ -227,11 +297,246 @@ file.find('http://localhost') # => 'DIRECT'
|
|
227
297
|
* timeRange(*args)
|
228
298
|
* alert(msg) (output on stderr by default)
|
229
299
|
|
300
|
+
## RSpec-integration
|
301
|
+
|
302
|
+
`proxy_pac_rb` comes with helpers and matchers for `rspec`. To make those
|
303
|
+
helpers and matchers available in your project, add this code snippet in your
|
304
|
+
project:
|
305
|
+
|
306
|
+
```
|
307
|
+
require 'proxy_pac_rb/rspec'
|
308
|
+
```
|
309
|
+
|
310
|
+
### Helpers
|
311
|
+
|
312
|
+
* `proxy_pac`:
|
313
|
+
|
314
|
+
This helper makes a proxy.pac available. It requires a source for your
|
315
|
+
proxy.pac given in `subject { }` - e.g. a file, a string, or a url. It
|
316
|
+
represents a [`ProxyPacFile`](lib/proxy_pac_rb/proxy_pac_file.rb).
|
317
|
+
|
318
|
+
* `time`:
|
319
|
+
|
320
|
+
The `time`-helper makes `1970-01-01 00:00:00` as time available. Overwrite
|
321
|
+
this helper at will with another time string or a time-object - e.g
|
322
|
+
`let(:time) { Time.now }`.
|
323
|
+
|
324
|
+
* `client_ip`:
|
325
|
+
|
326
|
+
The `client_ip`-helper makes `127.0.0.1` available. Overwrite it with a
|
327
|
+
different ip-address as string or an object which returns an ip-address on
|
328
|
+
`#to_s`.
|
329
|
+
|
330
|
+
* `root_path`:
|
331
|
+
|
332
|
+
The `root_path`-helper is meant for overriding. It is used to find your
|
333
|
+
"proxy.pac"-files. By default its value is `Dir.getwd` which is set by
|
334
|
+
`rspec`.
|
335
|
+
|
336
|
+
### Examples
|
337
|
+
|
338
|
+
To make it easier for you to start, you find some examples below.
|
339
|
+
|
340
|
+
**Type for specs**
|
341
|
+
|
342
|
+
It is important that you flag your specs with `type: :proxy_pac`. Otherwise the
|
343
|
+
helpers are not included and not available in your examples.
|
344
|
+
|
345
|
+
```ruby
|
346
|
+
RSpec.describe 'proxy.pac', type: :proxy_pac do
|
347
|
+
```
|
348
|
+
|
349
|
+
**Supported sources**
|
350
|
+
|
351
|
+
*String*
|
352
|
+
|
353
|
+
```ruby
|
354
|
+
RSpec.describe 'String', type: :proxy_pac do
|
355
|
+
subject do
|
356
|
+
<<-EOS.strip_heredoc.chomp
|
357
|
+
function FindProxyForURL(url, host) {
|
358
|
+
return "DIRECT";
|
359
|
+
}
|
360
|
+
EOS
|
361
|
+
end
|
362
|
+
end
|
363
|
+
```
|
364
|
+
|
365
|
+
*Local File*
|
366
|
+
|
367
|
+
```ruby
|
368
|
+
RSpec.describe 'proxy.pac', type: :proxy_pac do
|
369
|
+
subject { 'proxy.pac' }
|
370
|
+
end
|
371
|
+
```
|
372
|
+
|
373
|
+
*URL*
|
374
|
+
|
375
|
+
```ruby
|
376
|
+
RSpec.describe 'http://server/proxy.pac', type: :proxy_pac do
|
377
|
+
subject { 'http://server/proxy.pac' }
|
378
|
+
end
|
379
|
+
```
|
380
|
+
|
381
|
+
**Matchers**
|
382
|
+
|
383
|
+
*Readable*
|
384
|
+
|
385
|
+
To check if a proxy.pac could be read from filesystem or downloaded via HTTP,
|
386
|
+
check `be_readable`.
|
387
|
+
|
388
|
+
```ruby
|
389
|
+
require 'proxy_pac_rb/rspec'
|
390
|
+
|
391
|
+
RSpec.describe 'proxy.pac', type: :proxy_pac do
|
392
|
+
context 'when proxy pac exist' do
|
393
|
+
context 'when is file' do
|
394
|
+
subject { 'proxy.pac' }
|
395
|
+
it { expect(proxy_pac).to be_readable }
|
396
|
+
end
|
397
|
+
|
398
|
+
context 'when is url' do
|
399
|
+
subject { 'http://www.example.com/proxy.pac' }
|
400
|
+
it { expect(proxy_pac).to be_readable }
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
```
|
405
|
+
|
406
|
+
*Equal*
|
407
|
+
|
408
|
+
If you want to check if a proxy.pac is the same you can use the
|
409
|
+
`be_the_same_proxy_pac_file`-matcher.
|
410
|
+
|
411
|
+
```ruby
|
412
|
+
require 'proxy_pac_rb/rspec'
|
413
|
+
|
414
|
+
RSpec.describe 'proxy.pac', type: :proxy_pac do
|
415
|
+
subject do
|
416
|
+
<<-EOS.strip_heredoc.chomp
|
417
|
+
function FindProxyForURL(url, host) {
|
418
|
+
return "DIRECT";
|
419
|
+
}
|
420
|
+
EOS
|
421
|
+
end
|
422
|
+
context 'Check equality of proxy pac' do
|
423
|
+
context 'when proxy.pac is eq' do
|
424
|
+
it { expect(proxy_pac).to be_the_same_proxy_pac_file 'proxy.pac' }
|
425
|
+
end
|
426
|
+
|
427
|
+
context 'when proxy.pac is not eq' do
|
428
|
+
it { expect(proxy_pac).not_to be_the_same_proxy_pac_file 'proxy.pac' }
|
429
|
+
end
|
430
|
+
end
|
431
|
+
end
|
432
|
+
```
|
433
|
+
|
434
|
+
This is quite handy to compare a local proxy.pac with a remote one - e.g. a
|
435
|
+
deployed one.
|
436
|
+
|
437
|
+
```ruby
|
438
|
+
require 'proxy_pac_rb/rspec'
|
439
|
+
|
440
|
+
RSpec.describe 'proxy.pac', type: :proxy_pac do
|
441
|
+
let(:local_proxy_pac) { ProxyPacRb::ProxyPacFile.new(source: file) }
|
442
|
+
|
443
|
+
before(:each) do
|
444
|
+
ProxyPacRb::ProxyPacLoader.new.load(local_proxy_pac)
|
445
|
+
ProxyPacRb::ProxyPacCompressor.new.compress(local_proxy_pac) if local_proxy_pac.readable?
|
446
|
+
end
|
447
|
+
|
448
|
+
context 'when no proxy.pac is given' do
|
449
|
+
subject { 'http://server.example.com/proxy.pac' }
|
450
|
+
let(:file) { 'source/proxy.pac' }
|
451
|
+
|
452
|
+
it { expect(proxy_pac).to be_the_same_proxy_pac_file(local_proxy_pac) }
|
453
|
+
end
|
454
|
+
end
|
455
|
+
```
|
456
|
+
|
457
|
+
*Valid*
|
458
|
+
|
459
|
+
You want to check if your proxy.pac is valid. This will find `reference errors`
|
460
|
+
(e.g. unknown variables) and `syntax errors`.
|
461
|
+
|
462
|
+
```ruby
|
463
|
+
require 'proxy_pac_rb/rspec'
|
464
|
+
|
465
|
+
RSpec.describe 'proxy.pac', type: :proxy_pac do
|
466
|
+
subject do
|
467
|
+
<<-EOS.strip_heredoc.chomp
|
468
|
+
function FindProxyForURL(url, host) {
|
469
|
+
return "DIRECT";
|
470
|
+
}
|
471
|
+
EOS
|
472
|
+
end
|
473
|
+
context 'Check validity of proxy pac' do
|
474
|
+
context 'when proxy.pac is valid' do
|
475
|
+
it { expect(proxy_pac).to be_valid }
|
476
|
+
end
|
477
|
+
|
478
|
+
context 'when proxy.pac is not valid' do
|
479
|
+
subject do
|
480
|
+
<<-EOS.strip_heredoc.chomp
|
481
|
+
function FindProxyForURL(url, host) {
|
482
|
+
return adsf;
|
483
|
+
}
|
484
|
+
EOS
|
485
|
+
end
|
486
|
+
it { expect(proxy_pac).not_to be_valid }
|
487
|
+
end
|
488
|
+
end
|
489
|
+
end
|
490
|
+
```
|
491
|
+
|
492
|
+
*Parse proxy.pac*
|
493
|
+
|
494
|
+
To make some logic checks use the `be_downloaded_via`-matcher. This will parse
|
495
|
+
the proxy.pac and returns the proxy to be used for a given url.
|
496
|
+
|
497
|
+
```ruby
|
498
|
+
require 'proxy_pac_rb/rspec'
|
499
|
+
RSpec.describe 'proxy.pac', type: :proxy_pac do
|
500
|
+
subject do
|
501
|
+
<<-EOS.strip_heredoc.chomp
|
502
|
+
function FindProxyForURL(url, host) {
|
503
|
+
if (dnsDomainIs(host, 'www1.example.com'')) {
|
504
|
+
return "PROXY proxy1.example.com:8080";
|
505
|
+
} else {
|
506
|
+
return "PROXY proxy2.example.net:8080";
|
507
|
+
}
|
508
|
+
}
|
509
|
+
EOS
|
510
|
+
end
|
511
|
+
context 'Parse Proxy Pac' do
|
512
|
+
context 'when url is forwarded via' do
|
513
|
+
let(:url) { 'http://www1.example.com' }
|
514
|
+
it { expect(url).to be_downloaded_via 'PROXY proxy.example.com:8080' }
|
515
|
+
end
|
516
|
+
|
517
|
+
context 'when url is not forwarded via' do
|
518
|
+
let(:url) { 'http://www2.example.com' }
|
519
|
+
it { expect(url).not_to be_downloaded_via 'PROXY proxy.example.com:8080' }
|
520
|
+
end
|
521
|
+
end
|
522
|
+
end
|
523
|
+
```
|
524
|
+
|
230
525
|
## Developers
|
231
526
|
|
527
|
+
After checking out the repo, run `script/bootstrap` to install dependencies. Then, run
|
528
|
+
`script/console` for an interactive prompt that will allow you to experiment.
|
529
|
+
|
530
|
+
To install this gem onto your local machine, run `bundle exec rake gem:install`. To
|
531
|
+
release a new version, update the version number in `version.rb`, and then run
|
532
|
+
`bundle exec rake gem:release` to create a git tag for the version, push git
|
533
|
+
commits and tags, and push the `.gem` file to
|
534
|
+
[rubygems.org](https://rubygems.org).
|
535
|
+
|
232
536
|
### Contributing
|
233
537
|
|
234
|
-
If you want to contribute: fork, branch & pull request
|
538
|
+
If you want to contribute: fork, branch & pull request and please see
|
539
|
+
[CONTRIBUTING.md](CONTRIBUTING.md).
|
235
540
|
|
236
541
|
### Running Tests
|
237
542
|
|