webdrivers 3.2.0 → 3.2.1

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: 2aa8499f7225e17c17d4653cfcdbb5d0387805fa
4
- data.tar.gz: 8036fcb9040fc3852a04f6d4ec0dc688fa6ce8ff
3
+ metadata.gz: 9d9e5fa3b0bb58f58355559ad96a2915d089aeea
4
+ data.tar.gz: 9bed1f9723c15044589a1e514db681fa28190f47
5
5
  SHA512:
6
- metadata.gz: 3b87bb262f00d419f4eb347582dc93d689484ccabc189433b2631d0d21b4a0e419ba2a6b4f7b94b38ce6b181f95b952c92064cea96128d2500ccac204893c8bd
7
- data.tar.gz: 036b3660764a74fc2daa9cf5162c0d6f5aeda2c154a9cf59d675448c73b982d22316f5ecb2b9242a32edaf11c836b01651f6d1867903ae4f18deb1323b7106d2
6
+ metadata.gz: 22d871b657056542a63a7f8a336b2d2877a5426ea291ca23bb3c2d1fa01a9992015da95a49860276f7d563e079eb960ee7ead2f423df591bd646c92ab67c8086
7
+ data.tar.gz: ac8b1ba73a0c7e037419d13ddb3d18d77179265584d907001a1e14736544863b3dab6b1a72626c1399f1a961696c2c60a27943138f0a93fd83653c37a74946bc
@@ -1,3 +1,7 @@
1
+ ### 3.2.1 (2017-09-06)
2
+
3
+ * Fixed Proxy support so it actually works (thanks Cheezy)
4
+
1
5
  ### 3.2.0 (2017-08-21)
2
6
 
3
7
  * Implemented Proxy support
data/README.md CHANGED
@@ -24,7 +24,19 @@ in your Gemfile:
24
24
 
25
25
  in your project:
26
26
 
27
- `require 'webdrivers'`
27
+ `require 'webdrivers'
28
+
29
+ If there is a proxy between you and the Internet then you will need to configure
30
+ the gem to use the proxy. You can do this by calling the `configure` method.
31
+
32
+ ````ruby
33
+ Webdrivers.configure do |config|
34
+ config.proxy_addr = 'myproxy_address.com'
35
+ config.proxy_port = '8080'
36
+ config.proxy_user = 'username'
37
+ config.proxy_pass = 'password'
38
+ end
39
+ ````
28
40
 
29
41
  # License
30
42
 
@@ -7,7 +7,17 @@ require "webdrivers/iedriver"
7
7
  require "webdrivers/mswebdriver"
8
8
 
9
9
  module Webdrivers
10
- def self.logger
11
- @logger ||= Webdrivers::Logger.new
10
+
11
+ class << self
12
+
13
+ attr_accessor :proxy_addr, :proxy_port, :proxy_user, :proxy_pass
14
+
15
+ def logger
16
+ @logger ||= Webdrivers::Logger.new
17
+ end
18
+
19
+ def configure
20
+ yield self
21
+ end
12
22
  end
13
23
  end
@@ -31,7 +31,7 @@ module Webdrivers
31
31
  Webdrivers.logger.debug "Versions previously located on downloads site: #{@downloads.keys}" if @downloads
32
32
 
33
33
  @downloads ||= begin
34
- doc = Nokogiri::XML.parse(OpenURI.open_uri(base_url, proxy_opt))
34
+ doc = Nokogiri::XML.parse(get(base_url))
35
35
  items = doc.css("Contents Key").collect(&:text)
36
36
  items.select! {|item| item.include?(platform)}
37
37
  ds = items.each_with_object({}) do |item, hash|
@@ -1,5 +1,4 @@
1
1
  require 'rubygems/package'
2
- require 'open-uri'
3
2
  require 'zip'
4
3
 
5
4
  module Webdrivers
@@ -31,7 +30,7 @@ module Webdrivers
31
30
  Dir.chdir install_dir do
32
31
  FileUtils.rm_f filename
33
32
  open(filename, "wb") do |file|
34
- file.print open(url, proxy_opt, &:read)
33
+ file.print get(url)
35
34
  end
36
35
  raise "Could not download #{url}" unless File.exists? filename
37
36
  Webdrivers.logger.debug "Successfully downloaded #{filename}"
@@ -52,20 +51,37 @@ module Webdrivers
52
51
  binary
53
52
  end
54
53
 
55
- private
54
+ protected
55
+
56
+ def get(url, limit = 10)
57
+ raise StandardError, 'Too many HTTP redirects' if limit == 0
58
+
59
+ response = http.get_response(URI(url))
60
+
61
+ case response
62
+ when Net::HTTPSuccess then
63
+ response.body
64
+ when Net::HTTPRedirection
65
+ location = response['location']
66
+ Webdrivers.logger.debug "Redirected to #{location}"
67
+ get(location, limit - 1)
68
+ else
69
+ response.value
70
+ end
71
+ end
56
72
 
57
- def proxy_opt
58
- proxy_uri = ENV['WD_PROXY_URI']
59
- proxy_user = ENV['WD_PROXY_USER']
60
- proxy_pass = ENV['WD_PROXY_PASS']
61
-
62
- if proxy_uri && proxy_user
63
- {proxy_http_basic_authentication: [proxy_uri, proxy_user, proxy_pass]}
64
- elsif proxy_uri
65
- {proxy: proxy_uri}
66
- else
67
- {}
73
+ def http
74
+ if using_proxy
75
+ return Net::HTTP.Proxy(Webdrivers.proxy_addr, Webdrivers.proxy_port,
76
+ Webdrivers.proxy_user, Webdrivers.proxy_pass)
68
77
  end
78
+ return Net::HTTP
79
+ end
80
+
81
+ private
82
+
83
+ def using_proxy
84
+ Webdrivers.proxy_addr && Webdrivers.proxy_port
69
85
  end
70
86
 
71
87
  def download_url(version)
@@ -84,7 +100,7 @@ module Webdrivers
84
100
 
85
101
  # TODO - specify what gets rescued
86
102
  def site_available?
87
- open(base_url)
103
+ get(base_url)
88
104
  Webdrivers.logger.debug "Found Site: #{base_url}"
89
105
  true
90
106
  rescue
@@ -95,30 +111,30 @@ module Webdrivers
95
111
  def platform
96
112
  cfg = RbConfig::CONFIG
97
113
  case cfg['host_os']
98
- when /linux/
99
- cfg['host_cpu'] =~ /x86_64|amd64/ ? "linux64" : "linux32"
100
- when /darwin/
101
- "mac"
102
- else
103
- "win"
114
+ when /linux/
115
+ cfg['host_cpu'] =~ /x86_64|amd64/ ? "linux64" : "linux32"
116
+ when /darwin/
117
+ "mac"
118
+ else
119
+ "win"
104
120
  end
105
121
  end
106
122
 
107
123
  def decompress_file(filename)
108
124
  case filename
109
- when /tar\.gz$/
110
- Webdrivers.logger.debug "Decompressing tar"
111
- untargz_file(filename)
112
- when /tar\.bz2$/
113
- Webdrivers.logger.debug "Decompressing bz2"
114
- system "tar xjf #{filename}"
115
- filename.gsub('.tar.bz2', '')
116
- when /\.zip$/
117
- Webdrivers.logger.debug "Decompressing zip"
118
- unzip_file(filename)
119
- else
120
- Webdrivers.logger.debug "No Decompression needed"
121
- nil
125
+ when /tar\.gz$/
126
+ Webdrivers.logger.debug "Decompressing tar"
127
+ untargz_file(filename)
128
+ when /tar\.bz2$/
129
+ Webdrivers.logger.debug "Decompressing bz2"
130
+ system "tar xjf #{filename}"
131
+ filename.gsub('.tar.bz2', '')
132
+ when /\.zip$/
133
+ Webdrivers.logger.debug "Decompressing zip"
134
+ unzip_file(filename)
135
+ else
136
+ Webdrivers.logger.debug "No Decompression needed"
137
+ nil
122
138
  end
123
139
  end
124
140
 
@@ -23,7 +23,7 @@ module Webdrivers
23
23
  Webdrivers.logger.debug "Versions previously located on downloads site: #{@downloads.keys}" if @downloads
24
24
 
25
25
  @downloads ||= begin
26
- doc = Nokogiri::XML.parse(OpenURI.open_uri(base_url, proxy_opt))
26
+ doc = Nokogiri::XML.parse(get(base_url))
27
27
  items = doc.css(".release-downloads a").collect {|item| item["href"]}
28
28
  items.reject! {|item| item.include?('archive')}
29
29
  items.select! {|item| item.include?(platform)}
@@ -31,7 +31,7 @@ module Webdrivers
31
31
  Webdrivers.logger.debug "Versions previously located on downloads site: #{@downloads.keys}" if @downloads
32
32
 
33
33
  @downloads ||= begin
34
- doc = Nokogiri::XML.parse(OpenURI.open_uri(base_url, proxy_opt))
34
+ doc = Nokogiri::XML.parse(get(base_url))
35
35
  items = doc.css("Key").collect(&:text)
36
36
  items.select! { |item| item.include?('IEDriverServer_Win32') }
37
37
  ds = items.each_with_object({}) do |item, hash|
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ class FakeDriver < Webdrivers::Common
4
+ def self.http_object
5
+ self.http
6
+ end
7
+ end
8
+
9
+ describe "Support for proxies" do
10
+ let(:http_object) { FakeDriver.http_object }
11
+
12
+ before do
13
+ Webdrivers.proxy_addr = nil
14
+ Webdrivers.proxy_port = nil
15
+ Webdrivers.proxy_user = nil
16
+ Webdrivers.proxy_pass = nil
17
+ end
18
+
19
+ it 'should allow the proxy values to be set via configuration' do
20
+ Webdrivers.configure do |config|
21
+ config.proxy_addr = 'proxy_addr'
22
+ config.proxy_port = '8888'
23
+ config.proxy_user = 'proxy_user'
24
+ config.proxy_pass = 'proxy_pass'
25
+ end
26
+
27
+ expect(Webdrivers.proxy_addr).to eql 'proxy_addr'
28
+ expect(Webdrivers.proxy_port).to eql '8888'
29
+ expect(Webdrivers.proxy_user).to eql 'proxy_user'
30
+ expect(Webdrivers.proxy_pass).to eql 'proxy_pass'
31
+ end
32
+
33
+ it 'should use the Proxy when the proxy_addr is set' do
34
+ Webdrivers.configure do |config|
35
+ config.proxy_addr = 'proxy_addr'
36
+ config.proxy_port = '8080'
37
+ end
38
+
39
+ expect(http_object.instance_variable_get('@is_proxy_class')).to be true
40
+ end
41
+
42
+ it 'should not use the Proxy when proxy is not configured' do
43
+ expect(http_object.instance_variable_get('@is_proxy_class')).to be false
44
+ end
45
+ end
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "webdrivers"
6
- s.version = "3.2.0"
6
+ s.version = "3.2.1"
7
7
  s.authors = ["Titus Fortner"]
8
8
  s.email = ["titusfortner@gmail.com"]
9
9
  s.homepage = "https://github.com/titusfortner/webdrivers"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webdrivers
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Titus Fortner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-21 00:00:00.000000000 Z
11
+ date: 2017-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -107,6 +107,7 @@ files:
107
107
  - spec/geckodriver_spec.rb
108
108
  - spec/iedriver_spec.rb
109
109
  - spec/mswebdriver_spec.rb
110
+ - spec/proxy_support_spec.rb
110
111
  - spec/spec_helper.rb
111
112
  - webdrivers.gemspec
112
113
  homepage: https://github.com/titusfortner/webdrivers
@@ -138,4 +139,5 @@ test_files:
138
139
  - spec/geckodriver_spec.rb
139
140
  - spec/iedriver_spec.rb
140
141
  - spec/mswebdriver_spec.rb
142
+ - spec/proxy_support_spec.rb
141
143
  - spec/spec_helper.rb