hiptest-publisher 1.30.0 → 1.31.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hiptest-publisher/client.rb +49 -11
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e51e585e6cfddfb427d0ce4d5ccd898d812072b5def6ada9ac19eb2ebfec7b07
4
- data.tar.gz: d23a1a44229b281b0ae4a6ab8d561923f35d99fc3bba9cd5ad546217363f2a6a
3
+ metadata.gz: 16ac0103a98c523651a2cf5bd076ef8a6193053c14bb2b09535ea83b241035c8
4
+ data.tar.gz: 911faffe0592b0f17bdff8a64d7d3e19acd118c86f58b60b1dec24446f89453d
5
5
  SHA512:
6
- metadata.gz: ecb76a6be315f0ccc199e52708fcd9df128f04d1b3c0d66fd1327d09360b5975d3414887af2950f82ebda04581e0139307a014e7d869cf1a78102d77e23c66ed
7
- data.tar.gz: 3cae8f924fefc9bc926a6cee22463f3abfbd9afc917c9ae12d51e3baecd23927ef51d654cafba4f1db7442644a8f9d975f4cf055b6ab9477974f484441ce53bf
6
+ metadata.gz: 68d9c8b314466a693c2e738d32669c52ed3001fa6789b5c5732a374fb72beb3fd7faaafe9bc81ed271b629313ef158e049109b63a4c367159f7bd6ffb3e97024
7
+ data.tar.gz: a4e6406e141313255388544c6cd7c117b1ffd76500525a184cd01f490add5842035b6ecbea04bf808e50266c3859e8cc7133d3a21ff7a5f2f91d3b99fdac73dc
@@ -12,6 +12,20 @@ module Hiptest
12
12
  class ClientError < StandardError
13
13
  end
14
14
 
15
+ class RedirectionError < StandardError
16
+ attr_reader :redirect
17
+
18
+ def initialize(msg, redirect)
19
+ @redirect = redirect
20
+ super(msg)
21
+ end
22
+ end
23
+
24
+ class MaximumRedirectionReachedError < StandardError
25
+ end
26
+
27
+ MAX_REDIRECTION = 10
28
+
15
29
  class Client
16
30
  attr_reader :cli_options
17
31
 
@@ -109,16 +123,15 @@ module Hiptest
109
123
  def push_results
110
124
  # Code from: https://github.com/nicksieger/multipart-post
111
125
  uploaded = {}
112
- Dir.glob(cli_options.push.gsub('\\', '/')).each_with_index do |filename, index|
113
- uploaded["file-#{filename.normalize}"] = UploadIO.new(File.new(filename), "text", filename)
126
+ Dir.glob(cli_options.push.gsub('\\', '/')).each do |filename|
127
+ uploaded["file-#{filename.normalize}"] = filename
114
128
  end
115
129
 
116
130
  if cli_options.global_failure_on_missing_reports && uploaded.empty?
117
131
  return send_post_request(global_failure_url)
118
132
  end
119
133
 
120
- uri = URI.parse(url)
121
- send_request(Net::HTTP::Post::Multipart.new(uri, uploaded))
134
+ send_multipart_request(url, uploaded)
122
135
  end
123
136
 
124
137
  private
@@ -178,34 +191,59 @@ module Hiptest
178
191
  "#{cli_options.site}/publication/#{cli_options.token}"
179
192
  end
180
193
 
181
- def send_get_request(url)
194
+ def send_get_request(url, attempt = MAX_REDIRECTION)
195
+ raise MaximumRedirectionReachedError if attempt < 0
196
+
182
197
  uri = URI.parse(url)
183
- response = send_request(Net::HTTP::Get.new(uri))
184
- response
198
+ send_request(Net::HTTP::Get.new(uri))
199
+ rescue RedirectionError => err
200
+ send_get_request(err.redirect, attempt - 1)
185
201
  end
186
202
 
187
- def send_post_request(url)
203
+ def send_post_request(url, attempt = MAX_REDIRECTION)
204
+ raise MaximumRedirectionReachedError if attempt < 0
205
+
188
206
  uri = URI.parse(url)
189
- response = send_request(Net::HTTP::Post.new(uri))
190
- response
207
+ send_request(Net::HTTP::Post.new(uri))
208
+ rescue RedirectionError => err
209
+ send_post_request(err.redirect, attempt - 1)
210
+ end
211
+
212
+ def send_multipart_request(url, uploaded, attempt = MAX_REDIRECTION)
213
+ raise MaximumRedirectionReachedError if attempt < 0
214
+
215
+ uri = URI.parse(url)
216
+ files = {}
217
+ uploaded.each do |fieldname, filename|
218
+ files[fieldname] = UploadIO.new(File.new(filename), "text", filename)
219
+ end
220
+
221
+ send_request(Net::HTTP::Post::Multipart.new(uri, files))
222
+ rescue RedirectionError => err
223
+ send_multipart_request(err.redirect, uploaded, attempt - 1)
191
224
  end
192
225
 
193
226
  def send_request(request)
194
227
  request["User-Agent"] = "Ruby/hiptest-publisher"
195
228
  use_ssl = request.uri.scheme == "https"
229
+
196
230
  proxy_uri = find_proxy_uri(request.uri.hostname, request.uri.port)
197
231
  if proxy_uri
198
232
  proxy_address = proxy_uri.hostname
199
233
  proxy_port = proxy_uri.port
200
234
  proxy_user, proxy_pass = proxy_uri.userinfo.split(':', 2) if proxy_uri.userinfo
201
235
  end
236
+
202
237
  Net::HTTP.start(
203
238
  request.uri.hostname, request.uri.port,
204
239
  proxy_address, proxy_port, proxy_user, proxy_pass,
205
240
  use_ssl: use_ssl,
206
241
  verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
207
242
  @reporter.show_verbose_message(I18n.t(:request_sent, uri: request.uri))
208
- http.request(request)
243
+ response = http.request(request)
244
+
245
+ raise RedirectionError.new("Got redirected", response['location']) if response.is_a?(Net::HTTPRedirection)
246
+ response
209
247
  end
210
248
  end
211
249
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiptest-publisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.30.0
4
+ version: 1.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - HipTest R&D
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-24 00:00:00.000000000 Z
11
+ date: 2019-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -754,7 +754,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
754
754
  - !ruby/object:Gem::Version
755
755
  version: '0'
756
756
  requirements: []
757
- rubygems_version: 3.0.3
757
+ rubygems_version: 3.0.4
758
758
  signing_key:
759
759
  specification_version: 4
760
760
  summary: Export your tests from HipTest into executable tests.