proxy_tester 0.1.1 → 0.1.2

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
@@ -14,6 +14,7 @@ group :test do
14
14
  gem 'factory_girl'
15
15
  gem 'database_cleaner'
16
16
  gem 'coveralls'
17
+ gem 'webmock', require: 'webmock/rspec'
17
18
  end
18
19
 
19
20
  group :development do
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- proxy_tester (0.1.0)
4
+ proxy_tester (0.1.1)
5
5
  activerecord (~> 4.0)
6
6
  activesupport (~> 4.0)
7
7
  addressable
@@ -64,6 +64,8 @@ GEM
64
64
  simplecov (>= 0.7)
65
65
  term-ansicolor
66
66
  thor
67
+ crack (0.4.2)
68
+ safe_yaml (~> 1.0.0)
67
69
  crypt_keeper (0.13.1)
68
70
  activerecord (>= 3.0)
69
71
  activesupport (>= 3.0)
@@ -162,6 +164,7 @@ GEM
162
164
  rspec-mocks (2.14.6)
163
165
  ruby-progressbar (1.4.2)
164
166
  rugged (0.19.0)
167
+ safe_yaml (1.0.2)
165
168
  sequel (4.9.0)
166
169
  simplecov (0.8.2)
167
170
  docile (~> 1.1.0)
@@ -189,6 +192,9 @@ GEM
189
192
  tzinfo (0.3.39)
190
193
  versionomy (0.4.4)
191
194
  blockenspiel (>= 0.4.5)
195
+ webmock (1.17.4)
196
+ addressable (>= 2.2.7)
197
+ crack (>= 0.3.2)
192
198
  websocket-driver (0.3.2)
193
199
  xpath (2.0.0)
194
200
  nokogiri (~> 1.3)
@@ -227,4 +233,5 @@ DEPENDENCIES
227
233
  sinatra
228
234
  tmrb
229
235
  versionomy
236
+ webmock
230
237
  yard
@@ -30,14 +30,14 @@ module ProxyTester
30
30
  end
31
31
 
32
32
  def pac_file=(source)
33
- @pac_file = source
34
-
35
33
  uri = Addressable::URI.heuristic_parse(source)
36
34
 
37
35
  if uri.host.blank?
38
- @content = File.read(source)
36
+ @content = File.read(uri.path)
37
+ @pac_file = uri.path
39
38
  else
40
39
  @content = open(uri, { proxy: false }).string
40
+ @pac_file = uri.to_s
41
41
  end
42
42
 
43
43
  @content
@@ -49,6 +49,7 @@ module ProxyTester
49
49
 
50
50
  def result
51
51
  return PacResult.new if content.blank?
52
+ return PacResult.new if url.blank?
52
53
 
53
54
  env_hash = {}
54
55
  env_hash[:client_ip] = client_ip if client_ip
@@ -1,4 +1,4 @@
1
1
  #main ProxyTester
2
2
  module ProxyTester
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
@@ -14,6 +14,37 @@ describe CapybaraProxyPac do
14
14
  pac = CapybaraProxyPac.new
15
15
  expect { pac.pac_file = 'asdf' }.to raise_error Exceptions::PacFileNotFound
16
16
  end
17
+
18
+ it 'handles missing url' do
19
+ pac = CapybaraProxyPac.new
20
+ pac.pac_file = create_file('proxy.pac', valid_pac_file1)
21
+ expect { pac.host }.not_to raise_error
22
+ end
23
+ end
24
+
25
+ context '#pac_file' do
26
+ let(:pac_file) { create_file 'proxy.pac', valid_pac_file1 }
27
+
28
+ it 'reads from file' do
29
+ pac = CapybaraProxyPac.new
30
+ pac.pac_file = pac_file
31
+ expect(pac.pac_file).to eq pac_file
32
+ end
33
+
34
+ it 'reads from file url' do
35
+ pac = CapybaraProxyPac.new
36
+ pac.pac_file = 'file://' + pac_file
37
+ expect(pac.pac_file).to eq pac_file
38
+ end
39
+
40
+ it 'reads from url' do
41
+ url = 'http://pac-host.example.com/proxy.pac'
42
+ stub_request(:any, url).to_return(body: valid_pac_file1)
43
+
44
+ pac = CapybaraProxyPac.new
45
+ pac.pac_file = url
46
+ expect(pac.pac_file).to eq url
47
+ end
17
48
  end
18
49
 
19
50
  context '#host' do
@@ -18,25 +18,38 @@ describe 'returns proxy matcher' do
18
18
  set_offline true
19
19
  end
20
20
 
21
- it 'checks return proxy string' do
22
- file = create_file 'proxy.pac', valid_proxy_pac
23
- use_proxy :pac, file
21
+ context 'file' do
22
+ it 'checks return proxy string' do
23
+ file = create_file 'proxy.pac', valid_proxy_pac
24
+ use_proxy :pac, file
24
25
 
25
- visit 'http://example.com'
26
- expect(proxy_pac).to return_proxy('PROXY localhost2:8080')
26
+ visit 'http://example.com'
27
+ expect(proxy_pac).to return_proxy('PROXY localhost2:8080')
27
28
 
28
- visit 'http://otherdomain.com'
29
- expect(proxy_pac).to return_proxy('DIRECT')
30
- end
29
+ visit 'http://otherdomain.com'
30
+ expect(proxy_pac).to return_proxy('DIRECT')
31
+ end
32
+
33
+ it 'checks that a proxy string is not returned' do
34
+ file = create_file 'proxy.pac', valid_proxy_pac
35
+ use_proxy :pac, file
31
36
 
32
- it 'checks that a proxy string is not returned' do
33
- file = create_file 'proxy.pac', valid_proxy_pac
34
- use_proxy :pac, file
37
+ visit 'http://example.com'
38
+ expect(proxy_pac).not_to return_proxy('DIRECT')
39
+
40
+ visit 'http://otherdomain.com'
41
+ expect(proxy_pac).not_to return_proxy('PROXY localhost2:8080')
42
+ end
43
+ end
35
44
 
36
- visit 'http://example.com'
37
- expect(proxy_pac).not_to return_proxy('DIRECT')
45
+ context 'urls' do
46
+ it 'succeeds for example.com' do
47
+ url = 'http://pac-host.example.com/proxy.pac'
48
+ stub_request(:any, url).to_return(body: valid_proxy_pac)
38
49
 
39
- visit 'http://otherdomain.com'
40
- expect(proxy_pac).not_to return_proxy('PROXY localhost2:8080')
50
+ use_proxy :pac, url
51
+ visit 'http://example.com'
52
+ expect(proxy_pac).to return_proxy('PROXY localhost2:8080')
53
+ end
41
54
  end
42
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxy_tester
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: