From c6da9cadb346cc1d250c7ed6d8fd33c62a11030e Mon Sep 17 00:00:00 2001 From: hsbt Date: Fri, 18 May 2018 01:39:13 +0000 Subject: [PATCH] Merge RubyGems 2.7.7 see release details here: https://blog.rubygems.org/2018/05/18/2.7.7-released.html git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems.rb | 24 +++++++- lib/rubygems/bundler_version_finder.rb | 6 +- lib/rubygems/commands/push_command.rb | 2 +- lib/rubygems/commands/setup_command.rb | 2 +- lib/rubygems/commands/unpack_command.rb | 2 +- lib/rubygems/dependency.rb | 1 + lib/rubygems/dependency_installer.rb | 6 +- lib/rubygems/exceptions.rb | 6 +- lib/rubygems/indexer.rb | 2 +- lib/rubygems/installer.rb | 6 +- lib/rubygems/package.rb | 12 +++- lib/rubygems/remote_fetcher.rb | 2 +- lib/rubygems/request_set.rb | 4 +- lib/rubygems/server.rb | 6 +- lib/rubygems/source.rb | 2 +- lib/rubygems/specification.rb | 17 +++--- lib/rubygems/test_case.rb | 10 +++- lib/rubygems/test_utilities.rb | 2 +- lib/rubygems/user_interaction.rb | 4 ++ lib/rubygems/version.rb | 1 + test/rubygems/test_gem.rb | 14 ++--- .../test_gem_commands_setup_command.rb | 2 +- test/rubygems/test_gem_package.rb | 59 +++++++++++++++++-- test/rubygems/test_gem_package_tar_header.rb | 2 +- test/rubygems/test_gem_remote_fetcher.rb | 2 +- test/rubygems/test_gem_security_policy.rb | 6 +- test/rubygems/test_gem_server.rb | 16 ++--- test/rubygems/test_gem_specification.rb | 2 +- test/rubygems/test_gem_version.rb | 1 + 29 files changed, 161 insertions(+), 60 deletions(-) diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 2762bfcb88b1cf..830c16b7d74d50 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -10,7 +10,7 @@ require 'thread' module Gem - VERSION = "2.7.6" + VERSION = "2.7.7" end # Must be first since it unloads the prelude from 1.9.2 @@ -604,7 +604,7 @@ def self.find_home private_class_method :find_home - # FIXME deprecate these in 3.0 + # TODO: remove in RubyGems 4.0 ## # Zlib::GzipReader wrapper that unzips +data+. @@ -613,6 +613,11 @@ def self.gunzip(data) Gem::Util.gunzip data end + class << self + extend Gem::Deprecate + deprecate :gunzip, "Gem::Util.gunzip", 2018, 12 + end + ## # Zlib::GzipWriter wrapper that zips +data+. @@ -620,6 +625,11 @@ def self.gzip(data) Gem::Util.gzip data end + class << self + extend Gem::Deprecate + deprecate :gzip, "Gem::Util.gzip", 2018, 12 + end + ## # A Zlib::Inflate#inflate wrapper @@ -627,6 +637,11 @@ def self.inflate(data) Gem::Util.inflate data end + class << self + extend Gem::Deprecate + deprecate :inflate, "Gem::Util.inflate", 2018, 12 + end + ## # Top level install helper method. Allows you to install gems interactively: # @@ -1225,9 +1240,12 @@ def self.use_gemdeps path = nil class << self ## - # TODO remove with RubyGems 3.0 + # TODO remove with RubyGems 4.0 alias detect_gemdeps use_gemdeps # :nodoc: + + extend Gem::Deprecate + deprecate :detect_gemdeps, "Gem.use_gemdeps", 2018, 12 end # FIX: Almost everywhere else we use the `def self.` way of defining class diff --git a/lib/rubygems/bundler_version_finder.rb b/lib/rubygems/bundler_version_finder.rb index baca170840c8c1..2f448c956214ed 100644 --- a/lib/rubygems/bundler_version_finder.rb +++ b/lib/rubygems/bundler_version_finder.rb @@ -1,3 +1,7 @@ +# frozen_string_literal: true + +require "rubygems/util" + module Gem::BundlerVersionFinder @without_filtering = false @@ -102,7 +106,7 @@ def self.lockfile_contents lockfile = case gemfile when "gems.rb" then "gems.locked" else "#{gemfile}.lock" - end.untaint + end.dup.untaint return unless File.file?(lockfile) diff --git a/lib/rubygems/commands/push_command.rb b/lib/rubygems/commands/push_command.rb index d294cbc8df3217..613c4e6ddf682e 100644 --- a/lib/rubygems/commands/push_command.rb +++ b/lib/rubygems/commands/push_command.rb @@ -13,7 +13,7 @@ def description # :nodoc: The push command uploads a gem to the push server (the default is https://rubygems.org) and adds it to the index. -The gem can be removed from the index (but only the index) using the yank +The gem can be removed from the index and deleted from the server using the yank command. For further discussion see the help for the yank command. EOF end diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index ee6ce88eaeaaaa..b6690c9d54c66d 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -385,7 +385,7 @@ def install_default_bundler_gem each {|default_gem| rm_r File.join(bundler_spec.gems_dir, default_gem) } end - bundler_bin_dir = File.join(Gem.default_dir, 'gems', bundler_spec.full_name, bundler_spec.bindir) + bundler_bin_dir = bundler_spec.bin_dir bundler_bin_dir = File.join(options[:destdir], bundler_bin_dir) unless Gem.win_platform? mkdir_p bundler_bin_dir bundler_spec.executables.each do |e| diff --git a/lib/rubygems/commands/unpack_command.rb b/lib/rubygems/commands/unpack_command.rb index b873f20d280da2..bdcfd524f14237 100644 --- a/lib/rubygems/commands/unpack_command.rb +++ b/lib/rubygems/commands/unpack_command.rb @@ -183,7 +183,7 @@ def get_metadata path, security_policy = nil when 'metadata' then metadata = entry.read when 'metadata.gz' then - metadata = Gem.gunzip entry.read + metadata = Gem::Util.gunzip entry.read end end end diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb index 55873c71e87e23..346566679039dd 100644 --- a/lib/rubygems/dependency.rb +++ b/lib/rubygems/dependency.rb @@ -2,6 +2,7 @@ ## # The Dependency class holds a Gem name and a Gem::Requirement. +require "rubygems/bundler_version_finder" require "rubygems/requirement" class Gem::Dependency diff --git a/lib/rubygems/dependency_installer.rb b/lib/rubygems/dependency_installer.rb index 5a87f5095600dc..879e085359418f 100644 --- a/lib/rubygems/dependency_installer.rb +++ b/lib/rubygems/dependency_installer.rb @@ -113,7 +113,7 @@ def initialize options = {} ## #-- - # TODO remove, no longer used + # TODO remove at RubyGems 4, no longer used def add_found_dependencies to_do, dependency_list # :nodoc: seen = {} @@ -163,6 +163,7 @@ def add_found_dependencies to_do, dependency_list # :nodoc: dependency_list.remove_specs_unsatisfied_by dependencies end + deprecate :add_found_dependencies, :none, 2018, 12 ## # Creates an AvailableSet to install from based on +dep_or_name+ and @@ -321,7 +322,7 @@ def find_spec_by_name_and_version gem_name, # Gathers all dependencies necessary for the installation from local and # remote sources unless the ignore_dependencies was given. #-- - # TODO remove at RubyGems 3 + # TODO remove at RubyGems 4 def gather_dependencies # :nodoc: specs = @available.all_specs @@ -354,6 +355,7 @@ def gather_dependencies # :nodoc: @gems_to_install = dependency_list.dependency_order.reverse end + deprecate :gather_dependencies, :none, 2018, 12 def in_background what # :nodoc: fork_happened = false diff --git a/lib/rubygems/exceptions.rb b/lib/rubygems/exceptions.rb index b7528761fc2a41..328bd5f4768d73 100644 --- a/lib/rubygems/exceptions.rb +++ b/lib/rubygems/exceptions.rb @@ -4,6 +4,8 @@ # Each exception needs a brief description and the scenarios where it is # likely to be raised +require 'rubygems/deprecate' + ## # Base exception class for RubyGems. All exception raised by RubyGems are a # subclass of this one. @@ -11,10 +13,12 @@ class Gem::Exception < RuntimeError ## #-- - # TODO: remove in RubyGems 3, nobody sets this + # TODO: remove in RubyGems 4, nobody sets this attr_accessor :source_exception # :nodoc: + extend Gem::Deprecate + deprecate :source_exception, :none, 2018, 12 end class Gem::CommandLineError < Gem::Exception; end diff --git a/lib/rubygems/indexer.rb b/lib/rubygems/indexer.rb index 3ea994414bef7f..2e59e790d42fca 100644 --- a/lib/rubygems/indexer.rb +++ b/lib/rubygems/indexer.rb @@ -347,7 +347,7 @@ def paranoid(path, extension) data = Gem.read_binary path compressed_data = Gem.read_binary "#{path}.#{extension}" - unless data == Gem.inflate(compressed_data) then + unless data == Gem::Util.inflate(compressed_data) then raise "Compressed file #{compressed_path} does not match uncompressed file #{path}" end end diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index ee5fedeb64190d..0c58c29ac92af2 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -7,6 +7,7 @@ require 'rubygems/command' require 'rubygems/exceptions' +require 'rubygems/deprecate' require 'rubygems/package' require 'rubygems/ext' require 'rubygems/user_interaction' @@ -27,6 +28,8 @@ class Gem::Installer + extend Gem::Deprecate + ## # Paths where env(1) might live. Some systems are broken and have it in # /bin @@ -777,13 +780,14 @@ def build_extensions ## # Logs the build +output+ in +build_dir+, then raises Gem::Ext::BuildError. # - # TODO: Delete this for RubyGems 3. It remains for API compatibility + # TODO: Delete this for RubyGems 4. It remains for API compatibility def extension_build_error(build_dir, output, backtrace = nil) # :nodoc: builder = Gem::Ext::Builder.new spec, @build_args builder.build_error build_dir, output, backtrace end + deprecate :extension_build_error, :none, 2018, 12 ## # Reads the file index and extracts each file into the gem directory. diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index b924122827ddb0..729bbd6f791976 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -429,6 +429,14 @@ def install_location filename, destination_dir # :nodoc: destination end + def normalize_path(pathname) + if Gem.win_platform? + pathname.downcase + else + pathname + end + end + def mkdir_p_safe mkdir, mkdir_options, destination_dir, file_name destination_dir = realpath File.expand_path(destination_dir) parts = mkdir.split(File::SEPARATOR) @@ -437,7 +445,7 @@ def mkdir_p_safe mkdir, mkdir_options, destination_dir, file_name path = File.expand_path(path + File::SEPARATOR + basename) lstat = File.lstat path rescue nil if !lstat || !lstat.directory? - unless path.start_with? destination_dir and (FileUtils.mkdir path, mkdir_options rescue false) + unless normalize_path(path).start_with? normalize_path(destination_dir) and (FileUtils.mkdir path, mkdir_options rescue false) raise Gem::Package::PathError.new(file_name, destination_dir) end end @@ -591,7 +599,7 @@ def verify_entry entry end case file_name - when /^metadata(.gz)?$/ then + when "metadata", "metadata.gz" then load_spec entry when 'data.tar.gz' then verify_gz entry diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb index 8f0cf0b4026b7c..80fb1aaaa5c195 100644 --- a/lib/rubygems/remote_fetcher.rb +++ b/lib/rubygems/remote_fetcher.rb @@ -293,7 +293,7 @@ def fetch_path(uri, mtime = nil, head = false) if data and !head and uri.to_s =~ /\.gz$/ begin - data = Gem.gunzip data + data = Gem::Util.gunzip data rescue Zlib::GzipFile::Error raise FetchError.new("server did not return a valid file", uri.to_s) end diff --git a/lib/rubygems/request_set.rb b/lib/rubygems/request_set.rb index 95a8eed1af65ba..e54a7b8818c5b1 100644 --- a/lib/rubygems/request_set.rb +++ b/lib/rubygems/request_set.rb @@ -171,7 +171,9 @@ def install options, &block # :yields: request, installer rescue Gem::RuntimeRequirementNotMetError => e recent_match = req.spec.set.find_all(req.request).sort_by(&:version).reverse_each.find do |s| s = s.spec - s.required_ruby_version.satisfied_by?(Gem.ruby_version) && s.required_rubygems_version.satisfied_by?(Gem.rubygems_version) + s.required_ruby_version.satisfied_by?(Gem.ruby_version) && + s.required_rubygems_version.satisfied_by?(Gem.rubygems_version) && + Gem::Platform.installable?(s) end if recent_match suggestion = "The last version of #{req.request} to support your Ruby & RubyGems was #{recent_match.version}. Try installing it with `gem install #{recent_match.name} -v #{recent_match.version}`" diff --git a/lib/rubygems/server.rb b/lib/rubygems/server.rb index 62c3dfe9cfb318..9ebd2f5e44ff43 100644 --- a/lib/rubygems/server.rb +++ b/lib/rubygems/server.rb @@ -492,7 +492,7 @@ def latest_specs(req, res) specs = Marshal.dump specs if req.path =~ /\.gz$/ then - specs = Gem.gzip specs + specs = Gem::Util.gzip specs res['content-type'] = 'application/x-gzip' else res['content-type'] = 'application/octet-stream' @@ -553,7 +553,7 @@ def prerelease_specs req, res specs = Marshal.dump specs if req.path =~ /\.gz$/ then - specs = Gem.gzip specs + specs = Gem::Util.gzip specs res['content-type'] = 'application/x-gzip' else res['content-type'] = 'application/octet-stream' @@ -852,7 +852,7 @@ def specs(req, res) specs = Marshal.dump specs if req.path =~ /\.gz$/ then - specs = Gem.gzip specs + specs = Gem::Util.gzip specs res['content-type'] = 'application/x-gzip' else res['content-type'] = 'application/octet-stream' diff --git a/lib/rubygems/source.rb b/lib/rubygems/source.rb index b28b85066077d9..7f38b6325f3fe6 100644 --- a/lib/rubygems/source.rb +++ b/lib/rubygems/source.rb @@ -155,7 +155,7 @@ def fetch_spec name_tuple uri.path << '.rz' spec = fetcher.fetch_path uri - spec = Gem.inflate spec + spec = Gem::Util.inflate spec if update_cache? then FileUtils.mkdir_p cache_dir diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 2560324b7a2dd2..49cd50794fcfa5 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -40,6 +40,8 @@ class Gem::Specification < Gem::BasicSpecification + extend Gem::Deprecate + # REFACTOR: Consider breaking out this version stuff into a separate # module. There's enough special stuff around it that it may justify # a separate class. @@ -715,6 +717,7 @@ def test_files= files # :nodoc: # Deprecated: You must now specify the executable name to Gem.bin_path. attr_writer :default_executable + deprecate :default_executable=, :none, 2018, 12 ## # Allows deinstallation of gems with legacy platforms. @@ -1810,6 +1813,7 @@ def default_executable # :nodoc: end result end + deprecate :default_executable, :none, 2018, 12 ## # The default value for specification attribute +name+ @@ -2018,6 +2022,7 @@ def gems_dir def has_rdoc # :nodoc: true end + deprecate :has_rdoc, :none, 2018, 12 ## # Deprecated and ignored. @@ -2027,8 +2032,10 @@ def has_rdoc # :nodoc: def has_rdoc= ignored # :nodoc: @has_rdoc = true end + deprecate :has_rdoc=, :none, 2018, 12 alias :has_rdoc? :has_rdoc # :nodoc: + deprecate :has_rdoc?, :none, 2018, 12 ## # True if this gem has files in test_files @@ -3074,16 +3081,6 @@ def raw_require_paths # :nodoc: @require_paths end - extend Gem::Deprecate - - # TODO: - # deprecate :has_rdoc, :none, 2011, 10 - # deprecate :has_rdoc?, :none, 2011, 10 - # deprecate :has_rdoc=, :none, 2011, 10 - # deprecate :default_executable, :none, 2011, 10 - # deprecate :default_executable=, :none, 2011, 10 - # deprecate :file_name, :cache_file, 2011, 10 - # deprecate :full_gem_path, :cache_file, 2011, 10 end # DOC: What is this and why is it here, randomly, at the end of this file? diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index aa6df267f2d13a..f03515cc8f5226 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -88,6 +88,8 @@ module DefaultUserInteraction class Gem::TestCase < MiniTest::Unit::TestCase + extend Gem::Deprecate + attr_accessor :fetcher # :nodoc: attr_accessor :gem_repo # :nodoc: @@ -672,11 +674,13 @@ def quick_gem(name, version='2') end ## - # TODO: remove in RubyGems 3.0 + # TODO: remove in RubyGems 4.0 def quick_spec name, version = '2' # :nodoc: util_spec name, version end + deprecate :quick_spec, :util_spec, 2018, 12 + ## # Builds a gem from +spec+ and places it in File.join @gemhome, @@ -774,7 +778,7 @@ def save_loaded_features ## # new_spec is deprecated as it is never used. # - # TODO: remove in RubyGems 3.0 + # TODO: remove in RubyGems 4.0 def new_spec name, version, deps = nil, *files # :nodoc: require 'rubygems/specification' @@ -815,6 +819,8 @@ def new_spec name, version, deps = nil, *files # :nodoc: spec end + # TODO: mark deprecate after replacing util_spec from new_spec + # deprecate :new_spec, :none, 2018, 12 def new_default_spec(name, version, deps = nil, *files) spec = util_spec name, version, deps diff --git a/lib/rubygems/test_utilities.rb b/lib/rubygems/test_utilities.rb index 83c9d2d0fe3f69..3e17973dd4f095 100644 --- a/lib/rubygems/test_utilities.rb +++ b/lib/rubygems/test_utilities.rb @@ -64,7 +64,7 @@ def fetch_path path, mtime = nil, head = false data.call else if path.to_s =~ /gz$/ and not data.nil? and not data.empty? then - data = Gem.gunzip data + data = Gem::Util.gunzip data end data diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb index cacd782e080455..91236eec15f6c1 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -6,6 +6,7 @@ #++ require 'rubygems/util' +require 'rubygems/deprecate' ## # Module that defines the default UserInteraction. Any class including this @@ -170,6 +171,8 @@ def verbose msg = nil class Gem::StreamUI + extend Gem::Deprecate + ## # The input stream @@ -384,6 +387,7 @@ def alert_error(statement, question=nil) def debug(statement) @errs.puts statement end + deprecate :debug, :none, 2018, 12 ## # Terminate the application with exit code +status+, running any exit diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb index ff5c1c1e72fbed..fbf75996cd38ac 100644 --- a/lib/rubygems/version.rb +++ b/lib/rubygems/version.rb @@ -170,6 +170,7 @@ def version # True if the +version+ string matches RubyGems' requirements. def self.correct? version + return false if version.nil? !!(version.to_s =~ ANCHORED_VERSION_PATTERN) end diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 183771f0f3140e..a6741e02c0173e 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -387,7 +387,7 @@ def test_self_default_sources assert_equal %w[https://rubygems.org/], Gem.default_sources end - def test_self_detect_gemdeps + def test_self_use_gemdeps skip 'Insecure operation - chdir' if RUBY_VERSION <= "1.8.7" rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-' @@ -399,7 +399,7 @@ def test_self_detect_gemdeps begin Dir.chdir 'detect/a/b' - assert_equal add_bundler_full_name([]), Gem.detect_gemdeps.map(&:full_name) + assert_equal add_bundler_full_name([]), Gem.use_gemdeps.map(&:full_name) ensure Dir.chdir @tempdir end @@ -1214,7 +1214,7 @@ def test_self_gunzip input = "\x1F\x8B\b\0\xED\xA3\x1AQ\0\x03\xCBH" + "\xCD\xC9\xC9\a\0\x86\xA6\x106\x05\0\0\0" - output = Gem.gunzip input + output = Gem::Util.gunzip input assert_equal 'hello', output @@ -1226,7 +1226,7 @@ def test_self_gunzip def test_self_gzip input = 'hello' - output = Gem.gzip input + output = Gem::Util.gzip input zipped = StringIO.new output @@ -1450,12 +1450,12 @@ def test_auto_activation_of_specific_gemdeps_file ENV['RUBYGEMS_GEMDEPS'] = path - Gem.detect_gemdeps + Gem.use_gemdeps assert_equal add_bundler_full_name(%W(a-1 b-1 c-1)), loaded_spec_names end - def test_auto_activation_of_detected_gemdeps_file + def test_auto_activation_of_used_gemdeps_file skip 'Insecure operation - chdir' if RUBY_VERSION <= "1.8.7" util_clear_gems @@ -1476,7 +1476,7 @@ def test_auto_activation_of_detected_gemdeps_file ENV['RUBYGEMS_GEMDEPS'] = "-" expected_specs = [a, b, (Gem::USE_BUNDLER_FOR_GEMDEPS || nil) && util_spec("bundler", Bundler::VERSION), c].compact - assert_equal expected_specs, Gem.detect_gemdeps.sort_by { |s| s.name } + assert_equal expected_specs, Gem.use_gemdeps.sort_by { |s| s.name } end LIB_PATH = File.expand_path "../../../lib".dup.untaint, __FILE__.dup.untaint diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb index f2541a24c7205a..c4de8c53d5d935 100644 --- a/test/rubygems/test_gem_commands_setup_command.rb +++ b/test/rubygems/test_gem_commands_setup_command.rb @@ -10,7 +10,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase if File.exist?(bundler_gemspec) BUNDLER_VERS = File.read(bundler_gemspec).match(/VERSION = "(#{Gem::Version::VERSION_PATTERN})"/)[1] else - BUNDLER_VERS = "1.16.1" + BUNDLER_VERS = "1.16.2" end def setup diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb index d1664cf285874e..f8eb245f26c414 100644 --- a/test/rubygems/test_gem_package.rb +++ b/test/rubygems/test_gem_package.rb @@ -524,6 +524,21 @@ def test_extract_tar_gz_dot_file assert_path_exists extracted end + if Gem.win_platform? + def test_extract_tar_gz_case_insensitive + package = Gem::Package.new @gem + + tgz_io = util_tar_gz do |tar| + tar.add_file 'foo/file.rb', 0644 do |io| io.write 'hi' end + end + + package.extract_tar_gz tgz_io, @destination.upcase + + extracted = File.join @destination, 'foo/file.rb' + assert_path_exists extracted + end + end + def test_install_location package = Gem::Package.new @gem @@ -607,7 +622,7 @@ def test_install_location_suffix end def test_load_spec - entry = StringIO.new Gem.gzip @spec.to_yaml + entry = StringIO.new Gem::Util.gzip @spec.to_yaml def entry.full_name() 'metadata.gz' end package = Gem::Package.new 'nonexistent.gem' @@ -637,7 +652,7 @@ def test_verify_checksum_bad data_tgz = data_tgz.string gem = util_tar do |tar| - metadata_gz = Gem.gzip @spec.to_yaml + metadata_gz = Gem::Util.gzip @spec.to_yaml tar.add_file 'metadata.gz', 0444 do |io| io.write metadata_gz @@ -684,7 +699,7 @@ def test_verify_checksum_missing data_tgz = data_tgz.string gem = util_tar do |tar| - metadata_gz = Gem.gzip @spec.to_yaml + metadata_gz = Gem::Util.gzip @spec.to_yaml tar.add_file 'metadata.gz', 0444 do |io| io.write metadata_gz @@ -721,7 +736,7 @@ def test_verify_checksum_missing def test_verify_corrupt tf = Tempfile.open 'corrupt' do |io| - data = Gem.gzip 'a' * 10 + data = Gem::Util.gzip 'a' * 10 io.write \ tar_file_header('metadata.gz', "\000x", 0644, data.length, Time.now) io.write data @@ -845,7 +860,7 @@ def test_verify_security_policy_checksum_missing build.add_contents gem # write bogus data.tar.gz to foil signature - bogus_data = Gem.gzip 'hello' + bogus_data = Gem::Util.gzip 'hello' fake_signer = Class.new do def digest_name; 'SHA512'; end def digest_algorithm; Digest(:SHA512); end @@ -903,6 +918,40 @@ def entry.full_name() raise ArgumentError, 'whatever' end end assert_equal "package is corrupt, exception while verifying: whatever (ArgumentError) in #{@gem}", e.message + + valid_metadata = ["metadata", "metadata.gz"] + valid_metadata.each do |vm| + $spec_loaded = false + $good_name = vm + + entry = Object.new + def entry.full_name() $good_name end + + package = Gem::Package.new(@gem) + package.instance_variable_set(:@files, []) + def package.load_spec(entry) $spec_loaded = true end + + package.verify_entry(entry) + + assert $spec_loaded + end + + invalid_metadata = ["metadataxgz", "foobar\nmetadata", "metadata\nfoobar"] + invalid_metadata.each do |vm| + $spec_loaded = false + $bad_name = vm + + entry = Object.new + def entry.full_name() $bad_name end + + package = Gem::Package.new(@gem) + package.instance_variable_set(:@files, []) + def package.load_spec(entry) $spec_loaded = true end + + package.verify_entry(entry) + + refute $spec_loaded + end end def test_spec diff --git a/test/rubygems/test_gem_package_tar_header.rb b/test/rubygems/test_gem_package_tar_header.rb index 43f508df450938..f804b2d80851b7 100644 --- a/test/rubygems/test_gem_package_tar_header.rb +++ b/test/rubygems/test_gem_package_tar_header.rb @@ -158,7 +158,7 @@ def test_from_bad_octal header_s[124, 12] = val io = TempIO.new header_s assert_raises ArgumentError do - new_header = Gem::Package::TarHeader.from io + Gem::Package::TarHeader.from io end io.close! if io.respond_to? :close! end diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index 20e34e84e114ff..c48a5f538f671d 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -541,7 +541,7 @@ def test_fetch_path_gzip @fetcher = fetcher def fetcher.fetch_http(uri, mtime, head = nil) - Gem.gzip 'foo' + Gem::Util.gzip 'foo' end assert_equal 'foo', fetcher.fetch_path(@uri + 'foo.gz') diff --git a/test/rubygems/test_gem_security_policy.rb b/test/rubygems/test_gem_security_policy.rb index 4108551dca67de..6cd032baf511e8 100644 --- a/test/rubygems/test_gem_security_policy.rb +++ b/test/rubygems/test_gem_security_policy.rb @@ -450,7 +450,7 @@ def test_verify_signatures @spec.cert_chain = [PUBLIC_CERT.to_s] - metadata_gz = Gem.gzip @spec.to_yaml + metadata_gz = Gem::Util.gzip @spec.to_yaml package = Gem::Package.new 'nonexistent.gem' package.checksums[Gem::Security::DIGEST_NAME] = {} @@ -473,7 +473,7 @@ def test_verify_signatures_missing @spec.cert_chain = [PUBLIC_CERT.to_s] - metadata_gz = Gem.gzip @spec.to_yaml + metadata_gz = Gem::Util.gzip @spec.to_yaml package = Gem::Package.new 'nonexistent.gem' package.checksums[Gem::Security::DIGEST_NAME] = {} @@ -502,7 +502,7 @@ def test_verify_signatures_none @spec.cert_chain = [PUBLIC_CERT.to_s] - metadata_gz = Gem.gzip @spec.to_yaml + metadata_gz = Gem::Util.gzip @spec.to_yaml package = Gem::Package.new 'nonexistent.gem' package.checksums[Gem::Security::DIGEST_NAME] = {} diff --git a/test/rubygems/test_gem_server.rb b/test/rubygems/test_gem_server.rb index d8dd0b4acbe73e..8a3e6410aebdf8 100644 --- a/test/rubygems/test_gem_server.rb +++ b/test/rubygems/test_gem_server.rb @@ -127,7 +127,7 @@ def test_latest_specs_gz assert_match %r| \d\d:\d\d:\d\d |, @res['date'] assert_equal 'application/x-gzip', @res['content-type'] assert_equal [['a', Gem::Version.new(2), Gem::Platform::RUBY]], - Marshal.load(Gem.gunzip(@res.body)) + Marshal.load(Gem::Util.gunzip(@res.body)) end def test_listen @@ -177,7 +177,7 @@ def test_prerelease_specs_gz assert_match %r| \d\d:\d\d:\d\d |, @res['date'] assert_equal 'application/x-gzip', @res['content-type'] assert_equal [['a', v('3.a'), Gem::Platform::RUBY]], - Marshal.load(Gem.gunzip(@res.body)) + Marshal.load(Gem::Util.gunzip(@res.body)) end def test_quick_gemdirs @@ -236,7 +236,7 @@ def test_quick_marshal_a_1_gemspec_rz assert @res['date'] assert_equal 'application/x-deflate', @res['content-type'] - spec = Marshal.load Gem.inflate(@res.body) + spec = Marshal.load Gem::Util.inflate(@res.body) assert_equal 'a', spec.name assert_equal Gem::Version.new(1), spec.version end @@ -253,7 +253,7 @@ def test_quick_marshal_a_1_mswin32_gemspec_rz assert @res['date'] assert_equal 'application/x-deflate', @res['content-type'] - spec = Marshal.load Gem.inflate(@res.body) + spec = Marshal.load Gem::Util.inflate(@res.body) assert_equal 'a', spec.name assert_equal Gem::Version.new(1), spec.version assert_equal Gem::Platform.local, spec.platform @@ -269,7 +269,7 @@ def test_quick_marshal_a_3_a_gemspec_rz assert @res['date'] assert_equal 'application/x-deflate', @res['content-type'] - spec = Marshal.load Gem.inflate(@res.body) + spec = Marshal.load Gem::Util.inflate(@res.body) assert_equal 'a', spec.name assert_equal v('3.a'), spec.version end @@ -286,7 +286,7 @@ def test_quick_marshal_a_b_3_a_gemspec_rz assert @res['date'] assert_equal 'application/x-deflate', @res['content-type'] - spec = Marshal.load Gem.inflate(@res.body) + spec = Marshal.load Gem::Util.inflate(@res.body) assert_equal 'a-b', spec.name assert_equal v('3.a'), spec.version end @@ -303,7 +303,7 @@ def test_quick_marshal_a_b_1_3_a_gemspec_rz assert @res['date'] assert_equal 'application/x-deflate', @res['content-type'] - spec = Marshal.load Gem.inflate(@res.body) + spec = Marshal.load Gem::Util.inflate(@res.body) assert_equal 'a-b-1', spec.name assert_equal v('3.a'), spec.version end @@ -571,7 +571,7 @@ def test_specs_gz assert_equal [['a', Gem::Version.new(1), Gem::Platform::RUBY], ['a', Gem::Version.new(2), Gem::Platform::RUBY], ['a', v('3.a'), Gem::Platform::RUBY]], - Marshal.load(Gem.gunzip(@res.body)) + Marshal.load(Gem::Util.gunzip(@res.body)) end def test_uri_encode diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index badb297eee46a9..8a488f87d902f0 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -1133,7 +1133,7 @@ def test_self_remove_spec_removed def test_handles_private_null_type path = File.join DATA_PATH, "null-type.gemspec.rz" - data = Marshal.load Gem.inflate(Gem.read_binary(path)) + data = Marshal.load Gem::Util.inflate(Gem.read_binary(path)) assert_equal nil, data.rubyforge_project end diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb index 792ad5f0841f63..bddae7fdc3ec8a 100644 --- a/test/rubygems/test_gem_version.rb +++ b/test/rubygems/test_gem_version.rb @@ -46,6 +46,7 @@ def test_class_create def test_class_correct assert_equal true, Gem::Version.correct?("5.1") assert_equal false, Gem::Version.correct?("an incorrect version") + assert_equal false, Gem::Version.correct?(nil) end def test_class_new_subclass