proxy_pac_rb 0.2.5 → 0.2.6

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/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  coverage
6
+ tmp/
data/bin/pprb ADDED
@@ -0,0 +1,110 @@
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
@@ -0,0 +1,108 @@
1
+ Feature: Resolve proxy
2
+
3
+ As a proxy administrator
4
+ I want to resolve a proxy
5
+ To check the proxy pac
6
+
7
+ Scenario: Existing proxy.pac
8
+ Given a file named "proxy.pac" with:
9
+ """
10
+ function FindProxyForURL(url, host) {
11
+ return 'PROXY localhost:3128';
12
+ }
13
+ """
14
+ When I successfully run `pprb -p proxy.pac www.example.org`
15
+ Then the output should contain:
16
+ """
17
+ PROXY localhost:3128
18
+ """
19
+
20
+ Scenario: Existing proxy.pac with relative path
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 -p ./proxy.pac www.example.org`
28
+ Then the output should contain:
29
+ """
30
+ PROXY localhost:3128
31
+ """
32
+
33
+ Scenario: Non-Existing proxy.pac
34
+ When I run `pprb -p proxy.pac www.example.org`
35
+ Then the output should contain:
36
+ """
37
+ No such file or directory
38
+ """
39
+
40
+ Scenario: Missing url
41
+ Given a file named "proxy.pac" with:
42
+ """
43
+ function FindProxyForURL(url, host) {
44
+ return 'PROXY localhost:3128';
45
+ }
46
+ """
47
+ When I run `pprb -p proxy.pac`
48
+ Then the output should contain:
49
+ """
50
+ You need to provide at least one url
51
+ """
52
+
53
+ Scenario: Missing proxy parameter
54
+ Given a file named "proxy.pac" with:
55
+ """
56
+ function FindProxyForURL(url, host) {
57
+ return 'PROXY localhost:3128';
58
+ }
59
+ """
60
+ When I run `pprb www.example.org`
61
+ Then the output should contain:
62
+ """
63
+ You need to provide a proxy pac file
64
+ """
65
+
66
+ Scenario: Use client ip
67
+ Given a file named "proxy.pac" with:
68
+ """
69
+ function FindProxyForURL(url, host) {
70
+ if (isInNet(myIpAddress(), "10.0.0.0", "255.255.255.0")) {
71
+ return 'PROXY localhost:3128';
72
+ } else {
73
+ return 'DIRECT';
74
+ }
75
+ }
76
+ """
77
+ When I successfully run `pprb -p proxy.pac -c 10.0.0.1 www.example.org`
78
+ Then the output should contain:
79
+ """
80
+ PROXY localhost:3128
81
+ """
82
+ When I successfully run `pprb -p proxy.pac -c 192.0.0.1 www.example.org`
83
+ Then the output should contain:
84
+ """
85
+ DIRECT
86
+ """
87
+
88
+ Scenario: Use time
89
+ Given a file named "proxy.pac" with:
90
+ """
91
+ function FindProxyForURL(url, host) {
92
+ if (dateRange("JAN", "MAY")) {
93
+ return 'PROXY localhost:3128';
94
+ } else {
95
+ return 'DIRECT';
96
+ }
97
+ }
98
+ """
99
+ When I successfully run `pprb -p proxy.pac -t 2014-04-09 www.example.org`
100
+ Then the output should contain:
101
+ """
102
+ PROXY localhost:3128
103
+ """
104
+ When I successfully run `pprb -p proxy.pac -t 2014-12-07 www.example.org`
105
+ Then the output should contain:
106
+ """
107
+ DIRECT
108
+ """
File without changes
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+
3
+ require 'aruba/cucumber'
@@ -1,4 +1,4 @@
1
1
  #main ProxyPacRb
2
2
  module ProxyPacRb
3
- VERSION = '0.2.5'
3
+ VERSION = '0.2.6'
4
4
  end
data/tmp/aruba/.keep ADDED
File without changes
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.5
4
+ version: 0.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-19 00:00:00.000000000 Z
12
+ date: 2014-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -56,6 +56,7 @@ email:
56
56
  - dg1@vrnetze.de
57
57
  executables:
58
58
  - parsepac
59
+ - pprb
59
60
  extensions: []
60
61
  extra_rdoc_files: []
61
62
  files:
@@ -70,7 +71,11 @@ files:
70
71
  - README.md
71
72
  - Rakefile
72
73
  - bin/parsepac
74
+ - bin/pprb
73
75
  - features/.keep
76
+ - features/resolve_proxy.feature
77
+ - features/step_definitions.rb
78
+ - features/support/env.rb
74
79
  - files/sample.pac
75
80
  - files/sample2.pac
76
81
  - files/sample3.pac
@@ -102,6 +107,7 @@ files:
102
107
  - spec/support/reporting.rb
103
108
  - spec/support/rspec.rb
104
109
  - spec/support/string.rb
110
+ - tmp/aruba/.keep
105
111
  - tmp/functions.js
106
112
  - tmp/functions.rb
107
113
  - tmp/sample.pac
@@ -119,18 +125,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
125
  - - ! '>='
120
126
  - !ruby/object:Gem::Version
121
127
  version: '0'
122
- segments:
123
- - 0
124
- hash: 2846235873076525490
125
128
  required_rubygems_version: !ruby/object:Gem::Requirement
126
129
  none: false
127
130
  requirements:
128
131
  - - ! '>='
129
132
  - !ruby/object:Gem::Version
130
133
  version: '0'
131
- segments:
132
- - 0
133
- hash: 2846235873076525490
134
134
  requirements: []
135
135
  rubyforge_project:
136
136
  rubygems_version: 1.8.23
@@ -139,6 +139,9 @@ specification_version: 3
139
139
  summary: gem to parse proxy auto-config files.
140
140
  test_files:
141
141
  - features/.keep
142
+ - features/resolve_proxy.feature
143
+ - features/step_definitions.rb
144
+ - features/support/env.rb
142
145
  - spec/environment_spec.rb
143
146
  - spec/file_spec.rb
144
147
  - spec/parser_spec.rb