From 615ac3593499f54fde4b1eb0fba66b6bd944821b Mon Sep 17 00:00:00 2001 From: hsbt Date: Mon, 22 Oct 2018 00:27:02 +0000 Subject: Merge rubygems master branch from github.com/rubygems/rubygems. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/bundler_version_finder.rb | 6 +-- lib/rubygems/command.rb | 2 +- lib/rubygems/command_manager.rb | 4 +- lib/rubygems/commands/build_command.rb | 6 ++- lib/rubygems/commands/cert_command.rb | 16 +++---- lib/rubygems/commands/help_command.rb | 8 ++-- lib/rubygems/commands/setup_command.rb | 6 +-- lib/rubygems/commands/uninstall_command.rb | 2 +- lib/rubygems/commands/update_command.rb | 6 +-- lib/rubygems/compatibility.rb | 2 +- lib/rubygems/config_file.rb | 25 ++++++---- lib/rubygems/defaults.rb | 8 ++-- lib/rubygems/dependency.rb | 2 +- lib/rubygems/doctor.rb | 2 +- lib/rubygems/ext/builder.rb | 15 +++++- lib/rubygems/ext/ext_conf_builder.rb | 2 +- lib/rubygems/ext/rake_builder.rb | 10 ++-- lib/rubygems/install_update_options.rb | 24 ---------- lib/rubygems/installer.rb | 2 +- lib/rubygems/package.rb | 19 ++++++-- lib/rubygems/package/tar_header.rb | 2 +- lib/rubygems/platform.rb | 4 +- lib/rubygems/remote_fetcher.rb | 30 +----------- lib/rubygems/request_set/gem_dependency_api.rb | 8 ++-- lib/rubygems/requirement.rb | 6 +-- lib/rubygems/resolver/source_set.rb | 2 +- lib/rubygems/resolver/stats.rb | 2 +- lib/rubygems/safe_yaml.rb | 4 +- lib/rubygems/security.rb | 2 +- lib/rubygems/security/policies.rb | 2 +- lib/rubygems/security/policy.rb | 6 +-- lib/rubygems/security/signer.rb | 26 +++++++++-- lib/rubygems/security/trust_dir.rb | 2 +- lib/rubygems/server.rb | 10 ++-- lib/rubygems/source.rb | 29 ++++-------- lib/rubygems/spec_fetcher.rb | 6 +-- lib/rubygems/specification.rb | 65 ++++++++++++++------------ lib/rubygems/specification_policy.rb | 26 ++++++----- lib/rubygems/stub_specification.rb | 8 ++-- lib/rubygems/test_case.rb | 2 +- lib/rubygems/test_utilities.rb | 14 ------ lib/rubygems/text.rb | 2 +- lib/rubygems/uninstaller.rb | 4 +- lib/rubygems/version.rb | 2 +- 44 files changed, 206 insertions(+), 225 deletions(-) (limited to 'lib/rubygems') diff --git a/lib/rubygems/bundler_version_finder.rb b/lib/rubygems/bundler_version_finder.rb index 2f448c9562..7babeaa848 100644 --- a/lib/rubygems/bundler_version_finder.rb +++ b/lib/rubygems/bundler_version_finder.rb @@ -104,9 +104,9 @@ To install the missing version, run `gem install bundler:#{vr.first}` return unless gemfile lockfile = case gemfile - when "gems.rb" then "gems.locked" - else "#{gemfile}.lock" - end.dup.untaint + when "gems.rb" then "gems.locked" + else "#{gemfile}.lock" + end.dup.untaint return unless File.file?(lockfile) diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb index 71199c59b4..3fc8a70a3e 100644 --- a/lib/rubygems/command.rb +++ b/lib/rubygems/command.rb @@ -570,7 +570,7 @@ class Gem::Command # :stopdoc: - HELP = <<-HELP + HELP = <<-HELP.freeze RubyGems is a sophisticated package manager for Ruby. This is a basic help message containing pointers to more information. diff --git a/lib/rubygems/command_manager.rb b/lib/rubygems/command_manager.rb index 3dc5779c91..40ae6191c5 100644 --- a/lib/rubygems/command_manager.rb +++ b/lib/rubygems/command_manager.rb @@ -69,11 +69,11 @@ class Gem::CommandManager :update, :which, :yank, - ] + ].freeze ALIAS_COMMANDS = { 'i' => 'install' - } + }.freeze ## # Return the authoritative instance of the command manager. diff --git a/lib/rubygems/commands/build_command.rb b/lib/rubygems/commands/build_command.rb index f1d700349f..3c778cf705 100644 --- a/lib/rubygems/commands/build_command.rb +++ b/lib/rubygems/commands/build_command.rb @@ -55,7 +55,11 @@ with gem spec: spec = Gem::Specification.load File.basename(gemspec) if spec then - Gem::Package.build spec, options[:force], options[:strict] + Gem::Package.build( + spec, + options[:force], + options[:strict] + ) else alert_error "Error loading gemspec. Aborting." terminate_interaction 1 diff --git a/lib/rubygems/commands/cert_command.rb b/lib/rubygems/commands/cert_command.rb index 3f74508074..e93c39747c 100644 --- a/lib/rubygems/commands/cert_command.rb +++ b/lib/rubygems/commands/cert_command.rb @@ -149,15 +149,15 @@ class Gem::Commands::CertCommand < Gem::Command end def build_cert email, key # :nodoc: - expiration_length_days = options[:expiration_length_days] - age = - if expiration_length_days.nil? || expiration_length_days == 0 - Gem::Security::ONE_YEAR - else - Gem::Security::ONE_DAY * expiration_length_days - end + expiration_length_days = options[:expiration_length_days] || + Gem.configuration.cert_expiration_length_days + + cert = Gem::Security.create_cert_email( + email, + key, + (Gem::Security::ONE_DAY * expiration_length_days) + ) - cert = Gem::Security.create_cert_email email, key, age Gem::Security.write cert, "gem-public_cert.pem" end diff --git a/lib/rubygems/commands/help_command.rb b/lib/rubygems/commands/help_command.rb index 7d02022369..0c96963fac 100644 --- a/lib/rubygems/commands/help_command.rb +++ b/lib/rubygems/commands/help_command.rb @@ -4,7 +4,7 @@ require 'rubygems/command' class Gem::Commands::HelpCommand < Gem::Command # :stopdoc: - EXAMPLES = <<-EOF + EXAMPLES = <<-EOF.freeze Some examples of 'gem' usage. * Install 'rake', either from local directory or remote server: @@ -53,7 +53,7 @@ Some examples of 'gem' usage. gem update --system EOF - GEM_DEPENDENCIES = <<-EOF + GEM_DEPENDENCIES = <<-EOF.freeze A gem dependencies file allows installation of a consistent set of gems across multiple environments. The RubyGems implementation is designed to be compatible with Bundler's Gemfile format. You can see additional @@ -230,7 +230,7 @@ default. This may be overridden with the :development_group option: EOF - PLATFORMS = <<-'EOF' + PLATFORMS = <<-'EOF'.freeze RubyGems platforms are composed of three parts, a CPU, an OS, and a version. These values are taken from values in rbconfig.rb. You can view your current platform by running `gem environment`. @@ -277,7 +277,7 @@ platform. ["examples", EXAMPLES], ["gem_dependencies", GEM_DEPENDENCIES], ["platforms", PLATFORMS], - ] + ].freeze # :startdoc: def initialize diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index 281108ea1f..37abe3b2ec 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -9,7 +9,7 @@ class Gem::Commands::SetupCommand < Gem::Command HISTORY_HEADER = /^===\s*[\d.a-zA-Z]+\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/ VERSION_MATCHER = /^===\s*([\d.a-zA-Z]+)\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/ - ENV_PATHS = %w[/usr/bin/env /bin/env] + ENV_PATHS = %w[/usr/bin/env /bin/env].freeze def initialize require 'tmpdir' @@ -84,8 +84,8 @@ class Gem::Commands::SetupCommand < Gem::Command add_option '--[no-]regenerate-binstubs', 'Regenerate gem binstubs' do |value, options| - options[:regenerate_binstubs] = value - end + options[:regenerate_binstubs] = value + end add_option('-E', '--[no-]env-shebang', 'Rewrite executables with a shebang', diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb index 1ddc12c737..d1ffe675fe 100644 --- a/lib/rubygems/commands/uninstall_command.rb +++ b/lib/rubygems/commands/uninstall_command.rb @@ -20,7 +20,7 @@ class Gem::Commands::UninstallCommand < Gem::Command add_option('-a', '--[no-]all', 'Uninstall all matching versions' - ) do |value, options| + ) do |value, options| options[:all] = value end diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index 1c86ba6753..dc924265b0 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -168,12 +168,8 @@ command to remove old versions. Dir.chdir update_dir do say "Installing RubyGems #{version}" - # Make sure old rubygems isn't loaded - old = ENV["RUBYOPT"] - ENV.delete("RUBYOPT") if old - installed = system Gem.ruby, 'setup.rb', *args + installed = system Gem.ruby, '--disable-gems', 'setup.rb', *args say "RubyGems system software updated" if installed - ENV["RUBYOPT"] = old if old end end diff --git a/lib/rubygems/compatibility.rb b/lib/rubygems/compatibility.rb index 24c741e99b..b4332eb9f1 100644 --- a/lib/rubygems/compatibility.rb +++ b/lib/rubygems/compatibility.rb @@ -22,7 +22,7 @@ module Gem EXEEXT RUBY_SO_NAME arch bindir datadir libdir ruby_install_name ruby_version rubylibprefix sitedir sitelibdir vendordir vendorlibdir rubylibdir - ] + ].freeze unless defined?(ConfigMap) ## diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index 9ef1236204..f8782015a1 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -45,6 +45,7 @@ class Gem::ConfigFile DEFAULT_VERBOSITY = true DEFAULT_UPDATE_SOURCES = true DEFAULT_CONCURRENT_DOWNLOADS = 8 + DEFAULT_CERT_EXPIRATION_LENGTH_DAYS = 365 ## # For Ruby packagers to set configuration defaults. Set in @@ -135,6 +136,11 @@ class Gem::ConfigFile # sources to look for gems attr_accessor :sources + ## + # Expiration length to sign a certificate + + attr_accessor :cert_expiration_length_days + ## # Path name of directory or file of openssl client certificate, used for remote https connection with client authentication @@ -185,6 +191,7 @@ class Gem::ConfigFile @verbose = DEFAULT_VERBOSITY @update_sources = DEFAULT_UPDATE_SOURCES @concurrent_downloads = DEFAULT_CONCURRENT_DOWNLOADS + @cert_expiration_length_days = DEFAULT_CERT_EXPIRATION_LENGTH_DAYS operating_system_config = Marshal.load Marshal.dump(OPERATING_SYSTEM_DEFAULTS) platform_config = Marshal.load Marshal.dump(PLATFORM_DEFAULTS) @@ -202,15 +209,15 @@ class Gem::ConfigFile end # HACK these override command-line args, which is bad - @backtrace = @hash[:backtrace] if @hash.key? :backtrace - @bulk_threshold = @hash[:bulk_threshold] if @hash.key? :bulk_threshold - @home = @hash[:gemhome] if @hash.key? :gemhome - @path = @hash[:gempath] if @hash.key? :gempath - @update_sources = @hash[:update_sources] if @hash.key? :update_sources - @verbose = @hash[:verbose] if @hash.key? :verbose - @concurrent_downloads = @hash[:concurrent_downloads] if @hash.key? :concurrent_downloads - @disable_default_gem_server = @hash[:disable_default_gem_server] if @hash.key? :disable_default_gem_server - @sources = @hash[:sources] if @hash.key? :sources + @backtrace = @hash[:backtrace] if @hash.key? :backtrace + @bulk_threshold = @hash[:bulk_threshold] if @hash.key? :bulk_threshold + @home = @hash[:gemhome] if @hash.key? :gemhome + @path = @hash[:gempath] if @hash.key? :gempath + @update_sources = @hash[:update_sources] if @hash.key? :update_sources + @verbose = @hash[:verbose] if @hash.key? :verbose + @disable_default_gem_server = @hash[:disable_default_gem_server] if @hash.key? :disable_default_gem_server + @sources = @hash[:sources] if @hash.key? :sources + @cert_expiration_length_days = @hash[:cert_expiration_length_days] if @hash.key? :cert_expiration_length_days @ssl_verify_mode = @hash[:ssl_verify_mode] if @hash.key? :ssl_verify_mode @ssl_ca_cert = @hash[:ssl_ca_cert] if @hash.key? :ssl_ca_cert diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb index b8222877ae..334ef4d4c1 100644 --- a/lib/rubygems/defaults.rb +++ b/lib/rubygems/defaults.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true module Gem - DEFAULT_HOST = "https://rubygems.org" + DEFAULT_HOST = "https://rubygems.org".freeze @post_install_hooks ||= [] @done_installing_hooks ||= [] @@ -36,9 +36,9 @@ module Gem ] elsif RbConfig::CONFIG['rubylibprefix'] then [ - RbConfig::CONFIG['rubylibprefix'], - 'gems', - RbConfig::CONFIG['ruby_version'] + RbConfig::CONFIG['rubylibprefix'], + 'gems', + RbConfig::CONFIG['ruby_version'] ] else [ diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb index 3465666790..c06df0fa35 100644 --- a/lib/rubygems/dependency.rb +++ b/lib/rubygems/dependency.rb @@ -19,7 +19,7 @@ class Gem::Dependency TYPES = [ :development, :runtime, - ] + ].freeze ## # Dependency name or regular expression. diff --git a/lib/rubygems/doctor.rb b/lib/rubygems/doctor.rb index ec4a16c3f8..e5d8c43de8 100644 --- a/lib/rubygems/doctor.rb +++ b/lib/rubygems/doctor.rb @@ -26,7 +26,7 @@ class Gem::Doctor ['doc', ''], ['extensions', ''], ['gems', ''], - ] + ].freeze missing = Gem::REPOSITORY_SUBDIRECTORIES.sort - diff --git a/lib/rubygems/ext/builder.rb b/lib/rubygems/ext/builder.rb index 6382a8f5c7..b3b9033962 100644 --- a/lib/rubygems/ext/builder.rb +++ b/lib/rubygems/ext/builder.rb @@ -148,9 +148,21 @@ EOF def build_extension extension, dest_path # :nodoc: results = [] + # FIXME: Determine if this line is necessary and, if so, why. + # Notes: + # 1. As far as I can tell, this method is only called by +build_extensions+. + # 2. The existence of this line implies +extension+ is, or previously was, + # sometimes +false+ or +nil+. + # 3. #1 and #2 combined suggests, but does not confirm, that + # +@specs.extensions+ sometimes contained +false+ or +nil+ values. + # 4. Nothing seems to explicitly handle +extension+ being empty, + # which makes me wonder both what it should do and what it does. + # + # - @duckinator extension ||= '' # I wish I knew why this line existed + extension_dir = - File.expand_path File.join @gem_dir, File.dirname(extension) + File.expand_path File.join(@gem_dir, File.dirname(extension)) lib_dir = File.join @spec.full_gem_path, @spec.raw_require_paths.first builder = builder_for extension @@ -200,6 +212,7 @@ EOF FileUtils.rm_f @spec.gem_build_complete_path + # FIXME: action at a distance: @ran_rake modified deep in build_extension(). - @duckinator @ran_rake = false # only run rake once @spec.extensions.each do |extension| diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb index a17881a890..18e300d8c2 100644 --- a/lib/rubygems/ext/ext_conf_builder.rb +++ b/lib/rubygems/ext/ext_conf_builder.rb @@ -38,7 +38,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder destdir = ENV["DESTDIR"] begin - cmd = [Gem.ruby, "-r", get_relative_path(siteconf.path), File.basename(extension), *args].join ' ' + cmd = [Gem.ruby, "-I", File.expand_path("../../..", __FILE__), "-r", get_relative_path(siteconf.path), File.basename(extension), *args].join ' ' begin run cmd, results diff --git a/lib/rubygems/ext/rake_builder.rb b/lib/rubygems/ext/rake_builder.rb index 7a5a48c6cc..890803aaef 100644 --- a/lib/rubygems/ext/rake_builder.rb +++ b/lib/rubygems/ext/rake_builder.rb @@ -5,6 +5,8 @@ # See LICENSE.txt for permissions. #++ +require "shellwords" + class Gem::Ext::RakeBuilder < Gem::Ext::Builder def self.build(extension, dest_path, results, args=[], lib_dir=nil) @@ -14,9 +16,6 @@ class Gem::Ext::RakeBuilder < Gem::Ext::Builder run cmd, results end - # Deal with possible spaces in the path, e.g. C:/Program Files - dest_path = '"' + dest_path.to_s + '"' if dest_path.to_s.include?(' ') - rake = ENV['rake'] rake ||= begin @@ -26,9 +25,8 @@ class Gem::Ext::RakeBuilder < Gem::Ext::Builder rake ||= Gem.default_exec_format % 'rake' - cmd = "#{rake} RUBYARCHDIR=#{dest_path} RUBYLIBDIR=#{dest_path}" # ENV is frozen - - run cmd, results + rake_args = ["RUBYARCHDIR=#{dest_path}", "RUBYLIBDIR=#{dest_path}", *args] + run "#{rake} #{rake_args.shelljoin}", results results end diff --git a/lib/rubygems/install_update_options.rb b/lib/rubygems/install_update_options.rb index 75968605f1..824682f9ad 100644 --- a/lib/rubygems/install_update_options.rb +++ b/lib/rubygems/install_update_options.rb @@ -63,30 +63,6 @@ module Gem::InstallUpdateOptions options[:document] = [] end - add_option(:Deprecated, '--[no-]rdoc', - 'Generate RDoc for installed gems', - 'Use --document instead') do |value, options| - if value then - options[:document] << 'rdoc' - else - options[:document].delete 'rdoc' - end - - options[:document].uniq! - end - - add_option(:Deprecated, '--[no-]ri', - 'Generate ri data for installed gems.', - 'Use --document instead') do |value, options| - if value then - options[:document] << 'ri' - else - options[:document].delete 'ri' - end - - options[:document].uniq! - end - add_option(:"Install/Update", '-E', '--[no-]env-shebang', "Rewrite the shebang line on installed", "scripts to use /usr/bin/env") do |value, options| diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index a3bb9b821e..298a7053c7 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -34,7 +34,7 @@ class Gem::Installer # Paths where env(1) might live. Some systems are broken and have it in # /bin - ENV_PATHS = %w[/usr/bin/env /bin/env] + ENV_PATHS = %w[/usr/bin/env /bin/env].freeze ## # Deprecated in favor of Gem::Ext::BuildError diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index ec9541d19b..a71c41afc7 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -119,7 +119,7 @@ class Gem::Package # Permission for other files attr_accessor :data_mode - def self.build spec, skip_validation=false, strict_validation=false + def self.build spec, skip_validation = false, strict_validation = false gem_file = spec.file_name package = new gem_file @@ -263,7 +263,11 @@ class Gem::Package @spec.mark_version @spec.validate true, strict_validation unless skip_validation - setup_signer + setup_signer( + signer_options: { + expiration_length_days: Gem.configuration.cert_expiration_length_days + } + ) @gem.with_write_io do |gem_io| Gem::Package::TarWriter.new gem_io do |gem| @@ -521,10 +525,17 @@ EOM # Prepares the gem for signing and checksum generation. If a signing # certificate and key are not present only checksum generation is set up. - def setup_signer + def setup_signer(signer_options: {}) passphrase = ENV['GEM_PRIVATE_KEY_PASSPHRASE'] if @spec.signing_key then - @signer = Gem::Security::Signer.new @spec.signing_key, @spec.cert_chain, passphrase + @signer = + Gem::Security::Signer.new( + @spec.signing_key, + @spec.cert_chain, + passphrase, + signer_options + ) + @spec.signing_key = nil @spec.cert_chain = @signer.cert_chain.map { |cert| cert.to_s } else diff --git a/lib/rubygems/package/tar_header.rb b/lib/rubygems/package/tar_header.rb index fa1f5b6e46..d3c242f815 100644 --- a/lib/rubygems/package/tar_header.rb +++ b/lib/rubygems/package/tar_header.rb @@ -50,7 +50,7 @@ class Gem::Package::TarHeader :uid, :uname, :version, - ] + ].freeze ## # Pack format for a tar header diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb index 2dd9ed5782..1019fc22b9 100644 --- a/lib/rubygems/platform.rb +++ b/lib/rubygems/platform.rb @@ -195,12 +195,12 @@ class Gem::Platform # A pure-Ruby gem that may use Gem::Specification#extensions to build # binary files. - RUBY = 'ruby' + RUBY = 'ruby'.freeze ## # A platform-specific gem that is built for the packaging Ruby's platform. # This will be replaced with Gem::Platform::local. - CURRENT = 'current' + CURRENT = 'current'.freeze end diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb index 940523f246..7c4f3f9a6f 100644 --- a/lib/rubygems/remote_fetcher.rb +++ b/lib/rubygems/remote_fetcher.rb @@ -71,13 +71,10 @@ class Gem::RemoteFetcher # HTTP_PROXY_PASS) # * :no_proxy: ignore environment variables and _don't_ use a proxy # - # +dns+: An object to use for DNS resolution of the API endpoint. - # By default, use Resolv::DNS. - # # +headers+: A set of additional HTTP headers to be sent to the server when # fetching the gem. - def initialize(proxy=nil, dns=Resolv::DNS.new, headers={}) + def initialize(proxy=nil, dns=nil, headers={}) require 'net/http' require 'stringio' require 'time' @@ -90,34 +87,9 @@ class Gem::RemoteFetcher @pool_lock = Mutex.new @cert_files = Gem::Request.get_cert_files - @dns = dns @headers = headers end - ## - # Given a source at +uri+, calculate what hostname to actually - # connect to query the data for it. - - def api_endpoint(uri) - host = uri.host - - begin - res = @dns.getresource "_rubygems._tcp.#{host}", - Resolv::DNS::Resource::IN::SRV - rescue Resolv::ResolvError => e - verbose "Getting SRV record failed: #{e}" - uri - else - target = res.target.to_s.strip - - if URI("http://" + target).host.end_with?(".#{host}") - return URI.parse "#{uri.scheme}://#{target}#{uri.path}" - end - - uri - end - end - ## # Given a name and requirement, downloads this gem into cache and returns the # filename. Returns nil if the gem cannot be located. diff --git a/lib/rubygems/request_set/gem_dependency_api.rb b/lib/rubygems/request_set/gem_dependency_api.rb index a26e8b90a3..177079da03 100644 --- a/lib/rubygems/request_set/gem_dependency_api.rb +++ b/lib/rubygems/request_set/gem_dependency_api.rb @@ -48,7 +48,7 @@ class Gem::RequestSet::GemDependencyAPI :ruby_19 => %w[ruby rbx maglev], :ruby_20 => %w[ruby rbx maglev], :ruby_21 => %w[ruby rbx maglev], - } + }.freeze mswin = Gem::Platform.new 'x86-mswin32' mswin64 = Gem::Platform.new 'x64-mswin64' @@ -88,7 +88,7 @@ class Gem::RequestSet::GemDependencyAPI :x64_mingw => x64_mingw, :x64_mingw_20 => x64_mingw, :x64_mingw_21 => x64_mingw - } + }.freeze gt_eq_0 = Gem::Requirement.new '>= 0' tilde_gt_1_8_0 = Gem::Requirement.new '~> 1.8.0' @@ -129,7 +129,7 @@ class Gem::RequestSet::GemDependencyAPI :x64_mingw => gt_eq_0, :x64_mingw_20 => tilde_gt_2_0_0, :x64_mingw_21 => tilde_gt_2_1_0, - } + }.freeze WINDOWS = { # :nodoc: :mingw => :only, @@ -160,7 +160,7 @@ class Gem::RequestSet::GemDependencyAPI :x64_mingw => :only, :x64_mingw_20 => :only, :x64_mingw_21 => :only, - } + }.freeze ## # The gems required by #gem statements in the gem.deps.rb file diff --git a/lib/rubygems/requirement.rb b/lib/rubygems/requirement.rb index 0717739dc0..93bfe7d022 100644 --- a/lib/rubygems/requirement.rb +++ b/lib/rubygems/requirement.rb @@ -22,12 +22,12 @@ class Gem::Requirement ">=" => 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: quoted = OPS.keys.map { |k| Regexp.quote k }.join "|" - PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{Gem::Version::VERSION_PATTERN})\\s*" # :nodoc: + PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{Gem::Version::VERSION_PATTERN})\\s*".freeze # :nodoc: ## # A regular expression that matches a requirement @@ -37,7 +37,7 @@ class Gem::Requirement ## # The default requirement matches any version - DefaultRequirement = [">=", Gem::Version.new(0)] + DefaultRequirement = [">=", Gem::Version.new(0)].freeze ## # Raised when a bad requirement is encountered diff --git a/lib/rubygems/resolver/source_set.rb b/lib/rubygems/resolver/source_set.rb index 66f5963e54..696d963732 100644 --- a/lib/rubygems/resolver/source_set.rb +++ b/lib/rubygems/resolver/source_set.rb @@ -37,7 +37,7 @@ class Gem::Resolver::SourceSet < Gem::Resolver::Set @links[name] = source end -private + private def get_set(name) link = @links[name] diff --git a/lib/rubygems/resolver/stats.rb b/lib/rubygems/resolver/stats.rb index 3b95efebf7..64b458f504 100644 --- a/lib/rubygems/resolver/stats.rb +++ b/lib/rubygems/resolver/stats.rb @@ -32,7 +32,7 @@ class Gem::Resolver::Stats @iterations += 1 end - PATTERN = "%20s: %d\n" + PATTERN = "%20s: %d\n".freeze def display $stdout.puts "=== Resolver Statistics ===" diff --git a/lib/rubygems/safe_yaml.rb b/lib/rubygems/safe_yaml.rb index 949c7b4754..d610889995 100644 --- a/lib/rubygems/safe_yaml.rb +++ b/lib/rubygems/safe_yaml.rb @@ -19,12 +19,12 @@ module Gem Gem::Version::Requirement YAML::Syck::DefaultKey Syck::DefaultKey - ) + ).freeze WHITELISTED_SYMBOLS = %w( development runtime - ) + ).freeze if ::YAML.respond_to? :safe_load def self.safe_load input diff --git a/lib/rubygems/security.rb b/lib/rubygems/security.rb index dc5e91a6f4..f896039fa4 100644 --- a/lib/rubygems/security.rb +++ b/lib/rubygems/security.rb @@ -401,7 +401,7 @@ module Gem::Security 'keyUsage' => 'keyEncipherment,dataEncipherment,digitalSignature', 'subjectKeyIdentifier' => 'hash', - } + }.freeze def self.alt_name_or_x509_entry certificate, x509_entry alt_name = certificate.extensions.find do |extension| diff --git a/lib/rubygems/security/policies.rb b/lib/rubygems/security/policies.rb index f16c46306a..49ca8d860d 100644 --- a/lib/rubygems/security/policies.rb +++ b/lib/rubygems/security/policies.rb @@ -110,7 +110,7 @@ module Gem::Security 'MediumSecurity' => MediumSecurity, 'HighSecurity' => HighSecurity, # SigningPolicy is not intended for use by `gem -P` so do not list it - } + }.freeze end diff --git a/lib/rubygems/security/policy.rb b/lib/rubygems/security/policy.rb index f43e6c8c96..2e9159797c 100644 --- a/lib/rubygems/security/policy.rb +++ b/lib/rubygems/security/policy.rb @@ -196,9 +196,9 @@ class Gem::Security::Policy def inspect # :nodoc: ("[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, - ] + @name, @verify_chain, @verify_data, @verify_root, @verify_signer, + @only_signed, @only_trusted, + ] end ## diff --git a/lib/rubygems/security/signer.rb b/lib/rubygems/security/signer.rb index fc98f951bc..32dab9fa81 100644 --- a/lib/rubygems/security/signer.rb +++ b/lib/rubygems/security/signer.rb @@ -29,6 +29,15 @@ class Gem::Security::Signer attr_reader :digest_name # :nodoc: + ## + # Gem::Security::Signer options + + attr_reader :options + + DEFAULT_OPTIONS = { + expiration_length_days: 365 + }.freeze + ## # Attemps to re-sign an expired cert with a given private key def self.re_sign_cert(expired_cert, expired_cert_path, private_key) @@ -40,7 +49,11 @@ class Gem::Security::Signer Gem::Security.write(expired_cert, new_expired_cert_path) - re_signed_cert = Gem::Security.re_sign(expired_cert, private_key) + re_signed_cert = Gem::Security.re_sign( + expired_cert, + private_key, + (Gem::Security::ONE_DAY * Gem.configuration.cert_expiration_length_days) + ) Gem::Security.write(re_signed_cert, expired_cert_path) @@ -52,10 +65,11 @@ class Gem::Security::Signer # +chain+ containing X509 certificates, encoding certificates or paths to # certificates. - def initialize key, cert_chain, passphrase = nil + def initialize key, cert_chain, passphrase = nil, options = {} @cert_chain = cert_chain @key = key @passphrase = passphrase + @options = DEFAULT_OPTIONS.merge(options) unless @key then default_key = File.join Gem.default_key_path @@ -130,7 +144,9 @@ class Gem::Security::Signer raise Gem::Security::Exception, 'no certs provided' if @cert_chain.empty? if @cert_chain.length == 1 and @cert_chain.last.not_after < Time.now then - re_sign_key + re_sign_key( + expiration_length: (Gem::Security::ONE_DAY * options[:expiration_length_days]) + ) end full_name = extract_name @cert_chain.last @@ -154,7 +170,7 @@ class Gem::Security::Signer # be saved as ~/.gem/gem-public_cert.pem.expired.%Y%m%d%H%M%S where the # expiry time (not after) is used for the timestamp. - def re_sign_key # :nodoc: + def re_sign_key(expiration_length: Gem::Security::ONE_YEAR) # :nodoc: old_cert = @cert_chain.last disk_cert_path = File.join(Gem.default_cert_path) @@ -174,7 +190,7 @@ class Gem::Security::Signer unless File.exist?(old_cert_path) Gem::Security.write(old_cert, old_cert_path) - cert = Gem::Security.re_sign(old_cert, @key) + cert = Gem::Security.re_sign(old_cert, @key, expiration_length) Gem::Security.write(cert, disk_cert_path) diff --git a/lib/rubygems/security/trust_dir.rb b/lib/rubygems/security/trust_dir.rb index 62dbe29e4e..6d837affa1 100644 --- a/lib/rubygems/security/trust_dir.rb +++ b/lib/rubygems/security/trust_dir.rb @@ -11,7 +11,7 @@ class Gem::Security::TrustDir DEFAULT_PERMISSIONS = { :trust_dir => 0700, :trusted_cert => 0600, - } + }.freeze ## # The directory where trusted certificates will be stored. diff --git a/lib/rubygems/server.rb b/lib/rubygems/server.rb index 9ebd2f5e44..5c65f74aa3 100644 --- a/lib/rubygems/server.rb +++ b/lib/rubygems/server.rb @@ -35,7 +35,7 @@ class Gem::Server include ERB::Util include Gem::UserInteraction - SEARCH = <<-ERB + SEARCH = <<-ERB.freeze