proxy_pac_rb 0.6.9 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -0
- data/features/step_definitions.rb +1 -1
- data/lib/proxy_pac_rb.rb +6 -0
- data/lib/proxy_pac_rb/basic_configuration.rb +85 -0
- data/lib/proxy_pac_rb/code_configuration.rb +6 -0
- data/lib/proxy_pac_rb/rspec.rb +34 -2
- data/lib/proxy_pac_rb/version.rb +1 -1
- data/proxy_pac_rb.gemspec +1 -0
- data/spec/api/proxy_pac_dumper_spec.rb +1 -1
- data/spec/api/proxy_pac_loader_spec.rb +1 -1
- data/spec/basic_configuration_spec.rb +5 -0
- data/spec/code_configuration_spec.rb +24 -0
- data/spec/parser_spec.rb +1 -1
- data/spec/rspec/rspec_spec.rb +7 -3
- data/spec/rspec_integration_spec_helper.rb +2 -0
- data/spec/support/matchers/option.rb +31 -0
- data/spec/support/shared_examples/configuration.rb +38 -0
- metadata +28 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6882f46bded8f3ff2ad971b2b6eb2c4cfe6458e
|
4
|
+
data.tar.gz: 99a114959d3e42f3e242263e6a7627bbc8e0baf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70409e443bbbec0e96e33eea57b8d72406314fef6515d8e65f3f87920f64771cca71c3083367ef3c94e1b0674691c2bfe7f7c7f94ce2adf6cdb1f99d6170a6ef
|
7
|
+
data.tar.gz: c894044358c10a244165a0d8e5eb3f628758171198669cbbe940a4458278ef2fc16be95b0600f6e5436c19c54b55a3f69b2ccae2e1462671c6c405aea146cd4c
|
data/README.md
CHANGED
@@ -59,6 +59,9 @@ pprb find proxy -c 127.0.0.1 -t "2014-03-09 12:00:00" -p sample.pac -u https://g
|
|
59
59
|
# Or download via pprb directly and parse pac #2
|
60
60
|
pprb find proxy -c 127.0.0.1 -t "2014-03-09 12:00:00" -p https://github.com/fedux-org/proxy_pac_rb/raw/master/files/sample.pac -u https://github.com
|
61
61
|
|
62
|
+
# Or download this example if you are behind a coporate proxy via pprb directly and parse pac #3
|
63
|
+
pprb find proxy -c 127.0.0.1 -t "2014-03-09 12:00:00" -p https://github.com/fedux-org/proxy_pac_rb/raw/master/files/sample.pac -u https://github.com --use-proxy
|
64
|
+
|
62
65
|
# => url: result
|
63
66
|
# => https://github.com: DIRECT
|
64
67
|
```
|
@@ -340,6 +343,23 @@ require 'proxy_pac_rb/rspec'
|
|
340
343
|
"proxy.pac"-files. By default its value is `Dir.getwd` which is set by
|
341
344
|
`rspec`.
|
342
345
|
|
346
|
+
### Configuration
|
347
|
+
|
348
|
+
You can either configure `ProxyPacRb` either via a global `ProxyPacRb.configure`-block:
|
349
|
+
|
350
|
+
```ruby
|
351
|
+
ProxyPacRb.configure do |config|
|
352
|
+
config.use_proxy = true
|
353
|
+
end
|
354
|
+
```
|
355
|
+
|
356
|
+
or via `RSpec`-metadata:
|
357
|
+
|
358
|
+
```ruby
|
359
|
+
RSpec.describe 'proxy.pac', type: :proxy_pac, use_proxy: true do
|
360
|
+
end
|
361
|
+
```
|
362
|
+
|
343
363
|
### Examples
|
344
364
|
|
345
365
|
To make it easier for you to start, you find some examples below.
|
data/lib/proxy_pac_rb.rb
CHANGED
@@ -2,8 +2,10 @@ require 'active_support/core_ext/object/blank'
|
|
2
2
|
require 'active_support/core_ext/string/strip'
|
3
3
|
require 'active_support/core_ext/string/filters'
|
4
4
|
require 'active_support/core_ext/hash/deep_merge'
|
5
|
+
require 'active_support/core_ext/object/deep_dup'
|
5
6
|
require 'addressable/uri'
|
6
7
|
require 'ipaddr'
|
8
|
+
require 'set'
|
7
9
|
require 'thor'
|
8
10
|
require 'uglifier'
|
9
11
|
require 'optparse'
|
@@ -13,6 +15,7 @@ require 'excon'
|
|
13
15
|
require 'time'
|
14
16
|
require 'timeout'
|
15
17
|
require 'pathname'
|
18
|
+
require 'contracts'
|
16
19
|
|
17
20
|
require 'proxy_pac_rb/version'
|
18
21
|
require 'proxy_pac_rb/main'
|
@@ -35,6 +38,9 @@ require 'proxy_pac_rb/proxy_pac_loader'
|
|
35
38
|
require 'proxy_pac_rb/proxy_pac_linter'
|
36
39
|
require 'proxy_pac_rb/proxy_pac_parser'
|
37
40
|
|
41
|
+
require 'proxy_pac_rb/basic_configuration'
|
42
|
+
require 'proxy_pac_rb/code_configuration'
|
43
|
+
|
38
44
|
require 'proxy_pac_rb/cli_validator'
|
39
45
|
|
40
46
|
require 'proxy_pac_rb/cli/shared'
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module ProxyPacRb
|
2
|
+
# Basic configuration for ProxyPacRb
|
3
|
+
class BasicConfiguration
|
4
|
+
include Contracts
|
5
|
+
|
6
|
+
# A configuration option
|
7
|
+
class Option
|
8
|
+
attr_accessor :name, :value
|
9
|
+
|
10
|
+
def initialize(name:, value:)
|
11
|
+
@name = name
|
12
|
+
@value = value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def known_options
|
18
|
+
@known_options ||= {}
|
19
|
+
end
|
20
|
+
|
21
|
+
def option_writer(name, contract:, default:)
|
22
|
+
add_option(name, default)
|
23
|
+
|
24
|
+
Contract contract
|
25
|
+
define_method("#{name}=") { |v| find_option(name).value = v }
|
26
|
+
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def option_reader(name, value: nil)
|
31
|
+
add_option(name, value)
|
32
|
+
|
33
|
+
define_method(name) { find_option(name).value }
|
34
|
+
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def option(name, contract:, default:)
|
39
|
+
option_writer name, contract: contract, default: default
|
40
|
+
option_reader name
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def add_option(name, value = nil)
|
46
|
+
return if known_options.key?(name)
|
47
|
+
|
48
|
+
known_options[name] = Option.new(name: name, value: value)
|
49
|
+
|
50
|
+
self
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
attr_reader :local_options
|
55
|
+
private :local_options
|
56
|
+
|
57
|
+
def initialize
|
58
|
+
@local_options = self.class.known_options.deep_dup
|
59
|
+
end
|
60
|
+
|
61
|
+
# @yield [Configuration]
|
62
|
+
#
|
63
|
+
# Yields self
|
64
|
+
def configure
|
65
|
+
yield self if block_given?
|
66
|
+
end
|
67
|
+
|
68
|
+
def option?(name)
|
69
|
+
local_options.any? { |_, v| v.name == name }
|
70
|
+
end
|
71
|
+
|
72
|
+
# Set if name is option
|
73
|
+
def set_if_option(name, *args)
|
74
|
+
public_send("#{name}=".to_sym, *args) if option? name
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def find_option(name)
|
80
|
+
fail NotImplementedError, %(Unknown option "#{name}") unless option? name
|
81
|
+
|
82
|
+
local_options[name]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/lib/proxy_pac_rb/rspec.rb
CHANGED
@@ -8,11 +8,43 @@ ProxyPacRb.require_file_matching_pattern('rspec/shared_contexts/*.rb')
|
|
8
8
|
|
9
9
|
# Main Module
|
10
10
|
module ProxyPacRb
|
11
|
-
|
12
|
-
|
11
|
+
@configuration = CodeConfiguration.new
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def configure(&block)
|
15
|
+
@configuration.configure(&block)
|
16
|
+
|
17
|
+
@configuration
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
15
21
|
|
22
|
+
ProxyPacRb.configure do |config|
|
23
|
+
config.use_proxy = false
|
24
|
+
end
|
25
|
+
|
16
26
|
RSpec.configure do |config|
|
17
27
|
config.include ProxyPacRb::Rspec::Helpers, type: :proxy_pac
|
28
|
+
|
29
|
+
config.before :each do |example|
|
30
|
+
next unless self.class.include?(ProxyPacRb::Rspec::Helpers)
|
31
|
+
|
32
|
+
@proxy_pac_rb_config = ProxyPacRb.configure.dup \
|
33
|
+
unless defined?(@proxy_pac_rb_config) && @proxy_pac_rb_config.is_a?(ProxyPacRb::CodeConfiguration)
|
34
|
+
|
35
|
+
example.metadata.select { |k, _v| k != :proxy_pac_rb_config }.each do |k, v|
|
36
|
+
@proxy_pac_rb_config.set_if_option(k, v)
|
37
|
+
end
|
38
|
+
|
39
|
+
if @proxy_pac_rb_config.use_proxy == false
|
40
|
+
%w(
|
41
|
+
http_proxy
|
42
|
+
https_proxy
|
43
|
+
HTTP_PROXY
|
44
|
+
HTTPS_PROXY
|
45
|
+
).each do |v|
|
46
|
+
ENV.delete(v)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
18
50
|
end
|
data/lib/proxy_pac_rb/version.rb
CHANGED
data/proxy_pac_rb.gemspec
CHANGED
@@ -26,6 +26,7 @@ DESC
|
|
26
26
|
spec.add_runtime_dependency 'activesupport', '~>4.1'
|
27
27
|
spec.add_runtime_dependency 'uglifier', '~> 2.7.1'
|
28
28
|
spec.add_runtime_dependency 'excon', '~> 0.45.3'
|
29
|
+
spec.add_runtime_dependency 'contracts', '~> 0.9'
|
29
30
|
|
30
31
|
spec.required_ruby_version = '~> 2.0'
|
31
32
|
end
|
@@ -53,7 +53,7 @@ RSpec.describe ProxyPacLoader do
|
|
53
53
|
context 'when proxy pac is file' do
|
54
54
|
let(:file) { 'proxy.pac' }
|
55
55
|
let(:type) { :file }
|
56
|
-
let(:source) {
|
56
|
+
let(:source) { expand_path(file) }
|
57
57
|
|
58
58
|
before(:each) { allow(proxy_pac).to receive(:source).and_return(source) }
|
59
59
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ProxyPacRb::CodeConfiguration do
|
4
|
+
it_behaves_like 'a basic configuration'
|
5
|
+
|
6
|
+
describe '#use_proxy' do
|
7
|
+
subject(:config) { described_class.new }
|
8
|
+
|
9
|
+
context 'when default is used' do
|
10
|
+
it { expect(config.use_proxy).to be false }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when modified' do
|
14
|
+
context 'when valid value' do
|
15
|
+
before(:each) { config.use_proxy = true }
|
16
|
+
it { expect(config.use_proxy).to be true }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when invalid value' do
|
20
|
+
it { expect { config.use_proxy = '' }.to raise_error ArgumentError }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/parser_spec.rb
CHANGED
@@ -27,7 +27,7 @@ RSpec.describe ProxyPacRb::Parser do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'when path is given' do
|
30
|
-
let(:source) {
|
30
|
+
let(:source) { expand_path('proxy.pac') }
|
31
31
|
before(:each) { write_file(source, content) }
|
32
32
|
|
33
33
|
it { expect(proxy_pac).not_to be_nil }
|
data/spec/rspec/rspec_spec.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe ProxyPacRb do
|
4
|
-
|
5
|
-
expect(
|
3
|
+
RSpec.describe ProxyPacRb, type: :proxy_pac do
|
4
|
+
context 'when use_proxy is true', use_proxy: true do
|
5
|
+
it { expect(@proxy_pac_rb_config.use_proxy).to be true }
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'when use_proxy is false', use_proxy: false do
|
9
|
+
it { expect(@proxy_pac_rb_config.use_proxy).to be false }
|
6
10
|
end
|
7
11
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
RSpec::Matchers.define :be_valid_option do |_|
|
2
|
+
match do |actual|
|
3
|
+
subject.option?(actual)
|
4
|
+
end
|
5
|
+
|
6
|
+
failure_message do |actual|
|
7
|
+
format("expected that \"%s\" is a valid option", actual)
|
8
|
+
end
|
9
|
+
|
10
|
+
failure_message_when_negated do |actual|
|
11
|
+
format("expected that \"%s\" is not a valid option", actual)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec::Matchers.define :have_option_value do |expected|
|
16
|
+
match do |actual|
|
17
|
+
@old_actual = actual
|
18
|
+
@actual = subject.public_send(actual.to_sym)
|
19
|
+
values_match? expected, @actual
|
20
|
+
end
|
21
|
+
|
22
|
+
diffable
|
23
|
+
|
24
|
+
failure_message do |_actual|
|
25
|
+
format(%(expected that option "%s" has value "%s"), @old_actual, expected)
|
26
|
+
end
|
27
|
+
|
28
|
+
failure_message_when_negated do |_actual|
|
29
|
+
format(%(expected that option "%s" does not have value "%s"), @old_actual, expected)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
RSpec.shared_examples 'a basic configuration' do
|
2
|
+
subject(:config) do
|
3
|
+
Class.new(described_class) do
|
4
|
+
option :use_test, contract: { Contracts::Bool => Contracts::Bool }, default: false
|
5
|
+
end.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it { expect(config).not_to be_nil }
|
9
|
+
|
10
|
+
describe 'option?' do
|
11
|
+
let(:name) { :use_test }
|
12
|
+
|
13
|
+
context 'when valid option' do
|
14
|
+
it { expect(name).to be_valid_option }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when invalid_option' do
|
18
|
+
let(:name) { :blub }
|
19
|
+
it { expect(name).not_to be_valid_option }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'set_if_option' do
|
24
|
+
let(:name) { :use_test }
|
25
|
+
let(:value) { true }
|
26
|
+
|
27
|
+
context 'when valid option' do
|
28
|
+
before(:each) { config.set_if_option(name, value) }
|
29
|
+
it { expect(name).to have_option_value true }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when invalid_option' do
|
33
|
+
let(:name) { :blub }
|
34
|
+
|
35
|
+
it { expect { config.set_if_option(name, value) }.not_to raise_error }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
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.
|
4
|
+
version: 0.7.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-05-
|
11
|
+
date: 2015-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.45.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: contracts
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
69
83
|
description: |
|
70
84
|
"proxy_pac_rb" is a gem to compress, lint and parse proxy auto-config files. It comes with a cli program, some rack middlewares and can be used from within ruby scripts as well. "proxy_pac_rb" uses a JavaScript runtime to evaulate a proxy auto-config file the same way a browser does to determine what proxy (if any at all) should a program use to connect to a server. You must install on of the supported JavaScript runtimes: therubyracer or therubyrhino
|
71
85
|
email:
|
@@ -104,6 +118,7 @@ files:
|
|
104
118
|
- files/sample2.pac
|
105
119
|
- files/sample3.pac
|
106
120
|
- lib/proxy_pac_rb.rb
|
121
|
+
- lib/proxy_pac_rb/basic_configuration.rb
|
107
122
|
- lib/proxy_pac_rb/cli/compress.rb
|
108
123
|
- lib/proxy_pac_rb/cli/compress_proxy_pac.rb
|
109
124
|
- lib/proxy_pac_rb/cli/find.rb
|
@@ -116,6 +131,7 @@ files:
|
|
116
131
|
- lib/proxy_pac_rb/cli/shared.rb
|
117
132
|
- lib/proxy_pac_rb/cli/show.rb
|
118
133
|
- lib/proxy_pac_rb/cli_validator.rb
|
134
|
+
- lib/proxy_pac_rb/code_configuration.rb
|
119
135
|
- lib/proxy_pac_rb/encoding.rb
|
120
136
|
- lib/proxy_pac_rb/environment.rb
|
121
137
|
- lib/proxy_pac_rb/errors.rb
|
@@ -160,6 +176,8 @@ files:
|
|
160
176
|
- spec/api/proxy_pac_linter_spec.rb
|
161
177
|
- spec/api/proxy_pac_loader_spec.rb
|
162
178
|
- spec/api/proxy_pac_parser_spec.rb
|
179
|
+
- spec/basic_configuration_spec.rb
|
180
|
+
- spec/code_configuration_spec.rb
|
163
181
|
- spec/environment_spec.rb
|
164
182
|
- spec/parser_spec.rb
|
165
183
|
- spec/rack/proxy_pac_compressor_spec.rb
|
@@ -169,12 +187,15 @@ files:
|
|
169
187
|
- spec/rspec/readability_spec.rb
|
170
188
|
- spec/rspec/rspec_spec.rb
|
171
189
|
- spec/rspec/validitiy_spec.rb
|
190
|
+
- spec/rspec_integration_spec_helper.rb
|
172
191
|
- spec/spec_helper.rb
|
173
192
|
- spec/support/aruba.rb
|
174
193
|
- spec/support/matchers/file.rb
|
194
|
+
- spec/support/matchers/option.rb
|
175
195
|
- spec/support/rack_test.rb
|
176
196
|
- spec/support/reporting.rb
|
177
197
|
- spec/support/rspec.rb
|
198
|
+
- spec/support/shared_examples/configuration.rb
|
178
199
|
- spec/support/shared_examples/loader.rb
|
179
200
|
- spec/support/strip.rb
|
180
201
|
- spec/support/webmock.rb
|
@@ -238,6 +259,8 @@ test_files:
|
|
238
259
|
- spec/api/proxy_pac_linter_spec.rb
|
239
260
|
- spec/api/proxy_pac_loader_spec.rb
|
240
261
|
- spec/api/proxy_pac_parser_spec.rb
|
262
|
+
- spec/basic_configuration_spec.rb
|
263
|
+
- spec/code_configuration_spec.rb
|
241
264
|
- spec/environment_spec.rb
|
242
265
|
- spec/parser_spec.rb
|
243
266
|
- spec/rack/proxy_pac_compressor_spec.rb
|
@@ -247,12 +270,15 @@ test_files:
|
|
247
270
|
- spec/rspec/readability_spec.rb
|
248
271
|
- spec/rspec/rspec_spec.rb
|
249
272
|
- spec/rspec/validitiy_spec.rb
|
273
|
+
- spec/rspec_integration_spec_helper.rb
|
250
274
|
- spec/spec_helper.rb
|
251
275
|
- spec/support/aruba.rb
|
252
276
|
- spec/support/matchers/file.rb
|
277
|
+
- spec/support/matchers/option.rb
|
253
278
|
- spec/support/rack_test.rb
|
254
279
|
- spec/support/reporting.rb
|
255
280
|
- spec/support/rspec.rb
|
281
|
+
- spec/support/shared_examples/configuration.rb
|
256
282
|
- spec/support/shared_examples/loader.rb
|
257
283
|
- spec/support/strip.rb
|
258
284
|
- spec/support/webmock.rb
|