proxy_pac_rb 0.4.2 → 0.5.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.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -3
  3. data/CONTRIBUTING.md +61 -0
  4. data/Gemfile +2 -2
  5. data/Gemfile.lock +6 -14
  6. data/README.md +319 -14
  7. data/Rakefile +2 -96
  8. data/features/init_proxy_pac.feature +47 -0
  9. data/features/resolve_proxy.feature +1 -1
  10. data/features/step_definitions.rb +11 -0
  11. data/lib/proxy_pac_rb/cli/compress_proxy_pac.rb +1 -1
  12. data/lib/proxy_pac_rb/cli/find_proxy.rb +2 -0
  13. data/lib/proxy_pac_rb/cli/init.rb +10 -0
  14. data/lib/proxy_pac_rb/cli/init_proxy_pac.rb +98 -0
  15. data/lib/proxy_pac_rb/cli/lint.rb +0 -1
  16. data/lib/proxy_pac_rb/cli/lint_proxy_pac.rb +0 -1
  17. data/lib/proxy_pac_rb/cli/runner.rb +3 -0
  18. data/lib/proxy_pac_rb/environment.rb +13 -10
  19. data/lib/proxy_pac_rb/errors.rb +4 -0
  20. data/lib/proxy_pac_rb/javascript_compiler.rb +29 -0
  21. data/lib/proxy_pac_rb/main.rb +6 -0
  22. data/lib/proxy_pac_rb/parser.rb +2 -7
  23. data/lib/proxy_pac_rb/proxy_pac_file.rb +53 -5
  24. data/lib/proxy_pac_rb/proxy_pac_linter.rb +11 -5
  25. data/lib/proxy_pac_rb/proxy_pac_loader.rb +38 -5
  26. data/lib/proxy_pac_rb/proxy_pac_parser.rb +9 -21
  27. data/lib/proxy_pac_rb/rack/proxy_pac_compressor.rb +3 -3
  28. data/lib/proxy_pac_rb/rack/proxy_pac_linter.rb +3 -3
  29. data/lib/proxy_pac_rb/rspec/helpers/.keep +0 -0
  30. data/lib/proxy_pac_rb/rspec/helpers.rb +52 -0
  31. data/lib/proxy_pac_rb/rspec/matchers/.keep +0 -0
  32. data/lib/proxy_pac_rb/rspec/matchers/proxy.rb +23 -0
  33. data/lib/proxy_pac_rb/rspec/matchers/url.rb +13 -0
  34. data/lib/proxy_pac_rb/rspec/shared_contexts/.keep +0 -0
  35. data/lib/proxy_pac_rb/rspec/shared_examples/.keep +0 -0
  36. data/lib/proxy_pac_rb/rspec.rb +18 -0
  37. data/lib/proxy_pac_rb/version.rb +1 -1
  38. data/lib/proxy_pac_rb.rb +5 -1
  39. data/script/config.ru +8 -0
  40. data/spec/api/proxy_pac_compressor_spec.rb +31 -0
  41. data/spec/api/proxy_pac_dumper_spec.rb +67 -0
  42. data/spec/api/proxy_pac_file_spec.rb +90 -0
  43. data/spec/api/proxy_pac_linter_spec.rb +61 -0
  44. data/spec/api/proxy_pac_loader_spec.rb +88 -0
  45. data/spec/api/proxy_pac_parser_spec.rb +56 -0
  46. data/spec/environment_spec.rb +121 -78
  47. data/spec/parser_spec.rb +1 -1
  48. data/spec/rspec/compare_proxy_pac_files_spec.rb +62 -0
  49. data/spec/rspec/parse_proxy_pac_spec.rb +88 -0
  50. data/spec/rspec/readability_spec.rb +57 -0
  51. data/spec/rspec/rspec_spec.rb +7 -0
  52. data/spec/rspec/validitiy_spec.rb +48 -0
  53. data/spec/support/aruba.rb +0 -27
  54. data/spec/support/shared_examples/loader.rb +27 -0
  55. data/templates/build/middleman/config.rb +12 -0
  56. data/templates/build/middleman/script/build +2 -0
  57. data/templates/build/middleman/source/.keep +0 -0
  58. data/templates/default/.gitignore +24 -0
  59. data/templates/default/Gemfile +3 -0
  60. data/templates/default/Rakefile +1 -0
  61. data/templates/default/script/bootstrap +22 -0
  62. data/templates/new_proxy_pac.pac.erb +3 -0
  63. data/templates/test_framework/rspec/spec_helper.rb +9 -0
  64. data/templates/test_framework/rspec/support/aruba.rb +23 -0
  65. data/templates/test_framework/rspec/support/matchers/shared_contexts/.keep +0 -0
  66. data/templates/test_framework/rspec/support/proxy_pac_rb.rb +1 -0
  67. data/templates/test_framework/rspec/support/rspec.rb +20 -0
  68. data/templates/test_framework/rspec/support/shared_contexts/.keep +0 -0
  69. data/templates/test_framework/rspec/support/shared_examples/.keep +0 -0
  70. metadata +56 -6
  71. data/lib/proxy_pac_rb/proxy_pac.rb +0 -24
  72. data/script/test_web +0 -16
  73. data/spec/api_spec.rb +0 -207
@@ -1,161 +1,204 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe ProxyPacRb::Environment do
5
- let(:environment) do
6
- Environment.new(client_ip: '127.0.0.1', time: Time.now)
4
+ RSpec.describe ProxyPacRb::Environment do
5
+ let(:client_ip) { '127.0.0.1' }
6
+ let(:time) { '1970-01-01 00:00:00' }
7
+ let(:environment) { Environment.new(client_ip: client_ip, time: time) }
8
+
9
+ describe '#initialize' do
10
+ context 'when valid ip address is given' do
11
+ it { expect { environment }.not_to raise_error }
12
+ end
13
+
14
+ context 'when invalid ip address is given' do
15
+ let(:client_ip) { 'invalid_ip' }
16
+ it { expect { environment }.to raise_error IPAddr::InvalidAddressError }
17
+ end
18
+
19
+ context 'when ip address is given as ip address-object' do
20
+ let(:client_ip) { IPAddr.new('127.0.0.1') }
21
+ it { expect { environment }.not_to raise_error }
22
+ end
23
+
24
+ context 'when valid time is given' do
25
+ it { expect { environment }.not_to raise_error }
26
+ end
27
+
28
+ context 'when invalid time is given' do
29
+ let(:time) { 'invalid_time' }
30
+ it { expect { environment }.to raise_error ArgumentError }
31
+ end
32
+
33
+ context 'when time is given as time object' do
34
+ let(:time) { Time.parse('1970-01-01 00:00:00') }
35
+ it { expect { environment }.not_to raise_error }
36
+ end
7
37
  end
8
38
 
9
39
  describe '#isResolvable()' do
10
- it 'should return true for localhost' do
11
- expect(environment.isResolvable('localhost')).to be true
40
+ context 'when is "localhost"' do
41
+ it { expect(environment.isResolvable('localhost')).to be true }
12
42
  end
13
43
 
14
- it 'should return false for unexist.domain.localdomain' do
15
- expect(environment.isResolvable('unexist.domain.localdomain')).to be false
44
+ context 'when is "unexist.domain.localdomain"' do
45
+ it { expect(environment.isResolvable('unexist.domain.localdomain')).to be false }
16
46
  end
17
47
  end
18
48
 
19
49
  describe '#isPlainHostName' do
20
- it 'returns true for google' do
21
- result = environment.isPlainHostName('google')
22
- expect(result).to be true
50
+ context 'when is url contains plain hostname "example"' do
51
+ let(:result) { environment.isPlainHostName('example') }
52
+ it { expect(result).to be true }
23
53
  end
24
54
 
25
- it 'returns false for google.com' do
26
- result = environment.isPlainHostName('google.com')
27
- expect(result).to be false
55
+ context 'when is url contains hostname with domain "example.com"' do
56
+ let(:result) { environment.isPlainHostName('example.com') }
57
+ it { expect(result).to be false }
28
58
  end
29
59
  end
30
60
 
31
61
  describe '#dnsDomainIs' do
32
- it 'returns true for maps.google.com' do
33
- result = environment.dnsDomainIs('maps.google.com', '.google.com')
34
- expect(result).to be true
62
+ context 'when domain matches fqdn' do
63
+ let(:result) { environment.dnsDomainIs('maps.example.com', '.example.com') }
64
+ it { expect(result).to be true }
35
65
  end
36
66
 
37
- it 'returns false for maps.ms.com' do
38
- result = environment.dnsDomainIs('maps.ms.com', '.google.com')
39
- expect(result).to be false
67
+ context 'when domain does not match fqdn' do
68
+ let(:result) { environment.dnsDomainIs('maps.example.com', '.example.net') }
69
+ it { expect(result).to be false }
40
70
  end
41
71
  end
42
72
 
43
73
  describe '#localHostOrDomainIs' do
44
- it 'returns true for maps.google.com' do
45
- result = environment.localHostOrDomainIs('maps.google.com', 'maps.google.com')
46
- expect(result).to be true
74
+ context 'when fqdn matches fqdn' do
75
+ let(:result) { environment.localHostOrDomainIs('maps.example.com', 'maps.example.com') }
76
+ it { expect(result).to be true }
77
+ end
78
+
79
+ context 'when plain host is included in fqdn' do
80
+ let(:result) { environment.localHostOrDomainIs('maps', 'maps.example.com') }
81
+ it { expect(result).to be true }
47
82
  end
48
83
 
49
- it 'returns true for maps' do
50
- result = environment.localHostOrDomainIs('maps', 'maps.google.com')
51
- expect(result).to be true
84
+ context 'when fqdn does not match fqdn' do
85
+ let(:result) { environment.localHostOrDomainIs('maps.example.net', 'maps.example.com') }
86
+ it { expect(result).to be false }
52
87
  end
53
88
 
54
- it 'returns false for maps.ms.com' do
55
- result = environment.dnsDomainIs('maps.ms.com', '.google.com')
56
- expect(result).to be false
89
+ context 'when plain host is not included in fqdn' do
90
+ let(:result) { environment.localHostOrDomainIs('text', 'maps.example.com') }
91
+ it { expect(result).to be false }
57
92
  end
58
93
  end
59
94
 
60
95
  describe '#isInNet' do
61
- it 'returns true for 127.0.0.1' do
62
- result = environment.isInNet('127.0.0.1', '127.0.0.0', '255.255.255.0')
63
- expect(result).to be true
96
+ context 'when ip is included in network' do
97
+ let(:result) { environment.isInNet('127.0.0.1', '127.0.0.0', '255.255.255.0') }
98
+ it { expect(result).to be true }
64
99
  end
65
100
 
66
- it 'returns false for 10.0.0.1' do
67
- result = environment.isInNet('10.0.0.1', '127.0.0.0', '255.255.255.0')
68
- expect(result).to be false
101
+ context 'when ip is not included in network' do
102
+ let(:result) { environment.isInNet('10.0.0.1', '127.0.0.0', '255.255.255.0') }
103
+ it { expect(result).to be false }
69
104
  end
70
105
 
71
- it 'resolves host name' do
72
- name = 'google-public-dns-a.google.com'
73
- result = environment.isInNet(name, '8.0.0.0', '255.0.0.0')
74
- expect(result).to eq true
106
+ context 'when a resolveable hostname is given' do
107
+ let(:result) { environment.isInNet('www.example.net', '93.0.0.0', '255.0.0.0') }
108
+ it { expect(result).to eq true }
75
109
  end
76
110
 
77
- it 'handles not resolvable host names' do
78
- name = 'asdf.in.localhost.localdomain'
79
- result = environment.isInNet(name, '8.0.0.0', '255.0.0.0')
80
- expect(result).to eq false
111
+ context 'when a non-resolveable hostname is given' do
112
+ let(:result) { environment.isInNet('www.example.net.localdomain', '93.0.0.0', '255.0.0.0') }
113
+ it { expect(result).to eq false }
81
114
  end
82
115
 
83
- it 'handles empty strings' do
84
- result = environment.isInNet('', '8.0.0.0', '255.0.0.0')
85
- expect(result).to eq false
116
+ context 'when input is nil' do
117
+ let(:result) { environment.isInNet(nil, '93.0.0.0', '255.0.0.0') }
118
+ it { expect(result).to eq false }
86
119
  end
87
120
 
88
- it 'handles nil' do
89
- result = environment.isInNet(nil, '8.0.0.0', '255.0.0.0')
90
- expect(result).to eq false
121
+ context 'when input is empty string ""' do
122
+ let(:result) { environment.isInNet('', '93.0.0.0', '255.0.0.0') }
123
+ it { expect(result).to eq false }
91
124
  end
92
125
  end
93
126
 
94
127
  describe '#dnsResolve' do
95
- it 'returns the ip address for domain' do
96
- ip = '8.8.8.8'
97
- name = 'google-public-dns-a.google.com'
98
- expect(environment.dnsResolve(name)).to eq(ip)
128
+ context 'when a resolveable hostname is given' do
129
+ let(:result) { environment.dnsResolve('www.example.net') }
130
+ it { expect(result).to eq '93.184.216.34' }
99
131
  end
100
132
 
101
- it 'return nil for a not resolvable host name' do
102
- name = 'not.resolvable.localhost.localdomain'
103
- expect(environment.dnsResolve(name)).to eq(nil)
133
+ context 'when a resolveable hostname is given' do
134
+ let(:result) { environment.dnsResolve('www.example.net.localdomain') }
135
+ it { expect(result).to eq nil }
104
136
  end
105
137
 
106
- it 'handles nil values as input' do
107
- expect(environment.dnsResolve(nil)).to eq(nil)
138
+ context 'when input is nil' do
139
+ let(:result) { environment.dnsResolve(nil) }
140
+ it { expect(result).to eq nil }
108
141
  end
109
142
 
110
- it 'handles empty string as input' do
111
- expect(environment.dnsResolve('')).to eq(nil)
143
+ context 'when input is empty string ""' do
144
+ let(:result) { environment.dnsResolve('') }
145
+ it { expect(result).to eq nil }
112
146
  end
113
147
 
114
- it 'handles garbage as input' do
115
- expect(environment.dnsResolve('§§jk:')).to eq(nil)
148
+ context 'when input is gargabe' do
149
+ let(:result) { environment.dnsResolve('§§jk:') }
150
+ it { expect(result).to eq nil }
116
151
  end
117
152
  end
118
153
 
119
154
  describe '#dnsDomainLevels' do
120
- it 'returns the count of domain levels (dots)' do
121
- result = environment.dnsDomainLevels('maps.google.com')
122
- expect(result).to eq(2)
155
+ context 'when contains subdomains' do
156
+ let(:result) { environment.dnsDomainLevels('maps.example.com') }
157
+ it { expect(result).to eq 2 }
158
+ end
159
+
160
+ context 'when does not contain subdomains' do
161
+ let(:result) { environment.dnsDomainLevels('maps') }
162
+ it { expect(result).to eq 0 }
123
163
  end
124
164
  end
125
165
 
126
166
  describe '#shExpMatch' do
127
- it 'returns true for maps.google.com' do
128
- result = environment.shExpMatch('maps.google.com', '*.com')
129
- expect(result).to be true
167
+ context 'when pattern matches hostname' do
168
+ let(:result) { environment.shExpMatch('maps.example.com', '*.com') }
169
+ it { expect(result).to be true }
130
170
  end
131
171
 
132
- it 'returns false for maps.ms.com' do
133
- result = environment.shExpMatch('maps.ms.com', '*.de')
134
- expect(result).to be false
172
+ context 'when pattern does not match hostname' do
173
+ let(:result) { environment.shExpMatch('maps.example.com', '*.de') }
174
+ it { expect(result).to be false }
135
175
  end
136
176
  end
137
177
 
138
178
  describe '#alert' do
139
- it 'outputs msg' do
140
- result = capture(:stderr) do
141
- environment.alert('message')
179
+ context 'when message is given' do
180
+ let(:result) do
181
+ capture(:stderr) do
182
+ environment.alert('message')
183
+ end.chomp
142
184
  end
143
185
 
144
- expect(result.chomp).to eq('message')
186
+ it { expect(result).to eq 'message' }
145
187
  end
146
188
  end
147
189
 
148
190
  describe '#prepare' do
149
- it 'adds neccessary functions to source file' do
150
- string = ''
151
- environment.prepare(string)
191
+ context 'when valid' do
192
+ let(:string) { '' }
193
+
194
+ before(:each) { environment.prepare(string) }
152
195
 
153
196
  %w(
154
197
  myIpAddress
155
198
  weekdayRange
156
199
  dateRange
157
200
  timeRange
158
- ).each { |f| expect(string).to include(f) }
201
+ ).each { |f| it { expect(string).to include(f) } }
159
202
  end
160
203
  end
161
204
  end
data/spec/parser_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe ProxyPacRb::Parser do
4
+ RSpec.describe ProxyPacRb::Parser do
5
5
  subject(:proxy_pac) { Parser.new(environment: environment).parse(source) }
6
6
 
7
7
  let(:environment) { Environment.new }
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ require 'proxy_pac_rb/rspec'
3
+
4
+ RSpec.describe 'Compare to proxy.pac-files', type: :proxy_pac do
5
+ subject do
6
+ <<-EOS.strip_heredoc.chomp
7
+ function FindProxyForURL(url, host) {
8
+ return "DIRECT";
9
+ }
10
+ EOS
11
+ end
12
+
13
+ let(:file_a) do
14
+ <<-EOS.strip_heredoc.chomp
15
+ function FindProxyForURL(url, host) {
16
+ return "DIRECT";
17
+ }
18
+ EOS
19
+ end
20
+
21
+ let(:file_b) do
22
+ <<-EOS.strip_heredoc.chomp
23
+ function FindProxyForURL(url, host) {
24
+ return "DIRECT";
25
+ }
26
+ EOS
27
+ end
28
+
29
+ context 'when file "a" is already a ProxyPacFile' do
30
+ it { expect(proxy_pac).to be_the_same_proxy_pac_file file_b }
31
+ end
32
+
33
+ context 'when file "b" is already a ProxyPacFile' do
34
+ it { expect(file_b).to be_the_same_proxy_pac_file proxy_pac }
35
+ end
36
+
37
+ context 'when file "a" and file "b" are strings' do
38
+ context 'when both are eqal' do
39
+ it { expect(file_a).to be_the_same_proxy_pac_file file_b }
40
+ end
41
+
42
+ context 'when both are not eqal' do
43
+ let(:file_a) do
44
+ <<-EOS.strip_heredoc.chomp
45
+ function FindProxyForURL(url, host) {
46
+ return "DIRECT";
47
+ }
48
+ EOS
49
+ end
50
+
51
+ let(:file_b) do
52
+ <<-EOS.strip_heredoc.chomp
53
+ function FindProxyForURL(url, host) {
54
+ return "PROXY localhost:8080";
55
+ }
56
+ EOS
57
+ end
58
+
59
+ it { expect(file_a).not_to be_the_same_proxy_pac_file file_b }
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+ require 'proxy_pac_rb/rspec'
3
+
4
+ RSpec.describe 'Parse proxy.pac', type: :proxy_pac do
5
+ describe 'Browse url' do
6
+ subject do
7
+ <<-EOS.strip_heredoc.chomp
8
+ function FindProxyForURL(url, host) {
9
+ if (dnsDomainIs(host, 'localhost')) {
10
+ return "DIRECT";
11
+ } else {
12
+ return "PROXY proxy.example.com:3128";
13
+ }
14
+ }
15
+ EOS
16
+ end
17
+
18
+ context 'http://localhost' do
19
+ let(:url) { 'http://localhost' }
20
+ it { expect(url).to be_downloaded_via 'DIRECT' }
21
+ end
22
+
23
+ context 'http://www.example.org' do
24
+ let(:url) { 'http://www.example.org' }
25
+ it { expect(url).not_to be_downloaded_via 'DIRECT' }
26
+ end
27
+ end
28
+
29
+ describe 'Change time' do
30
+ subject do
31
+ <<-EOS.strip_heredoc.chomp
32
+ function FindProxyForURL(url, host) {
33
+ if (weekdayRange("FRI", "SAT")) {
34
+ return "PROXY localhost:8080";
35
+ } else {
36
+ return "DIRECT";
37
+ }
38
+ }
39
+ EOS
40
+ end
41
+
42
+ let(:url) { 'http://www.example.org' }
43
+
44
+ context 'when using default value Thursday, 1970-01-01' do
45
+ it { expect(url).to be_downloaded_via 'DIRECT' }
46
+ end
47
+
48
+ context 'when time is Thursday, 1970-01-01' do
49
+ let(:time) { '1970-01-01' }
50
+ it { expect(url).to be_downloaded_via 'DIRECT' }
51
+ end
52
+
53
+ context 'when time is Friday, 1970-01-02' do
54
+ let(:time) { '1970-01-02' }
55
+ it { expect(url).to be_downloaded_via 'PROXY localhost:8080' }
56
+ end
57
+ end
58
+
59
+ describe 'Change client ip' do
60
+ subject do
61
+ <<-EOS.strip_heredoc.chomp
62
+ function FindProxyForURL(url, host) {
63
+ if ( myIpAddress() == '127.0.0.2' ) {
64
+ return "PROXY localhost:8080";
65
+ } else {
66
+ return "DIRECT";
67
+ }
68
+ }
69
+ EOS
70
+ end
71
+
72
+ let(:url) { 'http://www.example.org' }
73
+
74
+ context 'when using default value for ip, 127.0.0.1' do
75
+ it { expect(url).to be_downloaded_via 'DIRECT' }
76
+ end
77
+
78
+ context 'when ip is 127.0.0.1' do
79
+ let(:client_ip) { '127.0.0.1' }
80
+ it { expect(url).to be_downloaded_via 'DIRECT' }
81
+ end
82
+
83
+ context 'when ip is 127.0.0.2' do
84
+ let(:client_ip) { '127.0.0.2' }
85
+ it { expect(url).to be_downloaded_via 'PROXY localhost:8080' }
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require 'proxy_pac_rb/rspec'
3
+
4
+ RSpec.describe 'Readability', type: :proxy_pac do
5
+ let(:content) do
6
+ <<-EOS.strip_heredoc.chomp
7
+ function FindProxyForURL(url, host) {
8
+ return "DIRECT";
9
+ }
10
+ EOS
11
+ end
12
+
13
+ context 'when is file' do
14
+ let(:root_path) { current_dir }
15
+
16
+ subject { 'proxy.pac' }
17
+
18
+ context 'when proxy pac exist' do
19
+ before :each do
20
+ write_file 'proxy.pac', content
21
+ end
22
+
23
+ it { expect(proxy_pac).to be_readable }
24
+ end
25
+
26
+ context 'when proxy pac does not exist' do
27
+ it { expect(proxy_pac).not_to be_readable }
28
+ end
29
+ end
30
+
31
+ context 'when is url' do
32
+ subject { 'http://www.example.com/proxy.pac' }
33
+
34
+ context 'when is readable' do
35
+ before(:each) { stub_request(:get, subject).to_return(body: content, status: 200) }
36
+ it { expect(proxy_pac).to be_readable }
37
+ end
38
+ context 'when is not readable' do
39
+ before(:each) { stub_request(:get, subject).to_raise(StandardError) }
40
+ it { expect(proxy_pac).not_to be_readable }
41
+ end
42
+ end
43
+
44
+ context 'when is string' do
45
+ context 'it is always readable' do
46
+ subject do
47
+ <<-EOS.strip_heredoc.chomp
48
+ function FindProxyForURL(url, host) {
49
+ return "DIRECT";
50
+ }
51
+ EOS
52
+ end
53
+
54
+ it { expect(proxy_pac).to be_readable }
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe ProxyPacRb do
4
+ it 'has a version number' do
5
+ expect(ProxyPacRb::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+ require 'proxy_pac_rb/rspec'
3
+
4
+ RSpec.describe 'Validity', type: :proxy_pac do
5
+ subject do
6
+ <<-EOS.strip_heredoc.chomp
7
+ function FindProxyForURL(url, host) {
8
+ return "DIRECT";
9
+ }
10
+ EOS
11
+ end
12
+
13
+ context 'when is valid' do
14
+ it { expect(proxy_pac).to be_valid }
15
+ end
16
+
17
+ context 'when is not valid' do
18
+ context 'when is not readable' do
19
+ subject { 'function Gargabe' }
20
+
21
+ it { expect(proxy_pac).not_to be_valid }
22
+ end
23
+
24
+ context 'when contains gargabe' do
25
+ subject do
26
+ <<-EOS.strip_heredoc.chomp
27
+ function FindProxyForURL(url, host) {
28
+ return $§"% "DIRECT";
29
+ }
30
+ EOS
31
+ end
32
+
33
+ it { expect(proxy_pac).not_to be_valid }
34
+ end
35
+
36
+ context 'when undefined variable is referenced' do
37
+ subject do
38
+ <<-EOS.strip_heredoc.chomp
39
+ function FindProxyForURL(url, host) {
40
+ return asdf;
41
+ }
42
+ EOS
43
+ end
44
+
45
+ it { expect(proxy_pac).not_to be_valid }
46
+ end
47
+ end
48
+ end
@@ -11,38 +11,11 @@ module SpecHelper
11
11
  def dirs
12
12
  @dirs ||= %w(tmp rspec)
13
13
  end
14
-
15
- def absolute_path(*args)
16
- in_current_dir { File.expand_path File.join(*args) }
17
- end
18
-
19
- def _create_file(*args)
20
- super
21
-
22
- self
23
- end
24
-
25
- def create_dir(*args)
26
- super
27
-
28
- self
29
- end
30
-
31
- def touch_file(file_name)
32
- in_current_dir do
33
- file_name = File.expand_path(file_name)
34
- _mkdir(File.dirname(file_name))
35
- FileUtils.touch file_name
36
- end
37
-
38
- self
39
- end
40
14
  end
41
15
  end
42
16
 
43
17
  RSpec.configure do |c|
44
18
  c.include SpecHelper::Aruba
45
-
46
19
  c.before :each do
47
20
  clean_current_dir
48
21
  restore_env
@@ -0,0 +1,27 @@
1
+ RSpec.shared_examples 'a loadable proxy.pac' do
2
+ it { loader.load(proxy_pac) }
3
+ end
4
+
5
+ RSpec.shared_examples 'an un-readable proxy.pac' do
6
+ before(:each) do
7
+ expect(proxy_pac).to receive(:message=)
8
+ expect(proxy_pac).to receive(:readable=).with(false)
9
+ allow(proxy_pac).to receive(:content?).and_return(false)
10
+ end
11
+
12
+ it { loader.load(proxy_pac) }
13
+ end
14
+
15
+ RSpec.shared_examples 'a readable proxy.pac' do
16
+ before :each do
17
+ expect(proxy_pac).to receive(:content=).with(content)
18
+ allow(proxy_pac).to receive(:content?).and_return(false)
19
+ end
20
+
21
+ before(:each) do
22
+ expect(proxy_pac).not_to receive(:message=)
23
+ expect(proxy_pac).to receive(:readable=).with(true)
24
+ end
25
+
26
+ it { loader.load(proxy_pac) }
27
+ end
@@ -0,0 +1,12 @@
1
+ require 'proxy_pac_rb/rack/proxy_pac_linter'
2
+ use ProxyPacRb::Rack::ProxyPacLinter
3
+
4
+ require 'proxy_pac_rb/rack/proxy_pac_compressor'
5
+ use ProxyPacRb::Rack::ProxyPacCompressor
6
+
7
+ page '*.pac', content_type: 'application/x-ns-proxy-autoconfig'
8
+
9
+ Dir.glob(File.join(source_dir, '**', '*.pac')).each do |f|
10
+ relative_path = Pathname.new(f).relative_path_from(Pathname.new(source_dir))
11
+ proxy(format('%s.raw', relative_path), relative_path.to_s, content_type: 'text/plain')
12
+ end
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bash
2
+ bundle exec middleman build --verbose
File without changes
@@ -0,0 +1,24 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore the build directory
11
+ /build
12
+
13
+ # Ignore cache
14
+ /.sass-cache
15
+ /.cache
16
+
17
+ # Ignore .DS_store file
18
+ .DS_Store
19
+
20
+ # Temp files
21
+ tmp/
22
+
23
+ # Logs
24
+ *.log