summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2022-10-06 15:43:48 +0900
committernagachika <nagachika@ruby-lang.org>2022-10-08 12:27:30 +0900
commitd77e6e653d32fa6287286cc68300abc0d1a299da (patch)
tree5eba1ad51312bb634e7660607e6cb699fad54607 /test
parentd2f4cbf04215e536bcd06fde9cc7cec3b5566707 (diff)
Merge RubyGems-3.3.23 and Bundler-2.3.23
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/helper.rb40
-rw-r--r--test/rubygems/packages/Bluebie-legs-0.6.2.gembin0 -> 14336 bytes
-rw-r--r--test/rubygems/test_gem.rb466
-rw-r--r--test/rubygems/test_gem_commands_owner_command.rb129
-rw-r--r--test/rubygems/test_gem_commands_push_command.rb67
-rw-r--r--test/rubygems/test_gem_commands_signin_command.rb31
-rw-r--r--test/rubygems/test_gem_commands_yank_command.rb18
-rw-r--r--test/rubygems/test_gem_gemcutter_utilities.rb28
-rw-r--r--test/rubygems/test_gem_package.rb15
-rw-r--r--test/rubygems/test_gem_platform.rb35
-rw-r--r--test/rubygems/test_gem_resolver.rb33
-rw-r--r--test/rubygems/test_require.rb10
-rw-r--r--test/rubygems/utilities.rb50
13 files changed, 603 insertions, 319 deletions
diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb
index 970ba09c10..1ed1523f73 100644
--- a/test/rubygems/helper.rb
+++ b/test/rubygems/helper.rb
@@ -2,26 +2,11 @@
require "rubygems"
-# If bundler gemspec exists, add to stubs
-bundler_gemspec = File.expand_path("../../bundler/bundler.gemspec", __dir__)
-if File.exist?(bundler_gemspec)
- Gem::Specification.dirs.unshift File.dirname(bundler_gemspec)
- Gem::Specification.class_variable_set :@@stubs, nil
- Gem::Specification.stubs
- Gem::Specification.dirs.shift
-end
-
begin
gem "test-unit", "~> 3.0"
rescue Gem::LoadError
end
-if File.exist?(bundler_gemspec)
- require_relative "../../bundler/lib/bundler"
-else
- require "bundler"
-end
-
require "test/unit"
ENV["JARS_SKIP"] = "true" if Gem.java_platform? # avoid unnecessary and noisy `jar-dependencies` post install hook
@@ -409,7 +394,6 @@ class Gem::TestCase < Test::Unit::TestCase
Gem.loaded_specs.clear
Gem.instance_variable_set(:@activated_gem_paths, 0)
Gem.clear_default_specs
- Bundler.reset!
Gem.configuration.verbose = true
Gem.configuration.update_sources = true
@@ -465,7 +449,7 @@ class Gem::TestCase < Test::Unit::TestCase
FileUtils.rm_rf @tempdir
- ENV.replace(@orig_env)
+ restore_env
Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE
Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE,
@@ -575,6 +559,7 @@ class Gem::TestCase < Test::Unit::TestCase
Dir.chdir directory do
unless File.exist? ".git"
system @git, "init", "--quiet"
+ system @git, "checkout", "-b", "master", "--quiet"
system @git, "config", "user.name", "RubyGems Tests"
system @git, "config", "user.email", "rubygems@example"
end
@@ -1301,6 +1286,10 @@ Also, a list:
$LOAD_PATH.find {|p| p == File.dirname($LOADED_FEATURES.find {|f| f.end_with?("/rubygems.rb") }) }
end
+ def bundler_path
+ $LOAD_PATH.find {|p| p == File.dirname($LOADED_FEATURES.find {|f| f.end_with?("/bundler.rb") }) }
+ end
+
def with_clean_path_to_ruby
orig_ruby = Gem.ruby
@@ -1581,6 +1570,23 @@ Also, a list:
PUBLIC_KEY = nil
PUBLIC_CERT = nil
end if Gem::HAVE_OPENSSL
+
+ private
+
+ def restore_env
+ unless Gem.win_platform?
+ ENV.replace(@orig_env)
+ return
+ end
+
+ # Fallback logic for Windows below to workaround
+ # https://bugs.ruby-lang.org/issues/16798. Can be dropped once all
+ # supported rubies include the fix for that.
+
+ ENV.clear
+
+ @orig_env.each {|k, v| ENV[k] = v }
+ end
end
# https://github.com/seattlerb/minitest/blob/13c48a03d84a2a87855a4de0c959f96800100357/lib/minitest/mock.rb#L192
diff --git a/test/rubygems/packages/Bluebie-legs-0.6.2.gem b/test/rubygems/packages/Bluebie-legs-0.6.2.gem
new file mode 100644
index 0000000000..60918f3bc5
--- /dev/null
+++ b/test/rubygems/packages/Bluebie-legs-0.6.2.gem
Binary files differ
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index bbb3e6dd0a..1b8527cce9 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -617,20 +617,22 @@ class TestGem < Gem::TestCase
end
def test_self_use_gemdeps
- with_rubygems_gemdeps("-") do
- FileUtils.mkdir_p "detect/a/b"
- FileUtils.mkdir_p "detect/a/Isolate"
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps("-") do
+ FileUtils.mkdir_p "detect/a/b"
+ FileUtils.mkdir_p "detect/a/Isolate"
- FileUtils.touch "detect/Isolate"
+ FileUtils.touch "detect/Isolate"
- begin
- Dir.chdir "detect/a/b"
+ begin
+ Dir.chdir "detect/a/b"
- Gem.use_gemdeps
+ Gem.use_gemdeps
- assert_equal add_bundler_full_name([]), loaded_spec_names
- ensure
- Dir.chdir @tempdir
+ assert_equal add_bundler_full_name([]), loaded_spec_names
+ ensure
+ Dir.chdir @tempdir
+ end
end
end
end
@@ -775,39 +777,40 @@ class TestGem < Gem::TestCase
end
def test_self_find_files_with_gemfile
- cwd = File.expand_path("test/rubygems", PROJECT_DIR)
- actual_load_path = $LOAD_PATH.unshift(cwd).dup
+ with_local_bundler_at(Gem.dir) do
+ cwd = File.expand_path("test/rubygems", PROJECT_DIR)
+ actual_load_path = $LOAD_PATH.unshift(cwd).dup
- discover_path = File.join "lib", "sff", "discover.rb"
+ discover_path = File.join "lib", "sff", "discover.rb"
- foo1, _ = %w[1 2].map do |version|
- spec = quick_gem "sff", version do |s|
- s.files << discover_path
+ foo1, _ = %w[1 2].map do |version|
+ spec = quick_gem "sff", version do |s|
+ s.files << discover_path
+ end
+
+ write_file(File.join "gems", spec.full_name, discover_path) do |fp|
+ fp.puts "# #{spec.full_name}"
+ end
+
+ spec
end
+ Gem.refresh
- write_file(File.join "gems", spec.full_name, discover_path) do |fp|
- fp.puts "# #{spec.full_name}"
+ write_file(File.join Dir.pwd, "Gemfile") do |fp|
+ fp.puts "source 'https://rubygems.org'"
+ fp.puts "gem '#{foo1.name}', '#{foo1.version}'"
end
+ Gem.use_gemdeps(File.join Dir.pwd, "Gemfile")
- spec
- end
- Gem.refresh
+ expected = [
+ File.expand_path("test/rubygems/sff/discover.rb", PROJECT_DIR),
+ File.join(foo1.full_gem_path, discover_path),
+ ].sort
- write_file(File.join Dir.pwd, "Gemfile") do |fp|
- fp.puts "source 'https://rubygems.org'"
- fp.puts "gem '#{foo1.name}', '#{foo1.version}'"
+ assert_equal expected, Gem.find_files("sff/discover").sort
+ assert_equal expected, Gem.find_files("sff/**.rb").sort, "[ruby-core:31730]"
+ assert_equal cwd, actual_load_path.shift
end
- Gem.use_gemdeps(File.join Dir.pwd, "Gemfile")
-
- expected = [
- File.expand_path("test/rubygems/sff/discover.rb", PROJECT_DIR),
- File.join(foo1.full_gem_path, discover_path),
- ].sort
-
- assert_equal expected, Gem.find_files("sff/discover").sort
- assert_equal expected, Gem.find_files("sff/**.rb").sort, "[ruby-core:31730]"
- ensure
- assert_equal cwd, actual_load_path.shift unless Gem.java_platform?
end
def test_self_find_latest_files
@@ -1335,12 +1338,10 @@ class TestGem < Gem::TestCase
refute Gem.try_activate "nonexistent"
end
- unless Gem.java_platform?
- expected = "Ignoring ext-1 because its extensions are not built. " +
- "Try: gem pristine ext --version 1\n"
+ expected = "Ignoring ext-1 because its extensions are not built. " +
+ "Try: gem pristine ext --version 1\n"
- assert_equal expected, err
- end
+ assert_equal expected, err
end
def test_self_use_paths_with_nils
@@ -1640,159 +1641,164 @@ class TestGem < Gem::TestCase
end
def test_auto_activation_of_specific_gemdeps_file
- a = util_spec "a", "1", nil, "lib/a.rb"
- b = util_spec "b", "1", nil, "lib/b.rb"
- c = util_spec "c", "1", nil, "lib/c.rb"
+ with_local_bundler_at(Gem.dir) do
+ a = util_spec "a", "1", nil, "lib/a.rb"
+ b = util_spec "b", "1", nil, "lib/b.rb"
+ c = util_spec "c", "1", nil, "lib/c.rb"
- install_specs a, b, c
+ install_specs a, b, c
- path = File.join @tempdir, "gem.deps.rb"
+ path = File.join @tempdir, "gem.deps.rb"
- File.open path, "w" do |f|
- f.puts "gem 'a'"
- f.puts "gem 'b'"
- f.puts "gem 'c'"
- end
+ File.open path, "w" do |f|
+ f.puts "gem 'a'"
+ f.puts "gem 'b'"
+ f.puts "gem 'c'"
+ end
- with_rubygems_gemdeps(path) do
- Gem.use_gemdeps
+ with_rubygems_gemdeps(path) do
+ Gem.use_gemdeps
- assert_equal add_bundler_full_name(%W[a-1 b-1 c-1]), loaded_spec_names
+ assert_equal add_bundler_full_name(%W[a-1 b-1 c-1]), loaded_spec_names
+ end
end
end
def test_auto_activation_of_used_gemdeps_file
- a = util_spec "a", "1", nil, "lib/a.rb"
- b = util_spec "b", "1", nil, "lib/b.rb"
- c = util_spec "c", "1", nil, "lib/c.rb"
+ with_local_bundler_at(Gem.dir) do
+ a = util_spec "a", "1", nil, "lib/a.rb"
+ b = util_spec "b", "1", nil, "lib/b.rb"
+ c = util_spec "c", "1", nil, "lib/c.rb"
- install_specs a, b, c
+ install_specs a, b, c
- path = File.join @tempdir, "gem.deps.rb"
+ path = File.join @tempdir, "gem.deps.rb"
- File.open path, "w" do |f|
- f.puts "gem 'a'"
- f.puts "gem 'b'"
- f.puts "gem 'c'"
- end
+ File.open path, "w" do |f|
+ f.puts "gem 'a'"
+ f.puts "gem 'b'"
+ f.puts "gem 'c'"
+ end
- with_rubygems_gemdeps("-") do
- expected_specs = [a, b, util_spec("bundler", Bundler::VERSION), c].compact.map(&:full_name)
+ with_rubygems_gemdeps("-") do
+ expected_specs = [a, b, util_spec("bundler", Bundler::VERSION), c].compact.map(&:full_name)
- Gem.use_gemdeps
+ Gem.use_gemdeps
- assert_equal expected_specs, loaded_spec_names
+ assert_equal expected_specs, loaded_spec_names
+ end
end
end
- BUNDLER_LIB_PATH = File.expand_path $LOAD_PATH.find {|lp| File.file?(File.join(lp, "bundler.rb")) }
- BUNDLER_FULL_NAME = "bundler-#{Bundler::VERSION}".freeze
-
def add_bundler_full_name(names)
- names << BUNDLER_FULL_NAME
+ names << "bundler-#{Bundler::VERSION}".freeze
names.sort!
names
end
def test_looks_for_gemdeps_files_automatically_from_binstubs
- pend "Requiring bundler messes things up" if Gem.java_platform?
+ path = File.join(@tempdir, "gd-tmp")
- a = util_spec "a", "1" do |s|
- s.executables = %w[foo]
- s.bindir = "exe"
- end
+ with_local_bundler_at(path) do
+ a = util_spec "a", "1" do |s|
+ s.executables = %w[foo]
+ s.bindir = "exe"
+ end
- write_file File.join(@tempdir, "exe", "foo") do |fp|
- fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
- end
+ write_file File.join(@tempdir, "exe", "foo") do |fp|
+ fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
+ end
- b = util_spec "b", "1", nil, "lib/b.rb"
- c = util_spec "c", "1", nil, "lib/c.rb"
+ b = util_spec "b", "1", nil, "lib/b.rb"
+ c = util_spec "c", "1", nil, "lib/c.rb"
- install_specs a, b, c
+ install_specs a, b, c
- path = File.join(@tempdir, "gd-tmp")
- install_gem a, :install_dir => path
- install_gem b, :install_dir => path
- install_gem c, :install_dir => path
+ install_gem a, :install_dir => path
+ install_gem b, :install_dir => path
+ install_gem c, :install_dir => path
- ENV["GEM_PATH"] = path
+ ENV["GEM_PATH"] = path
- with_rubygems_gemdeps("-") do
- new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
- new_RUBYOPT = "-I#{rubygems_path} -I#{BUNDLER_LIB_PATH}"
+ with_rubygems_gemdeps("-") do
+ new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
+ new_RUBYOPT = "-I#{rubygems_path} -I#{bundler_path}"
- path = File.join @tempdir, "gem.deps.rb"
+ path = File.join @tempdir, "gem.deps.rb"
- File.open path, "w" do |f|
- f.puts "gem 'a'"
- end
- out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
- IO.popen("foo", &:read).split(/\n/)
- end
+ File.open path, "w" do |f|
+ f.puts "gem 'a'"
+ end
+ out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+ IO.popen("foo", &:read).split(/\n/)
+ end
- File.open path, "a" do |f|
- f.puts "gem 'b'"
- f.puts "gem 'c'"
- end
- out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
- IO.popen("foo", &:read).split(/\n/)
- end
+ File.open path, "a" do |f|
+ f.puts "gem 'b'"
+ f.puts "gem 'c'"
+ end
+ out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+ IO.popen("foo", &:read).split(/\n/)
+ end
- assert_equal ["b-1", "c-1"], out - out0
+ assert_equal ["b-1", "c-1"], out - out0
+ end
end
end
def test_looks_for_gemdeps_files_automatically_from_binstubs_in_parent_dir
- pend "Requiring bundler messes things up" if Gem.java_platform?
+ path = File.join(@tempdir, "gd-tmp")
- a = util_spec "a", "1" do |s|
- s.executables = %w[foo]
- s.bindir = "exe"
- end
+ with_local_bundler_at(path) do
+ pend "IO.popen has issues on JRuby when passed :chdir" if Gem.java_platform?
- write_file File.join(@tempdir, "exe", "foo") do |fp|
- fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
- end
+ a = util_spec "a", "1" do |s|
+ s.executables = %w[foo]
+ s.bindir = "exe"
+ end
- b = util_spec "b", "1", nil, "lib/b.rb"
- c = util_spec "c", "1", nil, "lib/c.rb"
+ write_file File.join(@tempdir, "exe", "foo") do |fp|
+ fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
+ end
- install_specs a, b, c
+ b = util_spec "b", "1", nil, "lib/b.rb"
+ c = util_spec "c", "1", nil, "lib/c.rb"
- path = File.join(@tempdir, "gd-tmp")
- install_gem a, :install_dir => path
- install_gem b, :install_dir => path
- install_gem c, :install_dir => path
+ install_specs a, b, c
- ENV["GEM_PATH"] = path
+ install_gem a, :install_dir => path
+ install_gem b, :install_dir => path
+ install_gem c, :install_dir => path
- with_rubygems_gemdeps("-") do
- Dir.mkdir "sub1"
+ ENV["GEM_PATH"] = path
- new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
- new_RUBYOPT = "-I#{rubygems_path} -I#{BUNDLER_LIB_PATH}"
+ with_rubygems_gemdeps("-") do
+ Dir.mkdir "sub1"
- path = File.join @tempdir, "gem.deps.rb"
+ new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
+ new_RUBYOPT = "-I#{rubygems_path} -I#{bundler_path}"
- File.open path, "w" do |f|
- f.puts "gem 'a'"
- end
- out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
- IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
- end
+ path = File.join @tempdir, "gem.deps.rb"
- File.open path, "a" do |f|
- f.puts "gem 'b'"
- f.puts "gem 'c'"
- end
- out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
- IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
- end
+ File.open path, "w" do |f|
+ f.puts "gem 'a'"
+ end
+ out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+ IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
+ end
- Dir.rmdir "sub1"
+ File.open path, "a" do |f|
+ f.puts "gem 'b'"
+ f.puts "gem 'c'"
+ end
+ out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+ IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
+ end
- assert_equal ["b-1", "c-1"], out - out0
+ Dir.rmdir "sub1"
+
+ assert_equal ["b-1", "c-1"], out - out0
+ end
end
end
@@ -1837,52 +1843,47 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps
- gem_deps_file = "gem.deps.rb".tap(&Gem::UNTAINT)
- spec = util_spec "a", 1
- install_specs spec
+ with_local_bundler_at(Gem.dir) do
+ gem_deps_file = "gem.deps.rb".tap(&Gem::UNTAINT)
+ spec = util_spec "a", 1
+ install_specs spec
- spec = Gem::Specification.find {|s| s == spec }
- refute spec.activated?
+ spec = Gem::Specification.find {|s| s == spec }
+ refute spec.activated?
- File.open gem_deps_file, "w" do |io|
- io.write 'gem "a"'
- end
+ File.open gem_deps_file, "w" do |io|
+ io.write 'gem "a"'
+ end
- assert_nil Gem.gemdeps
+ assert_nil Gem.gemdeps
- Gem.use_gemdeps gem_deps_file
+ Gem.use_gemdeps gem_deps_file
- assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
- refute_nil Gem.gemdeps
+ assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
+ refute_nil Gem.gemdeps
+ end
end
def test_use_gemdeps_ENV
- with_rubygems_gemdeps(nil) do
- spec = util_spec "a", 1
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps(nil) do
+ spec = util_spec "a", 1
- refute spec.activated?
+ refute spec.activated?
- File.open "gem.deps.rb", "w" do |io|
- io.write 'gem "a"'
- end
+ File.open "gem.deps.rb", "w" do |io|
+ io.write 'gem "a"'
+ end
- Gem.use_gemdeps
+ Gem.use_gemdeps
- refute spec.activated?
+ refute spec.activated?
+ end
end
end
def test_use_gemdeps_argument_missing
- e = assert_raise ArgumentError do
- Gem.use_gemdeps "gem.deps.rb"
- end
-
- assert_equal "Unable to find gem dependencies file at gem.deps.rb",
- e.message
- end
-
- def test_use_gemdeps_argument_missing_match_ENV
- with_rubygems_gemdeps("gem.deps.rb") do
+ with_local_bundler_at(Gem.dir) do
e = assert_raise ArgumentError do
Gem.use_gemdeps "gem.deps.rb"
end
@@ -1892,85 +1893,108 @@ class TestGem < Gem::TestCase
end
end
+ def test_use_gemdeps_argument_missing_match_ENV
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps("gem.deps.rb") do
+ e = assert_raise ArgumentError do
+ Gem.use_gemdeps "gem.deps.rb"
+ end
+
+ assert_equal "Unable to find gem dependencies file at gem.deps.rb",
+ e.message
+ end
+ end
+ end
+
def test_use_gemdeps_automatic
- with_rubygems_gemdeps("-") do
- spec = util_spec "a", 1
- install_specs spec
- spec = Gem::Specification.find {|s| s == spec }
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps("-") do
+ spec = util_spec "a", 1
+ install_specs spec
+ spec = Gem::Specification.find {|s| s == spec }
- refute spec.activated?
+ refute spec.activated?
- File.open "Gemfile", "w" do |io|
- io.write 'gem "a"'
- end
+ File.open "Gemfile", "w" do |io|
+ io.write 'gem "a"'
+ end
- Gem.use_gemdeps
+ Gem.use_gemdeps
- assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
+ assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
+ end
end
end
def test_use_gemdeps_automatic_missing
- with_rubygems_gemdeps("-") do
- Gem.use_gemdeps
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps("-") do
+ Gem.use_gemdeps
- assert true # count
+ assert true # count
+ end
end
end
def test_use_gemdeps_disabled
- with_rubygems_gemdeps("") do
- spec = util_spec "a", 1
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps("") do
+ spec = util_spec "a", 1
- refute spec.activated?
+ refute spec.activated?
- File.open "gem.deps.rb", "w" do |io|
- io.write 'gem "a"'
- end
+ File.open "gem.deps.rb", "w" do |io|
+ io.write 'gem "a"'
+ end
- Gem.use_gemdeps
+ Gem.use_gemdeps
- refute spec.activated?
+ refute spec.activated?
+ end
end
end
def test_use_gemdeps_missing_gem
- with_rubygems_gemdeps("x") do
- File.open "x", "w" do |io|
- io.write 'gem "a"'
- end
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps("x") do
+ File.open "x", "w" do |io|
+ io.write 'gem "a"'
+ end
- expected = <<-EXPECTED
+ expected = <<-EXPECTED
Could not find gem 'a' in locally installed gems.
You may need to `bundle install` to install missing gems
EXPECTED
- Gem::Deprecate.skip_during do
- actual_stdout, actual_stderr = capture_output do
- Gem.use_gemdeps
+ Gem::Deprecate.skip_during do
+ actual_stdout, actual_stderr = capture_output do
+ Gem.use_gemdeps
+ end
+ assert_empty actual_stdout
+ assert_equal(expected, actual_stderr)
end
- assert_empty actual_stdout
- assert_equal(expected, actual_stderr)
end
end
end
def test_use_gemdeps_specific
- with_rubygems_gemdeps("x") do
- spec = util_spec "a", 1
- install_specs spec
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps("x") do
+ spec = util_spec "a", 1
+ install_specs spec
- spec = Gem::Specification.find {|s| s == spec }
- refute spec.activated?
+ spec = Gem::Specification.find {|s| s == spec }
+ refute spec.activated?
- File.open "x", "w" do |io|
- io.write 'gem "a"'
- end
+ File.open "x", "w" do |io|
+ io.write 'gem "a"'
+ end
- Gem.use_gemdeps
+ Gem.use_gemdeps
- assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
+ assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
+ end
end
end
@@ -2109,4 +2133,22 @@ You may need to `bundle install` to install missing gems
ensure
ENV["RUBYGEMS_GEMDEPS"] = rubygems_gemdeps
end
+
+ def with_local_bundler_at(path)
+ require "bundler"
+
+ # If bundler gemspec exists, pretend it's installed
+ bundler_gemspec = File.expand_path("../../bundler/bundler.gemspec", __dir__)
+ if File.exist?(bundler_gemspec)
+ target_gemspec_location = "#{path}/specifications/bundler-#{Bundler::VERSION}.gemspec"
+
+ FileUtils.mkdir_p File.dirname(target_gemspec_location)
+
+ File.write target_gemspec_location, Gem::Specification.load(bundler_gemspec).to_ruby_for_cache
+ end
+
+ yield
+ ensure
+ Bundler.reset!
+ end
end
diff --git a/test/rubygems/test_gem_commands_owner_command.rb b/test/rubygems/test_gem_commands_owner_command.rb
index ca77041000..32bfbb7a66 100644
--- a/test/rubygems/test_gem_commands_owner_command.rb
+++ b/test/rubygems/test_gem_commands_owner_command.rb
@@ -36,7 +36,7 @@ class TestGemCommandsOwnerCommand < Gem::TestCase
- id: 4
EOF
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
use_ui @stub_ui do
@cmd.show_owners("freewill")
@@ -66,7 +66,7 @@ EOF
- id: 4
EOF
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
assert_raise Psych::DisallowedClass do
use_ui @ui do
@@ -80,7 +80,7 @@ EOF
host = "http://rubygems.example"
ENV["RUBYGEMS_HOST"] = host
- @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
+ @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
use_ui @stub_ui do
@cmd.show_owners("freewill")
@@ -95,7 +95,7 @@ EOF
host = "http://rubygems.example"
@cmd.host = host
- @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
+ @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
use_ui @stub_ui do
@cmd.show_owners("freewill")
@@ -107,7 +107,7 @@ EOF
def test_show_owners_denied
response = "You don't have permission to push to this gem"
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 403, "Forbidden"]
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = HTTPResponseFactory.create(body: response, code: 403, msg: "Forbidden")
assert_raise Gem::MockGemUi::TermError do
use_ui @stub_ui do
@@ -118,9 +118,32 @@ EOF
assert_match response, @stub_ui.output
end
+ def test_show_owners_permanent_redirect
+ host = "http://rubygems.example"
+ ENV["RUBYGEMS_HOST"] = host
+ path = "/api/v1/gems/freewill/owners.yaml"
+ redirected_uri = "https://rubygems.example#{path}"
+
+ @stub_fetcher.data["#{host}#{path}"] = HTTPResponseFactory.create(
+ body: "",
+ code: "301",
+ msg: "Moved Permanently",
+ headers: { "location" => redirected_uri }
+ )
+
+ assert_raise Gem::MockGemUi::TermError do
+ use_ui @stub_ui do
+ @cmd.show_owners("freewill")
+ end
+ end
+
+ response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
+ assert_match response, @stub_ui.output
+ end
+
def test_show_owners_key
response = "- email: user1@example.com\n"
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
File.open Gem.configuration.credentials_path, "a" do |f|
f.write ":other: 701229f217cdf23b1344c7b4b54ca97"
end
@@ -134,7 +157,7 @@ EOF
def test_add_owners
response = "Owner added successfully."
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, "OK"]
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
use_ui @stub_ui do
@cmd.add_owners("freewill", ["user-new1@example.com"])
@@ -149,12 +172,33 @@ EOF
def test_add_owners_denied
response = "You don't have permission to push to this gem"
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 403, "Forbidden"]
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 403, msg: "Forbidden")
+
+ use_ui @stub_ui do
+ @cmd.add_owners("freewill", ["user-new1@example.com"])
+ end
+
+ assert_match response, @stub_ui.output
+ end
+
+ def test_add_owners_permanent_redirect
+ host = "http://rubygems.example"
+ ENV["RUBYGEMS_HOST"] = host
+ path = "/api/v1/gems/freewill/owners"
+ redirected_uri = "https://rubygems.example#{path}"
+
+ @stub_fetcher.data["#{host}#{path}"] = HTTPResponseFactory.create(
+ body: "",
+ code: "308",
+ msg: "Permanent Redirect",
+ headers: { "location" => redirected_uri }
+ )
use_ui @stub_ui do
@cmd.add_owners("freewill", ["user-new1@example.com"])
end
+ response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
assert_match response, @stub_ui.output
end
@@ -162,8 +206,8 @@ EOF
host = "http://rubygems.example"
add_owner_response = "Owner added successfully."
show_owners_response = "- email: user1@example.com\n"
- @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners"] = [add_owner_response, 200, "OK"]
- @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [show_owners_response, 200, "OK"]
+ @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: add_owner_response, code: 200, msg: "OK")
+ @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = HTTPResponseFactory.create(body: show_owners_response, code: 200, msg: "OK")
@cmd.handle_options %W[--host #{host} --add user-new1@example.com freewill]
@@ -178,7 +222,7 @@ EOF
def test_add_owners_key
response = "Owner added successfully."
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, "OK"]
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
File.open Gem.configuration.credentials_path, "a" do |f|
f.write ":other: 701229f217cdf23b1344c7b4b54ca97"
end
@@ -192,7 +236,7 @@ EOF
def test_remove_owners
response = "Owner removed successfully."
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, "OK"]
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
use_ui @stub_ui do
@cmd.remove_owners("freewill", ["user-remove1@example.com"])
@@ -207,7 +251,7 @@ EOF
def test_remove_owners_denied
response = "You don't have permission to push to this gem"
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 403, "Forbidden"]
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 403, msg: "Forbidden")
use_ui @stub_ui do
@cmd.remove_owners("freewill", ["user-remove1@example.com"])
@@ -216,9 +260,46 @@ EOF
assert_match response, @stub_ui.output
end
+ def test_remove_owners_permanent_redirect
+ host = "http://rubygems.example"
+ ENV["RUBYGEMS_HOST"] = host
+ path = "/api/v1/gems/freewill/owners"
+ redirected_uri = "https://rubygems.example#{path}"
+ @stub_fetcher.data["#{host}#{path}"] = HTTPResponseFactory.create(
+ body: "",
+ code: "308",
+ msg: "Permanent Redirect",
+ headers: { "location" => redirected_uri }
+ )
+
+ use_ui @stub_ui do
+ @cmd.remove_owners("freewill", ["user-remove1@example.com"])
+ end
+
+ response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
+ assert_match response, @stub_ui.output
+
+ path = "/api/v1/gems/freewill/owners"
+ redirected_uri = "https://rubygems.example#{path}"
+
+ @stub_fetcher.data["#{host}#{path}"] = HTTPResponseFactory.create(
+ body: "",
+ code: "308",
+ msg: "Permanent Redirect",
+ headers: { "location" => redirected_uri }
+ )
+
+ use_ui @stub_ui do
+ @cmd.add_owners("freewill", ["user-new1@example.com"])
+ end
+
+ response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
+ assert_match response, @stub_ui.output
+ end
+
def test_remove_owners_key
response = "Owner removed successfully."
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, "OK"]
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 200, msg: "OK")
File.open Gem.configuration.credentials_path, "a" do |f|
f.write ":other: 701229f217cdf23b1344c7b4b54ca97"
end
@@ -232,7 +313,7 @@ EOF
def test_remove_owners_missing
response = "Owner could not be found."
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 404, "Not Found"]
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 404, msg: "Not Found")
use_ui @stub_ui do
@cmd.remove_owners("freewill", ["missing@example"])
@@ -246,8 +327,8 @@ EOF
response_success = "Owner added successfully."
@stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [
- [response_fail, 401, "Unauthorized"],
- [response_success, 200, "OK"],
+ HTTPResponseFactory.create(body: response_fail, code: 401, msg: "Unauthorized"),
+ HTTPResponseFactory.create(body: response_success, code: 200, msg: "OK"),
]
@otp_ui = Gem::MockGemUi.new "111111\n"
@@ -263,7 +344,7 @@ EOF
def test_otp_verified_failure
response = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
- @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 401, "Unauthorized"]
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = HTTPResponseFactory.create(body: response, code: 401, msg: "Unauthorized")
@otp_ui = Gem::MockGemUi.new "111111\n"
use_ui @otp_ui do
@@ -281,10 +362,10 @@ EOF
response_success = "Owner removed successfully."
@stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [
- [response_forbidden, 403, "Forbidden"],
- [response_success, 200, "OK"],
+ HTTPResponseFactory.create(body: response_forbidden, code: 403, msg: "Forbidden"),
+ HTTPResponseFactory.create(body: response_success, code: 200, msg: "OK"),
]
- @stub_fetcher.data["#{Gem.host}/api/v1/api_key"] = ["", 200, "OK"]
+ @stub_fetcher.data["#{Gem.host}/api/v1/api_key"] = HTTPResponseFactory.create(body: "", code: 200, msg: "OK")
@cmd.instance_variable_set :@scope, :remove_owner
@stub_ui = Gem::MockGemUi.new "some@mail.com\npass\n"
@@ -305,10 +386,10 @@ EOF
response_success = "Owner added successfully."
@stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [
- [response_forbidden, 403, "Forbidden"],
- [response_success, 200, "OK"],
+ HTTPResponseFactory.create(body: response_forbidden, code: 403, msg: "Forbidden"),
+ HTTPResponseFactory.create(body: response_success, code: 200, msg: "OK"),
]
- @stub_fetcher.data["#{Gem.host}/api/v1/api_key"] = ["", 200, "OK"]
+ @stub_fetcher.data["#{Gem.host}/api/v1/api_key"] = HTTPResponseFactory.create(body: "", code: 200, msg: "OK")
@cmd.instance_variable_set :@scope, :add_owner
@stub_ui = Gem::MockGemUi.new "some@mail.com\npass\n"
diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb
index f38a2ae7a1..ef7730558d 100644
--- a/test/rubygems/test_gem_commands_push_command.rb
+++ b/test/rubygems/test_gem_commands_push_command.rb
@@ -68,7 +68,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
def test_execute
@response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, "OK"]
+ @fetcher.data["#{Gem.host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
@cmd.options[:args] = [@path]
@@ -84,7 +84,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
host = "https://other.example"
@response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{host}/api/v1/gems"] = [@response, 200, "OK"]
+ @fetcher.data["#{host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
@fetcher.data["#{Gem.host}/api/v1/gems"] =
["fail", 500, "Internal Server Error"]
@@ -105,7 +105,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
end
@response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{@spec.metadata['allowed_push_host']}/api/v1/gems"] = [@response, 200, "OK"]
+ @fetcher.data["#{@spec.metadata['allowed_push_host']}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
@fetcher.data["#{Gem.host}/api/v1/gems"] =
["fail", 500, "Internal Server Error"]
@@ -136,7 +136,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
ENV["RUBYGEMS_HOST"] = @host
Gem.configuration.disable_default_gem_server = true
@response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
send_battery
end
@@ -163,14 +163,14 @@ class TestGemCommandsPushCommand < Gem::TestCase
FileUtils.rm Gem.configuration.credentials_path
@response = "Successfully registered gem: freebird (1.0.1)"
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
send_battery
end
def test_sending_gem
@response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
send_battery
end
@@ -197,7 +197,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
FileUtils.rm Gem.configuration.credentials_path
@response = "Successfully registered gem: freebird (1.0.1)"
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
send_battery
end
@@ -212,7 +212,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
ENV["GEM_HOST_API_KEY"] = "PRIVKEY"
@response = "Successfully registered gem: freebird (1.0.1)"
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
send_battery
end
@@ -238,7 +238,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
FileUtils.rm Gem.configuration.credentials_path
@response = "Successfully registered gem: freebird (1.0.1)"
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
send_battery
end
@@ -309,7 +309,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
FileUtils.rm Gem.configuration.credentials_path
@response = "Successfully registered gem: freebird (1.0.1)"
- @fetcher.data["#{host}/api/v1/gems"] = [@response, 200, "OK"]
+ @fetcher.data["#{host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
# do not set @host
use_ui(@ui) { @cmd.send_gem(@path) }
@@ -325,6 +325,27 @@ class TestGemCommandsPushCommand < Gem::TestCase
assert_match @response, @ui.output
end
+ def test_sending_gem_to_host_permanent_redirect
+ @host = "http://rubygems.example"
+ redirected_uri = "https://rubygems.example/api/v1/gems"
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(
+ body: "",
+ code: 308,
+ msg: "Permanent Redirect",
+ headers: { "Location" => redirected_uri }
+ )
+
+ assert_raise Gem::MockGemUi::TermError do
+ use_ui @ui do
+ @cmd.instance_variable_set :@host, @host
+ @cmd.send_gem(@path)
+ end
+ end
+
+ response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
+ assert_match response, @ui.output
+ end
+
def test_raises_error_with_no_arguments
def @cmd.sign_in(*); end
assert_raise Gem::CommandLineError do
@@ -334,7 +355,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
def test_sending_gem_denied
response = "You don't have permission to push to this gem"
- @fetcher.data["#{@host}/api/v1/gems"] = [response, 403, "Forbidden"]
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: response, code: 403, msg: "Forbidden")
@cmd.instance_variable_set :@host, @host
assert_raise Gem::MockGemUi::TermError do
@@ -348,7 +369,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
def test_sending_gem_key
@response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, "OK"]
+ @fetcher.data["#{@host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
File.open Gem.configuration.credentials_path, "a" do |f|
f.write ":other: 701229f217cdf23b1344c7b4b54ca97"
end
@@ -367,8 +388,8 @@ class TestGemCommandsPushCommand < Gem::TestCase
response_success = "Successfully registered gem: freewill (1.0.0)"
@fetcher.data["#{Gem.host}/api/v1/gems"] = [
- [response_fail, 401, "Unauthorized"],
- [response_success, 200, "OK"],
+ HTTPResponseFactory.create(body: response_fail, code: 401, msg: "Unauthorized"),
+ HTTPResponseFactory.create(body: response_success, code: 200, msg: "OK"),
]
@otp_ui = Gem::MockGemUi.new "111111\n"
@@ -384,7 +405,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
def test_otp_verified_failure
response = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
- @fetcher.data["#{Gem.host}/api/v1/gems"] = [response, 401, "Unauthorized"]
+ @fetcher.data["#{Gem.host}/api/v1/gems"] = HTTPResponseFactory.create(body: response, code: 401, msg: "Unauthorized")
@otp_ui = Gem::MockGemUi.new "111111\n"
assert_raise Gem::MockGemUi::TermError do
@@ -405,12 +426,12 @@ class TestGemCommandsPushCommand < Gem::TestCase
response_success = "Successfully registered gem: freewill (1.0.0)"
@fetcher.data["#{@host}/api/v1/gems"] = [
- [response_mfa_enabled, 401, "Unauthorized"],
- [response_forbidden, 403, "Forbidden"],
- [response_success, 200, "OK"],
+ HTTPResponseFactory.create(body: response_mfa_enabled, code: 401, msg: "Unauthorized"),
+ HTTPResponseFactory.create(body: response_forbidden, code: 403, msg: "Forbidden"),
+ HTTPResponseFactory.create(body: response_success, code: 200, msg: "OK"),
]
- @fetcher.data["#{@host}/api/v1/api_key"] = ["", 200, "OK"]
+ @fetcher.data["#{@host}/api/v1/api_key"] = HTTPResponseFactory.create(body: "", code: 200, msg: "OK")
@cmd.instance_variable_set :@host, @host
@cmd.instance_variable_set :@scope, :push_rubygem
@@ -438,16 +459,16 @@ class TestGemCommandsPushCommand < Gem::TestCase
response_profile = "mfa: disabled\n"
@fetcher.data["#{@host}/api/v1/gems"] = [
- [response_success, 200, "OK"],
+ HTTPResponseFactory.create(body: response_success, code: 200, msg: "OK"),
]
@fetcher.data["#{@host}/api/v1/api_key"] = [
- [response_mfa_enabled, 401, "Unauthorized"],
- ["", 200, "OK"],
+ HTTPResponseFactory.create(body: response_mfa_enabled, code: 401, msg: "Unauthorized"),
+ HTTPResponseFactory.create(body: "", code: 200, msg: "OK"),
]
@fetcher.data["#{@host}/api/v1/profile/me.yaml"] = [
- [response_profile, 200, "OK"],
+ HTTPResponseFactory.create(body: response_profile, code: 200, msg: "OK"),
]
@cmd.instance_variable_set :@scope, :push_rubygem
diff --git a/test/rubygems/test_gem_commands_signin_command.rb b/test/rubygems/test_gem_commands_signin_command.rb
index ce745bff20..281e4f9eac 100644
--- a/test/rubygems/test_gem_commands_signin_command.rb
+++ b/test/rubygems/test_gem_commands_signin_command.rb
@@ -71,6 +71,31 @@ class TestGemCommandsSigninCommand < Gem::TestCase
assert_equal api_key, credentials[host]
end
+ def test_execute_with_host_permanent_redirect
+ host = "http://rubygems.example/"
+ ENV["RUBYGEMS_HOST"] = host
+ path = "/api/v1/api_key"
+ redirected_uri = "http://rubygems.example#{path}"
+ fetcher = Gem::FakeFetcher.new
+ fetcher.data["#{host}#{path}"] = HTTPResponseFactory.create(
+ body: "",
+ code: "308",
+ msg: "Permanent Redirect",
+ headers: { "location" => redirected_uri }
+ )
+ Gem::RemoteFetcher.fetcher = fetcher
+ ui = Gem::MockGemUi.new("you@example.com\nsecret\n\n\n\n\n\n\n\n\n")
+
+ assert_raise Gem::MockGemUi::TermError do
+ use_ui ui do
+ @cmd.execute
+ end
+ end
+
+ response = "The request has redirected permanently to #{redirected_uri}. Please check your defined push host URL."
+ assert_match response, ui.output
+ end
+
def test_execute_with_valid_creds_set_for_default_host
util_capture { @cmd.execute }
@@ -186,7 +211,7 @@ class TestGemCommandsSigninCommand < Gem::TestCase
# Set the expected response for the Web-API supplied
ENV["RUBYGEMS_HOST"] = host
data_key = "#{ENV['RUBYGEMS_HOST']}/api/v1/api_key"
- fetcher.data[data_key] = [api_key, 200, "OK"]
+ fetcher.data[data_key] = HTTPResponseFactory.create(body: api_key, code: 200, msg: "OK")
use_ui key_name_ui do
@cmd.execute
@@ -209,8 +234,8 @@ class TestGemCommandsSigninCommand < Gem::TestCase
def util_capture(ui_stub = nil, host = nil, api_key = nil, fetcher = Gem::FakeFetcher.new, mfa_level = "disabled", warning = nil)
api_key ||= "a5fdbb6ba150cbb83aad2bb2fede64cf040453903"
- response = [api_key, 200, "OK"]
- profile_response = [ "mfa: #{mfa_level}\nwarning: #{warning}" , 200, "OK"]
+ response = HTTPResponseFactory.create(body: api_key, code: 200, msg: "OK")
+ profile_response = HTTPResponseFactory.create(body: "mfa: #{mfa_level}\nwarning: #{warning}", code: 200, msg: "OK")
email = "you@example.com"
password = "secret"
diff --git a/test/rubygems/test_gem_commands_yank_command.rb b/test/rubygems/test_gem_commands_yank_command.rb
index 878b52416e..d14395a75e 100644
--- a/test/rubygems/test_gem_commands_yank_command.rb
+++ b/test/rubygems/test_gem_commands_yank_command.rb
@@ -43,7 +43,7 @@ class TestGemCommandsYankCommand < Gem::TestCase
def test_execute
yank_uri = "http://example/api/v1/gems/yank"
- @fetcher.data[yank_uri] = ["Successfully yanked", 200, "OK"]
+ @fetcher.data[yank_uri] = HTTPResponseFactory.create(body: "Successfully yanked", code: 200, msg: "OK")
@cmd.options[:args] = %w[a]
@cmd.options[:added_platform] = true
@@ -69,8 +69,8 @@ class TestGemCommandsYankCommand < Gem::TestCase
response_fail = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
yank_uri = "http://example/api/v1/gems/yank"
@fetcher.data[yank_uri] = [
- [response_fail, 401, "Unauthorized"],
- ["Successfully yanked", 200, "OK"],
+ HTTPResponseFactory.create(body: response_fail, code: 401, msg: "Unauthorized"),
+ HTTPResponseFactory.create(body: "Successfully yanked", code: 200, msg: "OK"),
]
@cmd.options[:args] = %w[a]
@@ -92,7 +92,7 @@ class TestGemCommandsYankCommand < Gem::TestCase
def test_execute_with_otp_failure
response = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
yank_uri = "http://example/api/v1/gems/yank"
- @fetcher.data[yank_uri] = [response, 401, "Unauthorized"]
+ @fetcher.data[yank_uri] = HTTPResponseFactory.create(body: response, code: 401, msg: "Unauthorized")
@cmd.options[:args] = %w[a]
@cmd.options[:added_platform] = true
@@ -111,7 +111,7 @@ class TestGemCommandsYankCommand < Gem::TestCase
def test_execute_key
yank_uri = "http://example/api/v1/gems/yank"
- @fetcher.data[yank_uri] = ["Successfully yanked", 200, "OK"]
+ @fetcher.data[yank_uri] = HTTPResponseFactory.create(body: "Successfully yanked", code: 200, msg: "OK")
@cmd.options[:args] = %w[a]
@cmd.options[:version] = req("= 1.0")
@@ -129,7 +129,7 @@ class TestGemCommandsYankCommand < Gem::TestCase
def test_execute_host
host = "https://other.example"
yank_uri = "#{host}/api/v1/gems/yank"
- @fetcher.data[yank_uri] = ["Successfully yanked", 200, "OK"]
+ @fetcher.data[yank_uri] = HTTPResponseFactory.create(body: "Successfully yanked", code: 200, msg: "OK")
@cmd.options[:args] = %w[a]
@cmd.options[:version] = req("= 1.0")
@@ -154,11 +154,11 @@ class TestGemCommandsYankCommand < Gem::TestCase
host = "http://example"
@fetcher.data["#{host}/api/v1/gems/yank"] = [
- [response_forbidden, 403, "Forbidden"],
- [response_success, 200, "OK"],
+ HTTPResponseFactory.create(body: response_forbidden, code: 403, msg: "Forbidden"),
+ HTTPResponseFactory.create(body: response_success, code: 200, msg: "OK"),
]
- @fetcher.data["#{host}/api/v1/api_key"] = ["", 200, "OK"]
+ @fetcher.data["#{host}/api/v1/api_key"] = HTTPResponseFactory.create(body: "", code: 200, msg: "OK")
@cmd.options[:args] = %w[a]
@cmd.options[:added_platform] = true
@cmd.options[:version] = req("= 1.0")
diff --git a/test/rubygems/test_gem_gemcutter_utilities.rb b/test/rubygems/test_gem_gemcutter_utilities.rb
index 2ca5b402d9..5e59733d5a 100644
--- a/test/rubygems/test_gem_gemcutter_utilities.rb
+++ b/test/rubygems/test_gem_gemcutter_utilities.rb
@@ -93,7 +93,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
def test_sign_in
api_key = "a5fdbb6ba150cbb83aad2bb2fede64cf040453903"
- util_sign_in [api_key, 200, "OK"]
+ util_sign_in HTTPResponseFactory.create(body: api_key, code: 200, msg: "OK")
assert_match %r{Enter your RubyGems.org credentials.}, @sign_in_ui.output
assert @fetcher.last_request["authorization"]
@@ -106,7 +106,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
def test_sign_in_with_host
api_key = "a5fdbb6ba150cbb83aad2bb2fede64cf040453903"
- util_sign_in [api_key, 200, "OK"], "http://example.com", ["http://example.com"]
+ util_sign_in HTTPResponseFactory.create(body: api_key, code: 200, msg: "OK"), "http://example.com", ["http://example.com"]
assert_match "Enter your http://example.com credentials.",
@sign_in_ui.output
@@ -120,7 +120,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
def test_sign_in_with_host_nil
api_key = "a5fdbb6ba150cbb83aad2bb2fede64cf040453903"
- util_sign_in [api_key, 200, "OK"], nil, [nil]
+ util_sign_in HTTPResponseFactory.create(body: api_key, code: 200, msg: "OK"), nil, [nil]
assert_match "Enter your RubyGems.org credentials.",
@sign_in_ui.output
@@ -133,7 +133,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
def test_sign_in_with_host_ENV
api_key = "a5fdbb6ba150cbb83aad2bb2fede64cf040453903"
- util_sign_in [api_key, 200, "OK"], "http://example.com"
+ util_sign_in HTTPResponseFactory.create(body: api_key, code: 200, msg: "OK"), "http://example.com"
assert_match "Enter your http://example.com credentials.",
@sign_in_ui.output
@@ -148,7 +148,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
api_key = "a5fdbb6ba150cbb83aad2bb2fede64cf040453903"
Gem.configuration.rubygems_api_key = api_key
- util_sign_in [api_key, 200, "OK"]
+ util_sign_in HTTPResponseFactory.create(body: api_key, code: 200, msg: "OK")
assert_equal "", @sign_in_ui.output
end
@@ -157,7 +157,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
api_key = "a5fdbb6ba150cbb83aad2bb2fede64cf040453903"
Gem.configuration.api_keys[:KEY] = "other"
@cmd.options[:key] = :KEY
- util_sign_in [api_key, 200, "OK"]
+ util_sign_in HTTPResponseFactory.create(body: api_key, code: 200, msg: "OK")
assert_equal "", @sign_in_ui.output
end
@@ -169,7 +169,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
File.open Gem.configuration.credentials_path, "w" do |f|
f.write Hash[:other_api_key, other_api_key].to_yaml
end
- util_sign_in [api_key, 200, "OK"]
+ util_sign_in HTTPResponseFactory.create(body: api_key, code: 200, msg: "OK")
assert_match %r{Enter your RubyGems.org credentials.}, @sign_in_ui.output
assert_match %r{Signed in.}, @sign_in_ui.output
@@ -181,7 +181,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
def test_sign_in_with_bad_credentials
assert_raise Gem::MockGemUi::TermError do
- util_sign_in ["Access Denied.", 403, "Forbidden"]
+ util_sign_in HTTPResponseFactory.create(body: "Access Denied.", code: 403, msg: "Forbidden")
end
assert_match %r{Enter your RubyGems.org credentials.}, @sign_in_ui.output
@@ -192,7 +192,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
ENV["GEM_HOST_OTP_CODE"] = "111111"
api_key = "a5fdbb6ba150cbb83aad2bb2fede64cf040453903"
- util_sign_in [api_key, 200, "OK"]
+ util_sign_in HTTPResponseFactory.create(body: api_key, code: 200, msg: "OK")
assert_match "Signed in with API key:", @sign_in_ui.output
assert_equal "111111", @fetcher.last_request["OTP"]
@@ -204,7 +204,11 @@ class TestGemGemcutterUtilities < Gem::TestCase
util_sign_in(proc do
@call_count ||= 0
- (@call_count += 1).odd? ? [response_fail, 401, "Unauthorized"] : [api_key, 200, "OK"]
+ if (@call_count += 1).odd?
+ HTTPResponseFactory.create(body: response_fail, code: 401, msg: "Unauthorized")
+ else
+ HTTPResponseFactory.create(body: api_key, code: 200, msg: "OK")
+ end
end, nil, [], "111111\n")
assert_match "You have enabled multi-factor authentication. Please enter OTP code.", @sign_in_ui.output
@@ -217,7 +221,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
response = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
assert_raise Gem::MockGemUi::TermError do
- util_sign_in [response, 401, "Unauthorized"], nil, [], "111111\n"
+ util_sign_in HTTPResponseFactory.create(body: response, code: 401, msg: "Unauthorized"), nil, [], "111111\n"
end
assert_match "You have enabled multi-factor authentication. Please enter OTP code.", @sign_in_ui.output
@@ -229,7 +233,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
def util_sign_in(response, host = nil, args = [], extra_input = "")
email = "you@example.com"
password = "secret"
- profile_response = [ "mfa: disabled\n" , 200, "OK"]
+ profile_response = HTTPResponseFactory.create(body: "mfa: disabled\n", code: 200, msg: "OK")
if host
ENV["RUBYGEMS_HOST"] = host
diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb
index 9295f42dba..eebe4d86d0 100644
--- a/test/rubygems/test_gem_package.rb
+++ b/test/rubygems/test_gem_package.rb
@@ -510,6 +510,21 @@ class TestGemPackage < Gem::Package::TarTestCase
assert_path_exist @destination
end
+ def test_extract_file_permissions
+ pend "chmod not supported" if win_platform?
+
+ gem_with_long_permissions = File.expand_path("packages/Bluebie-legs-0.6.2.gem", __dir__)
+
+ package = Gem::Package.new gem_with_long_permissions
+
+ package.extract_files @destination
+
+ filepath = File.join @destination, "README.rdoc"
+ assert_path_exist filepath
+
+ assert_equal 0104444, File.stat(filepath).mode
+ end
+
def test_extract_tar_gz_absolute
package = Gem::Package.new @gem
diff --git a/test/rubygems/test_gem_platform.rb b/test/rubygems/test_gem_platform.rb
index 576f150219..61547d8972 100644
--- a/test/rubygems/test_gem_platform.rb
+++ b/test/rubygems/test_gem_platform.rb
@@ -333,6 +333,34 @@ class TestGemPlatform < Gem::TestCase
refute(arm_linux_uclibceabi === arm_linux_eabi, "linux-uclibceabi =~ linux-eabi")
end
+ def test_eabi_and_nil_version_combination_strictness
+ arm_linux = Gem::Platform.new "arm-linux"
+ arm_linux_eabi = Gem::Platform.new "arm-linux-eabi"
+ arm_linux_eabihf = Gem::Platform.new "arm-linux-eabihf"
+ arm_linux_gnueabi = Gem::Platform.new "arm-linux-gnueabi"
+ arm_linux_gnueabihf = Gem::Platform.new "arm-linux-gnueabihf"
+ arm_linux_musleabi = Gem::Platform.new "arm-linux-musleabi"
+ arm_linux_musleabihf = Gem::Platform.new "arm-linux-musleabihf"
+ arm_linux_uclibceabi = Gem::Platform.new "arm-linux-uclibceabi"
+ arm_linux_uclibceabihf = Gem::Platform.new "arm-linux-uclibceabihf"
+
+ # generic arm host runtime with eabi modifier accepts generic arm gems
+ assert(arm_linux === arm_linux_eabi, "arm-linux =~ arm-linux-eabi")
+ assert(arm_linux === arm_linux_eabihf, "arm-linux =~ arm-linux-eabihf")
+
+ # explicit gnu arm host runtime with eabi modifier accepts generic arm gems
+ assert(arm_linux === arm_linux_gnueabi, "arm-linux =~ arm-linux-gnueabi")
+ assert(arm_linux === arm_linux_gnueabihf, "arm-linux =~ arm-linux-gnueabihf")
+
+ # musl arm host runtime accepts libc-generic or statically linked gems...
+ assert(arm_linux === arm_linux_musleabi, "arm-linux =~ arm-linux-musleabi")
+ assert(arm_linux === arm_linux_musleabihf, "arm-linux =~ arm-linux-musleabihf")
+
+ # other libc arm hosts are not glibc compatible
+ refute(arm_linux === arm_linux_uclibceabi, "arm-linux =~ arm-linux-uclibceabi")
+ refute(arm_linux === arm_linux_uclibceabihf, "arm-linux =~ arm-linux-uclibceabihf")
+ end
+
def test_equals3_cpu_arm
arm = Gem::Platform.new "arm-linux"
armv5 = Gem::Platform.new "armv5-linux"
@@ -452,6 +480,13 @@ class TestGemPlatform < Gem::TestCase
assert_equal 1, result.scan(/@version=/).size
end
+ def test_gem_platform_match_with_string_argument
+ util_set_arch "x86_64-linux-musl"
+
+ assert(Gem::Platform.match(Gem::Platform.new("x86_64-linux")), "should match Gem::Platform")
+ assert(Gem::Platform.match("x86_64-linux"), "should match String platform")
+ end
+
def assert_local_match(name)
assert_match Gem::Platform.local, name
end
diff --git a/test/rubygems/test_gem_resolver.rb b/test/rubygems/test_gem_resolver.rb
index c816d5484b..54497c6e4f 100644
--- a/test/rubygems/test_gem_resolver.rb
+++ b/test/rubygems/test_gem_resolver.rb
@@ -391,6 +391,39 @@ class TestGemResolver < Gem::TestCase
end
end
+ def test_pick_generic_linux_variants_on_musl_linux
+ util_set_arch "aarch64-linux-musl" do
+ is = Gem::Resolver::IndexSpecification
+
+ linux = Gem::Platform.new("aarch64-linux")
+
+ spec_fetcher do |fetcher|
+ fetcher.spec "libv8-node", "15.14.0.1" do |s|
+ s.platform = linux
+ end
+
+ fetcher.spec "libv8-node", "15.14.0.1"
+ end
+
+ v15 = v("15.14.0.1")
+ source = Gem::Source.new @gem_repo
+
+ s = set
+
+ v15_ruby = is.new s, "libv8-node", v15, source, Gem::Platform::RUBY
+ v15_linux = is.new s, "libv8-node", v15, source, linux.to_s
+
+ s.add v15_linux
+ s.add v15_ruby
+
+ ad = make_dep "libv8-node", "= 15.14.0.1"
+
+ res = Gem::Resolver.new([ad], s)
+
+ assert_resolves_to [v15_linux.spec], res
+ end
+ end
+
def test_only_returns_spec_once
a1 = util_spec "a", "1", "c" => "= 1"
b1 = util_spec "b", "1", "c" => "= 1"
diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb
index 6135acea92..222bdcfb28 100644
--- a/test/rubygems/test_require.rb
+++ b/test/rubygems/test_require.rb
@@ -252,9 +252,9 @@ class TestGemRequire < Gem::TestCase
# Activates a-1, but not b-1 and b-2
assert_require "test_gem_require_a"
assert_equal %w[a-1], loaded_spec_names
- assert $LOAD_PATH.include? a1.load_paths[0]
- refute $LOAD_PATH.include? b1.load_paths[0]
- refute $LOAD_PATH.include? b2.load_paths[0]
+ assert $LOAD_PATH.include? a1.full_require_paths[0]
+ refute $LOAD_PATH.include? b1.full_require_paths[0]
+ refute $LOAD_PATH.include? b2.full_require_paths[0]
assert_equal unresolved_names, ["b (>= 1)"]
@@ -265,13 +265,13 @@ class TestGemRequire < Gem::TestCase
# and as a result #gem_original_require returns false.
refute require("benchmark"), "the benchmark stdlib should be recognized as already loaded"
- assert_includes $LOAD_PATH, b2.load_paths[0]
+ assert_includes $LOAD_PATH, b2.full_require_paths[0]
assert_includes $LOAD_PATH, rubylibdir
message = proc {
"this test relies on the b-2 gem lib/ to be before stdlib to make sense\n" +
$LOAD_PATH.pretty_inspect
}
- assert_operator $LOAD_PATH.index(b2.load_paths[0]), :<, $LOAD_PATH.index(rubylibdir), message
+ assert_operator $LOAD_PATH.index(b2.full_require_paths[0]), :<, $LOAD_PATH.index(rubylibdir), message
# We detected that we should activate b-2, so we did so, but
# then #gem_original_require decided "I've already got some benchmark.rb" loaded.
diff --git a/test/rubygems/utilities.rb b/test/rubygems/utilities.rb
index c01f7acd48..8b9fa98e3d 100644
--- a/test/rubygems/utilities.rb
+++ b/test/rubygems/utilities.rb
@@ -54,13 +54,21 @@ class Gem::FakeFetcher
raise Gem::RemoteFetcher::FetchError.new("no data for #{path}", path)
end
- if @data[path].kind_of?(Array) && @data[path].first.kind_of?(Array)
+ if @data[path].kind_of?(Array)
@data[path].shift
else
@data[path]
end
end
+ def create_response(uri)
+ data = find_data(uri)
+ response = data.respond_to?(:call) ? data.call : data
+ raise TypeError, "#{response.class} is not a type of Net::HTTPResponse" unless response.kind_of?(Net::HTTPResponse)
+
+ response
+ end
+
def fetch_path(path, mtime = nil, head = false)
data = find_data(path)
@@ -85,26 +93,16 @@ class Gem::FakeFetcher
# Thanks, FakeWeb!
def open_uri_or_path(path)
- data = find_data(path)
- body, code, msg = data
+ find_data(path)
- response = Net::HTTPResponse.send(:response_class, code.to_s).new("1.0", code.to_s, msg)
- response.instance_variable_set(:@body, body)
- response.instance_variable_set(:@read, true)
- response
+ create_response(uri)
end
def request(uri, request_class, last_modified = nil)
- data = find_data(uri)
- body, code, msg = (data.respond_to?(:call) ? data.call : data)
-
@last_request = request_class.new uri.request_uri
yield @last_request if block_given?
- response = Net::HTTPResponse.send(:response_class, code.to_s).new("1.0", code.to_s, msg)
- response.instance_variable_set(:@body, body)
- response.instance_variable_set(:@read, true)
- response
+ create_response(uri)
end
def pretty_print(q) # :nodoc:
@@ -164,6 +162,30 @@ class Gem::FakeFetcher
end
end
+##
+# The HTTPResponseFactory allows easy creation of Net::HTTPResponse instances in RubyGems tests:
+#
+# Example:
+#
+# HTTPResponseFactory.create(
+# body: "",
+# code: 301,
+# msg: "Moved Permanently",
+# headers: { "location" => "http://example.com" }
+# )
+#
+
+class HTTPResponseFactory
+ def self.create(body:, code:, msg:, headers: {})
+ response = Net::HTTPResponse.send(:response_class, code.to_s).new("1.0", code.to_s, msg)
+ response.instance_variable_set(:@body, body)
+ response.instance_variable_set(:@read, true)
+ headers.each {|name, value| response[name] = value }
+
+ response
+ end
+end
+
# :stopdoc:
class Gem::RemoteFetcher
def self.fetcher=(fetcher)