proxy_pac_rb 0.2.6 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -35,6 +35,7 @@ gem 'fedux_org-stdlib', group: [:development, :test], require: false
35
35
  gem 'bundler', '~> 1.3', group: [:development, :test], require: false
36
36
  gem 'erubis', group: [:development, :test]
37
37
  gem 'versionomy', group: [:development, :test], require: false
38
+ gem 'sinatra', group: [:development, :test], require: 'sinatra/base'
38
39
  gem 'activesupport', '~> 4.0.0', group: [:development, :test], require: false
39
40
 
40
41
  gem 'awesome_print', group: [:development, :test], require: 'ap'
data/README.md CHANGED
@@ -55,7 +55,7 @@ After installing the `proxy_pac_rb` gem you must install a JavaScript runtime. C
55
55
  curl -L -o sample.pac https://github.com/dg-vrnetze/proxy_pac_rb/raw/master/files/sample.pac
56
56
 
57
57
  # Parse pac
58
- parsepac -c 127.0.0.1 -t "2014-03-09 12:00:00" -p sample.pac https://github.com
58
+ pprb -c 127.0.0.1 -t "2014-03-09 12:00:00" -p sample.pac https://github.com
59
59
 
60
60
  # => url: result
61
61
  # => https://github.com: DIRECT
data/bin/pprb CHANGED
@@ -6,6 +6,8 @@ require 'proxy_pac_rb'
6
6
  require 'ostruct'
7
7
  require 'ipaddr'
8
8
  require 'optparse'
9
+ require 'addressable/uri'
10
+ require 'open-uri'
9
11
 
10
12
  module ProxyPacRb
11
13
  class Cli
@@ -52,7 +54,7 @@ module ProxyPacRb
52
54
  Validator.new(cli.options).validate
53
55
 
54
56
  environment = ProxyPacRb::Environment.new(client_ip: cli.options.client_ip, time: cli.options.time)
55
- file = ProxyPacRb::Parser.new(environment).read(cli.options.proxy_pac_file)
57
+ file = ProxyPacRb::Parser.new(environment).source(cli.options.proxy_pac_file)
56
58
 
57
59
  $stderr.printf("%30s: %-s\n", 'url', 'result')
58
60
  cli.options.urls.each do |u|
@@ -83,8 +85,14 @@ module ProxyPacRb
83
85
  options.time = Time.parse(t)
84
86
  end
85
87
 
86
- opts.on('-p', '--proxy-pac FILE', 'Proxy.pac-file') do |f|
87
- options.proxy_pac_file = ::File.expand_path(::File.join(Dir.getwd, f))
88
+ opts.on('-p', '--proxy-pac FILE|URL', 'Proxy.pac-file') do |f|
89
+ uri = Addressable::URI.parse(f)
90
+
91
+ if uri.host.nil?
92
+ uri.path = ::File.expand_path(uri.path)
93
+ end
94
+
95
+ options.proxy_pac_file = open(uri, { proxy: false }).read
88
96
  end
89
97
 
90
98
  opts.on_tail("-h", "--help", "Show this message") do
@@ -30,6 +30,19 @@ Feature: Resolve proxy
30
30
  PROXY localhost:3128
31
31
  """
32
32
 
33
+ Scenario: Existing proxy.pac with url
34
+ Given a file named "proxy.pac" with:
35
+ """
36
+ function FindProxyForURL(url, host) {
37
+ return 'PROXY localhost:3128';
38
+ }
39
+ """
40
+ When I successfully run `pprb -p http://127.0.0.1:4567/proxy.pac www.example.org`
41
+ Then the output should contain:
42
+ """
43
+ PROXY localhost:3128
44
+ """
45
+
33
46
  Scenario: Non-Existing proxy.pac
34
47
  When I run `pprb -p proxy.pac www.example.org`
35
48
  Then the output should contain:
@@ -1,4 +1,4 @@
1
1
  #main ProxyPacRb
2
2
  module ProxyPacRb
3
- VERSION = '0.2.6'
3
+ VERSION = '0.3.0'
4
4
  end
@@ -1,4 +1,7 @@
1
1
  #!/bin/sh
2
+ bundle exec script/test_web &
2
3
 
3
4
  bundle exec cucumber
4
- bundle exec rspec spec/features
5
+
6
+ pkill -P $$
7
+
data/script/ci CHANGED
@@ -1,3 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
+ bundle exec script/test_web &
4
+
3
5
  bundle exec rake test:coveralls
6
+
7
+ pkill -P $$
data/script/test_web ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler'
4
+ Bundler.require :default, :test, :development
5
+
6
+ require 'sinatra/base'
7
+
8
+ class Server < Sinatra::Base
9
+ get '/:name' do
10
+ root_directory = Pathname.new(File.expand_path('../../tmp/aruba', __FILE__))
11
+ File.read(File.join(root_directory, params[:name]))
12
+ end
13
+ end
14
+
15
+ Server.run!
data/script/unit_test CHANGED
@@ -1,3 +1,7 @@
1
1
  #!/bin/sh
2
+ bundle exec script/test_web &
2
3
 
3
4
  bundle exec rspec
5
+
6
+ pkill -P $$
7
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxy_pac_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -55,7 +55,6 @@ description: ! 'This gem uses a JavaScript runtime to evaulate a proxy auto-conf
55
55
  email:
56
56
  - dg1@vrnetze.de
57
57
  executables:
58
- - parsepac
59
58
  - pprb
60
59
  extensions: []
61
60
  extra_rdoc_files: []
@@ -70,7 +69,6 @@ files:
70
69
  - LICENSE.md
71
70
  - README.md
72
71
  - Rakefile
73
- - bin/parsepac
74
72
  - bin/pprb
75
73
  - features/.keep
76
74
  - features/resolve_proxy.feature
@@ -97,6 +95,7 @@ files:
97
95
  - script/ci
98
96
  - script/console
99
97
  - script/release
98
+ - script/test_web
100
99
  - script/unit_test
101
100
  - spec/environment_spec.rb
102
101
  - spec/file_spec.rb
@@ -107,7 +106,6 @@ files:
107
106
  - spec/support/reporting.rb
108
107
  - spec/support/rspec.rb
109
108
  - spec/support/string.rb
110
- - tmp/aruba/.keep
111
109
  - tmp/functions.js
112
110
  - tmp/functions.rb
113
111
  - tmp/sample.pac
data/bin/parsepac DELETED
@@ -1,110 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $LOAD_PATH << File.expand_path('../../lib', __FILE__)
4
-
5
- require 'proxy_pac_rb'
6
- require 'ostruct'
7
- require 'ipaddr'
8
- require 'optparse'
9
-
10
- module ProxyPacRb
11
- class Cli
12
-
13
- class Validator
14
- private
15
-
16
- attr_reader :options
17
-
18
- public
19
-
20
- def initialize(options)
21
- @options = options
22
- end
23
-
24
- def validate
25
- exit_with_message 'You need to provide at least one url. Multiple urls need to be separated by a space.' if empty_url?
26
- exit_with_message 'You need to provide a proxy pac file.' if empty_pac_file?
27
- end
28
-
29
- private
30
-
31
- def empty_url?
32
- options.urls.empty?
33
- end
34
-
35
- def empty_pac_file?
36
- options.proxy_pac_file.nil?
37
- end
38
-
39
- def exit_with_message(msg)
40
- $stderr.puts msg
41
- exit 1
42
- end
43
-
44
- end
45
-
46
- attr_accessor :options
47
-
48
- def self.start(argv = $*)
49
- cli = new
50
- cli.parse(argv)
51
-
52
- Validator.new(cli.options).validate
53
-
54
- environment = ProxyPacRb::Environment.new(client_ip: cli.options.client_ip, time: cli.options.time)
55
- file = ProxyPacRb::Parser.new(environment).read(cli.options.proxy_pac_file)
56
-
57
- $stderr.printf("%30s: %-s\n", 'url', 'result')
58
- cli.options.urls.each do |u|
59
- begin
60
- $stderr.printf("%30s: %-s\n", u, file.find(u))
61
- rescue Exceptions::UrlInvalid
62
- $stderr.puts "You provide an invalid url \"#{u}\". Please use a correct one."
63
- end
64
- end
65
- end
66
-
67
- def initialize
68
- @options = OpenStruct.new
69
-
70
- @options.client_ip = IPAddr.new('127.0.0.1')
71
- @options.time = Time.now
72
- end
73
-
74
- def parse(argv)
75
- parser = OptionParser.new do |opts|
76
- opts.banner = "Usage: parsepac [options] url1 [url2..urln]"
77
-
78
- opts.on('-c', '--client-ip IP', 'Client ip address') do |i|
79
- options.client_ip = IPAddr.new(i)
80
- end
81
-
82
- opts.on('-t', '--time YYYY-MM-DD HH:MM:SS', 'Time to use during lookup url') do |t|
83
- options.time = Time.parse(t)
84
- end
85
-
86
- opts.on('-p', '--proxy-pac FILE', 'Proxy.pac-file') do |f|
87
- options.proxy_pac_file = ::File.expand_path(::File.join(Dir.getwd, f))
88
- end
89
-
90
- opts.on_tail("-h", "--help", "Show this message") do
91
- $stderr.puts opts
92
- exit
93
- end
94
-
95
- opts.on_tail("--version", "Show version") do
96
- $stderr.puts ProxyPacRb::VERSION
97
- exit
98
- end
99
- end
100
-
101
- $stderr.puts parser.help if argv.empty?
102
-
103
- parser.parse!(argv)
104
- options.urls = argv
105
- end
106
- end
107
- end
108
-
109
- ProxyPacRb::Cli.start
110
- exit 0
data/tmp/aruba/.keep DELETED
File without changes