diff options
author | Hiroshi SHIBATA <[email protected]> | 2020-12-08 16:33:39 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2020-12-08 17:30:02 +0900 |
commit | 4aca77edde91f826aa243e268bf1ef5214530583 () | |
tree | ef0cf1a95fcced00ca5fa40f3412c567bf95d705 | |
parent | 6a6a24df9b72750d12f9b15192bdb7517e668efb (diff) |
Merge prepare version of RubyGems 3.2.0
Notes: Merged: https://.com/ruby/ruby/pull/3864
134 files changed, 2003 insertions, 746 deletions
@@ -8,7 +8,7 @@ require 'rbconfig' module Gem - VERSION = "3.2.0.rc.2".freeze end # Must be first since it unloads the prelude from 1.9.2 @@ -119,6 +119,10 @@ module Gem # to avoid deprecation warnings in Ruby 2.7. UNTAINT = RUBY_VERSION < '2.7' ? :untaint.to_sym : proc{} ## # An Array of Regexps that match windows Ruby platforms. @@ -975,7 +979,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} val = RbConfig::CONFIG[key] next unless val and not val.empty? ".#{val}" - end ].compact.uniq end @@ -73,7 +73,7 @@ class Gem::AvailableSet end def match_platform! - @set.reject! {|t| !Gem::Platform.match(t.spec.platform) } @sorted = nil self end @@ -73,7 +73,7 @@ class Gem::CommandManager ].freeze ALIAS_COMMANDS = { - 'i' => 'install' }.freeze ## @@ -174,8 +174,8 @@ class Gem::CommandManager else cmd_name = args.shift.downcase cmd = find_command cmd_name - cmd.invoke_with_build_args args, build_args cmd.deprecation_warning if cmd.deprecated? end end @@ -61,14 +61,18 @@ Gems can be saved to a specified filename with the output option: end def execute - gem_name = get_one_optional_argument || find_gemspec - build_gem(gem_name) end private - def find_gemspec - gemspecs = Dir.glob("*.gemspec").sort if gemspecs.size > 1 alert_error "Multiple gemspecs found: #{gemspecs}, please specify one" @@ -78,28 +82,19 @@ Gems can be saved to a specified filename with the output option: gemspecs.first end - def build_gem(gem_name) - gemspec = File.exist?(gem_name) ? gem_name : "#{gem_name}.gemspec" - - if File.exist?(gemspec) - spec = Gem::Specification.load(gemspec) - - if options[:build_path] - Dir.chdir(File.dirname(gemspec)) do - spec = Gem::Specification.load(File.basename(gemspec)) - build_package(spec) - end - else - build_package(spec) - end else - alert_error "Gemspec file not found: #{gemspec}" terminate_interaction(1) end end - def build_package(spec) if spec Gem::Package.build( spec, @@ -112,4 +107,26 @@ Gems can be saved to a specified filename with the output option: terminate_interaction 1 end end end @@ -311,4 +311,4 @@ For further reading on signing gems see `ri Gem::Security`. # It's simple, but is all we need email =~ /\A.+@.+\z/ end -end if defined?(OpenSSL::SSL) @@ -332,6 +332,8 @@ platform. @command_manager.command_names.each do |cmd_name| command = @command_manager[cmd_name] summary = if command command.summary @@ -53,7 +53,7 @@ permission to. def execute @host = options[:host] - sign_in name = get_one_gem_name add_owners name, options[:add] @@ -102,10 +102,18 @@ permission to. private def send_owner_request(method, name, owner) - rubygems_api_request method, "api/v1/gems/#{name}/owners" do |request| request.set_form_data 'email' => owner request.add_field "Authorization", api_key request.add_field "OTP", options[:otp] if options[:otp] end end end @@ -170,7 +170,7 @@ extensions will be restored. :install_dir => spec.base_dir, :env_shebang => env_shebang, :build_args => spec.build_args, - :bin_dir => bin_dir } if options[:only_executables] @@ -61,7 +61,7 @@ The push command will use ~/.gem/credentials to authenticate to a server, but yo options[:host] end - sign_in @host send_gem(gem_name) end @@ -86,7 +86,7 @@ The push command will use ~/.gem/credentials to authenticate to a server, but yo private def send_push_request(name, args) - rubygems_api_request(*args) do |request| request.body = Gem.read_binary name request.add_field "Content-Length", request.body.size request.add_field "Content-Type", "application/octet-stream" @@ -100,7 +100,11 @@ The push command will use ~/.gem/credentials to authenticate to a server, but yo [ gem_metadata["default_gem_server"], - gem_metadata["allowed_push_host"] ] end end @@ -9,6 +9,14 @@ class Gem::Commands::QueryCommand < Gem::Command include Gem::QueryUtils def initialize(name = 'query', summary = 'Query gem information in local or remote repositories') super name, summary, @@ -23,4 +31,13 @@ class Gem::Commands::QueryCommand < Gem::Command add_query_options end end @@ -1,8 +1,12 @@ # frozen_string_literal: true require 'rubygems/command' require 'rubygems/server' class Gem::Commands::ServerCommand < Gem::Command def initialize super 'server', 'Documentation and gem repository HTTP server', :port => 8808, :gemdir => [], :daemon => false @@ -322,13 +322,10 @@ By default, this RubyGems will install gem as: libs.each do |tool, path| say "Installing #{tool}" if @verbose - lib_files = rb_files_in path - lib_files.concat(bundler_template_files) if tool == 'Bundler' - - pem_files = pem_files_in path Dir.chdir path do - install_file_list(lib_files + pem_files, lib_dir) end end end @@ -394,10 +391,6 @@ By default, this RubyGems will install gem as: specs_dir = File.join(options[:destdir], specs_dir) unless Gem.win_platform? mkdir_p specs_dir, :mode => 0755 - # Workaround for non-git environment. - gemspec = File.open('bundler/bundler.gemspec', 'rb'){|f| f.read.gsub(/`git ls-files -z`/, "''") } - File.open('bundler/bundler.gemspec', 'w'){|f| f.write gemspec } - bundler_spec = Gem::Specification.load("bundler/bundler.gemspec") bundler_spec.files = Dir.chdir("bundler") { Dir["{*.md,{lib,exe,man}/**/*}"] } bundler_spec.executables -= %w[bundler bundle_ruby] @@ -518,44 +511,24 @@ By default, this RubyGems will install gem as: [lib_dir, bin_dir] end - def pem_files_in(dir) - Dir.chdir dir do - Dir[File.join('**', '*pem')] - end - end - - def rb_files_in(dir) Dir.chdir dir do - Dir[File.join('**', '*rb')] end end # for installation of bundler as default gems def bundler_man1_files_in(dir) Dir.chdir dir do - Dir['bundle*.1{,.txt,.ronn}'] end end # for installation of bundler as default gems def bundler_man5_files_in(dir) Dir.chdir dir do - Dir['gemfile.5{,.txt,.ronn}'] - end - end - - def bundler_template_files - Dir.chdir "bundler/lib" do - Dir.glob(File.join('bundler', 'templates', '**', '*'), File::FNM_DOTMATCH). - select{|f| !File.directory?(f) } - end - end - - # for cleanup old bundler files - def template_files_in(dir) - Dir.chdir dir do - Dir.glob(File.join('templates', '**', '*'), File::FNM_DOTMATCH). - select{|f| !File.directory?(f) } end end @@ -595,11 +568,9 @@ abort "#{deprecation_message}" lib_dirs = { File.join(lib_dir, 'rubygems') => 'lib/rubygems' } lib_dirs[File.join(lib_dir, 'bundler')] = 'bundler/lib/bundler' lib_dirs.each do |old_lib_dir, new_lib_dir| - lib_files = rb_files_in(new_lib_dir) - lib_files.concat(template_files_in(new_lib_dir)) if new_lib_dir =~ /bundler/ - old_lib_files = rb_files_in(old_lib_dir) - old_lib_files.concat(template_files_in(old_lib_dir)) if old_lib_dir =~ /bundler/ to_remove = old_lib_files - lib_files @@ -617,16 +588,25 @@ abort "#{deprecation_message}" def remove_old_man_files(man_dir) man_dirs = { man_dir => "bundler/man" } man_dirs.each do |old_man_dir, new_man_dir| - ["1", "5"].each do |section| - man_files = send(:"bundler_man#{section}_files_in", new_man_dir) - old_man_dir_with_section = "#{old_man_dir}/man#{section}" - old_man_files = send(:"bundler_man#{section}_files_in", old_man_dir_with_section) - man_to_remove = old_man_files - man_files - remove_file_list(man_to_remove, old_man_dir_with_section) - end end end @@ -34,6 +34,10 @@ class Gem::Commands::SourcesCommand < Gem::Command options[:update] = value end add_proxy_option end @@ -71,7 +75,7 @@ class Gem::Commands::SourcesCommand < Gem::Command Do you want to add this source? QUESTION - terminate_interaction 1 unless ask_yes_no question end end @@ -86,7 +90,7 @@ https://rubygems.org is recommended for security over #{uri} Do you want to add this insecure source? QUESTION - terminate_interaction 1 unless ask_yes_no question end end @@ -126,6 +126,12 @@ Specific fields in the specification can be extracted in YAML format: terminate_interaction 1 end unless options[:all] specs = [specs.max_by {|s| s.version }] end @@ -47,7 +47,7 @@ data you will need to change them immediately and yank your gem. def execute @host = options[:host] - sign_in @host version = get_version_from_requirements(options[:version]) platform = get_platform_from_requirements(options) @@ -72,7 +72,7 @@ data you will need to change them immediately and yank your gem. def yank_api_request(method, version, platform, api) name = get_one_gem_name - response = rubygems_api_request(method, api, host) do |request| request.add_field("Authorization", api_key) request.add_field("OTP", options[:otp]) if options[:otp] @@ -93,7 +93,7 @@ data you will need to change them immediately and yank your gem. nil end - def get_platform_from_requirements(requirements) - Gem.platforms[1].to_s if requirements.key? :added_platform end end @@ -17,6 +17,8 @@ module Kernel private :gem_original_require end ## # When RubyGems is required, Kernel#require is replaced with our own which # is capable of loading gems on demand. @@ -166,6 +168,7 @@ module Kernel end end end private :require @@ -1,12 +1,12 @@ # frozen_string_literal: true # `uplevel` keyword argument of Kernel#warn is available since ruby 2.5. -if RUBY_VERSION >= "2.5" module Kernel rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path. - original_warn = method(:warn) remove_method :warn @@ -17,9 +17,9 @@ if RUBY_VERSION >= "2.5" module_function define_method(:warn) {|*messages, **kw| unless uplevel = kw[:uplevel] if Gem.java_platform? - return original_warn.call(*messages) else - return original_warn.call(*messages, **kw) end end @@ -45,11 +45,10 @@ if RUBY_VERSION >= "2.5" end end end - uplevel = start end - kw[:uplevel] = uplevel - original_warn.call(*messages, **kw) } end end @@ -38,13 +38,13 @@ module Gem [ File.dirname(RbConfig::CONFIG['sitedir']), 'Gems', - RbConfig::CONFIG['ruby_version'] ] else [ RbConfig::CONFIG['rubylibprefix'], 'gems', - RbConfig::CONFIG['ruby_version'] ] end @@ -281,7 +281,7 @@ class Gem::Dependency if platform_only matches.reject! do |spec| - spec.nil? || !Gem::Platform.match(spec.platform) end end @@ -27,7 +27,7 @@ class Gem::DependencyInstaller :wrappers => true, :build_args => nil, :build_docs_in_background => false, - :install_as_default => false }.freeze ## @@ -283,10 +283,9 @@ class Gem::DependencyInstaller request_set.development_shallow = @dev_shallow request_set.soft_missing = @force request_set.prerelease = @prerelease - request_set.remote = false unless consider_remote? installer_set = Gem::Resolver::InstallerSet.new @domain - installer_set.ignore_installed = @only_install_dir if consider_local? if dep_or_name =~ /\.gem$/ and File.file? dep_or_name @@ -307,6 +306,7 @@ class Gem::DependencyInstaller dependency = if spec = installer_set.local?(dep_or_name) Gem::Dependency.new spec.name, version elsif String === dep_or_name Gem::Dependency.new dep_or_name, version @@ -321,6 +321,7 @@ class Gem::DependencyInstaller installer_set.add_always_install dependency request_set.always_install = installer_set.always_install if @ignore_dependencies installer_set.ignore_dependencies = true @@ -10,14 +10,6 @@ require_relative '../user_interaction' class Gem::Ext::Builder include Gem::UserInteraction - ## - # The builder shells-out to run various commands after changing the - # directory. This means multiple installations cannot be allowed to build - # extensions in parallel as they may change each other's directories leading - # to broken extensions or failed installations. - - CHDIR_MUTEX = Mutex.new # :nodoc: - attr_accessor :build_args # :nodoc: def self.class_name @@ -25,8 +17,8 @@ class Gem::Ext::Builder $1.downcase end - def self.make(dest_path, results) - unless File.exist? 'Makefile' raise Gem::InstallError, 'Makefile not found' end @@ -44,32 +36,32 @@ class Gem::Ext::Builder cmd = [ make_program, destdir, - target ].join(' ').rstrip begin - run(cmd, results, "make #{target}".rstrip) rescue Gem::InstallError raise unless target == 'clean' # ignore clean failure end end end - def self.run(command, results, command_name = nil) verbose = Gem.configuration.really_verbose begin rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], nil if verbose - puts("current directory: #{Dir.pwd}") p(command) end - results << "current directory: #{Dir.pwd}" results << (command.respond_to?(:shelljoin) ? command.shelljoin : command) require "open3" # Set $SOURCE_DATE_EPOCH for the subprocess. env = {'SOURCE_DATE_EPOCH' => Gem.source_date_epoch_string} - output, status = Open3.capture2e(env, *command) if verbose puts output else @@ -161,22 +153,10 @@ EOF begin FileUtils.mkdir_p dest_path - CHDIR_MUTEX.synchronize do - pwd = Dir.getwd - Dir.chdir extension_dir - begin - results = builder.build(extension, dest_path, - results, @build_args, lib_dir) - - verbose { results.join("\n") } - ensure - begin - Dir.chdir pwd - rescue SystemCallError - Dir.chdir dest_path - end - end - end write_gem_make_out results.join "\n" rescue => e @@ -201,6 +181,7 @@ EOF dest_path = @spec.extension_dir FileUtils.rm_f @spec.gem_build_complete_path @spec.extensions.each do |extension| @@ -2,15 +2,15 @@ require_relative '../command' class Gem::Ext::CmakeBuilder < Gem::Ext::Builder - def self.build(extension, dest_path, results, args=[], lib_dir=nil) - unless File.exist?('Makefile') cmd = "cmake . -DCMAKE_INSTALL_PREFIX=#{dest_path}" cmd << " #{Gem::Command.build_args.join ' '}" unless Gem::Command.build_args.empty? - run cmd, results end - make dest_path, results results end @@ -6,15 +6,15 @@ #++ class Gem::Ext::ConfigureBuilder < Gem::Ext::Builder - def self.build(extension, dest_path, results, args=[], lib_dir=nil) - unless File.exist?('Makefile') cmd = "sh ./configure --prefix=#{dest_path}" cmd << " #{args.join ' '}" unless args.empty? - run cmd, results end - make dest_path, results results end @@ -8,11 +8,11 @@ require 'shellwords' class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder - def self.build(extension, dest_path, results, args=[], lib_dir=nil) require 'fileutils' require 'tempfile' - tmp_dest = Dir.mktmpdir(".gem.", ".") # Some versions of `mktmpdir` return absolute paths, which will break make # if the paths contain spaces. However, on Ruby 1.9.x on Windows, relative @@ -23,9 +23,9 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder # spaces do not work. # # Details: https://.com/rubygems/rubygems/issues/977#issuecomment-171544940 - tmp_dest = get_relative_path(tmp_dest) - Tempfile.open %w[siteconf .rb], "." do |siteconf| siteconf.puts "require 'rbconfig'" siteconf.puts "dest_path = #{tmp_dest.dump}" %w[sitearchdir sitelibdir].each do |dir| @@ -38,19 +38,22 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder destdir = ENV["DESTDIR"] begin cmd = Gem.ruby.shellsplit << "-I" << File.expand_path("../../..", __FILE__) << - "-r" << get_relative_path(siteconf.path) << File.basename(extension) cmd.push(*args) begin - run(cmd, results) do |s, r| - if File.exist? 'mkmf.log' unless s.success? r << "To see why this extension failed to compile, please check" \ " the mkmf.log which can be found here:\n" r << " " + File.join(dest_path, 'mkmf.log') + "\n" end - FileUtils.mv 'mkmf.log', dest_path end end siteconf.unlink @@ -58,18 +61,20 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder ENV["DESTDIR"] = nil - make dest_path, results if tmp_dest # TODO remove in RubyGems 3 if Gem.install_extension_in_lib and lib_dir FileUtils.mkdir_p lib_dir - entries = Dir.entries(tmp_dest) - %w[. ..] - entries = entries.map {|entry| File.join tmp_dest, entry } FileUtils.cp_r entries, lib_dir, :remove_destination => true end - FileUtils::Entry_.new(tmp_dest).traverse do |ent| destent = ent.class.new(dest_path, ent.rel) destent.exist? or FileUtils.mv(ent.path, destent.path) end @@ -87,8 +92,8 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder private - def self.get_relative_path(path) - path[0..Dir.pwd.length - 1] = '.' if path.start_with?(Dir.pwd) path end end @@ -8,9 +8,9 @@ require "shellwords" class Gem::Ext::RakeBuilder < Gem::Ext::Builder - def self.build(extension, dest_path, results, args=[], lib_dir=nil) if File.basename(extension) =~ /mkrf_conf/i - run([Gem.ruby, File.basename(extension), *args], results) end rake = ENV['rake'] @@ -26,7 +26,7 @@ class Gem::Ext::RakeBuilder < Gem::Ext::Builder end rake_args = ["RUBYARCHDIR=#{dest_path}", "RUBYLIBDIR=#{dest_path}", *args] - run(rake + rake_args, results) results end @@ -8,10 +8,12 @@ require 'rubygems/text' module Gem::GemcutterUtilities ERROR_CODE = 1 include Gem::Text attr_writer :host ## # Add the --key option @@ -72,7 +74,7 @@ module Gem::GemcutterUtilities # # If +allowed_push_host+ metadata is present, then it will only allow that host. - def rubygems_api_request(method, path, host = nil, allowed_push_host = nil, &block) require 'net/http' self.host = host if host @@ -95,11 +97,19 @@ module Gem::GemcutterUtilities request_method = Net::HTTP.const_get method.to_s.capitalize response = Gem::RemoteFetcher.fetcher.request(uri, request_method, &block) - return response unless mfa_unauthorized?(response) - Gem::RemoteFetcher.fetcher.request(uri, request_method) do |req| - req.add_field "OTP", get_otp - block.call(req) end end @@ -112,19 +122,37 @@ module Gem::GemcutterUtilities ask 'Code: ' end ## # Signs in with the RubyGems API at +sign_in_host+ and sets the rubygems API # key. - def sign_in(sign_in_host = nil) sign_in_host ||= self.host return if api_key - pretty_host = if Gem::DEFAULT_HOST == sign_in_host - 'RubyGems.org' - else - sign_in_host - end say "Enter your #{pretty_host} credentials." say "Don't have an account yet? " + @@ -134,14 +162,18 @@ module Gem::GemcutterUtilities password = ask_for_password "Password: " say "\n" - response = rubygems_api_request(:get, "api/v1/api_key", - sign_in_host) do |request| request.basic_auth email, password request.add_field "OTP", options[:otp] if options[:otp] end with_response response do |resp| - say "Signed in." set_api_key host, resp.body end end @@ -195,4 +227,48 @@ module Gem::GemcutterUtilities end end end @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'rubygems' require 'rubygems/package' -require 'time' require 'tmpdir' ## @@ -122,10 +122,10 @@ module Gem::InstallUpdateOptions options[:minimal_deps] = true end - add_option(:"Install/Update", "--minimal-deps", "Don't upgrade any dependencies that already", "meet version requirements") do |value, options| - options[:minimal_deps] = true end add_option(:"Install/Update", "--[no-]post-install-message", @@ -12,7 +12,6 @@ require 'rubygems/deprecate' require 'rubygems/package' require 'rubygems/ext' require 'rubygems/user_interaction' -require 'fileutils' ## # The installer installs the files contained in the .gem into the Gem.home. @@ -433,7 +432,7 @@ class Gem::Installer # def default_spec_file - File.join Gem.default_specifications_dir, "#{spec.full_name}.gemspec" end ## @@ -492,7 +491,11 @@ class Gem::Installer mode = File.stat(bin_path).mode dir_mode = options[:prog_mode] || (mode | 0111) - FileUtils.chmod dir_mode, bin_path unless dir_mode == mode check_executable_overwrite filename @@ -527,6 +530,7 @@ class Gem::Installer def generate_bin_script(filename, bindir) bin_script_path = File.join bindir, formatted_program_filename(filename) FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers File.open bin_script_path, 'wb', 0755 do |file| @@ -670,7 +674,7 @@ class Gem::Installer :env_shebang => false, :force => false, :only_install_dir => false, - :post_install_message => true }.merge options @env_shebang = options[:env_shebang] @@ -693,11 +697,10 @@ class Gem::Installer @build_args = options[:build_args] || Gem::Command.build_args unless @build_root.nil? - require 'pathname' - @build_root = Pathname.new(@build_root).expand_path - @bin_dir = File.join(@build_root, options[:bin_dir] || Gem.bindir(@gem_home)) - @gem_home = File.join(@build_root, @gem_home) - alert_warning "You build with buildroot.\n Build root: #{@build_root}\n Bin dir: #{@bin_dir}\n Gem home: #{@gem_home}" end end @@ -108,9 +108,9 @@ class Gem::InstallerTestCase < Gem::TestCase # # And returns a Gem::Installer for the @spec that installs into @gemhome - def setup_base_installer @gem = setup_base_gem - util_installer @spec, @gemhome end ## @@ -182,7 +182,7 @@ class Gem::InstallerTestCase < Gem::TestCase # lib/code.rb # ext/a/mkrf_conf.rb - def util_setup_gem(ui = @ui) @spec.files << File.join('lib', 'code.rb') @spec.extensions << File.join('ext', 'a', 'mkrf_conf.rb') @@ -214,17 +214,18 @@ class Gem::InstallerTestCase < Gem::TestCase end end - Gem::Installer.at @gem end ## # Creates an installer for +spec+ that will install into +gem_home+. If # +user+ is true a user-install will be performed. - def util_installer(spec, gem_home, user=false) Gem::Installer.at(spec.cache_file, :install_dir => gem_home, - :user_install => user) end @@symlink_supported = nil @@ -59,7 +59,7 @@ class Gem::NameTuple # Indicate if this NameTuple matches the current platform. def match_platform? - Gem::Platform.match @platform end ## @@ -1,7 +1,7 @@ # frozen_string_literal: true -begin - require "openssl" -rescue LoadError => e - raise unless e.path == 'openssl' end @@ -44,7 +44,6 @@ require "rubygems" require 'rubygems/security' require 'rubygems/user_interaction' -require 'zlib' class Gem::Package include Gem::UserInteraction @@ -186,6 +185,8 @@ class Gem::Package # Creates a new package that will read or write to the file +gem+. def initialize(gem, security_policy) # :notnew: @gem = gem @build_time = Gem.source_date_epoch @@ -297,7 +298,7 @@ class Gem::Package setup_signer( signer_options: { - expiration_length_days: Gem.configuration.cert_expiration_length_days } ) @@ -229,7 +229,7 @@ class Gem::Package::TarHeader gname, oct(devmajor, 7), oct(devminor, 7), - prefix ] header = header.pack PACK_FORMAT @@ -90,7 +90,7 @@ class Gem::Package::TarTestCase < Gem::TestCase ASCIIZ("wheel", 32), # char gname[32]; ASCIIZ Z(to_oct(0, 7)), # char devmajor[8]; 0 padded, octal, null Z(to_oct(0, 7)), # char devminor[8]; 0 padded, octal, null - ASCIIZ(dname, 155) # char prefix[155]; ASCII + (Z unless filled) ] h = arr.join @@ -9,11 +9,7 @@ require "rubygems/deprecate" class Gem::Platform @local = nil - attr_accessor :cpu - - attr_accessor :os - - attr_accessor :version def self.local arch = RbConfig::CONFIG['arch'] @@ -22,18 +18,33 @@ class Gem::Platform end def self.match(platform) - Gem.platforms.any? do |local_platform| platform.nil? or local_platform == platform or (local_platform != Gem::Platform::RUBY and local_platform =~ platform) end end def self.installable?(spec) if spec.respond_to? :installable_platform? spec.installable_platform? else - match spec.platform end end @@ -57,15 +57,6 @@ module Gem::QueryUtils "--local --name-matches // --no-details --versions --no-installed" end - def description # :nodoc: - <<-EOF -The query command is the basis for the list and search commands. - -You should really use the list and search commands instead. This command -is too hard to use. - EOF - end - def execute gem_names = Array(options[:name]) @@ -78,7 +78,6 @@ class Gem::RemoteFetcher def initialize(proxy=nil, dns=nil, headers={}) require 'net/http' require 'stringio' - require 'time' require 'uri' Socket.do_not_reverse_lookup = true @@ -263,7 +262,7 @@ class Gem::RemoteFetcher rescue Timeout::Error raise UnknownHostError.new('timed out', uri) rescue IOError, SocketError, SystemCallError, - *(OpenSSL::SSL::SSLError if defined?(OpenSSL)) => e if e.message =~ /getaddrinfo/ raise UnknownHostError.new('no such name', uri) else @@ -1,6 +1,5 @@ # frozen_string_literal: true require 'net/http' -require 'time' require 'rubygems/user_interaction' class Gem::Request @@ -45,7 +44,8 @@ class Gem::Request end def self.configure_connection_for_https(connection, cert_files) - require 'openssl' connection.use_ssl = true connection.verify_mode = Gem.configuration.ssl_verify_mode || OpenSSL::SSL::VERIFY_PEER @@ -125,7 +125,7 @@ class Gem::Request def connection_for(uri) @connection_pool.checkout - rescue defined?(OpenSSL::SSL) ? OpenSSL::SSL::SSLError : Errno::EHOSTDOWN, Errno::EHOSTDOWN => e raise Gem::RemoteFetcher::FetchError.new(e.message, uri) end @@ -143,6 +143,7 @@ class Gem::Request request.add_field 'Keep-Alive', '30' if @last_modified request.add_field 'If-Modified-Since', @last_modified.httpdate end @@ -88,7 +88,7 @@ class Gem::RequestSet::GemDependencyAPI :truffleruby => Gem::Platform::RUBY, :x64_mingw => x64_mingw, :x64_mingw_20 => x64_mingw, - :x64_mingw_21 => x64_mingw }.freeze gt_eq_0 = Gem::Requirement.new '>= 0' @@ -379,7 +379,7 @@ class Gem::RequestSet::GemDependencyAPI Gem::Requirement.create requirements end - return unless gem_platforms options groups = gem_group name, options @@ -532,7 +532,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # Handles the platforms: option from +options+. Returns true if the # platform matches the current platform. - def gem_platforms(options) # :nodoc: platform_names = Array(options.delete :platform) platform_names.concat Array(options.delete :platforms) platform_names.concat @current_platforms if @current_platforms @@ -543,7 +543,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta raise ArgumentError, "unknown platform #{platform_name.inspect}" unless platform = PLATFORM_MAP[platform_name] - next false unless Gem::Platform.match platform if engines = ENGINE_MAP[platform_name] next false unless engines.include? Gem.ruby_engine @@ -16,7 +16,7 @@ class Gem::Requirement "<" => lambda {|v, r| v < r }, ">=" => lambda {|v, r| v >= r }, "<=" => lambda {|v, r| v <= r }, - "~>" => lambda {|v, r| v >= r && v.release < r.bump } }.freeze SOURCE_SET_REQUIREMENT = Struct.new(:for_lockfile).new "!" # :nodoc: @@ -281,7 +281,7 @@ class Gem::Resolver amount_constrained(dependency), conflicts[name] ? 0 : 1, activated.vertex_named(name).payload ? 0 : search_for(dependency).count, - i # for stable sort ] end end @@ -28,12 +28,20 @@ class Gem::Resolver::ActivationRequest when Gem::Specification @spec == other when Gem::Resolver::ActivationRequest - @spec == other.spec && @request == other.request else false end end ## # Is this activation request for a development dependency? @@ -46,6 +46,10 @@ class Gem::Resolver::APISpecification < Gem::Resolver::Specification @dependencies == other.dependencies end def fetch_development_dependencies # :nodoc: spec = source.fetch_spec Gem::NameTuple.new @name, @version, @platform @@ -53,7 +57,7 @@ class Gem::Resolver::APISpecification < Gem::Resolver::Specification end def installable_platform? # :nodoc: - Gem::Platform.match @platform end def pretty_print(q) # :nodoc: @@ -85,7 +85,7 @@ class Gem::Resolver::Conflict activated, requirement, request_path(@activated).reverse.join(", depends on\n "), request_path(@failed_dep).reverse.join(", depends on\n "), - matching, ] end @@ -28,7 +28,7 @@ class Gem::Resolver::DependencyRequest when Gem::Dependency @dependency == other when Gem::Resolver::DependencyRequest - @dependency == other.dependency && @requester == other.requester else false end @@ -33,6 +33,17 @@ class Gem::Resolver::IndexSpecification < Gem::Resolver::Specification spec.dependencies end def inspect # :nodoc: '#<%s %s source %s>' % [self.class, full_name, @source] end @@ -32,7 +32,6 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set super() @domain = domain - @remote = consider_remote? @f = Gem::SpecFetcher.fetcher @@ -170,7 +169,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set always_install = @always_install.map {|s| s.full_name } '#<%s domain: %s specs: %p always install: %p>' % [ - self.class, @domain, @specs.keys, always_install, ] end @@ -28,7 +28,7 @@ class Gem::Resolver::LockSet < Gem::Resolver::Set def add(name, version, platform) # :nodoc: version = Gem::Version.new version specs = [ - Gem::Resolver::LockSpecification.new(self, name, version, @sources, platform) ] @specs.concat specs @@ -1,9 +1,10 @@ # frozen_string_literal: true -require 'rubygems/resolver/molinillo/lib/molinillo/gem_metadata' -require 'rubygems/resolver/molinillo/lib/molinillo/errors' -require 'rubygems/resolver/molinillo/lib/molinillo/resolver' -require 'rubygems/resolver/molinillo/lib/molinillo/modules/ui' -require 'rubygems/resolver/molinillo/lib/molinillo/modules/specification_provider' # Gem::Resolver::Molinillo is a generic dependency resolution algorithm. module Gem::Resolver::Molinillo @@ -1,4 +1,5 @@ # frozen_string_literal: true module Gem::Resolver::Molinillo # @!visibility private module Delegates @@ -45,6 +46,12 @@ module Gem::Resolver::Molinillo current_state = state || Gem::Resolver::Molinillo::ResolutionState.empty current_state.conflicts end end end end @@ -1,4 +1,5 @@ # frozen_string_literal: true module Gem::Resolver::Molinillo module Delegates # Delegates all {Gem::Resolver::Molinillo::SpecificationProvider} methods to a @@ -1,9 +1,10 @@ # frozen_string_literal: true require 'set' require 'tsort' -require 'rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log' -require 'rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex' module Gem::Resolver::Molinillo # A directed acyclic graph that is tuned to hold named dependencies @@ -123,6 +124,7 @@ module Gem::Resolver::Molinillo dot.join("\n") end # @return [Boolean] whether the two dependency graphs are equal, determined # by a recursive traversal of each {#root_vertices} and its # {Vertex#successors} @@ -147,8 +149,8 @@ module Gem::Resolver::Molinillo vertex = add_vertex(name, payload, root) vertex.explicit_requirements << requirement if root parent_names.each do |parent_name| - parent_node = vertex_named(parent_name) - add_edge(parent_node, vertex, requirement) end vertex end @@ -189,7 +191,7 @@ module Gem::Resolver::Molinillo # @return [Edge] the added edge def add_edge(origin, destination, requirement) if destination.path_to?(origin) - raise CircularDependencyError.new([origin, destination]) end add_edge_no_circular(origin, destination, requirement) end @@ -218,5 +220,37 @@ module Gem::Resolver::Molinillo def add_edge_no_circular(origin, destination, requirement) log.add_edge_no_circular(self, origin.name, destination.name, requirement) end end end @@ -1,4 +1,5 @@ # frozen_string_literal: true module Gem::Resolver::Molinillo class DependencyGraph # An action that modifies a {DependencyGraph} that is reversible. @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'rubygems/resolver/molinillo/lib/molinillo/dependency_graph/action' module Gem::Resolver::Molinillo class DependencyGraph # @!visibility private @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'rubygems/resolver/molinillo/lib/molinillo/dependency_graph/action' module Gem::Resolver::Molinillo class DependencyGraph # @!visibility private @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'rubygems/resolver/molinillo/lib/molinillo/dependency_graph/action' module Gem::Resolver::Molinillo class DependencyGraph # @!visibility private @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'rubygems/resolver/molinillo/lib/molinillo/dependency_graph/action' module Gem::Resolver::Molinillo class DependencyGraph # @!visibility private @@ -1,10 +1,11 @@ # frozen_string_literal: true -require 'rubygems/resolver/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular' -require 'rubygems/resolver/molinillo/lib/molinillo/dependency_graph/add_vertex' -require 'rubygems/resolver/molinillo/lib/molinillo/dependency_graph/delete_edge' -require 'rubygems/resolver/molinillo/lib/molinillo/dependency_graph/detach_vertex_named' -require 'rubygems/resolver/molinillo/lib/molinillo/dependency_graph/set_payload' -require 'rubygems/resolver/molinillo/lib/molinillo/dependency_graph/tag' module Gem::Resolver::Molinillo class DependencyGraph @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'rubygems/resolver/molinillo/lib/molinillo/dependency_graph/action' module Gem::Resolver::Molinillo class DependencyGraph # @!visibility private @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'rubygems/resolver/molinillo/lib/molinillo/dependency_graph/action' module Gem::Resolver::Molinillo class DependencyGraph # @!visibility private @@ -13,11 +14,11 @@ module Gem::Resolver::Molinillo end # (see Action#up) - def up(_graph) end # (see Action#down) - def down(_graph) end # @!group Tag @@ -1,4 +1,5 @@ # frozen_string_literal: true module Gem::Resolver::Molinillo class DependencyGraph # A vertex in a {DependencyGraph} that encapsulates a {#name} and a @@ -32,7 +33,7 @@ module Gem::Resolver::Molinillo # @return [Array<Object>] all of the requirements that required # this vertex def requirements - incoming_edges.map(&:requirement) + explicit_requirements end # @return [Array<Edge>] the edges of {#graph} that have `self` as their @@ -49,14 +50,25 @@ module Gem::Resolver::Molinillo incoming_edges.map(&:origin) end - # @return [Array<Vertex>] the vertices of {#graph} where `self` is a # {#descendent?} def recursive_predecessors - vertices = predecessors - vertices += vertices.map(&:recursive_predecessors).flatten(1) - vertices.uniq! vertices end # @return [Array<Vertex>] the vertices of {#graph} that have an edge with # `self` as their {Edge#origin} @@ -64,14 +76,25 @@ module Gem::Resolver::Molinillo outgoing_edges.map(&:destination) end - # @return [Array<Vertex>] the vertices of {#graph} where `self` is an # {#ancestor?} def recursive_successors - vertices = successors - vertices += vertices.map(&:recursive_successors).flatten(1) - vertices.uniq! vertices end # @return [String] a string suitable for debugging def inspect @@ -107,11 +130,21 @@ module Gem::Resolver::Molinillo # dependency graph? # @return true iff there is a path following edges within this {#graph} def path_to?(other) - equal?(other) || successors.any? { |v| v.path_to?(other) } end alias descendent? path_to? # Is there a path from `other` to `self` following edges in the # dependency graph? # @return true iff there is a path following edges within this {#graph} @@ -1,4 +1,5 @@ # frozen_string_literal: true module Gem::Resolver::Molinillo # An error that occurred during the resolution process class ResolverError < StandardError; end @@ -17,7 +18,7 @@ module Gem::Resolver::Molinillo # @param [Array<Object>] required_by @see {#required_by} def initialize(dependency, required_by = []) @dependency = dependency - @required_by = required_by super() end @@ -41,11 +42,11 @@ module Gem::Resolver::Molinillo attr_reader :dependencies # Initializes a new error with the given circular vertices. - # @param [Array<DependencyGraph::Vertex>] nodes the nodes in the dependency # that caused the error - def initialize(nodes) - super "There is a circular dependency between #{nodes.map(&:name).join(' and ')}" - @dependencies = nodes.map(&:payload).to_set end end @@ -55,11 +56,16 @@ module Gem::Resolver::Molinillo # resolution to fail attr_reader :conflicts # Initializes a new error with the given version conflicts. # @param [{String => Resolution::Conflict}] conflicts see {#conflicts} - def initialize(conflicts) pairs = [] - conflicts.values.flatten.map(&:requirements).flatten.each do |conflicting| conflicting.each do |source, conflict_requirements| conflict_requirements.each do |c| pairs << [c, source] @@ -69,7 +75,69 @@ module Gem::Resolver::Molinillo super "Unable to satisfy the following requirements:\n\n" \ "#{pairs.map { |r, d| "- `#{r}` required by `#{d}`" }.join("\n")}" @conflicts = conflicts end end end @@ -1,5 +1,6 @@ # frozen_string_literal: true module Gem::Resolver::Molinillo # The version of Gem::Resolver::Molinillo. - VERSION = '0.5.7'.freeze end @@ -1,4 +1,5 @@ # frozen_string_literal: true module Gem::Resolver::Molinillo # Provides information about specifcations and dependencies to the resolver, # allowing the {Resolver} class to remain generic while still providing power @@ -1,4 +1,5 @@ # frozen_string_literal: true module Gem::Resolver::Molinillo # Conveys information about the resolution process to a user. module UI @@ -48,7 +49,8 @@ module Gem::Resolver::Molinillo if debug? debug_info = yield debug_info = debug_info.inspect unless debug_info.is_a?(String) - output.puts debug_info.split("\n").map { |s| ' ' * depth + s } end end @@ -1,4 +1,5 @@ # frozen_string_literal: true module Gem::Resolver::Molinillo class Resolver # A specific resolution from a given {Resolver} @@ -8,22 +9,125 @@ module Gem::Resolver::Molinillo # @attr [{String,Nil=>[Object]}] requirements the requirements that caused the conflict # @attr [Object, nil] existing the existing spec that was in conflict with # the {#possibility} - # @attr [Object] possibility the spec that was unable to be activated due - # to a conflict # @attr [Object] locked_requirement the relevant locking requirement. # @attr [Array<Array<Object>>] requirement_trees the different requirement # trees that led to every requirement for the conflicting name. # @attr [{String=>Object}] activated_by_name the already-activated specs. Conflict = Struct.new( :requirement, :requirements, :existing, - :possibility, :locked_requirement, :requirement_trees, - :activated_by_name ) # @return [SpecificationProvider] the provider that knows about # dependencies, requirements, specifications, versions, etc. attr_reader :specification_provider @@ -64,7 +168,7 @@ module Gem::Resolver::Molinillo start_resolution while state - break unless state.requirements.any? || state.requirement indicate_progress if state.respond_to?(:pop_possibility_state) # DependencyState debug(depth) { "Creating possibility state for #{requirement} (#{possibilities.count} remaining)" } @@ -78,7 +182,7 @@ module Gem::Resolver::Molinillo process_topmost_state end - activated.freeze ensure end_resolution end @@ -103,12 +207,25 @@ module Gem::Resolver::Molinillo def start_resolution @started_at = Time.now - handle_missing_or_push_dependency_state(initial_state) debug { "Starting resolution (#{@started_at})\nUser-requested dependencies: #{original_requested}" } resolver_ui.before_resolution end # Ends the resolution process # @return [void] def end_resolution @@ -121,11 +238,11 @@ module Gem::Resolver::Molinillo debug { 'Activated: ' + Hash[activated.vertices.select { |_n, v| v.payload }].keys.join(', ') } if state end - require 'rubygems/resolver/molinillo/lib/molinillo/state' - require 'rubygems/resolver/molinillo/lib/molinillo/modules/specification_provider' - require 'rubygems/resolver/molinillo/lib/molinillo/delegates/resolution_state' - require 'rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider' include Gem::Resolver::Molinillo::Delegates::ResolutionState include Gem::Resolver::Molinillo::Delegates::SpecificationProvider @@ -136,9 +253,12 @@ module Gem::Resolver::Molinillo if possibility attempt_to_activate else - create_conflict if state.is_a? PossibilityState - unwind_for_conflict until possibility && state.is_a?(DependencyState) end end # @return [Object] the current possibility that the resolution is trying @@ -153,63 +273,292 @@ module Gem::Resolver::Molinillo states.last end - # Creates the initial state for the resolution, based upon the # {#requested} dependencies - # @return [DependencyState] the initial state for the resolution - def initial_state graph = DependencyGraph.new.tap do |dg| - original_requested.each { |r| dg.add_vertex(name_for(r), nil, true).tap { |v| v.explicit_requirements << r } } dg.tag(:initial_state) end - requirements = sort_dependencies(original_requested, graph, {}) - initial_requirement = requirements.shift - DependencyState.new( - initial_requirement && name_for(initial_requirement), - requirements, - graph, - initial_requirement, - initial_requirement && search_for(initial_requirement), - 0, - {} - ) end # Unwinds the states stack because a conflict has been encountered # @return [void] def unwind_for_conflict - debug(depth) { "Unwinding for conflict: #{requirement} to #{state_index_for_unwind / 2}" } conflicts.tap do |c| - sliced_states = states.slice!((state_index_for_unwind + 1)..-1) - raise VersionConflict.new(c) unless state activated.rewind_to(sliced_states.first || :initial_state) if sliced_states state.conflicts = c index = states.size - 1 @parents_of.each { |_, a| a.reject! { |i| i >= index } } end end - # @return [Integer] The index to which the resolution should unwind in the - # case of conflict. - def state_index_for_unwind - current_requirement = requirement - existing_requirement = requirement_for_existing_name(name) - index = -1 - [current_requirement, existing_requirement].each do |r| - until r.nil? - current_state = find_state_for(r) - if state_any?(current_state) - current_index = states.index(current_state) - index = current_index if current_index > index - break end - r = parent_of(r) end end - index end # @return [Object] the requirement that led to `requirement` being added # to the list of requirements. def parent_of(requirement) @@ -219,29 +568,27 @@ module Gem::Resolver::Molinillo parent_state.requirement end # @return [Object] the requirement that led to a version of a possibility # with the given name being activated. def requirement_for_existing_name(name) - return nil unless activated.vertex_named(name).payload states.find { |s| s.name == name }.requirement end # @return [ResolutionState] the state whose `requirement` is the given # `requirement`. def find_state_for(requirement) return nil unless requirement - states.reverse_each.find { |i| requirement == i.requirement && i.is_a?(DependencyState) } - end - - # @return [Boolean] whether or not the given state has any possibilities - # left. - def state_any?(state) - state && state.possibilities.any? end # @return [Conflict] a {Conflict} that reflects the failure to activate # the {#possibility} in conjunction with the current {#state} - def create_conflict vertex = activated.vertex_named(name) locked_requirement = locked_requirement_named(name) @@ -250,18 +597,21 @@ module Gem::Resolver::Molinillo requirements[name_for_explicit_dependency_source] = vertex.explicit_requirements end requirements[name_for_locking_dependency_source] = [locked_requirement] if locked_requirement - vertex.incoming_edges.each { |edge| (requirements[edge.origin.payload] ||= []).unshift(edge.requirement) } activated_by_name = {} - activated.each { |v| activated_by_name[v.name] = v.payload if v.payload } conflicts[name] = Conflict.new( requirement, requirements, - vertex.payload, possibility, locked_requirement, requirement_trees, - activated_by_name ) end @@ -272,6 +622,7 @@ module Gem::Resolver::Molinillo vertex.requirements.map { |r| requirement_tree_for(r) } end # @return [Array<Object>] the list of requirements that led to # `requirement` being required. def requirement_tree_for(requirement) @@ -311,116 +662,47 @@ module Gem::Resolver::Molinillo # @return [void] def attempt_to_activate debug(depth) { 'Attempting to activate ' + possibility.to_s } - existing_node = activated.vertex_named(name) - if existing_node.payload - debug(depth) { "Found existing spec (#{existing_node.payload})" } - attempt_to_activate_existing_spec(existing_node) else - attempt_to_activate_new_spec - end - end - - # Attempts to activate the current {#possibility} (given that it has - # already been activated) - # @return [void] - def attempt_to_activate_existing_spec(existing_node) - existing_spec = existing_node.payload - if requirement_satisfied_by?(requirement, activated, existing_spec) - new_requirements = requirements.dup - push_state_for_requirements(new_requirements, false) - else - return if attempt_to_swap_possibility - create_conflict - debug(depth) { "Unsatisfied by existing spec (#{existing_node.payload})" } - unwind_for_conflict - end - end - - # Attempts to swp the current {#possibility} with the already-activated - # spec with the given name - # @return [Boolean] Whether the possibility was swapped into {#activated} - def attempt_to_swap_possibility - activated.tag(:swap) - vertex = activated.vertex_named(name) - activated.set_payload(name, possibility) - if !vertex.requirements. - all? { |r| requirement_satisfied_by?(r, activated, possibility) } || - !new_spec_satisfied? - activated.rewind_to(:swap) - return - end - fixup_swapped_children(vertex) - activate_spec - end - - # Ensures there are no orphaned successors to the given {vertex}. - # @param [DependencyGraph::Vertex] vertex the vertex to fix up. - # @return [void] - def fixup_swapped_children(vertex) # rubocop:disable Metrics/CyclomaticComplexity - payload = vertex.payload - deps = dependencies_for(payload).group_by(&method(:name_for)) - vertex.outgoing_edges.each do |outgoing_edge| - requirement = outgoing_edge.requirement - parent_index = @parents_of[requirement].last - succ = outgoing_edge.destination - matching_deps = Array(deps[succ.name]) - dep_matched = matching_deps.include?(requirement) - - # only push the current index when it was originally required by the - # same named spec - if parent_index && states[parent_index].name == name - @parents_of[requirement].push(states.size - 1) end - - if matching_deps.empty? && !succ.root? && succ.predecessors.to_a == [vertex] - debug(depth) { "Removing orphaned spec #{succ.name} after swapping #{name}" } - succ.requirements.each { |r| @parents_of.delete(r) } - - removed_names = activated.detach_vertex_named(succ.name).map(&:name) - requirements.delete_if do |r| - # the only removed vertices are those with no other requirements, - # so it's safe to delete only based upon name here - removed_names.include?(name_for(r)) - end - elsif !dep_matched - debug(depth) { "Removing orphaned dependency #{requirement} after swapping #{name}" } - # also reset if we're removing the edge, but only if its parent has - # already been fixed up - @parents_of[requirement].push(states.size - 1) if @parents_of[requirement].empty? - - activated.delete_edge(outgoing_edge) - requirements.delete(requirement) end end end - # Attempts to activate the current {#possibility} (given that it hasn't - # already been activated) # @return [void] - def attempt_to_activate_new_spec - if new_spec_satisfied? - activate_spec else create_conflict unwind_for_conflict end end - # @return [Boolean] whether the current spec is satisfied as a new - # possibility. - def new_spec_satisfied? - unless requirement_satisfied_by?(requirement, activated, possibility) - debug(depth) { 'Unsatisfied by requested spec' } - return false - end - - locked_requirement = locked_requirement_named(name) - - locked_spec_satisfied = !locked_requirement || - requirement_satisfied_by?(locked_requirement, activated, possibility) - debug(depth) { 'Unsatisfied by locked spec' } unless locked_spec_satisfied - - locked_spec_satisfied end # @param [String] requirement_name the spec name to search for @@ -434,7 +716,7 @@ module Gem::Resolver::Molinillo # Add the current {#possibility} to the dependency graph of the current # {#state} # @return [void] - def activate_spec conflicts.delete(name) debug(depth) { "Activated #{name} at #{possibility}" } activated.set_payload(name, possibility) @@ -442,14 +724,14 @@ module Gem::Resolver::Molinillo end # Requires the dependencies that the recently activated spec has - # @param [Object] activated_spec the specification that has just been # activated # @return [void] - def require_nested_dependencies_for(activated_spec) - nested_dependencies = dependencies_for(activated_spec) debug(depth) { "Requiring nested dependencies (#{nested_dependencies.join(', ')})" } nested_dependencies.each do |d| - activated.add_child_vertex(name_for(d), nil, [name_for(activated_spec)], d) parent_index = states.size - 1 parents = @parents_of[d] parents << parent_index if parents.empty? @@ -461,23 +743,82 @@ module Gem::Resolver::Molinillo # Pushes a new {DependencyState} that encapsulates both existing and new # requirements # @param [Array] new_requirements # @return [void] def push_state_for_requirements(new_requirements, requires_sort = true, new_activated = activated) new_requirements = sort_dependencies(new_requirements.uniq, new_activated, conflicts) if requires_sort - new_requirement = new_requirements.shift new_name = new_requirement ? name_for(new_requirement) : ''.freeze - possibilities = new_requirement ? search_for(new_requirement) : [] handle_missing_or_push_dependency_state DependencyState.new( new_name, new_requirements, new_activated, - new_requirement, possibilities, depth, conflicts.dup ) end # Pushes a new {DependencyState}. # If the {#specification_provider} says to # {SpecificationProvider#allow_missing?} that particular requirement, and # there are no possibilities for that requirement, then `state` is not - # pushed, and the node in {#activated} is removed, and we continue # resolving the remaining requirements. # @param [DependencyState] state # @return [void] @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'rubygems/resolver/molinillo/lib/molinillo/dependency_graph' module Gem::Resolver::Molinillo # This class encapsulates a dependency resolver. @@ -8,7 +9,7 @@ module Gem::Resolver::Molinillo # # class Resolver - require 'rubygems/resolver/molinillo/lib/molinillo/resolution' # @return [SpecificationProvider] the specification provider used # in the resolution process @@ -1,4 +1,5 @@ # frozen_string_literal: true module Gem::Resolver::Molinillo # A state that a {Resolution} can be in # @attr [String] name the name of the current requirement @@ -7,7 +8,8 @@ module Gem::Resolver::Molinillo # @attr [Object] requirement the current requirement # @attr [Object] possibilities the possibilities to satisfy the current requirement # @attr [Integer] depth the depth of the resolution - # @attr [Set<Object>] conflicts unresolved conflicts ResolutionState = Struct.new( :name, :requirements, @@ -15,14 +17,15 @@ module Gem::Resolver::Molinillo :requirement, :possibilities, :depth, - :conflicts ) class ResolutionState # Returns an empty resolution state # @return [ResolutionState] an empty state def self.empty - new(nil, [], DependencyGraph.new, nil, nil, 0, Set.new) end end @@ -40,7 +43,8 @@ module Gem::Resolver::Molinillo requirement, [possibilities.pop], depth + 1, - conflicts.dup ).tap do |state| state.activated.tag(state) end @@ -104,7 +104,7 @@ class Gem::Resolver::Specification # Returns true if this specification is installable on this platform. def installable_platform? - Gem::Platform.match spec.platform end def local? # :nodoc: @@ -88,7 +88,7 @@ class Gem::S3URISigner "AWS4-HMAC-SHA256", date_time, credential_info, - Digest::SHA256.hexdigest(canonical_request) ].join("\n") end @@ -6,7 +6,6 @@ #++ require 'rubygems/exceptions' -require 'fileutils' require_relative 'openssl' ## @@ -592,7 +591,7 @@ module Gem::Security end -if defined?(OpenSSL::SSL) require 'rubygems/security/policy' require 'rubygems/security/policies' require 'rubygems/security/trust_dir' @@ -194,7 +194,7 @@ class Gem::Security::Policy ("[Policy: %s - data: %p signer: %p chain: %p root: %p " + "signed-only: %p trusted-only: %p]") % [ @name, @verify_chain, @verify_data, @verify_root, @verify_signer, - @only_signed, @only_trusted, ] end @@ -34,7 +34,7 @@ class Gem::Security::Signer attr_reader :options DEFAULT_OPTIONS = { - expiration_length_days: 365 }.freeze ## @@ -771,7 +771,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } doc_items << { :name => base_name, :url => doc_root(new_path), - :summary => '' } end @@ -79,7 +79,7 @@ class Gem::Source def dependency_resolver_set # :nodoc: return Gem::Resolver::IndexSet.new self if 'file' == uri.scheme - bundler_api_uri = uri + './api/v1/dependencies' begin fetcher = Gem::RemoteFetcher.fetcher @@ -130,7 +130,7 @@ class Gem::Source spec_file_name = name_tuple.spec_name - source_uri = uri + "#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}" cache_dir = cache_dir source_uri @@ -174,7 +174,7 @@ class Gem::Source file = FILES[type] fetcher = Gem::RemoteFetcher.fetcher file_name = "#{file}.#{Gem.marshal_version}" - spec_path = uri + "#{file_name}.gz" cache_dir = cache_dir spec_path local_file = File.join(cache_dir, file_name) retried = false @@ -223,7 +223,13 @@ class Gem::Source def typo_squatting?(host, distance_threshold=4) return if @uri.host.nil? - levenshtein_distance(@uri.host, host) <= distance_threshold end end @@ -98,7 +98,7 @@ class Gem::SpecFetcher found[source] = specs.select do |tup| if dependency.match?(tup) - if matching_platform and !Gem::Platform.match(tup.platform) pm = ( rejected_specs[dependency] ||= \ Gem::PlatformMismatch.new(tup.name, tup.version)) @@ -77,18 +77,18 @@ class Gem::Specification < Gem::BasicSpecification -1 => ['(RubyGems versions up to and including 0.7 did not have versioned specifications)'], 1 => [ 'Deprecated "test_suite_file" in favor of the new, but equivalent, "test_files"', - '"test_file=x" is a shortcut for "test_files=[x]"' ], 2 => [ 'Added "required_rubygems_version"', 'Now forward-compatible with future versions', ], 3 => [ - 'Added Fixnum validation to the specification_version' ], 4 => [ - 'Added sandboxed freeform metadata to the specification version.' - ] }.freeze MARSHAL_FIELDS = { # :nodoc: @@ -804,7 +804,7 @@ class Gem::Specification < Gem::BasicSpecification stubs = stubs.uniq {|stub| stub.full_name } _resort!(stubs) - @@stubs_by_name = stubs.select {|s| Gem::Platform.match s.platform }.group_by(&:name) stubs end end @@ -831,7 +831,7 @@ class Gem::Specification < Gem::BasicSpecification @@stubs_by_name[name] else pattern = "#{name}-*.gemspec" - stubs = installed_stubs(dirs, pattern).select {|s| Gem::Platform.match s.platform } + default_stubs(pattern) stubs = stubs.uniq {|stub| stub.full_name }.group_by(&:name) stubs.each_value {|v| _resort!(v) } @@ -1344,7 +1344,7 @@ class Gem::Specification < Gem::BasicSpecification true, # has_rdoc @new_platform, @licenses, - @metadata ] end @@ -2450,7 +2450,7 @@ class Gem::Specification < Gem::BasicSpecification :version, :has_rdoc, :default_executable, - :metadata ] @@attributes.each do |attr_name| @@ -1,23 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs -MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 -d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j -ZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAwMFoXDTMxMTExMDAwMDAwMFowbDEL -MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3 -LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFuY2Ug -RVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm -+9S75S0tMqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTW -PNt0OKRKzE0lgvdKpVMSOO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEM -xChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFB -Ik5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQNAQTXKFx01p8VdteZOE3 -hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUeh10aUAsg -EsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQF -MAMBAf8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaA -FLE+w2kD+L9HAdSYJhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3Nec -nzyIZgYIVyHbIUf4KmeqvxgydkAQV8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6z -eM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jF -hS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2 -Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe -vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep -+OkuE6N36B9K ------END CERTIFICATE----- @@ -29,7 +29,7 @@ class Gem::StubSpecification < Gem::BasicSpecification # in their require paths, so lets take advantage of that by pre-allocating # a require path list for that case. REQUIRE_PATH_LIST = { # :nodoc: - 'lib' => ['lib'].freeze }.freeze def initialize(data, extensions) @@ -252,14 +252,14 @@ class Gem::TestCase < Minitest::Test msg = message(msg) do 'Expected output containing make command "%s": %s' % [ ('%s %s' % [make_command, target]).rstrip, - output.inspect ] end else msg = message(msg) do 'Expected make command "%s": %s' % [ ('%s %s' % [make_command, target]).rstrip, - output.inspect ] end end @@ -335,6 +335,7 @@ class Gem::TestCase < Minitest::Test @git = ENV['GIT'] || (win_platform? ? 'git.exe' : 'git') Gem.ensure_gem_subdirectories @gemhome @orig_LOAD_PATH = $LOAD_PATH.dup $LOAD_PATH.map! do |s| @@ -360,26 +361,23 @@ class Gem::TestCase < Minitest::Test Gem.send :remove_instance_variable, :@ruby_version if Gem.instance_variables.include? :@ruby_version - FileUtils.mkdir_p @gemhome FileUtils.mkdir_p @userhome ENV['GEM_PRIVATE_KEY_PASSPHRASE'] = PRIVATE_KEY_PASSPHRASE - @default_dir = File.join @tempdir, 'default' - @default_spec_dir = File.join @default_dir, "specifications", "default" if Gem.java_platform? @orig_default_gem_home = RbConfig::CONFIG['default_gem_home'] - RbConfig::CONFIG['default_gem_home'] = @default_dir else - Gem.instance_variable_set(:@default_dir, @default_dir) end - FileUtils.mkdir_p @default_spec_dir Gem::Specification.unresolved_deps.clear Gem.use_paths(@gemhome) - Gem::Security.reset - Gem.loaded_specs.clear Gem.instance_variable_set(:@activated_gem_paths, 0) Gem.clear_default_specs @@ -448,6 +446,8 @@ class Gem::TestCase < Minitest::Test Gem.ruby = @orig_ruby if @orig_ruby if Gem.java_platform? RbConfig::CONFIG['default_gem_home'] = @orig_default_gem_home else @@ -741,7 +741,7 @@ class Gem::TestCase < Minitest::Test def install_specs(*specs) specs.each do |spec| - Gem::Installer.for_spec(spec).install end Gem.searcher = nil @@ -751,19 +751,6 @@ class Gem::TestCase < Minitest::Test # Installs the provided default specs including writing the spec file def install_default_gems(*specs) - install_default_specs(*specs) - - specs.each do |spec| - File.open spec.loaded_from, 'w' do |io| - io.write spec.to_ruby_for_cache - end - end - end - - ## - # Install the provided default specs - - def install_default_specs(*specs) specs.each do |spec| installer = Gem::Installer.for_spec(spec, :install_as_default => true) installer.install @@ -792,7 +779,7 @@ class Gem::TestCase < Minitest::Test def new_default_spec(name, version, deps = nil, *files) spec = util_spec name, version, deps - spec.loaded_from = File.join(@default_spec_dir, spec.spec_name) spec.files = files lib_dir = File.join(@tempdir, "default_gems", "lib") @@ -1517,7 +1504,7 @@ Also, a list: PRIVATE_KEY = nil PUBLIC_KEY = nil PUBLIC_CERT = nil - end if defined?(OpenSSL::SSL) end require 'rubygems/test_utilities' @@ -1,5 +1,4 @@ # frozen_string_literal: true -require 'cgi' ## # The UriFormatter handles URIs from user-input and escaping. @@ -18,6 +17,8 @@ class Gem::UriFormatter # Creates a new URI formatter for +uri+. def initialize(uri) @uri = uri end @@ -73,4 +73,10 @@ module Gem::VersionOption end end end @@ -3,7 +3,7 @@ require 'rubygems/test_case' require 'net/http' require 'rubygems/openssl' -unless defined?(OpenSSL::SSL) warn 'Skipping bundled certificates tests. openssl not found.' end @@ -46,11 +46,15 @@ class TestBundledCA < Gem::TestCase assert_https('rubygems.org') end - def test_accessing_fastly - assert_https('rubygems.global.ssl.fastly.net') end def test_accessing_new_index - assert_https('fastly.rubygems.org') end -end if defined?(OpenSSL::SSL) @@ -164,7 +164,7 @@ class TestGem < Gem::TestCase :prog_mode => win_platform? ? 0410 : 0510, :data_mode => 0640, :wrappers => true, - :format_executable => format_executable } Dir.chdir @tempdir do Dir.mkdir 'bin' @@ -765,7 +765,7 @@ class TestGem < Gem::TestCase 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 @@ -1532,7 +1532,7 @@ class TestGem < Gem::TestCase tests = [ [:dir0, [ Gem.dir, Gem.user_dir], m0], - [:dir1, [ Gem.user_dir, Gem.dir], m1] ] tests.each do |_name, _paths, expected| @@ -231,7 +231,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase end assert_equal '', @ui.output - assert_equal "ERROR: Gemspec file not found: some_gem.gemspec\n", @ui.error end def test_execute_outside_dir @@ -272,8 +272,200 @@ class TestGemCommandsBuildCommand < Gem::TestCase assert_equal "this is a summary", spec.summary end def test_can_find_gemspecs_without_dot_gemspec - gemspec_file = File.join(@tempdir, @gem.spec_name) File.open gemspec_file + ".gemspec", 'w' do |gs| gs.write @gem.to_ruby @@ -390,7 +582,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase end def test_build_signed_gem - skip 'openssl is missing' unless defined?(OpenSSL::SSL) && !java_platform? trust_dir = Gem::Security.trust_dir @@ -417,7 +609,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase end def test_build_signed_gem_with_cert_expiration_length_days - skip 'openssl is missing' unless defined?(OpenSSL::SSL) && !java_platform? gem_path = File.join Gem.user_home, ".gem" Dir.mkdir gem_path @@ -461,7 +653,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase end def test_build_auto_resign_cert - skip 'openssl is missing' unless defined?(OpenSSL::SSL) && !java_platform? gem_path = File.join Gem.user_home, ".gem" Dir.mkdir gem_path @@ -2,7 +2,7 @@ require 'rubygems/test_case' require 'rubygems/commands/cert_command' -unless defined?(OpenSSL::SSL) warn 'Skipping `gem cert` tests. openssl not found.' end @@ -805,4 +805,4 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis assert_equal "invalid argument: --sign #{nonexistent}: does not exist", e.message end -end if defined?(OpenSSL::SSL) && !Gem.java_platform? @@ -221,7 +221,7 @@ class TestGemCommandsCleanupCommand < Gem::TestCase @b_2 = util_spec 'b', 3 install_gem @b_1 - install_default_specs @b_default install_gem @b_2 @cmd.options[:args] = [] @@ -227,7 +227,7 @@ lib/foo.rb nil, "default/gem.rb") default_gem_spec.executables = ["default_command"] default_gem_spec.files += ["default_gem.so"] - install_default_specs(default_gem_spec) @cmd.options[:args] = %w[default] @@ -238,7 +238,7 @@ lib/foo.rb expected = [ [RbConfig::CONFIG['bindir'], 'default_command'], [RbConfig::CONFIG['rubylibdir'], 'default/gem.rb'], - [RbConfig::CONFIG['archdir'], 'default_gem.so'] ].sort.map{|a|File.join a }.join "\n" assert_equal expected, @ui.output.chomp @@ -40,10 +40,12 @@ class TestGemCommandsHelpCommand < Gem::TestCase util_gem 'commands' do |out, err| mgr.command_names.each do |cmd| - assert_match(/\s+#{cmd}\s+\S+/, out) end - if defined?(OpenSSL::SSL) assert_empty err refute_match 'No command found for ', out @@ -51,6 +53,17 @@ class TestGemCommandsHelpCommand < Gem::TestCase end end def test_gem_no_args_shows_help util_gem do |out, err| assert_match(/Usage:/, out) @@ -410,7 +410,7 @@ ERROR: Possible alternatives: non_existent_with_hint expected = [ "ERROR: Could not find a valid gem 'non-existent_with-hint' (>= 0) in any repository", - "ERROR: Possible alternatives: nonexistent-with_hint" ] output = @ui.error.split "\n" @@ -247,7 +247,7 @@ EOF @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [ [response_fail, 401, 'Unauthorized'], - [response_success, 200, 'OK'] ] @otp_ui = Gem::MockGemUi.new "111111\n" @@ -275,4 +275,52 @@ EOF assert_match 'Code: ', @otp_ui.output assert_equal '111111', @stub_fetcher.last_request['OTP'] end end @@ -568,7 +568,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase assert_equal([ "Restoring gems to pristine condition...", "Cached gem for a-2 not found, attempting to fetch...", - "Skipped a-2, it was not found from cache and remote sources" ], @ui.output.split("\n")) assert_empty @ui.error @@ -577,7 +577,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase def test_execute_default_gem default_gem_spec = new_default_spec("default", "2.0.0.0", nil, "default/gem.rb") - install_default_specs(default_gem_spec) @cmd.options[:args] = %w[default] @@ -152,7 +152,7 @@ class TestGemCommandsPushCommand < Gem::TestCase keys = { :rubygems_api_key => 'KEY', - @host => @api_key } FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path @@ -187,7 +187,7 @@ class TestGemCommandsPushCommand < Gem::TestCase keys = { :rubygems_api_key => 'KEY', - @host => @api_key } FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path @@ -271,7 +271,7 @@ class TestGemCommandsPushCommand < Gem::TestCase keys = { :rubygems_api_key => 'KEY', - @host => @api_key } FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path @@ -302,7 +302,7 @@ class TestGemCommandsPushCommand < Gem::TestCase api_key = "PRIVKEY" keys = { - host => api_key } FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path @@ -373,7 +373,7 @@ class TestGemCommandsPushCommand < Gem::TestCase @fetcher.data["#{Gem.host}/api/v1/gems"] = [ [response_fail, 401, 'Unauthorized'], - [response_success, 200, 'OK'] ] @otp_ui = Gem::MockGemUi.new "111111\n" @@ -404,6 +404,32 @@ class TestGemCommandsPushCommand < Gem::TestCase assert_equal '111111', @fetcher.last_request['OTP'] end private def singleton_gem_class @@ -644,7 +644,7 @@ a (2 universal-darwin, 1 ruby x86-linux) spec_fetcher {|fetcher| fetcher.spec 'a', 2 } a1 = new_default_spec 'a', 1 - install_default_specs a1 use_ui @stub_ui do @cmd.execute @@ -663,7 +663,7 @@ EOF def test_execute_show_default_gems_with_platform a1 = new_default_spec 'a', 1 a1.platform = 'java' - install_default_specs a1 use_ui @stub_ui do @cmd.execute @@ -685,7 +685,7 @@ EOF end a1 = new_default_spec 'a', 1 - install_default_specs a1 @cmd.handle_options %w[-l -d] @@ -26,12 +26,12 @@ class TestGemCommandsSetupCommand < Gem::TestCase bundler/exe/bundle bundler/lib/bundler.rb bundler/lib/bundler/b.rb bundler/lib/bundler/templates/.circleci/config.yml bundler/lib/bundler/templates/.travis.yml bundler/man/bundle-b.1 - bundler/man/bundle-b.1.ronn bundler/man/gemfile.5 - bundler/man/gemfile.5.ronn ] create_dummy_files(filelist) @@ -155,23 +155,18 @@ class TestGemCommandsSetupCommand < Gem::TestCase assert_match %r{\A#!\s*#{bin_env}#{ruby_exec}}, File.read(gem_bin_path) end - def test_pem_files_in - assert_equal %w[rubygems/ssl_certs/rubygems.org/foo.pem], - @cmd.pem_files_in('lib').sort - end - - def test_rb_files_in - assert_equal %w[rubygems.rb rubygems/test_case.rb], - @cmd.rb_files_in('lib').sort end def test_bundler_man1_files_in - assert_equal %w[bundle-b.1 bundle-b.1.ronn], @cmd.bundler_man1_files_in('bundler/man').sort end def test_bundler_man5_files_in - assert_equal %w[gemfile.5 gemfile.5.ronn], @cmd.bundler_man5_files_in('bundler/man').sort end @@ -187,7 +182,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase assert_path_exists File.join(dir, 'bundler.rb') assert_path_exists File.join(dir, 'bundler/b.rb') - assert_path_exists File.join(dir, 'bundler/templates/.circleci/config.yml') assert_path_exists File.join(dir, 'bundler/templates/.travis.yml') end end @@ -199,9 +194,9 @@ class TestGemCommandsSetupCommand < Gem::TestCase @cmd.install_man dir assert_path_exists File.join("#{dir}/man1", 'bundle-b.1') - assert_path_exists File.join("#{dir}/man1", 'bundle-b.1.ronn') assert_path_exists File.join("#{dir}/man5", 'gemfile.5') - assert_path_exists File.join("#{dir}/man5", 'gemfile.5.ronn') end end @@ -297,7 +292,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase @cmd.remove_old_lib_files lib - files_that_go.each {|file| refute_path_exists file } files_that_stay.each {|file| assert_path_exists file } end @@ -313,8 +308,8 @@ class TestGemCommandsSetupCommand < Gem::TestCase gemfile_5_ronn = File.join man, 'man5', 'gemfile.5.ronn' gemfile_5_txt = File.join man, 'man5', 'gemfile.5.txt' - files_that_go = [bundle_b_1_txt, gemfile_5_txt] - files_that_stay = [ruby_1, bundle_b_1, bundle_b_1_ronn, gemfile_5, gemfile_5_ronn] create_dummy_files(files_that_go + files_that_stay) @@ -73,14 +73,38 @@ class TestGemCommandsSigninCommand < Gem::TestCase assert_equal api_key, credentials[:rubygems_api_key] end # Utility method to capture IO/UI within the block passed - def util_capture(ui_stub = nil, host = nil, api_key = nil) api_key ||= 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' response = [api_key, 200, 'OK'] email = '[email protected]' password = 'secret' - fetcher = Gem::FakeFetcher.new # Set the expected response for the Web-API supplied ENV['RUBYGEMS_HOST'] = host || Gem::DEFAULT_HOST @@ -88,7 +112,7 @@ class TestGemCommandsSigninCommand < Gem::TestCase fetcher.data[data_key] = response Gem::RemoteFetcher.fetcher = fetcher - sign_in_ui = ui_stub || Gem::MockGemUi.new("#{email}\n#{password}\n") use_ui sign_in_ui do yield @@ -107,6 +107,36 @@ class TestGemCommandsSourcesCommand < Gem::TestCase assert_empty ui.error end def test_execute_add_deny_typo_squatting_source rubygems_org = "https://rubyems.org" @@ -283,6 +313,36 @@ source http://gems.example.com/ already present in the cache assert_empty @ui.error end def test_execute_add_https_rubygems_org https_rubygems_org = 'https://rubygems.org/' @@ -186,6 +186,34 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase assert_equal Gem::Version.new("1"), spec.version end def test_execute_remote_without_prerelease spec_fetcher do |fetcher| fetcher.spec 'foo', '2.0.0' @@ -198,13 +198,13 @@ class TestGemCommandsUpdateCommand < Gem::TestCase def test_execute_system_specific_newer_than_or_equal_to_3_2_leaves_plugins_dir_alone spec_fetcher do |fetcher| - fetcher.download 'rubygems-update', 3.2 do |s| s.files = %w[setup.rb] end end @cmd.options[:args] = [] - @cmd.options[:system] = "3.2" FileUtils.mkdir_p Gem.plugindir plugin_file = File.join(Gem.plugindir, 'a_plugin.rb') @@ -70,7 +70,7 @@ class TestGemCommandsYankCommand < Gem::TestCase yank_uri = 'http://example/api/v1/gems/yank' @fetcher.data[yank_uri] = [ [response_fail, 401, 'Unauthorized'], - ['Successfully yanked', 200, 'OK'] ] @cmd.options[:args] = %w[a] @@ -147,4 +147,34 @@ class TestGemCommandsYankCommand < Gem::TestCase assert_equal 'key', @fetcher.last_request['Authorization'] assert_equal [yank_uri], @fetcher.paths end end @@ -528,6 +528,40 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[a-1 e-1], inst.installed_gems.map {|s| s.full_name } end def test_install_no_document util_setup_gems @@ -749,7 +783,7 @@ class TestGemDependencyInstaller < Gem::TestCase inst = nil Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new inst.install 'a' end @@ -842,7 +876,7 @@ class TestGemDependencyInstaller < Gem::TestCase require 'rubygems/openssl' - if defined? OpenSSL def test_install_security_policy util_setup_gems @@ -139,8 +139,8 @@ class TestGemDependencyList < Gem::TestCase exp = { "b" => [ - Gem::Dependency.new("a", ">= 1") - ] } assert_equal exp, @deplist.why_not_ok? @@ -30,9 +30,8 @@ class TestGemExtBuilder < Gem::TestCase ENV['DESTDIR'] = 'destination' results = [] - Dir.chdir @ext do - File.open 'Makefile', 'w' do |io| - io.puts <<-MAKEFILE all: \t@#{Gem.ruby} -e "puts %Q{all: \#{ENV['DESTDIR']}}" @@ -41,12 +40,11 @@ clean: install: \t@#{Gem.ruby} -e "puts %Q{install: \#{ENV['DESTDIR']}}" - MAKEFILE - end - - Gem::Ext::Builder.make @dest_path, results end results = results.join("\n").b assert_match %r{"DESTDIR=#{ENV['DESTDIR']}" clean$}, results @@ -64,20 +62,18 @@ install: ENV['DESTDIR'] = 'destination' results = [] - Dir.chdir @ext do - File.open 'Makefile', 'w' do |io| - io.puts <<-MAKEFILE all: \t@#{Gem.ruby} -e "puts %Q{all: \#{ENV['DESTDIR']}}" install: \t@#{Gem.ruby} -e "puts %Q{install: \#{ENV['DESTDIR']}}" - MAKEFILE - end - - Gem::Ext::Builder.make @dest_path, results end results = results.join("\n").b assert_match %r{"DESTDIR=#{ENV['DESTDIR']}" clean$}, results @@ -36,9 +36,7 @@ install (FILES test.txt DESTINATION bin) output = [] - Dir.chdir @ext do - Gem::Ext::CmakeBuilder.build nil, @dest_path, output - end output = output.join "\n" @@ -54,9 +52,7 @@ install (FILES test.txt DESTINATION bin) output = [] error = assert_raises Gem::InstallError do - Dir.chdir @ext do - Gem::Ext::CmakeBuilder.build nil, @dest_path, output - end end output = output.join "\n" @@ -77,9 +73,7 @@ install (FILES test.txt DESTINATION bin) output = [] - Dir.chdir @ext do - Gem::Ext::CmakeBuilder.build nil, @dest_path, output - end output = output.join "\n" @@ -25,9 +25,7 @@ class TestGemExtConfigureBuilder < Gem::TestCase output = [] - Dir.chdir @ext do - Gem::Ext::ConfigureBuilder.build nil, @dest_path, output - end assert_match(/^current directory:/, output.shift) assert_equal "sh ./configure --prefix=#{@dest_path}", output.shift @@ -48,9 +46,7 @@ class TestGemExtConfigureBuilder < Gem::TestCase output = [] error = assert_raises Gem::InstallError do - Dir.chdir @ext do - Gem::Ext::ConfigureBuilder.build nil, @dest_path, output - end end shell_error_msg = %r{(\./configure: .*)|((?:[Cc]an't|cannot) open '?\./configure'?(?:: No such file or directory)?)} @@ -74,9 +70,7 @@ class TestGemExtConfigureBuilder < Gem::TestCase end output = [] - Dir.chdir @ext do - Gem::Ext::ConfigureBuilder.build nil, @dest_path, output - end assert_contains_make_command 'clean', output[1] assert_contains_make_command '', output[4] @@ -29,12 +29,9 @@ class TestGemExtExtConfBuilder < Gem::TestCase output = [] - Dir.chdir @ext do - result = - Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output - assert_same result, output - end assert_match(/^current directory:/, output[0]) assert_match(/^#{Gem.ruby}.* extconf.rb/, output[1]) @@ -59,9 +56,7 @@ class TestGemExtExtConfBuilder < Gem::TestCase output = [] - Dir.chdir @ext do - Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output - end assert_equal "creating Makefile\n", output[2] assert_contains_make_command 'clean', output[4] @@ -86,9 +81,7 @@ class TestGemExtExtConfBuilder < Gem::TestCase output = [] assert_raises Gem::InstallError do - Dir.chdir @ext do - Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output - end end assert_equal "creating Makefile\n", output[2] @@ -112,9 +105,7 @@ class TestGemExtExtConfBuilder < Gem::TestCase output = [] error = assert_raises Gem::InstallError do - Dir.chdir @ext do - Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output - end end assert_equal 'extconf failed, exit code 1', error.message @@ -139,9 +130,7 @@ class TestGemExtExtConfBuilder < Gem::TestCase output = [] - Dir.chdir @ext do - Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output - end refute_includes(output, "To see why this extension failed to compile, please check the mkmf.log which can be found here:\n") @@ -181,9 +170,7 @@ end output = [] - Dir.chdir @ext do - Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output - end assert_contains_make_command 'clean', output[4] assert_contains_make_command '', output[7] @@ -207,9 +194,7 @@ end makefile.puts "install:" end - Dir.chdir @ext do - Gem::Ext::ExtConfBuilder.make @ext, output - end assert_contains_make_command 'clean', output[1] assert_contains_make_command '', output[4] @@ -218,9 +203,7 @@ end def test_class_make_no_Makefile error = assert_raises Gem::InstallError do - Dir.chdir @ext do - Gem::Ext::ExtConfBuilder.make @ext, ['output'] - end end assert_equal 'Makefile not found', error.message @@ -18,9 +18,7 @@ class TestGemExtRakeBuilder < Gem::TestCase output = [] build_rake_in do |rake| - Dir.chdir @ext do - Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', @dest_path, output - end output = output.join "\n" @@ -38,10 +36,8 @@ class TestGemExtRakeBuilder < Gem::TestCase output = [] build_rake_in do |rake| - Dir.chdir @ext do - non_empty_args_list = [''] - Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', @dest_path, output, non_empty_args_list - end output = output.join "\n" @@ -55,9 +51,7 @@ class TestGemExtRakeBuilder < Gem::TestCase output = [] build_rake_in do |rake| - Dir.chdir @ext do - Gem::Ext::RakeBuilder.build "ext/Rakefile", @dest_path, output, ["test1", "test2"] - end output = output.join "\n" @@ -72,9 +66,7 @@ class TestGemExtRakeBuilder < Gem::TestCase build_rake_in(false) do |rake| error = assert_raises Gem::InstallError do - Dir.chdir @ext do - Gem::Ext::RakeBuilder.build "mkrf_conf.rb", @dest_path, output - end end assert_match %r{^rake failed}, error.message @@ -74,17 +74,18 @@ class TestGemGemRunner < Gem::TestCase args = %w[query] use_ui @ui do - assert_nil @runner.run(args) end assert_match(/WARNING: query command is deprecated. It will be removed in Rubygems [0-9]+/, @ui.error) end def test_info_succeeds args = %w[info] use_ui @ui do - assert_nil @runner.run(args) end assert_empty @ui.error @@ -94,7 +95,7 @@ class TestGemGemRunner < Gem::TestCase args = %w[list] use_ui @ui do - assert_nil @runner.run(args) end assert_empty @ui.error @@ -104,7 +105,7 @@ class TestGemGemRunner < Gem::TestCase args = %w[search] use_ui @ui do - assert_nil @runner.run(args) end assert_empty @ui.error @@ -32,7 +32,7 @@ class TestGemGemcutterUtilities < Gem::TestCase def test_alternate_key_alternate_host keys = { :rubygems_api_key => 'KEY', - "http://rubygems.engineyard.com" => "EYKEY" } FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path @@ -202,7 +202,7 @@ class TestGemGemcutterUtilities < Gem::TestCase assert_match 'You have enabled multi-factor authentication. Please enter OTP code.', @sign_in_ui.output assert_match 'Code: ', @sign_in_ui.output - assert_match 'Signed in.', @sign_in_ui.output assert_equal '111111', @fetcher.last_request['OTP'] end @@ -233,7 +233,7 @@ class TestGemGemcutterUtilities < Gem::TestCase @fetcher.data["#{host}/api/v1/api_key"] = response Gem::RemoteFetcher.fetcher = @fetcher - @sign_in_ui = Gem::MockGemUi.new("#{email}\n#{password}\n" + extra_input) use_ui @sign_in_ui do if args.length > 0 @@ -30,7 +30,7 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase args.concat %w[--vendor] unless Gem.java_platform? - args.concat %w[-P HighSecurity] if defined?(OpenSSL::SSL) assert @cmd.handles?(args) end @@ -92,7 +92,7 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase end def test_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) @cmd.handle_options %w[-P HighSecurity] @@ -100,7 +100,7 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase end def test_security_policy_unknown - skip 'openssl is missing' unless defined?(OpenSSL::SSL) @cmd.add_install_update_options @@ -192,4 +192,16 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase assert_equal true, @cmd.options[:post_install_message] end end @@ -83,7 +83,7 @@ end end def test_check_executable_overwrite_default_bin_dir - installer = setup_base_installer bindir(Gem.bindir) do util_conflict_executable false @@ -143,7 +143,7 @@ gem 'other', version end def test_check_executable_overwrite_other_gem - installer = setup_base_installer util_conflict_executable true @@ -287,7 +287,7 @@ gem 'other', version end def test_ensure_loadable_spec_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) _, a_gem = util_gem 'a', 2 do |s| s.add_dependency 'garbage ~> 5' @@ -345,7 +345,7 @@ gem 'other', version options = { :bin_dir => bin_dir, - :install_dir => "/non/existent" } inst = Gem::Installer.at '', options @@ -794,10 +794,35 @@ gem 'other', version assert_equal spec, installer.install - assert !File.exist?(system_path), 'plugin not written to user plugins_dir' assert File.exist?(user_path), 'plugin not written to user plugins_dir' end def test_keeps_plugins_up_to_date # NOTE: version a-2 is already installed by setup hooks @@ -1134,7 +1159,7 @@ gem 'other', version Gem::Package.build @spec end end - installer = Gem::Installer.at @gem build_rake_in do use_ui @ui do assert_equal @spec, installer.install @@ -1156,6 +1181,15 @@ gem 'other', version assert_path_exists gem_dir end def test_install_missing_dirs installer = setup_base_installer @@ -1337,7 +1371,7 @@ gem 'other', version # reinstall the gem, this is also the same as pristine use_ui @ui do - installer = Gem::Installer.at path installer.install end @@ -1537,6 +1571,7 @@ gem 'other', version installer = setup_base_installer @spec.add_dependency 'b', '> 5' installer = util_setup_gem use_ui @ui do assert_raises Gem::InstallError do @@ -1781,13 +1816,24 @@ gem 'other', version def test_process_options_build_root build_root = File.join @tempdir, 'build_root' @gem = setup_base_gem - installer = Gem::Installer.at @gem, :build_root => build_root - assert_equal Pathname(build_root), installer.build_root - assert_equal File.join(build_root, @gemhome, 'bin'), installer.bin_dir - assert_equal File.join(build_root, @gemhome), installer.gem_home end def test_shebang_arguments @@ -2169,6 +2215,23 @@ gem 'other', version assert_equal ['exe/executable'], default_spec.files end def test_package_attribute gem = quick_gem 'c' do |spec| util_make_exec spec, '#!/usr/bin/ruby', 'exe' @@ -95,7 +95,7 @@ class TestGemPackage < Gem::Package::TarTestCase 'SHA256' => { 'metadata.gz' => metadata_sha256, 'data.tar.gz' => Digest::SHA256.hexdigest(tar), - } } assert_equal expected, YAML.load(checksums) @@ -252,7 +252,7 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_build_auto_signed - skip 'openssl is missing' unless defined?(OpenSSL::SSL) FileUtils.mkdir_p File.join(Gem.user_home, '.gem') @@ -295,7 +295,7 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_build_auto_signed_encrypted_key - skip 'openssl is missing' unless defined?(OpenSSL::SSL) FileUtils.mkdir_p File.join(Gem.user_home, '.gem') @@ -364,7 +364,7 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_build_signed - skip 'openssl is missing' unless defined?(OpenSSL::SSL) spec = Gem::Specification.new 'build', '1' spec.summary = 'build' @@ -401,7 +401,7 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_build_signed_encrypted_key - skip 'openssl is missing' unless defined?(OpenSSL::SSL) spec = Gem::Specification.new 'build', '1' spec.summary = 'build' @@ -957,7 +957,7 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_verify_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) package = Gem::Package.new @gem package.security_policy = Gem::Security::HighSecurity @@ -974,7 +974,7 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_verify_security_policy_low_security - skip 'openssl is missing' unless defined?(OpenSSL::SSL) @spec.cert_chain = [PUBLIC_CERT.to_pem] @spec.signing_key = PRIVATE_KEY @@ -994,7 +994,7 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_verify_security_policy_checksum_missing - skip 'openssl is missing' unless defined?(OpenSSL::SSL) @spec.cert_chain = [PUBLIC_CERT.to_pem] @spec.signing_key = PRIVATE_KEY @@ -23,7 +23,7 @@ unless Gem.java_platform? # jruby can't require the simple_gem file end def test_contents_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) @package.security_policy = Gem::Security::AlmostNoSecurity @@ -44,7 +44,7 @@ unless Gem.java_platform? # jruby can't require the simple_gem file end def test_extract_files_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) @package.security_policy = Gem::Security::AlmostNoSecurity @@ -58,7 +58,7 @@ unless Gem.java_platform? # jruby can't require the simple_gem file end def test_spec_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) @package.security_policy = Gem::Security::AlmostNoSecurity @@ -68,7 +68,7 @@ unless Gem.java_platform? # jruby can't require the simple_gem file end def test_verify - skip 'openssl is missing' unless defined?(OpenSSL::SSL) assert @package.verify @@ -117,7 +117,7 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase end def test_add_file_signer - skip 'openssl is missing' unless defined?(OpenSSL::SSL) signer = Gem::Security::Signer.new PRIVATE_KEY, [PUBLIC_CERT] @@ -11,10 +11,69 @@ class TestGemPlatform < Gem::TestCase end def test_self_match - assert Gem::Platform.match(nil), 'nil == ruby' - assert Gem::Platform.match(Gem::Platform.local), 'exact match' - assert Gem::Platform.match(Gem::Platform.local.to_s), '=~ match' - assert Gem::Platform.match(Gem::Platform::RUBY), 'ruby' end def test_self_new @@ -2,13 +2,9 @@ require 'rubygems/test_case' require 'webrick' -begin - require 'webrick/https' -rescue LoadError => e - raise unless e.path == 'openssl' -end -unless defined?(OpenSSL::SSL) warn 'Skipping Gem::RemoteFetcher tests. openssl not found.' end @@ -667,7 +663,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== def test_fetch_s3_config_creds Gem.configuration[:s3_source] = { - 'my-bucket' => {:id => 'testuser', :secret => 'testpass'} } url = 's3://my-bucket/gems/specs.4.8.gz' Time.stub :now, Time.at(1561353581) do @@ -679,7 +675,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== def test_fetch_s3_config_creds_with_region Gem.configuration[:s3_source] = { - '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 @@ -691,7 +687,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== def test_fetch_s3_config_creds_with_token Gem.configuration[:s3_source] = { - '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 @@ -706,7 +702,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== ENV['AWS_SECRET_ACCESS_KEY'] = 'testpass' ENV['AWS_SESSION_TOKEN'] = nil Gem.configuration[:s3_source] = { - 'my-bucket' => {:provider => 'env'} } url = 's3://my-bucket/gems/specs.4.8.gz' Time.stub :now, Time.at(1561353581) do @@ -722,7 +718,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== ENV['AWS_SECRET_ACCESS_KEY'] = 'testpass' ENV['AWS_SESSION_TOKEN'] = nil Gem.configuration[:s3_source] = { - 'my-bucket' => {:provider => 'env', :region => 'us-west-2'} } url = 's3://my-bucket/gems/specs.4.8.gz' Time.stub :now, Time.at(1561353581) do @@ -738,7 +734,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== ENV['AWS_SECRET_ACCESS_KEY'] = 'testpass' ENV['AWS_SESSION_TOKEN'] = 'testtoken' Gem.configuration[:s3_source] = { - 'my-bucket' => {:provider => 'env'} } url = 's3://my-bucket/gems/specs.4.8.gz' Time.stub :now, Time.at(1561353581) do @@ -758,7 +754,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== def test_fetch_s3_instance_profile_creds Gem.configuration[:s3_source] = { - 'my-bucket' => {:provider => 'instance_profile'} } url = 's3://my-bucket/gems/specs.4.8.gz' @@ -772,7 +768,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== def test_fetch_s3_instance_profile_creds_with_region Gem.configuration[:s3_source] = { - 'my-bucket' => {:provider => 'instance_profile', :region => 'us-west-2'} } url = 's3://my-bucket/gems/specs.4.8.gz' @@ -786,7 +782,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== def test_fetch_s3_instance_profile_creds_with_token Gem.configuration[:s3_source] = { - 'my-bucket' => {:provider => 'instance_profile'} } url = 's3://my-bucket/gems/specs.4.8.gz' @@ -816,7 +812,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== def test_fetch_s3_no_host Gem.configuration[:s3_source] = { - 'my-bucket' => {:id => 'testuser', :secret => 'testpass'} } url = 's3://other-bucket/gems/specs.4.8.gz' @@ -1062,7 +1058,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== :SSLCertificate => cert('ssl_cert.pem'), :SSLPrivateKey => key('ssl_key.pem'), :SSLVerifyClient => nil, - :SSLCertName => nil }.merge(config)) server.mount_proc("/yaml") do |req, res| res.body = "--- true\n" @@ -1145,4 +1141,4 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== def key(filename) OpenSSL::PKey::RSA.new(File.read(File.join(__dir__, filename))) end -end if defined?(OpenSSL::SSL) @@ -4,7 +4,7 @@ require 'rubygems/request' require 'ostruct' require 'base64' -unless defined?(OpenSSL::SSL) warn 'Skipping Gem::Request tests. openssl not found.' end @@ -506,4 +506,4 @@ ERROR: Certificate is an invalid CA certificate @response end end -end if defined?(OpenSSL::SSL) @@ -51,7 +51,7 @@ class TestGemRequestSetLockfile < Gem::TestCase expected = [ 'DEPENDENCIES', ' a', - nil ] assert_equal expected, out @@ -78,7 +78,7 @@ class TestGemRequestSetLockfile < Gem::TestCase expected = [ 'DEPENDENCIES', ' a (~> 2.0)', - nil ] assert_equal expected, out @@ -111,7 +111,7 @@ class TestGemRequestSetLockfile < Gem::TestCase ' a (2)', ' b', ' b (2)', - nil ] assert_equal expected, out @@ -139,7 +139,7 @@ class TestGemRequestSetLockfile < Gem::TestCase 'PLATFORMS', ' ruby', ' x86-darwin-8', - nil ] assert_equal expected, out @@ -39,7 +39,7 @@ class TestGemResolverAPISet < Gem::TestCase { :name => 'a', :number => '1', :platform => 'ruby', - :dependencies => [], }, ] @fetcher.data["#{@dep_uri}?gems=a"] = Marshal.dump data @@ -49,7 +49,7 @@ class TestGemResolverAPISet < Gem::TestCase a_dep = @DR::DependencyRequest.new dep('a'), nil expected = [ - @DR::APISpecification.new(set, data.first) ] assert_equal expected, set.find_all(a_dep) @@ -62,7 +62,7 @@ class TestGemResolverAPISet < Gem::TestCase { :name => 'a', :number => '1', :platform => 'ruby', - :dependencies => [], }, ] @fetcher.data["#{@dep_uri}?gems=a"] = Marshal.dump data @@ -74,7 +74,7 @@ class TestGemResolverAPISet < Gem::TestCase set.prefetch [a_dep] expected = [ - @DR::APISpecification.new(set, data.first) ] assert_equal expected, set.find_all(a_dep) @@ -114,7 +114,7 @@ class TestGemResolverAPISet < Gem::TestCase { :name => 'a', :number => '1', :platform => 'ruby', - :dependencies => [], }, ] @fetcher.data["#{@dep_uri}?gems=a,b"] = Marshal.dump data @@ -138,7 +138,7 @@ class TestGemResolverAPISet < Gem::TestCase { :name => 'a', :number => '1', :platform => 'ruby', - :dependencies => [], }, ] @fetcher.data["#{@dep_uri}?gems=a"] = Marshal.dump data @@ -163,7 +163,7 @@ class TestGemResolverAPISet < Gem::TestCase { :name => 'a', :number => '1', :platform => 'ruby', - :dependencies => [], }, ] @fetcher.data["#{@dep_uri}?gems=a,b"] = Marshal.dump data @@ -187,7 +187,7 @@ class TestGemResolverAPISet < Gem::TestCase { :name => 'a', :number => '1', :platform => 'ruby', - :dependencies => [], }, ] @fetcher.data["#{@dep_uri}?gems=a,b"] = Marshal.dump data @@ -73,7 +73,7 @@ class TestGemResolverConflict < Gem::TestCase expected = [ 'net-ssh (>= 2.0.13), 2.2.2 activated', - 'rye (= 0.9.8), 0.9.8 activated' ] assert_equal expected, conflict.request_path(child.requester) @@ -51,7 +51,7 @@ class TestGemResolverVendorSet < Gem::TestCase source = Gem::Source::Vendor.new directory expected = [ - Gem::Resolver::VendorSpecification.new(@set, spec, source) ] assert_equal expected, found @@ -2,7 +2,7 @@ require 'rubygems/test_case' require 'rubygems/security' -unless defined?(OpenSSL::SSL) warn 'Skipping Gem::Security tests. openssl not found.' end @@ -309,4 +309,4 @@ class TestGemSecurity < Gem::TestCase assert_equal key.to_pem, key_from_file.to_pem end -end if defined?(OpenSSL::SSL) && !Gem.java_platform? @@ -2,7 +2,7 @@ require 'rubygems/test_case' -unless defined?(OpenSSL::SSL) warn 'Skipping Gem::Security::Policy tests. openssl not found.' end @@ -532,4 +532,4 @@ class TestGemSecurityPolicy < Gem::TestCase return digests, signatures end -end if defined?(OpenSSL::SSL) @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'rubygems/test_case' -unless defined?(OpenSSL::SSL) warn 'Skipping Gem::Security::Signer tests. openssl not found.' end @@ -214,4 +214,4 @@ toqvglr0kdbknSRRjBVLK6tsgr07aLT9gNP7mTW2PA== signer.sign 'hello' end end -end if defined?(OpenSSL::SSL) @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'rubygems/test_case' -unless defined?(OpenSSL::SSL) warn 'Skipping Gem::Security::TrustDir tests. openssl not found.' end @@ -95,4 +95,4 @@ class TestGemSecurityTrustDir < Gem::TestCase assert_equal mask, File.stat(@dest_dir).mode unless win_platform? end -end if defined?(OpenSSL::SSL) @@ -240,6 +240,11 @@ class TestGemSource < Gem::TestCase refute rubygems_source.typo_squatting?("rubysertgems.org") end def test_typo_squatting_custom_distance_threshold rubygems_source = Gem::Source.new("https://rubgems.org") distance_threshold = 5 @@ -0,0 +1,49 @@ @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'benchmark' require 'rubygems/test_case' require 'pathname' require 'stringio' require 'rubygems/ext' @@ -1999,7 +2000,7 @@ dependencies: [] test_cases = { 'i386-mswin32' => 'a-1-x86-mswin32-60', 'i386-mswin32_80' => 'a-1-x86-mswin32-80', - 'i386-mingw32' => 'a-1-x86-mingw32' } test_cases.each do |arch, expected| @@ -3035,7 +3036,7 @@ Please report a bug if this causes problems. specification.define_singleton_method(:find_all_by_name) do |dep_name| [ specification.new {|s| s.name = "z", s.version = Gem::Version.new("1") }, - specification.new {|s| s.name = "z", s.version = Gem::Version.new("2") } ] end @@ -3578,7 +3579,7 @@ Did you mean 'Ruby'? "one" => "two", "home" => "three", "homepage_uri" => "https://example.com/user/repo", - "funding_uri" => "https://example.com/donate" } end @@ -3838,7 +3839,7 @@ end default_gem_spec = new_default_spec("default", "2.0.0.0", nil, "default/gem.rb") - spec_path = File.join(@default_spec_dir, default_gem_spec.spec_name) write_file(spec_path) do |file| file.print(default_gem_spec.to_ruby) end @@ -177,7 +177,7 @@ class TestGemUninstaller < Gem::InstallerTestCase @spec.files += %w[lib/rubygems_plugin.rb] - Gem::Installer.at(Gem::Package.build(@spec)).install plugin_path = File.join Gem.plugindir, 'a_plugin.rb' assert File.exist?(plugin_path), 'plugin not written' @@ -194,7 +194,7 @@ class TestGemUninstaller < Gem::InstallerTestCase @spec.files += %w[lib/rubygems_plugin.rb] - Gem::Installer.at(Gem::Package.build(@spec)).install plugin_path = File.join Gem.plugindir, 'a_plugin.rb' assert File.exist?(plugin_path), 'plugin not written' @@ -212,7 +212,7 @@ class TestGemUninstaller < Gem::InstallerTestCase @spec.files += %w[lib/rubygems_plugin.rb] - Gem::Installer.at(Gem::Package.build(@spec)).install plugin_path = File.join Gem.plugindir, 'a_plugin.rb' assert File.exist?(plugin_path), 'plugin not written' @@ -314,7 +314,7 @@ create_makefile '#{@spec.name}' use_ui @ui do path = Gem::Package.build @spec - installer = Gem::Installer.at path installer.install end @@ -633,19 +633,19 @@ create_makefile '#{@spec.name}' plugin_path = File.join Gem.plugindir, 'a_plugin.rb' @spec.version = '1' - Gem::Installer.at(Gem::Package.build(@spec)).install refute File.exist?(plugin_path), 'version without plugin installed, but plugin written' @spec.files += %w[lib/rubygems_plugin.rb] @spec.version = '2' - Gem::Installer.at(Gem::Package.build(@spec)).install assert File.exist?(plugin_path), 'version with plugin installed, but plugin not written' assert_match %r{\Arequire.*a-2/lib/rubygems_plugin\.rb}, File.read(plugin_path), 'written plugin has incorrect content' @spec.version = '3' - Gem::Installer.at(Gem::Package.build(@spec)).install assert File.exist?(plugin_path), 'version with plugin installed, but plugin removed' assert_match %r{\Arequire.*a-3/lib/rubygems_plugin\.rb}, File.read(plugin_path), 'old version installed, but plugin updated' @@ -26,7 +26,7 @@ class TestGemValidator < Gem::TestCase @spec.file_name => [ Gem::Validator::ErrorData.new('lib/b.rb', 'Missing file'), Gem::Validator::ErrorData.new('lib/c.rb', 'Extra file'), - ] } assert_equal expected, alien @@ -56,7 +56,7 @@ class TestGemVersionOption < Gem::TestCase @cmd.handle_options %w[--platform ruby] expected = [ - Gem::Platform::RUBY ] assert_equal expected, Gem.platforms @@ -120,7 +120,7 @@ class TestGemRequire < Gem::TestCase c1 = new_default_spec "c", "1", nil, "c/c.rb" c2 = new_default_spec "c", "2", nil, "c/c.rb" - install_default_specs c1, c2, b1, a1 dir = Dir.mktmpdir("test_require", @tempdir) dash_i_arg = File.join dir, 'lib' @@ -405,8 +405,8 @@ class TestGemRequire < Gem::TestCase # Remove an old default gem version directly from disk as if someone ran # gem cleanup. - FileUtils.rm_rf(File.join @default_dir, "#{b1.full_name}") - FileUtils.rm_rf(File.join @default_spec_dir, "#{b1.full_name}.gemspec") # Require gems that have not been removed. assert_require 'a/b' @@ -433,7 +433,7 @@ class TestGemRequire < Gem::TestCase def test_default_gem_only default_gem_spec = new_default_spec("default", "2.0.0.0", nil, "default/gem.rb") - install_default_specs(default_gem_spec) assert_require "default/gem" assert_equal %w[default-2.0.0.0], loaded_spec_names end @@ -441,7 +441,7 @@ class TestGemRequire < Gem::TestCase def test_default_gem_require_activates_just_once default_gem_spec = new_default_spec("default", "2.0.0.0", nil, "default/gem.rb") - install_default_specs(default_gem_spec) assert_require "default/gem" @@ -506,7 +506,7 @@ class TestGemRequire < Gem::TestCase def test_default_gem_and_normal_gem default_gem_spec = new_default_spec("default", "2.0.0.0", nil, "default/gem.rb") - install_default_specs(default_gem_spec) normal_gem_spec = util_spec("default", "3.0", nil, "lib/default/gem.rb") install_specs(normal_gem_spec) @@ -544,11 +544,11 @@ class TestGemRequire < Gem::TestCase def test_default_gem_prerelease default_gem_spec = new_default_spec("default", "2.0.0", nil, "default/gem.rb") - install_default_specs(default_gem_spec) normal_gem_higher_prerelease_spec = util_spec("default", "3.0.0.rc2", nil, "lib/default/gem.rb") - install_default_specs(normal_gem_higher_prerelease_spec) assert_require "default/gem" assert_equal %w[default-3.0.0.rc2], loaded_spec_names @@ -586,7 +586,7 @@ class TestGemRequire < Gem::TestCase def test_require_when_gem_defined default_gem_spec = new_default_spec("default", "2.0.0.0", nil, "default/gem.rb") - install_default_specs(default_gem_spec) c = Class.new do def self.gem(*args) raise "received #gem with #{args.inspect}" @@ -677,6 +677,47 @@ class TestGemRequire < Gem::TestCase end end end end private |