proxy_rb 0.2.1 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fa700a6b39f4d950941f67dfc35147b1ed88420
4
- data.tar.gz: 1a2de5927281397d6d141fbea2ed21b1ec515859
3
+ metadata.gz: f8f2ff7a132c447ec0c846e16e286c898a1221c5
4
+ data.tar.gz: f5f80b116193df7695e0b5f0e52c614f889b04bc
5
5
  SHA512:
6
- metadata.gz: 90d3e09c2e2c30bf7b64f8fad31dbea529f5043e9d6965c178b17eec16a8d991fd733e21d672bdaea84448d477f438662c2b2646e2c4cb10e5c49e37493ac5d0
7
- data.tar.gz: b63c5ca58039720f82086226a64ab566461153cace8b5b1e6a7b7743266fcc8f62f93cc514d59a364e38a2b8544485fd9dfea14199384db07f6ebc04c8542e58
6
+ metadata.gz: f837422215bb89b1e17be474ad595afaaa79173b8b3eca6b06b50f62c35229e0d2e841c14187926269660a74a7d3b251faf4729586b7d6a2c8c22957e6297e1c
7
+ data.tar.gz: ed4e7b774c23faa1738f3ed37df85caa9b3311ff5b9b745a019021bdee1176cbc2c11c2def73c0c07e7aac769810e3467026ff888bb6a99daf8eabf1a6f02bd5
data/.travis.yml CHANGED
@@ -12,3 +12,7 @@ before_install:
12
12
  - curl -o /tmp/vault.zip https://releases.hashicorp.com/vault/0.5.1/vault_0.5.1_linux_amd64.zip
13
13
  - unzip /tmp/vault.zip
14
14
  - install -D -m 0755 /tmp/vault ./bin/vault
15
+ addons:
16
+ apt:
17
+ packages:
18
+ - libwebkit-dev
data/CONTRIBUTING.md CHANGED
@@ -17,7 +17,7 @@ Here are some ways *you* can contribute:
17
17
  * by closing [issues][]
18
18
  * by reviewing patches
19
19
 
20
- [issues]: https://github.com/fedux-org/proxy_pac_rb/issues
20
+ [issues]: https://github.com/fedux-org/proxy_rb/issues
21
21
 
22
22
  ## Submitting an Issue
23
23
 
@@ -25,7 +25,7 @@ We use the [GitHub issue tracker][issues] to track bugs and features. Before
25
25
  submitting a bug report or feature request, check to make sure it hasn't
26
26
  already been submitted.
27
27
 
28
- When submitting a bug report, please include a [Gist][] that includes a *stack
28
+ When submitting a bug report, please include a [Gist][gist] that includes a *stack
29
29
  trace* and any details that may be necessary to reproduce the bug, including
30
30
  your *gem version*, *Ruby version*, and *operating system*. Ideally, a bug report
31
31
  should include a pull request with failing specs.
data/Gemfile CHANGED
@@ -4,6 +4,8 @@ source 'https://rubygems.org'
4
4
  # Specify your gem's dependencies in local_pac.gemspec
5
5
  gemspec
6
6
 
7
+ gem 'poltergeist'
8
+
7
9
  group :debug do
8
10
  gem 'pry'
9
11
  gem 'byebug'
data/README.md CHANGED
@@ -20,82 +20,59 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- ### Rspec-Integration
23
+ ### Getting started
24
24
 
25
- ```ruby
26
- require 'proxy_rb/rspec'
27
-
28
- RSpec.describe 'Infrastructure A' do
29
- describe 'proxy1' do
30
- subject { 'proxy1.example.com' }
31
-
32
- context 'request resource via http' do
33
- let(:resource) { Resource.new('http://example.com') }
34
-
35
- context 'when url is readable' do
36
- it { expect(proxy).to forward_url(resource) }
37
- end
38
-
39
- context 'when website needs to be browsed' do
40
- before(:each) { download(resource) }
41
- it { expect(resource).to have_content('Example') }
42
- end
25
+ The following steps are only a suggestion. If you normally use a different
26
+ workflow, this is ok. Just make sure, that the `proxy_rb/rspec`-file is
27
+ required by `spec/spec_helper.rb` directly or indirectly.
43
28
 
44
- context 'when proxy authentication is needed' do
45
- let(:user) { ProxyUser.new(name: 'user1') }
46
- before(:each) { download(resource) }
29
+ *Initialize RSpec*
47
30
 
48
- it { expect(resource).to have_content('Example') }
49
- end
50
-
51
- context 'when upload uses post http method' do
52
- let(:data) { 'data' }
53
- before(:each) { upload(resource, data) }
31
+ ~~~bash
32
+ bundle exec rspec --init
33
+ ~~~
54
34
 
55
- it { expect(resource).to have_content('Example') }
56
- end
35
+ *Modify "spec/spec_helper.rb"*
57
36
 
58
- context 'when upload uses put http method' do
59
- let(:data) { 'data' }
60
- before(:each) { upload(resource, data, method: 'put') }
37
+ Add the following lines.
61
38
 
62
- it { expect(resource).to have_content('Example') }
63
- end
64
- end
39
+ ~~~ruby
40
+ # Loading support files
41
+ Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require_relative f }
42
+ Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require_relative f }
43
+ ~~~
65
44
 
66
- context 'request resource via https' do
67
- let(:resource) { Resource.new('https://example.com') }
68
- end
45
+ *Load library*
69
46
 
70
- context 'request resource via ftp' do
71
- let(:resource) { Resource.new('ftp://example.com/file.txt') }
47
+ Create a file named `spec/support/proxy_rb.rb`.
72
48
 
73
- context 'when website needs to be browsed' do
74
- before(:each) { download(resource) }
75
- it { expect(resource).to have_content('Example') }
76
- end
49
+ ~~~ruby
50
+ require 'proxy_rb/rspec'
51
+ ~~~
77
52
 
78
- context 'when url is readable' do
79
- it { expect(proxy).to forward_url(resource) }
80
- end
53
+ *Create first Tests*
81
54
 
82
- context 'when authentication is needed' do
83
- let(:user) { ProxyUser.new(name: 'user1') }
84
- before(:each) { download(resource) }
55
+ Create a file named `spec/test_spec.rb`.
85
56
 
86
- it { expect(resource).to have_content('Example') }
87
- end
57
+ ~~~ruby
58
+ require 'spec_helper'
88
59
 
89
- context 'when upload' do
90
- let(:data) { File.open('file.txt') }
91
- before(:each) { upload(resource, data) }
60
+ RSpec.describe 'My Proxy' do
61
+ describe 'Production' do
62
+ subject { 'http://localhost:8080' }
92
63
 
93
- it { expect(resource).to have_content('Example') }
94
- end
64
+ before :each do
65
+ visit 'http://example.com'
95
66
  end
67
+
68
+ it { expect(request).to be_successful }
96
69
  end
97
70
  end
98
- ```
71
+ ~~~
72
+
73
+ ### Getting on with "proxy_rb"
74
+
75
+ Please have a look at our "feature"-files found [here](features/).
99
76
 
100
77
  ### Authentication
101
78
 
@@ -105,6 +82,12 @@ Please have a look at
105
82
  ["features/authentication.feature"](features/authentication.feature) for
106
83
  detailed information.
107
84
 
85
+ ### Driver
86
+
87
+ You can choose between two drivers to sent your requests: "Poltergeist" and
88
+ "Webkit". Please have a look at
89
+ ["features/drivers.feature"](features/drivers.feature) for detailed
90
+ information.
108
91
 
109
92
  ## Development
110
93
 
@@ -130,8 +113,8 @@ export PATH=~/bin:$PATH
130
113
 
131
114
  ### Scripts
132
115
 
133
- After checking out the repo, run `script/bootstrap` to install dependencies.
134
- Then, run `script/console` for an interactive prompt that will allow you to
116
+ After checking out the repo, run `bin/bootstrap` to install dependencies.
117
+ Then, run `bin/console` for an interactive prompt that will allow you to
135
118
  experiment.
136
119
 
137
120
  To install this gem onto your local machine, run `bundle exec rake gem:install`. To
@@ -139,11 +122,3 @@ release a new version, update the version number in `version.rb`, and then run
139
122
  `bundle exec rake gem:release` to create a git tag for the version, push git
140
123
  commits and tags, and push the `.gem` file to
141
124
  [rubygems.org](https://rubygems.org).
142
-
143
- ## Contributing
144
-
145
- 1. Fork it ( https://github.com/[my-github-username]/proxy_rb/fork )
146
- 2. Create your feature branch (`git checkout -b my-new-feature`)
147
- 3. Commit your changes (`git commit -am 'Add some feature'`)
148
- 4. Push to the branch (`git push origin my-new-feature`)
149
- 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env rake
2
2
  # frozen_string_literal: true
3
3
 
4
- namespace :gems do
4
+ namespace :gem do
5
5
  require 'bundler/gem_tasks'
6
6
  end
7
7
 
@@ -8,6 +8,8 @@ require 'proxy_rb/basic_configuration/in_config_wrapper'
8
8
  require 'proxy_rb/password_fetchers/basic_password_fetcher'
9
9
  require 'proxy_rb/password_fetchers/environment_password_fetcher'
10
10
 
11
+ require 'proxy_rb/drivers/webkit_driver'
12
+
11
13
  # ProxyRb
12
14
  module ProxyRb
13
15
  # ProxyRb Configuration
@@ -15,6 +17,7 @@ module ProxyRb
15
17
  # This defines the configuration options of proxy_rb
16
18
  class Configuration < BasicConfiguration
17
19
  option_accessor :password_fetcher, contract: { PasswordFetchers::BasicPasswordFetcher => PasswordFetchers::BasicPasswordFetcher }, default: ProxyRb::PasswordFetchers::EnvironmentPasswordFetcher.new(prefix: 'SECRET')
20
+ option_accessor :driver, contract: { Drivers::BasicDriver => Drivers::BasicDriver }, default: ProxyRb::Drivers::WebkitDriver.new
18
21
  end
19
22
  end
20
23
 
@@ -5,13 +5,7 @@ require 'shellwords'
5
5
  module ProxyRb
6
6
  # Hold proxy credentials
7
7
  class Credentials
8
- protected
9
-
10
- attr_reader :password
11
-
12
- public
13
-
14
- attr_reader :user_name
8
+ attr_reader :user_name, :password
15
9
 
16
10
  # @param [String] user_name
17
11
  # The user name to use for authentication against proxy
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ # ProxyRb
3
+ module ProxyRb
4
+ # Drivers
5
+ module Drivers
6
+ # Basic Driver
7
+ class BasicDriver
8
+ # Configure driver
9
+ def configure_driver
10
+ ::Capybara.run_server = false
11
+ end
12
+
13
+ # Register proxy
14
+ def register(_proxy)
15
+ raise NoMethodError, 'You need to implement this in your driver'
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+ require 'proxy_rb/drivers/basic_driver'
3
+ require 'capybara'
4
+
5
+ begin
6
+ require 'capybara/poltergeist'
7
+ rescue LoadError
8
+ ProxyRb.logger.error %(Error loading `poltergeist`-gem. Please add `gem poltergeist` to your `Gemfile`)
9
+ exit 1
10
+ end
11
+
12
+ # ProxyRb
13
+ module ProxyRb
14
+ # Drivers
15
+ module Drivers
16
+ # Driver for Poltergeist
17
+ class PoltergeistDriver < BasicDriver
18
+ # Register proxy
19
+ #
20
+ # @param [HttpProxy] proxy
21
+ # The HTTP proxy which should be used for fetching content
22
+ def register(proxy)
23
+ if proxy.empty?
24
+ ::Capybara.current_driver = :poltergeist
25
+ return
26
+ end
27
+
28
+ cli_parameters = []
29
+ cli_parameters << "--proxy=#{proxy.url}" unless proxy.url.empty?
30
+ cli_parameters << "--proxy-auth=#{proxy.credentials}" unless proxy.credentials.empty?
31
+
32
+ options = {
33
+ phantomjs_options: cli_parameters,
34
+ js_errors: false,
35
+ phantomjs_logger: $stderr
36
+ }
37
+
38
+ unless ::Capybara.drivers.key? proxy.to_ref
39
+ ::Capybara.register_driver proxy.to_ref do |app|
40
+ ::Capybara::Poltergeist::Driver.new(app, options)
41
+ end
42
+ end
43
+
44
+ ::Capybara.current_driver = proxy.to_ref
45
+ end
46
+
47
+ def rescuable_errors
48
+ [::Capybara::Poltergeist::TimeoutError]
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+ require 'proxy_rb/drivers/basic_driver'
3
+
4
+ begin
5
+ require 'capybara/webkit'
6
+ rescue LoadError
7
+ ProxyRb.logger.error %(Error loading `capybara-webkit`-gem. Please add `gem capybara-webkit` to your `Gemfile`)
8
+ exit 1
9
+ end
10
+
11
+ # rubocop:disable Style/SymbolProc
12
+ ::Capybara::Webkit.configure do |config|
13
+ config.allow_unknown_urls
14
+ end
15
+ # rubocop:enable Style/SymbolProc
16
+
17
+ # ProxyRb
18
+ module ProxyRb
19
+ # Drivers
20
+ module Drivers
21
+ # Driver for Capybara-Webkit
22
+ class WebkitDriver < BasicDriver
23
+ # Register proxy
24
+ #
25
+ # @param [HttpProxy] proxy
26
+ # The HTTP proxy which should be used for fetching content
27
+ def register(proxy)
28
+ if proxy.empty?
29
+ ::Capybara.current_driver = :webkit
30
+ return
31
+ end
32
+
33
+ options = {
34
+ proxy: {
35
+ host: proxy.host,
36
+ port: proxy.port,
37
+ user: proxy.user,
38
+ pass: proxy.password
39
+ }
40
+ }
41
+
42
+ unless ::Capybara.drivers.key? proxy.to_ref
43
+ ::Capybara.register_driver proxy.to_ref do |app|
44
+ ::Capybara::Webkit::Driver.new(app, Capybara::Webkit::Configuration.to_hash.merge(options))
45
+ end
46
+ end
47
+
48
+ ::Capybara.current_driver = proxy.to_ref
49
+ end
50
+
51
+ def rescuable_errors
52
+ [::Capybara::Webkit::TimeoutError]
53
+ end
54
+ end
55
+ end
56
+ end
@@ -8,45 +8,39 @@ require 'proxy_rb/proxy_url_parser'
8
8
  module ProxyRb
9
9
  # Represent proxy
10
10
  class HttpProxy
11
- protected
12
-
13
11
  attr_reader :url, :credentials
14
12
 
15
- public
16
-
17
13
  def initialize(parser)
18
14
  @url = parser.proxy_url
19
15
  @credentials = parser.credentials
20
16
  end
21
17
 
22
- # Convert to parameters for PhantomJS
23
- #
24
- # @return [Array]
25
- # An array of parameters for PhantomJS
26
- def to_phantom_js
27
- result = []
28
- result << "--proxy=#{url}" unless url.empty?
29
- result << "--proxy-auth=#{credentials}" unless credentials.empty?
30
-
31
- result
18
+ def host
19
+ url.host
32
20
  end
33
21
 
34
- # Convert to symbol to reference the proxy
35
- #
36
- # @return [Symbol]
37
- # <host>_<port>_<credentials>
38
- def to_sym
39
- Shellwords.escape(*[host, port, credentials.user_name].compact.join('_')).to_sym
22
+ def port
23
+ url.port
40
24
  end
41
25
 
42
- private
26
+ def user
27
+ credentials.user_name
28
+ end
43
29
 
44
- def host
45
- url.host
30
+ def password
31
+ credentials.password
46
32
  end
47
33
 
48
- def port
49
- url.port
34
+ def empty?
35
+ host.nil? || host.empty?
36
+ end
37
+
38
+ # Convert to symbol to reference the proxy
39
+ #
40
+ # @return [Symbol]
41
+ # <host>_<port>_<credentials>
42
+ def to_ref
43
+ Shellwords.escape(*[host, port, user].compact.join('_')).to_sym
50
44
  end
51
45
  end
52
46
  end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
1
2
  # No proxy
2
3
  class NoProxy
3
4
  def self.to_s
4
- ""
5
+ ''
5
6
  end
6
7
 
7
8
  def self.nil?
@@ -21,6 +22,6 @@ class NoProxy
21
22
  end
22
23
 
23
24
  def to_s
24
- ""
25
+ ''
25
26
  end
26
27
  end
@@ -24,7 +24,16 @@ module ProxyRb
24
24
  # @return [ProxyUrl]
25
25
  # The parsed url
26
26
  def self.parse(string)
27
- new(Addressable::URI.heuristic_parse(string.to_s))
27
+ string = string.to_s
28
+ string = if string.empty?
29
+ string
30
+ elsif string.start_with?('http://')
31
+ string
32
+ else
33
+ 'http://' + string
34
+ end
35
+
36
+ new(Addressable::URI.heuristic_parse(string))
28
37
  end
29
38
 
30
39
  protected
@@ -46,7 +55,7 @@ module ProxyRb
46
55
  end
47
56
 
48
57
  def to_s
49
- return "" if empty?
58
+ return '' if empty?
50
59
 
51
60
  url.to_s
52
61
  end
@@ -21,9 +21,13 @@ module ProxyRb
21
21
  page.status_code.to_s.start_with?('2', '3')
22
22
  end
23
23
 
24
- # def forbidden?
25
- # page.status_code == 403
26
- # end
24
+ # The request is forbidden
25
+ #
26
+ # @return [TrueClass, FalseClass]
27
+ # The result
28
+ def forbidden?
29
+ page.status_code == 403
30
+ end
27
31
 
28
32
  # def invalid?
29
33
  # page.status_code == 401
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- require 'capybara/poltergeist'
3
2
 
4
3
  require 'proxy_rb'
5
4
  require 'proxy_rb/resource'
@@ -28,19 +27,12 @@ module ProxyRb
28
27
  ).each { |v| ENV.delete v }
29
28
  end
30
29
 
31
- def register_capybara_driver_for_proxy(proxy)
32
- options = {
33
- phantomjs_options: proxy.to_phantom_js,
34
- js_errors: false,
35
- phantomjs_logger: $stderr
36
- }
37
-
38
- ::Capybara.register_driver proxy.to_sym do |app|
39
- ::Capybara::Poltergeist::Driver.new(app, options)
40
- end
30
+ def configure_driver
31
+ ProxyRb.config.driver.configure_driver
32
+ end
41
33
 
42
- ::Capybara.run_server = false
43
- ::Capybara.current_driver = proxy.to_sym
34
+ def register_capybara_driver_for_proxy(proxy)
35
+ ProxyRb.config.driver.register proxy
44
36
  end
45
37
  end
46
38
  end
@@ -61,11 +53,12 @@ module ProxyRb
61
53
  resource = Resource.new(url)
62
54
 
63
55
  NonIncludes.clear_environment
56
+ NonIncludes.configure_driver
64
57
  NonIncludes.register_capybara_driver_for_proxy(proxy)
65
58
 
66
59
  begin
67
60
  super(resource.to_url)
68
- rescue ::Capybara::Poltergeist::TimeoutError
61
+ rescue *ProxyRb.config.driver.rescuable_errors
69
62
  raise ProxyRb::UrlTimeoutError, "Failed to fetch #{resource.to_url}: Timeout occured."
70
63
  end
71
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  # Main Module
3
3
  module ProxyRb
4
- VERSION = '0.2.1'.freeze
4
+ VERSION = '0.3.0'
5
5
  end
data/proxy_rb.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency 'rake', '~> 10.0'
23
23
 
24
24
  spec.add_runtime_dependency 'capybara'
25
- spec.add_runtime_dependency 'poltergeist'
25
+ spec.add_runtime_dependency 'capybara-webkit'
26
26
 
27
27
  spec.add_runtime_dependency 'addressable'
28
28
  spec.add_runtime_dependency 'contracts'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxy_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Meyer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-29 00:00:00.000000000 Z
11
+ date: 2016-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: poltergeist
56
+ name: capybara-webkit
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -147,7 +147,6 @@ files:
147
147
  - fixtures/proxy-config/.rspec
148
148
  - fixtures/proxy-config/README.md
149
149
  - fixtures/proxy-config/Rakefile
150
- - fixtures/proxy-config/bin/http_server
151
150
  - fixtures/proxy-config/spec/spec_helper.rb
152
151
  - fixtures/proxy-config/spec/support/aruba.rb
153
152
  - fixtures/proxy-config/spec/support/proxy_rb.rb
@@ -157,6 +156,9 @@ files:
157
156
  - lib/proxy_rb/basic_configuration/option.rb
158
157
  - lib/proxy_rb/configuration.rb
159
158
  - lib/proxy_rb/credentials.rb
159
+ - lib/proxy_rb/drivers/basic_driver.rb
160
+ - lib/proxy_rb/drivers/poltergeist_driver.rb
161
+ - lib/proxy_rb/drivers/webkit_driver.rb
160
162
  - lib/proxy_rb/errors.rb
161
163
  - lib/proxy_rb/http_downloader.rb
162
164
  - lib/proxy_rb/http_proxy.rb
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'webrick'
5
-
6
- server = WEBrick::HTTPServer.new(
7
- Port: 8000
8
- )
9
-
10
- server.mount_proc '/' do |_req, res|
11
- res.body = 'Example Domain'
12
- end
13
-
14
- server.start