summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_remote_fetcher.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rubygems/test_gem_remote_fetcher.rb')
-rw-r--r--test/rubygems/test_gem_remote_fetcher.rb497
1 files changed, 253 insertions, 244 deletions
diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb
index fa82a117a1..e71b2f5ff6 100644
--- a/test/rubygems/test_gem_remote_fetcher.rb
+++ b/test/rubygems/test_gem_remote_fetcher.rb
@@ -1,15 +1,16 @@
# frozen_string_literal: true
-require_relative 'helper'
-require 'webrick'
-require 'webrick/https' if Gem::HAVE_OPENSSL
+require_relative "helper"
+
+require "webrick"
+require "webrick/https" if Gem::HAVE_OPENSSL
unless Gem::HAVE_OPENSSL
- warn 'Skipping Gem::RemoteFetcher tests. openssl not found.'
+ warn "Skipping Gem::RemoteFetcher tests. openssl not found."
end
-require 'rubygems/remote_fetcher'
-require 'rubygems/package'
+require "rubygems/remote_fetcher"
+require "rubygems/package"
# = Testing Proxy Settings
#
@@ -28,7 +29,7 @@ require 'rubygems/package'
class TestGemRemoteFetcher < Gem::TestCase
include Gem::DefaultUserInteraction
- SERVER_DATA = <<-EOY.freeze
+ SERVER_DATA = <<-EOY
--- !ruby/object:Gem::Cache
gems:
rake-0.4.11: !ruby/object:Gem::Specification
@@ -69,7 +70,7 @@ gems:
dependencies: []
EOY
- PROXY_DATA = SERVER_DATA.gsub(/0.4.11/, '0.4.2')
+ PROXY_DATA = SERVER_DATA.gsub(/0.4.11/, "0.4.2")
# Generated via:
# x = OpenSSL::PKey::DH.new(2048) # wait a while...
@@ -104,11 +105,11 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
@cache_dir = File.join @gemhome, "cache"
# TODO: why does the remote fetcher need it written to disk?
- @a1, @a1_gem = util_gem 'a', '1' do |s|
- s.executables << 'a_bin'
+ @a1, @a1_gem = util_gem "a", "1" do |s|
+ s.executables << "a_bin"
end
- @a1.loaded_from = File.join(@gemhome, 'specifications', @a1.full_name)
+ @a1.loaded_from = File.join(@gemhome, "specifications", @a1.full_name)
Gem::RemoteFetcher.fetcher = nil
@stub_ui = Gem::MockGemUi.new
@@ -130,7 +131,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
end
def test_self_fetcher_with_proxy
- proxy_uri = 'http://proxy.example.com'
+ proxy_uri = "http://proxy.example.com"
Gem.configuration[:http_proxy] = proxy_uri
Gem::RemoteFetcher.fetcher = nil
@@ -149,34 +150,34 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
@fetcher.fetch_path("gems.example.com/yaml", nil, true)
end
- assert_equal 'uri scheme is invalid: nil', e.message
+ assert_equal "uri scheme is invalid: nil", e.message
end
def test_no_proxy
use_ui @stub_ui do
assert_data_from_server @fetcher.fetch_path(@server_uri)
response = @fetcher.fetch_path(@server_uri, nil, true)
- assert_equal SERVER_DATA.size, response['content-length'].to_i
+ assert_equal SERVER_DATA.size, response["content-length"].to_i
end
end
def test_cache_update_path
- uri = URI 'http://example/file'
- path = File.join @tempdir, 'file'
+ uri = Gem::URI "http://example/file"
+ path = File.join @tempdir, "file"
- fetcher = util_fuck_with_fetcher 'hello'
+ fetcher = util_fuck_with_fetcher "hello"
data = fetcher.cache_update_path uri, path
- assert_equal 'hello', data
+ assert_equal "hello", data
- assert_equal 'hello', File.read(path)
+ assert_equal "hello", File.read(path)
end
def test_cache_update_path_with_utf8_internal_encoding
- with_internal_encoding('UTF-8') do
- uri = URI 'http://example/file'
- path = File.join @tempdir, 'file'
+ with_internal_encoding("UTF-8") do
+ uri = Gem::URI "http://example/file"
+ path = File.join @tempdir, "file"
data = String.new("\xC8").force_encoding(Encoding::BINARY)
fetcher = util_fuck_with_fetcher data
@@ -189,14 +190,14 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
end
def test_cache_update_path_no_update
- uri = URI 'http://example/file'
- path = File.join @tempdir, 'file'
+ uri = Gem::URI "http://example/file"
+ path = File.join @tempdir, "file"
- fetcher = util_fuck_with_fetcher 'hello'
+ fetcher = util_fuck_with_fetcher "hello"
data = fetcher.cache_update_path uri, path, false
- assert_equal 'hello', data
+ assert_equal "hello", data
assert_path_not_exist path
end
@@ -205,12 +206,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
fetcher = Gem::RemoteFetcher.fetcher
fetcher.instance_variable_set :@test_data, data
- unless blow
- def fetcher.fetch_path(arg, *rest)
- @test_arg = arg
- @test_data
- end
- else
+ if blow
def fetcher.fetch_path(arg, *rest)
# OMG I'm such an ass
class << self; remove_method :fetch_path; end
@@ -219,7 +215,12 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
@test_data
end
- raise Gem::RemoteFetcher::FetchError.new("haha!", '')
+ raise Gem::RemoteFetcher::FetchError.new("haha!", "")
+ end
+ else
+ def fetcher.fetch_path(arg, *rest)
+ @test_arg = arg
+ @test_data
end
end
@@ -228,14 +229,14 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_download
a1_data = nil
- File.open @a1_gem, 'rb' do |fp|
+ File.open @a1_gem, "rb" do |fp|
a1_data = fp.read
end
fetcher = util_fuck_with_fetcher a1_data
a1_cache_gem = @a1.cache_file
- assert_equal a1_cache_gem, fetcher.download(@a1, 'http://gems.example.com')
+ assert_equal a1_cache_gem, fetcher.download(@a1, "http://gems.example.com")
assert_equal("http://gems.example.com/gems/a-1.gem",
fetcher.instance_variable_get(:@test_arg).to_s)
assert File.exist?(a1_cache_gem)
@@ -243,14 +244,14 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_download_with_auth
a1_data = nil
- File.open @a1_gem, 'rb' do |fp|
+ File.open @a1_gem, "rb" do |fp|
a1_data = fp.read
end
fetcher = util_fuck_with_fetcher a1_data
a1_cache_gem = @a1.cache_file
- assert_equal a1_cache_gem, fetcher.download(@a1, 'http://user:password@gems.example.com')
+ assert_equal a1_cache_gem, fetcher.download(@a1, "http://user:password@gems.example.com")
assert_equal("http://user:password@gems.example.com/gems/a-1.gem",
fetcher.instance_variable_get(:@test_arg).to_s)
assert File.exist?(a1_cache_gem)
@@ -258,14 +259,14 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_download_with_token
a1_data = nil
- File.open @a1_gem, 'rb' do |fp|
+ File.open @a1_gem, "rb" do |fp|
a1_data = fp.read
end
fetcher = util_fuck_with_fetcher a1_data
a1_cache_gem = @a1.cache_file
- assert_equal a1_cache_gem, fetcher.download(@a1, 'http://token@gems.example.com')
+ assert_equal a1_cache_gem, fetcher.download(@a1, "http://token@gems.example.com")
assert_equal("http://token@gems.example.com/gems/a-1.gem",
fetcher.instance_variable_get(:@test_arg).to_s)
assert File.exist?(a1_cache_gem)
@@ -273,14 +274,14 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_download_with_x_oauth_basic
a1_data = nil
- File.open @a1_gem, 'rb' do |fp|
+ File.open @a1_gem, "rb" do |fp|
a1_data = fp.read
end
fetcher = util_fuck_with_fetcher a1_data
a1_cache_gem = @a1.cache_file
- assert_equal a1_cache_gem, fetcher.download(@a1, 'http://token:x-oauth-basic@gems.example.com')
+ assert_equal a1_cache_gem, fetcher.download(@a1, "http://token:x-oauth-basic@gems.example.com")
assert_equal("http://token:x-oauth-basic@gems.example.com/gems/a-1.gem",
fetcher.instance_variable_get(:@test_arg).to_s)
assert File.exist?(a1_cache_gem)
@@ -288,14 +289,14 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_download_with_encoded_auth
a1_data = nil
- File.open @a1_gem, 'rb' do |fp|
+ File.open @a1_gem, "rb" do |fp|
a1_data = fp.read
end
fetcher = util_fuck_with_fetcher a1_data
a1_cache_gem = @a1.cache_file
- assert_equal a1_cache_gem, fetcher.download(@a1, 'http://user:%25pas%25sword@gems.example.com')
+ assert_equal a1_cache_gem, fetcher.download(@a1, "http://user:%25pas%25sword@gems.example.com")
assert_equal("http://user:%25pas%25sword@gems.example.com/gems/a-1.gem",
fetcher.instance_variable_get(:@test_arg).to_s)
assert File.exist?(a1_cache_gem)
@@ -306,10 +307,11 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
inst = Gem::RemoteFetcher.fetcher
- assert_equal @a1.cache_file, inst.download(@a1, 'http://gems.example.com')
+ assert_equal @a1.cache_file, inst.download(@a1, "http://gems.example.com")
end
def test_download_local
+ omit "doesn't work if tempdir has +" if @tempdir.include?("+")
FileUtils.mv @a1_gem, @tempdir
local_path = File.join @tempdir, @a1.file_name
inst = nil
@@ -322,7 +324,8 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
end
def test_download_local_space
- space_path = File.join @tempdir, 'space path'
+ omit "doesn't work if tempdir has +" if @tempdir.include?("+")
+ space_path = File.join @tempdir, "space path"
FileUtils.mkdir space_path
FileUtils.mv @a1_gem, space_path
local_path = File.join space_path, @a1.file_name
@@ -336,17 +339,15 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
end
def test_download_install_dir
- a1_data = File.open @a1_gem, 'rb' do |fp|
- fp.read
- end
+ a1_data = File.open @a1_gem, "rb", &:read
fetcher = util_fuck_with_fetcher a1_data
- install_dir = File.join @tempdir, 'more_gems'
+ install_dir = File.join @tempdir, "more_gems"
a1_cache_gem = File.join install_dir, "cache", @a1.file_name
FileUtils.mkdir_p(File.dirname(a1_cache_gem))
- actual = fetcher.download(@a1, 'http://gems.example.com', install_dir)
+ actual = fetcher.download(@a1, "http://gems.example.com", install_dir)
assert_equal a1_cache_gem, actual
assert_equal("http://gems.example.com/gems/a-1.gem",
@@ -355,14 +356,19 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
assert File.exist?(a1_cache_gem)
end
- unless win_platform? || Process.uid.zero? # File.chmod doesn't work
+ unless Gem.win_platform? || Process.uid.zero? # File.chmod doesn't work
def test_download_local_read_only
+ omit "doesn't work if tempdir has +" if @tempdir.include?("+")
FileUtils.mv @a1_gem, @tempdir
local_path = File.join @tempdir, @a1.file_name
inst = nil
- FileUtils.chmod 0555, @a1.cache_dir
- FileUtils.mkdir_p File.join(Gem.user_dir, "cache") rescue nil
- FileUtils.chmod 0555, File.join(Gem.user_dir, "cache")
+ FileUtils.chmod 0o555, @a1.cache_dir
+ begin
+ FileUtils.mkdir_p File.join(Gem.user_dir, "cache")
+ rescue StandardError
+ nil
+ end
+ FileUtils.chmod 0o555, File.join(Gem.user_dir, "cache")
Dir.chdir @tempdir do
inst = Gem::RemoteFetcher.fetcher
@@ -371,35 +377,37 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
assert_equal(File.join(@tempdir, @a1.file_name),
inst.download(@a1, local_path))
ensure
- FileUtils.chmod 0755, File.join(Gem.user_dir, "cache")
- FileUtils.chmod 0755, @a1.cache_dir
+ if local_path
+ FileUtils.chmod 0o755, File.join(Gem.user_dir, "cache")
+ FileUtils.chmod 0o755, @a1.cache_dir
+ end
end
def test_download_read_only
- FileUtils.chmod 0555, @a1.cache_dir
- FileUtils.chmod 0555, @gemhome
+ FileUtils.chmod 0o555, @a1.cache_dir
+ FileUtils.chmod 0o555, @gemhome
fetcher = util_fuck_with_fetcher File.read(@a1_gem)
- fetcher.download(@a1, 'http://gems.example.com')
+ fetcher.download(@a1, "http://gems.example.com")
a1_cache_gem = File.join Gem.user_dir, "cache", @a1.file_name
assert File.exist? a1_cache_gem
ensure
- FileUtils.chmod 0755, @gemhome
- FileUtils.chmod 0755, @a1.cache_dir
+ FileUtils.chmod 0o755, @gemhome
+ FileUtils.chmod 0o755, @a1.cache_dir
end
end
def test_download_platform_legacy
- original_platform = 'old-platform'
+ original_platform = "old-platform"
- e1, e1_gem = util_gem 'e', '1' do |s|
+ e1, e1_gem = util_gem "e", "1" do |s|
s.platform = Gem::Platform::CURRENT
s.instance_variable_set :@original_platform, original_platform
end
- e1.loaded_from = File.join(@gemhome, 'specifications', e1.full_name)
+ e1.loaded_from = File.join(@gemhome, "specifications", e1.full_name)
e1_data = nil
- File.open e1_gem, 'rb' do |fp|
+ File.open e1_gem, "rb" do |fp|
e1_data = fp.read
end
@@ -407,7 +415,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
e1_cache_gem = e1.cache_file
- assert_equal e1_cache_gem, fetcher.download(e1, 'http://gems.example.com')
+ assert_equal e1_cache_gem, fetcher.download(e1, "http://gems.example.com")
assert_equal("http://gems.example.com/gems/#{e1.original_name}.gem",
fetcher.instance_variable_get(:@test_arg).to_s)
@@ -415,6 +423,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
end
def test_download_same_file
+ omit "doesn't work if tempdir has +" if @tempdir.include?("+")
FileUtils.mv @a1_gem, @tempdir
local_path = File.join @tempdir, @a1.file_name
inst = nil
@@ -435,14 +444,14 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
inst = Gem::RemoteFetcher.fetcher
e = assert_raise ArgumentError do
- inst.download @a1, 'ftp://gems.rubyforge.org'
+ inst.download @a1, "ftp://gems.rubyforge.org"
end
- assert_equal 'unsupported URI scheme ftp', e.message
+ assert_equal "unsupported URI scheme ftp", e.message
end
def test_download_to_cache
- @a2, @a2_gem = util_gem 'a', '2'
+ @a2, @a2_gem = util_gem "a", "2"
util_setup_spec_fetcher @a1, @a2
@fetcher.instance_variable_set :@a1, @a1
@@ -458,7 +467,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
end
end
- gem = Gem::RemoteFetcher.fetcher.download_to_cache dep 'a'
+ gem = Gem::RemoteFetcher.fetcher.download_to_cache dep "a"
assert_equal @a2.file_name, File.basename(gem)
end
@@ -468,10 +477,10 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
@fetcher = fetcher
def fetcher.fetch_http(uri, mtime, head = nil)
- Gem::Util.gzip 'foo'
+ Gem::Util.gzip "foo"
end
- assert_equal 'foo', fetcher.fetch_path(@uri + 'foo.gz')
+ assert_equal "foo", fetcher.fetch_path(@uri + "foo.gz")
end
def test_fetch_path_gzip_unmodified
@@ -482,7 +491,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
nil
end
- assert_nil fetcher.fetch_path(@uri + 'foo.gz', Time.at(0))
+ assert_nil fetcher.fetch_path(@uri + "foo.gz", Time.at(0))
end
def test_fetch_path_io_error
@@ -493,7 +502,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
raise EOFError
end
- url = 'http://example.com/uri'
+ url = "http://example.com/uri"
e = assert_raise Gem::RemoteFetcher::FetchError do
fetcher.fetch_path url
@@ -511,7 +520,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
raise SocketError
end
- url = 'http://example.com/uri'
+ url = "http://example.com/uri"
e = assert_raise Gem::RemoteFetcher::FetchError do
fetcher.fetch_path url
@@ -526,17 +535,17 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
@fetcher = fetcher
def fetcher.fetch_http(uri, mtime = nil, head = nil)
- raise Errno::ECONNREFUSED, 'connect(2)'
+ raise Errno::ECONNREFUSED, "connect(2)"
end
- url = 'http://example.com/uri'
+ url = "http://example.com/uri"
e = assert_raise Gem::RemoteFetcher::FetchError do
fetcher.fetch_path url
end
- assert_match %r{ECONNREFUSED:.*connect\(2\) \(#{Regexp.escape url}\)\z},
- e.message
+ assert_match(/ECONNREFUSED:.*connect\(2\) \(#{Regexp.escape url}\)\z/,
+ e.message)
assert_equal url, e.uri
end
@@ -545,17 +554,17 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
@fetcher = fetcher
def fetcher.fetch_http(uri, mtime = nil, head = nil)
- raise Timeout::Error, 'timed out'
+ raise Gem::Timeout::Error, "timed out"
end
- url = 'http://example.com/uri'
+ url = "http://example.com/uri"
e = assert_raise Gem::RemoteFetcher::FetchError do
fetcher.fetch_path url
end
- assert_match %r{Timeout::Error: timed out \(#{Regexp.escape url}\)\z},
- e.message
+ assert_match(/Gem::Timeout::Error: timed out \(#{Regexp.escape url}\)\z/,
+ e.message)
assert_equal url, e.uri
end
@@ -564,17 +573,17 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
@fetcher = fetcher
def fetcher.fetch_http(uri, mtime = nil, head = nil)
- raise SocketError, 'getaddrinfo: nodename nor servname provided'
+ raise SocketError, "getaddrinfo: nodename nor servname provided"
end
- url = 'http://example.com/uri'
+ url = "http://example.com/uri"
e = assert_raise Gem::RemoteFetcher::FetchError do
fetcher.fetch_path url
end
- assert_match %r{SocketError: getaddrinfo: nodename nor servname provided \(#{Regexp.escape url}\)\z},
- e.message
+ assert_match(/SocketError: getaddrinfo: nodename nor servname provided \(#{Regexp.escape url}\)\z/,
+ e.message)
assert_equal url, e.uri
end
@@ -586,7 +595,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
raise OpenSSL::SSL::SSLError
end
- url = 'http://example.com/uri'
+ url = "http://example.com/uri"
e = assert_raise Gem::RemoteFetcher::FetchError do
fetcher.fetch_path url
@@ -604,12 +613,12 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
nil
end
- assert_nil fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0))
+ assert_nil fetcher.fetch_path(Gem::URI.parse(@gem_repo), Time.at(0))
end
def test_implicit_no_proxy
use_ui @stub_ui do
- ENV['http_proxy'] = 'http://fakeurl:12345'
+ ENV["http_proxy"] = "http://fakeurl:12345"
fetcher = Gem::RemoteFetcher.new :no_proxy
@fetcher = fetcher
assert_data_from_server fetcher.fetch_path(@server_uri)
@@ -618,7 +627,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_implicit_proxy
use_ui @stub_ui do
- ENV['http_proxy'] = @proxy_uri
+ ENV["http_proxy"] = @proxy_uri
fetcher = Gem::RemoteFetcher.new nil
@fetcher = fetcher
assert_data_from_proxy fetcher.fetch_path(@server_uri)
@@ -627,7 +636,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_implicit_upper_case_proxy
use_ui @stub_ui do
- ENV['HTTP_PROXY'] = @proxy_uri
+ ENV["HTTP_PROXY"] = @proxy_uri
fetcher = Gem::RemoteFetcher.new nil
@fetcher = fetcher
assert_data_from_proxy fetcher.fetch_path(@server_uri)
@@ -645,41 +654,42 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_fetch_http
fetcher = Gem::RemoteFetcher.new nil
@fetcher = fetcher
- url = 'http://gems.example.com/redirect'
+ url = "http://gems.example.com/redirect"
def fetcher.request(uri, request_class, last_modified = nil)
- url = 'http://gems.example.com/redirect'
- unless defined? @requested
- @requested = true
- res = Net::HTTPMovedPermanently.new nil, 301, nil
- res.add_field 'Location', url
- res
+ url = "http://gems.example.com/redirect"
+ if defined? @requested
+ res = Gem::Net::HTTPOK.new nil, 200, nil
+ def res.body
+ "real_path"
+ end
else
- res = Net::HTTPOK.new nil, 200, nil
- def res.body() 'real_path' end
- res
+ @requested = true
+ res = Gem::Net::HTTPMovedPermanently.new nil, 301, nil
+ res.add_field "Location", url
end
+ res
end
- data = fetcher.fetch_http URI.parse(url)
+ data = fetcher.fetch_http Gem::URI.parse(url)
- assert_equal 'real_path', data
+ assert_equal "real_path", data
end
def test_fetch_http_redirects
fetcher = Gem::RemoteFetcher.new nil
@fetcher = fetcher
- url = 'http://gems.example.com/redirect'
+ url = "http://gems.example.com/redirect"
def fetcher.request(uri, request_class, last_modified = nil)
- url = 'http://gems.example.com/redirect'
- res = Net::HTTPMovedPermanently.new nil, 301, nil
- res.add_field 'Location', url
+ url = "http://gems.example.com/redirect"
+ res = Gem::Net::HTTPMovedPermanently.new nil, 301, nil
+ res.add_field "Location", url
res
end
e = assert_raise Gem::RemoteFetcher::FetchError do
- fetcher.fetch_http URI.parse(url)
+ fetcher.fetch_http Gem::URI.parse(url)
end
assert_equal "too many redirects (#{url})", e.message
@@ -688,15 +698,15 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_fetch_http_redirects_without_location
fetcher = Gem::RemoteFetcher.new nil
@fetcher = fetcher
- url = 'http://gems.example.com/redirect'
+ url = "http://gems.example.com/redirect"
def fetcher.request(uri, request_class, last_modified = nil)
- res = Net::HTTPMovedPermanently.new nil, 301, nil
+ res = Gem::Net::HTTPMovedPermanently.new nil, 301, nil
res
end
e = assert_raise Gem::RemoteFetcher::FetchError do
- fetcher.fetch_http URI.parse(url)
+ fetcher.fetch_http Gem::URI.parse(url)
end
assert_equal "redirecting but no redirect location was given (#{url})", e.message
@@ -704,13 +714,13 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_fetch_http_with_additional_headers
ENV["http_proxy"] = @proxy_uri
- ENV["no_proxy"] = URI::parse(@server_uri).host
+ ENV["no_proxy"] = Gem::URI.parse(@server_uri).host
fetcher = Gem::RemoteFetcher.new nil, nil, { "X-Captain" => "murphy" }
@fetcher = fetcher
assert_equal "murphy", fetcher.fetch_path(@server_uri)
end
- def assert_fetch_s3(url, signature, token=nil, region='us-east-1', instance_profile_json=nil)
+ def assert_fetch_s3(url, signature, token=nil, region="us-east-1", instance_profile_json=nil)
fetcher = Gem::RemoteFetcher.new nil
@fetcher = fetcher
$fetched_uri = nil
@@ -718,13 +728,15 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def fetcher.request(uri, request_class, last_modified = nil)
$fetched_uri = uri
- res = Net::HTTPOK.new nil, 200, nil
- def res.body() 'success' end
+ res = Gem::Net::HTTPOK.new nil, 200, nil
+ def res.body
+ "success"
+ end
res
end
def fetcher.s3_uri_signer(uri)
- require 'json'
+ require "json"
s3_uri_signer = Gem::S3URISigner.new(uri)
def s3_uri_signer.ec2_metadata_credentials_json
JSON.parse($instance_profile)
@@ -735,21 +747,21 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
s3_uri_signer
end
- data = fetcher.fetch_s3 URI.parse(url)
+ data = fetcher.fetch_s3 Gem::URI.parse(url)
assert_equal "https://my-bucket.s3.#{region}.amazonaws.com/gems/specs.4.8.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=testuser%2F20190624%2F#{region}%2Fs3%2Faws4_request&X-Amz-Date=20190624T050641Z&X-Amz-Expires=86400#{token ? "&X-Amz-Security-Token=" + token : ""}&X-Amz-SignedHeaders=host&X-Amz-Signature=#{signature}", $fetched_uri.to_s
- assert_equal 'success', data
+ assert_equal "success", data
ensure
$fetched_uri = nil
end
def test_fetch_s3_config_creds
Gem.configuration[:s3_source] = {
- 'my-bucket' => { :id => 'testuser', :secret => 'testpass' },
+ "my-bucket" => { id: "testuser", secret: "testpass" },
}
- url = 's3://my-bucket/gems/specs.4.8.gz'
- Time.stub :now, Time.at(1561353581) do
- assert_fetch_s3 url, '20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b'
+ url = "s3://my-bucket/gems/specs.4.8.gz"
+ Time.stub :now, Time.at(1_561_353_581) do
+ assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b"
end
ensure
Gem.configuration[:s3_source] = nil
@@ -757,11 +769,11 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_fetch_s3_config_creds_with_region
Gem.configuration[:s3_source] = {
- 'my-bucket' => { :id => 'testuser', :secret => 'testpass', :region => 'us-west-2' },
+ "my-bucket" => { id: "testuser", secret: "testpass", region: "us-west-2" },
}
- url = 's3://my-bucket/gems/specs.4.8.gz'
- Time.stub :now, Time.at(1561353581) do
- assert_fetch_s3 url, '4afc3010757f1fd143e769f1d1dabd406476a4fc7c120e9884fd02acbb8f26c9', nil, 'us-west-2'
+ url = "s3://my-bucket/gems/specs.4.8.gz"
+ Time.stub :now, Time.at(1_561_353_581) do
+ assert_fetch_s3 url, "4afc3010757f1fd143e769f1d1dabd406476a4fc7c120e9884fd02acbb8f26c9", nil, "us-west-2"
end
ensure
Gem.configuration[:s3_source] = nil
@@ -769,79 +781,79 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_fetch_s3_config_creds_with_token
Gem.configuration[:s3_source] = {
- 'my-bucket' => { :id => 'testuser', :secret => 'testpass', :security_token => 'testtoken' },
+ "my-bucket" => { id: "testuser", secret: "testpass", security_token: "testtoken" },
}
- url = 's3://my-bucket/gems/specs.4.8.gz'
- Time.stub :now, Time.at(1561353581) do
- assert_fetch_s3 url, '935160a427ef97e7630f799232b8f208c4a4e49aad07d0540572a2ad5fe9f93c', 'testtoken'
+ url = "s3://my-bucket/gems/specs.4.8.gz"
+ Time.stub :now, Time.at(1_561_353_581) do
+ assert_fetch_s3 url, "935160a427ef97e7630f799232b8f208c4a4e49aad07d0540572a2ad5fe9f93c", "testtoken"
end
ensure
Gem.configuration[:s3_source] = nil
end
def test_fetch_s3_env_creds
- ENV['AWS_ACCESS_KEY_ID'] = 'testuser'
- ENV['AWS_SECRET_ACCESS_KEY'] = 'testpass'
- ENV['AWS_SESSION_TOKEN'] = nil
+ ENV["AWS_ACCESS_KEY_ID"] = "testuser"
+ ENV["AWS_SECRET_ACCESS_KEY"] = "testpass"
+ ENV["AWS_SESSION_TOKEN"] = nil
Gem.configuration[:s3_source] = {
- 'my-bucket' => { :provider => 'env' },
+ "my-bucket" => { provider: "env" },
}
- url = 's3://my-bucket/gems/specs.4.8.gz'
- Time.stub :now, Time.at(1561353581) do
- assert_fetch_s3 url, '20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b'
+ url = "s3://my-bucket/gems/specs.4.8.gz"
+ Time.stub :now, Time.at(1_561_353_581) do
+ assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b"
end
ensure
- ENV.each_key {|key| ENV.delete(key) if key.start_with?('AWS') }
+ ENV.each_key {|key| ENV.delete(key) if key.start_with?("AWS") }
Gem.configuration[:s3_source] = nil
end
def test_fetch_s3_env_creds_with_region
- ENV['AWS_ACCESS_KEY_ID'] = 'testuser'
- ENV['AWS_SECRET_ACCESS_KEY'] = 'testpass'
- ENV['AWS_SESSION_TOKEN'] = nil
+ ENV["AWS_ACCESS_KEY_ID"] = "testuser"
+ ENV["AWS_SECRET_ACCESS_KEY"] = "testpass"
+ ENV["AWS_SESSION_TOKEN"] = nil
Gem.configuration[:s3_source] = {
- 'my-bucket' => { :provider => 'env', :region => 'us-west-2' },
+ "my-bucket" => { provider: "env", region: "us-west-2" },
}
- url = 's3://my-bucket/gems/specs.4.8.gz'
- Time.stub :now, Time.at(1561353581) do
- assert_fetch_s3 url, '4afc3010757f1fd143e769f1d1dabd406476a4fc7c120e9884fd02acbb8f26c9', nil, 'us-west-2'
+ url = "s3://my-bucket/gems/specs.4.8.gz"
+ Time.stub :now, Time.at(1_561_353_581) do
+ assert_fetch_s3 url, "4afc3010757f1fd143e769f1d1dabd406476a4fc7c120e9884fd02acbb8f26c9", nil, "us-west-2"
end
ensure
- ENV.each_key {|key| ENV.delete(key) if key.start_with?('AWS') }
+ ENV.each_key {|key| ENV.delete(key) if key.start_with?("AWS") }
Gem.configuration[:s3_source] = nil
end
def test_fetch_s3_env_creds_with_token
- ENV['AWS_ACCESS_KEY_ID'] = 'testuser'
- ENV['AWS_SECRET_ACCESS_KEY'] = 'testpass'
- ENV['AWS_SESSION_TOKEN'] = 'testtoken'
+ ENV["AWS_ACCESS_KEY_ID"] = "testuser"
+ ENV["AWS_SECRET_ACCESS_KEY"] = "testpass"
+ ENV["AWS_SESSION_TOKEN"] = "testtoken"
Gem.configuration[:s3_source] = {
- 'my-bucket' => { :provider => 'env' },
+ "my-bucket" => { provider: "env" },
}
- url = 's3://my-bucket/gems/specs.4.8.gz'
- Time.stub :now, Time.at(1561353581) do
- assert_fetch_s3 url, '935160a427ef97e7630f799232b8f208c4a4e49aad07d0540572a2ad5fe9f93c', 'testtoken'
+ url = "s3://my-bucket/gems/specs.4.8.gz"
+ Time.stub :now, Time.at(1_561_353_581) do
+ assert_fetch_s3 url, "935160a427ef97e7630f799232b8f208c4a4e49aad07d0540572a2ad5fe9f93c", "testtoken"
end
ensure
- ENV.each_key {|key| ENV.delete(key) if key.start_with?('AWS') }
+ ENV.each_key {|key| ENV.delete(key) if key.start_with?("AWS") }
Gem.configuration[:s3_source] = nil
end
def test_fetch_s3_url_creds
- url = 's3://testuser:testpass@my-bucket/gems/specs.4.8.gz'
- Time.stub :now, Time.at(1561353581) do
- assert_fetch_s3 url, '20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b'
+ url = "s3://testuser:testpass@my-bucket/gems/specs.4.8.gz"
+ Time.stub :now, Time.at(1_561_353_581) do
+ assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b"
end
end
def test_fetch_s3_instance_profile_creds
Gem.configuration[:s3_source] = {
- 'my-bucket' => { :provider => 'instance_profile' },
+ "my-bucket" => { provider: "instance_profile" },
}
- url = 's3://my-bucket/gems/specs.4.8.gz'
- Time.stub :now, Time.at(1561353581) do
- assert_fetch_s3 url, '20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b', nil, 'us-east-1',
+ url = "s3://my-bucket/gems/specs.4.8.gz"
+ Time.stub :now, Time.at(1_561_353_581) do
+ assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b", nil, "us-east-1",
'{"AccessKeyId": "testuser", "SecretAccessKey": "testpass"}'
end
ensure
@@ -850,12 +862,12 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_fetch_s3_instance_profile_creds_with_region
Gem.configuration[:s3_source] = {
- 'my-bucket' => { :provider => 'instance_profile', :region => 'us-west-2' },
+ "my-bucket" => { provider: "instance_profile", region: "us-west-2" },
}
- url = 's3://my-bucket/gems/specs.4.8.gz'
- Time.stub :now, Time.at(1561353581) do
- assert_fetch_s3 url, '4afc3010757f1fd143e769f1d1dabd406476a4fc7c120e9884fd02acbb8f26c9', nil, 'us-west-2',
+ url = "s3://my-bucket/gems/specs.4.8.gz"
+ Time.stub :now, Time.at(1_561_353_581) do
+ assert_fetch_s3 url, "4afc3010757f1fd143e769f1d1dabd406476a4fc7c120e9884fd02acbb8f26c9", nil, "us-west-2",
'{"AccessKeyId": "testuser", "SecretAccessKey": "testpass"}'
end
ensure
@@ -864,12 +876,12 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_fetch_s3_instance_profile_creds_with_token
Gem.configuration[:s3_source] = {
- 'my-bucket' => { :provider => 'instance_profile' },
+ "my-bucket" => { provider: "instance_profile" },
}
- url = 's3://my-bucket/gems/specs.4.8.gz'
- Time.stub :now, Time.at(1561353581) do
- assert_fetch_s3 url, '935160a427ef97e7630f799232b8f208c4a4e49aad07d0540572a2ad5fe9f93c', 'testtoken', 'us-east-1',
+ url = "s3://my-bucket/gems/specs.4.8.gz"
+ Time.stub :now, Time.at(1_561_353_581) do
+ assert_fetch_s3 url, "935160a427ef97e7630f799232b8f208c4a4e49aad07d0540572a2ad5fe9f93c", "testtoken", "us-east-1",
'{"AccessKeyId": "testuser", "SecretAccessKey": "testpass", "Token": "testtoken"}'
end
ensure
@@ -881,42 +893,42 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
@fetcher = fetcher
e = assert_raise Gem::RemoteFetcher::FetchError do
- fetcher.fetch_s3 URI.parse(url)
+ fetcher.fetch_s3 Gem::URI.parse(url)
end
assert_match expected_message, e.message
end
def test_fetch_s3_no_source_key
- url = 's3://my-bucket/gems/specs.4.8.gz'
- refute_fetch_s3 url, 'no s3_source key exists in .gemrc'
+ url = "s3://my-bucket/gems/specs.4.8.gz"
+ refute_fetch_s3 url, "no s3_source key exists in .gemrc"
end
def test_fetch_s3_no_host
Gem.configuration[:s3_source] = {
- 'my-bucket' => { :id => 'testuser', :secret => 'testpass' },
+ "my-bucket" => { id: "testuser", secret: "testpass" },
}
- url = 's3://other-bucket/gems/specs.4.8.gz'
- refute_fetch_s3 url, 'no key for host other-bucket in s3_source in .gemrc'
+ url = "s3://other-bucket/gems/specs.4.8.gz"
+ refute_fetch_s3 url, "no key for host other-bucket in s3_source in .gemrc"
ensure
Gem.configuration[:s3_source] = nil
end
def test_fetch_s3_no_id
- Gem.configuration[:s3_source] = { 'my-bucket' => { :secret => 'testpass' } }
+ Gem.configuration[:s3_source] = { "my-bucket" => { secret: "testpass" } }
- url = 's3://my-bucket/gems/specs.4.8.gz'
- refute_fetch_s3 url, 's3_source for my-bucket missing id or secret'
+ url = "s3://my-bucket/gems/specs.4.8.gz"
+ refute_fetch_s3 url, "s3_source for my-bucket missing id or secret"
ensure
Gem.configuration[:s3_source] = nil
end
def test_fetch_s3_no_secret
- Gem.configuration[:s3_source] = { 'my-bucket' => { :id => 'testuser' } }
+ Gem.configuration[:s3_source] = { "my-bucket" => { id: "testuser" } }
- url = 's3://my-bucket/gems/specs.4.8.gz'
- refute_fetch_s3 url, 's3_source for my-bucket missing id or secret'
+ url = "s3://my-bucket/gems/specs.4.8.gz"
+ refute_fetch_s3 url, "s3_source for my-bucket missing id or secret"
ensure
Gem.configuration[:s3_source] = nil
end
@@ -924,7 +936,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_observe_no_proxy_env_single_host
use_ui @stub_ui do
ENV["http_proxy"] = @proxy_uri
- ENV["no_proxy"] = URI::parse(@server_uri).host
+ ENV["no_proxy"] = Gem::URI.parse(@server_uri).host
fetcher = Gem::RemoteFetcher.new nil
@fetcher = fetcher
assert_data_from_server fetcher.fetch_path(@server_uri)
@@ -934,7 +946,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_observe_no_proxy_env_list
use_ui @stub_ui do
ENV["http_proxy"] = @proxy_uri
- ENV["no_proxy"] = "fakeurl.com, #{URI::parse(@server_uri).host}"
+ ENV["no_proxy"] = "fakeurl.com, #{Gem::URI.parse(@server_uri).host}"
fetcher = Gem::RemoteFetcher.new nil
@fetcher = fetcher
assert_data_from_server fetcher.fetch_path(@server_uri)
@@ -946,8 +958,8 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
@fetcher = fetcher
assert_throws :block_called do
- fetcher.request URI('http://example'), Net::HTTP::Get do |req|
- assert_kind_of Net::HTTPGenericRequest, req
+ fetcher.request Gem::URI("http://example"), Gem::Net::HTTP::Get do |req|
+ assert_kind_of Gem::Net::HTTPGenericRequest, req
throw :block_called
end
end
@@ -964,38 +976,40 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_ssl_connection
ssl_server = start_ssl_server
- temp_ca_cert = File.join(__dir__, 'ca_cert.pem')
+ temp_ca_cert = File.join(__dir__, "ca_cert.pem")
with_configured_fetcher(":ssl_ca_cert: #{temp_ca_cert}") do |fetcher|
fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml")
end
end
def test_ssl_client_cert_auth_connection
- ssl_server = start_ssl_server({
- :SSLVerifyClient =>
- OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT })
+ ssl_server = start_ssl_server(
+ { SSLVerifyClient: OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT }
+ )
- temp_ca_cert = File.join(__dir__, 'ca_cert.pem')
- temp_client_cert = File.join(__dir__, 'client.pem')
+ temp_ca_cert = File.join(__dir__, "ca_cert.pem")
+ temp_client_cert = File.join(__dir__, "client.pem")
with_configured_fetcher(
- ":ssl_ca_cert: #{temp_ca_cert}\n" +
- ":ssl_client_cert: #{temp_client_cert}\n") do |fetcher|
+ ":ssl_ca_cert: #{temp_ca_cert}\n" \
+ ":ssl_client_cert: #{temp_client_cert}\n"
+ ) do |fetcher|
fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml")
end
end
def test_do_not_allow_invalid_client_cert_auth_connection
- ssl_server = start_ssl_server({
- :SSLVerifyClient =>
- OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT })
+ ssl_server = start_ssl_server(
+ { SSLVerifyClient: OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT }
+ )
- temp_ca_cert = File.join(__dir__, 'ca_cert.pem')
- temp_client_cert = File.join(__dir__, 'invalid_client.pem')
+ temp_ca_cert = File.join(__dir__, "ca_cert.pem")
+ temp_client_cert = File.join(__dir__, "invalid_client.pem")
with_configured_fetcher(
- ":ssl_ca_cert: #{temp_ca_cert}\n" +
- ":ssl_client_cert: #{temp_client_cert}\n") do |fetcher|
+ ":ssl_ca_cert: #{temp_ca_cert}\n" \
+ ":ssl_client_cert: #{temp_client_cert}\n"
+ ) do |fetcher|
assert_raise Gem::RemoteFetcher::FetchError do
fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml")
end
@@ -1020,7 +1034,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_do_not_follow_insecure_redirect
ssl_server = start_ssl_server
- temp_ca_cert = File.join(__dir__, 'ca_cert.pem')
+ temp_ca_cert = File.join(__dir__, "ca_cert.pem")
expected_error_message =
"redirecting to non-https resource: #{@server_uri} (https://localhost:#{ssl_server.config[:Port]}/insecure_redirect?to=#{@server_uri})"
@@ -1046,8 +1060,8 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def with_configured_fetcher(config_str = nil, &block)
if config_str
- temp_conf = File.join @tempdir, '.gemrc'
- File.open temp_conf, 'w' do |fp|
+ temp_conf = File.join @tempdir, ".gemrc"
+ File.open temp_conf, "w" do |fp|
fp.puts config_str
end
Gem.configuration = Gem::ConfigFile.new %W[--config-file #{temp_conf}]
@@ -1080,7 +1094,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
end
class NilLog < WEBrick::Log
- def log(level, data) #Do nothing
+ def log(level, data) # Do nothing
end
end
@@ -1115,8 +1129,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
@ssl_server_thread.kill.join
@ssl_server_thread = nil
end
- utils = WEBrick::Utils # TimeoutHandler is since 1.9
- utils::TimeoutHandler.terminate if defined?(utils::TimeoutHandler.terminate)
+ WEBrick::Utils::TimeoutHandler.terminate
end
def normal_server_port
@@ -1132,32 +1145,30 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
null_logger = NilLog.new
server = WEBrick::HTTPServer.new({
- :Port => 0,
- :Logger => null_logger,
- :AccessLog => [],
- :SSLEnable => true,
- :SSLCACertificateFile => File.join(__dir__, 'ca_cert.pem'),
- :SSLCertificate => cert('ssl_cert.pem'),
- :SSLPrivateKey => key('ssl_key.pem'),
- :SSLVerifyClient => nil,
- :SSLCertName => nil,
+ Port: 0,
+ Logger: null_logger,
+ AccessLog: [],
+ SSLEnable: true,
+ SSLCACertificateFile: File.join(__dir__, "ca_cert.pem"),
+ SSLCertificate: cert("ssl_cert.pem"),
+ SSLPrivateKey: key("ssl_key.pem"),
+ SSLVerifyClient: nil,
+ SSLCertName: nil,
}.merge(config))
- server.mount_proc("/yaml") do |req, res|
+ server.mount_proc("/yaml") do |_req, res|
res.body = "--- true\n"
end
server.mount_proc("/insecure_redirect") do |req, res|
- res.set_redirect(WEBrick::HTTPStatus::MovedPermanently, req.query['to'])
+ res.set_redirect(WEBrick::HTTPStatus::MovedPermanently, req.query["to"])
end
server.ssl_context.tmp_dh_callback = proc { TEST_KEY_DH2048 }
t = Thread.new do
- begin
- server.start
- rescue Exception => ex
- puts "ERROR during server thread: #{ex.message}"
- raise
- ensure
- server.shutdown
- end
+ server.start
+ rescue StandardError => ex
+ puts "ERROR during server thread: #{ex.message}"
+ raise
+ ensure
+ server.shutdown
end
while server.status != :Running
sleep 0.1
@@ -1174,43 +1185,41 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def start_server(data)
null_logger = NilLog.new
s = WEBrick::HTTPServer.new(
- :Port => 0,
- :DocumentRoot => nil,
- :Logger => null_logger,
- :AccessLog => null_logger
+ Port: 0,
+ DocumentRoot: nil,
+ Logger: null_logger,
+ AccessLog: null_logger
)
- s.mount_proc("/kill") {|req, res| s.shutdown }
+ s.mount_proc("/kill") {|_req, _res| s.shutdown }
s.mount_proc("/yaml") do |req, res|
if req["X-Captain"]
res.body = req["X-Captain"]
elsif @enable_yaml
res.body = data
- res['Content-Type'] = 'text/plain'
- res['content-length'] = data.size
+ res["Content-Type"] = "text/plain"
+ res["content-length"] = data.size
else
res.status = "404"
res.body = "<h1>NOT FOUND</h1>"
- res['Content-Type'] = 'text/html'
+ res["Content-Type"] = "text/html"
end
end
- s.mount_proc("/yaml.Z") do |req, res|
+ s.mount_proc("/yaml.Z") do |_req, res|
if @enable_zip
res.body = Zlib::Deflate.deflate(data)
- res['Content-Type'] = 'text/plain'
+ res["Content-Type"] = "text/plain"
else
res.status = "404"
res.body = "<h1>NOT FOUND</h1>"
- res['Content-Type'] = 'text/html'
+ res["Content-Type"] = "text/html"
end
end
th = Thread.new do
- begin
- s.start
- rescue Exception => ex
- abort "ERROR during server thread: #{ex.message}"
- ensure
- s.shutdown
- end
+ s.start
+ rescue StandardError => ex
+ abort "ERROR during server thread: #{ex.message}"
+ ensure
+ s.shutdown
end
th[:server] = s
th