1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
hsbt 2018-10-22 00:27:02 +00:00
parent ff31b35f6a
commit 615ac35934
62 changed files with 386 additions and 410 deletions

View file

@ -9,7 +9,7 @@
require 'rbconfig'
module Gem
VERSION = "3.0.0.beta1"
VERSION = "3.0.0.beta1".freeze
end
# Must be first since it unloads the prelude from 1.9.2
@ -126,14 +126,14 @@ module Gem
/mingw/i,
/mswin/i,
/wince/i,
]
].freeze
GEM_DEP_FILES = %w[
gem.deps.rb
gems.rb
Gemfile
Isolate
]
].freeze
##
# Subdirectories in a gem repository
@ -145,7 +145,7 @@ module Gem
extensions
gems
specifications
]
].freeze
##
# Subdirectories in a gem repository for default gems
@ -153,7 +153,7 @@ module Gem
REPOSITORY_DEFAULT_GEM_SUBDIRECTORIES = %w[
gems
specifications/default
]
].freeze
##
# Exception classes used in a Gem.read_binary +rescue+ statement. Not all of
@ -1342,7 +1342,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
##
# Location of Marshal quick gemspecs on remote repositories
MARSHAL_SPEC_DIR = "quick/Marshal.#{Gem.marshal_version}/"
MARSHAL_SPEC_DIR = "quick/Marshal.#{Gem.marshal_version}/".freeze
autoload :BundlerVersionFinder, 'rubygems/bundler_version_finder'
autoload :ConfigFile, 'rubygems/config_file'

View file

@ -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)

View file

@ -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.

View file

@ -69,11 +69,11 @@ class Gem::CommandManager
:update,
:which,
:yank,
]
].freeze
ALIAS_COMMANDS = {
'i' => 'install'
}
}.freeze
##
# Return the authoritative instance of the command manager.

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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',

View file

@ -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

View file

@ -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

View file

@ -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)
##

View file

@ -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

View file

@ -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
[

View file

@ -19,7 +19,7 @@ class Gem::Dependency
TYPES = [
:development,
:runtime,
]
].freeze
##
# Dependency name or regular expression.

View file

@ -26,7 +26,7 @@ class Gem::Doctor
['doc', ''],
['extensions', ''],
['gems', ''],
]
].freeze
missing =
Gem::REPOSITORY_SUBDIRECTORIES.sort -

View file

@ -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|

View file

@ -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

View file

@ -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

View file

@ -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|

View file

@ -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

View file

@ -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

View file

@ -50,7 +50,7 @@ class Gem::Package::TarHeader
:uid,
:uname,
:version,
]
].freeze
##
# Pack format for a tar header

View file

@ -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

View file

@ -71,13 +71,10 @@ class Gem::RemoteFetcher
# HTTP_PROXY_PASS)
# * <tt>:no_proxy</tt>: 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.

View file

@ -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

View file

@ -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

View file

@ -37,7 +37,7 @@ class Gem::Resolver::SourceSet < Gem::Resolver::Set
@links[name] = source
end
private
private
def get_set(name)
link = @links[name]

View file

@ -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 ==="

View file

@ -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

View file

@ -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|

View file

@ -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

View file

@ -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
##

View file

@ -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)

View file

@ -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.

View file

@ -35,7 +35,7 @@ class Gem::Server
include ERB::Util
include Gem::UserInteraction
SEARCH = <<-ERB
SEARCH = <<-ERB.freeze
<form class="headerSearch" name="headerSearchForm" method="get" action="/rdoc">
<div id="search" style="float:right">
<label for="q">Filter/Search</label>
@ -45,7 +45,7 @@ class Gem::Server
</form>
ERB
DOC_TEMPLATE = <<-'ERB'
DOC_TEMPLATE = <<-'ERB'.freeze
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
@ -129,7 +129,7 @@ class Gem::Server
ERB
# CSS is copy & paste from rdoc-style.css, RDoc V1.0.1 - 20041108
RDOC_CSS = <<-CSS
RDOC_CSS = <<-CSS.freeze
body {
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size: 90%;
@ -339,7 +339,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
.ruby-value { color: #7fffd4; background: transparent; }
CSS
RDOC_NO_DOCUMENTATION = <<-'ERB'
RDOC_NO_DOCUMENTATION = <<-'ERB'.freeze
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@ -373,7 +373,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
</html>
ERB
RDOC_SEARCH_TEMPLATE = <<-'ERB'
RDOC_SEARCH_TEMPLATE = <<-'ERB'.freeze
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

View file

@ -16,7 +16,7 @@ class Gem::Source
:released => 'specs',
:latest => 'latest_specs',
:prerelease => 'prerelease_specs',
}
}.freeze
##
# The URI this source will fetch gems from.
@ -36,15 +36,6 @@ class Gem::Source
end
@uri = uri
@api_uri = nil
end
##
# Use an SRV record on the host to look up the true endpoint for the index.
def api_uri # :nodoc:
require 'rubygems/remote_fetcher'
@api_uri ||= Gem::RemoteFetcher.fetcher.api_endpoint uri
end
##
@ -87,9 +78,9 @@ class Gem::Source
# Returns a Set that can fetch specifications from this source.
def dependency_resolver_set # :nodoc:
return Gem::Resolver::IndexSet.new self if 'file' == api_uri.scheme
return Gem::Resolver::IndexSet.new self if 'file' == uri.scheme
bundler_api_uri = api_uri + './api/v1/dependencies'
bundler_api_uri = uri + './api/v1/dependencies'
begin
fetcher = Gem::RemoteFetcher.fetcher
@ -140,9 +131,9 @@ class Gem::Source
spec_file_name = name_tuple.spec_name
uri = api_uri + "#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}"
source_uri = uri + "#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}"
cache_dir = cache_dir uri
cache_dir = cache_dir source_uri
local_spec = File.join cache_dir, spec_file_name
@ -152,9 +143,9 @@ class Gem::Source
return spec if spec
end
uri.path << '.rz'
source_uri.path << '.rz'
spec = fetcher.fetch_path uri
spec = fetcher.fetch_path source_uri
spec = Gem::Util.inflate spec
if update_cache? then
@ -184,7 +175,7 @@ class Gem::Source
file = FILES[type]
fetcher = Gem::RemoteFetcher.fetcher
file_name = "#{file}.#{Gem.marshal_version}"
spec_path = api_uri + "#{file_name}.gz"
spec_path = uri + "#{file_name}.gz"
cache_dir = cache_dir spec_path
local_file = File.join(cache_dir, file_name)
retried = false
@ -212,7 +203,7 @@ class Gem::Source
def download(spec, dir=Dir.pwd)
fetcher = Gem::RemoteFetcher.fetcher
fetcher.download spec, api_uri.to_s, dir
fetcher.download spec, uri.to_s, dir
end
def pretty_print q # :nodoc:
@ -220,7 +211,7 @@ class Gem::Source
q.breakable
q.text @uri.to_s
if api = api_uri
if api = uri
q.breakable
q.text 'API URI: '
q.text api.to_s

View file

@ -203,9 +203,9 @@ class Gem::SpecFetcher
matches = if matches.empty? && type != :prerelease
suggest_gems_from_name gem_name, :prerelease
else
matches.uniq.sort_by { |name, dist| dist }
end
else
matches.uniq.sort_by { |name, dist| dist }
end
matches.first(5).map { |name, dist| name }
end

View file

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# frozen_string_literal: true
# -*- coding: utf-8 -*-
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
@ -89,13 +89,13 @@ class Gem::Specification < Gem::BasicSpecification
'Added "required_rubygems_version"',
'Now forward-compatible with future versions',
],
3 => [
'Added Fixnum validation to the specification_version'
3 => [
'Added Fixnum validation to the specification_version'
],
4 => [
4 => [
'Added sandboxed freeform metadata to the specification version.'
]
}
}.freeze
MARSHAL_FIELDS = { # :nodoc:
-1 => 16,
@ -103,12 +103,14 @@ class Gem::Specification < Gem::BasicSpecification
2 => 16,
3 => 17,
4 => 18,
}
}.freeze
today = Time.now.utc
TODAY = Time.utc(today.year, today.month, today.day) # :nodoc:
# rubocop:disable Style/MutableConstant
LOAD_CACHE = {} # :nodoc:
# rubocop:enable Style/MutableConstant
private_constant :LOAD_CACHE if defined? private_constant
@ -163,19 +165,21 @@ class Gem::Specification < Gem::BasicSpecification
:version => nil,
}.freeze
# rubocop:disable Style/MutableConstant
INITIALIZE_CODE_FOR_DEFAULTS = { } # :nodoc:
# rubocop:enable Style/MutableConstant
@@default_value.each do |k,v|
INITIALIZE_CODE_FOR_DEFAULTS[k] = case v
when [], {}, true, false, nil, Numeric, Symbol
v.inspect
when String
v.dump
when Numeric
"default_value(:#{k})"
else
"default_value(:#{k}).dup"
end
when [], {}, true, false, nil, Numeric, Symbol
v.inspect
when String
v.dump
when Numeric
"default_value(:#{k})"
else
"default_value(:#{k}).dup"
end
end
@@attributes = @@default_value.keys.sort_by { |s| s.to_s }
@ -260,22 +264,11 @@ class Gem::Specification < Gem::BasicSpecification
].flatten.compact.uniq.sort
end
######################################################################
# :section: Recommended gemspec attributes
##
# Singular writer for #authors
# A list of authors for this gem.
#
# Usage:
#
# spec.author = 'John Jones'
def author= o
self.authors = [o]
end
##
# Sets the list of authors, ensuring it is an array.
# Alternatively, a single author can be specified by assigning a string to
# `spec.author`
#
# Usage:
#
@ -285,6 +278,9 @@ class Gem::Specification < Gem::BasicSpecification
@authors = Array(value).flatten.grep(String)
end
######################################################################
# :section: Recommended gemspec attributes
##
# A long description of this gem
#
@ -403,6 +399,17 @@ class Gem::Specification < Gem::BasicSpecification
######################################################################
# :section: Optional gemspec attributes
##
# Singular (alternative) writer for #authors
#
# Usage:
#
# spec.author = 'John Jones'
def author= o
self.authors = [o]
end
##
# The path in the gem for executable scripts. Usually 'bin'
#

View file

@ -4,6 +4,8 @@ require 'uri'
class Gem::SpecificationPolicy < SimpleDelegator
VALID_NAME_PATTERN = /\A[a-zA-Z0-9\.\-\_]+\z/ # :nodoc:
SPECIAL_CHARACTERS = /\A[#{Regexp.escape('.-_')}]+/ # :nodoc:
VALID_URI_PATTERN = %r{\Ahttps?:\/\/([^\s:@]+:[^\s:@]*@)?[A-Za-z\d\-]+(\.[A-Za-z\d\-]+)+\.?(:\d{1,5})?([\/?]\S*)?\z} # :nodoc:
METADATA_LINK_KEYS = %w[
@ -14,7 +16,7 @@ class Gem::SpecificationPolicy < SimpleDelegator
mailing_list_uri
source_code_uri
wiki_uri
] # :nodoc:
].freeze # :nodoc:
def initialize(specification)
@warnings = 0
@ -219,12 +221,14 @@ open-ended dependency on #{dep} is not recommended
end
def validate_name
if !name.is_a?(String) then
if !name.is_a?(String)
error "invalid value for attribute name: \"#{name.inspect}\" must be a string"
elsif name !~ /[a-zA-Z]/ then
elsif name !~ /[a-zA-Z]/
error "invalid value for attribute name: #{name.dump} must include at least one letter"
elsif name !~ VALID_NAME_PATTERN then
elsif name !~ VALID_NAME_PATTERN
error "invalid value for attribute name: #{name.dump} can only include letters, numbers, dashes, and underscores"
elsif name =~ SPECIAL_CHARACTERS
error "invalid value for attribute name: #{name.dump} can not begin with a period, dash, or underscore"
end
end
@ -257,9 +261,9 @@ open-ended dependency on #{dep} is not recommended
def validate_platform
case platform
when Gem::Platform, Gem::Platform::RUBY then # ok
else
error "invalid platform #{platform.inspect}, see Gem::Platform"
when Gem::Platform, Gem::Platform::RUBY then # ok
else
error "invalid platform #{platform.inspect}, see Gem::Platform"
end
end
@ -272,10 +276,10 @@ open-ended dependency on #{dep} is not recommended
def validate_array_attribute(field)
val = self.send(field)
klass = case field
when :dependencies then
Gem::Dependency
else
String
when :dependencies then
Gem::Dependency
else
String
end
unless Array === val and val.all? {|x| x.kind_of?(klass)} then

View file

@ -6,10 +6,10 @@
class Gem::StubSpecification < Gem::BasicSpecification
# :nodoc:
PREFIX = "# stub: "
PREFIX = "# stub: ".freeze
# :nodoc:
OPEN_MODE = 'r:UTF-8:-'
OPEN_MODE = 'r:UTF-8:-'.freeze
class StubLine # :nodoc: all
attr_reader :name, :version, :platform, :require_paths, :extensions,
@ -22,7 +22,7 @@ class Gem::StubSpecification < Gem::BasicSpecification
'lib' => 'lib'.freeze,
'test' => 'test'.freeze,
'ext' => 'ext'.freeze,
}
}.freeze
# These are common require path lists. This hash is used to optimize
# and consolidate require_path objects. Most specs just specify "lib"
@ -30,7 +30,7 @@ class Gem::StubSpecification < Gem::BasicSpecification
# a require path list for that case.
REQUIRE_PATH_LIST = { # :nodoc:
'lib' => ['lib'].freeze
}
}.freeze
def initialize data, extensions
parts = data[PREFIX.length..-1].split(" ".freeze, 4)

View file

@ -1540,7 +1540,7 @@ Also, a list:
# :stopdoc:
# only available in RubyGems tests
PRIVATE_KEY_PASSPHRASE = 'Foo bar'
PRIVATE_KEY_PASSPHRASE = 'Foo bar'.freeze
begin
PRIVATE_KEY = load_key 'private'

View file

@ -25,17 +25,11 @@ class Gem::FakeFetcher
attr_reader :data
attr_reader :last_request
attr_reader :api_endpoints
attr_accessor :paths
def initialize
@data = {}
@paths = []
@api_endpoints = {}
end
def api_endpoint(uri)
@api_endpoints[uri] || uri
end
def find_data(path)
@ -111,14 +105,6 @@ class Gem::FakeFetcher
q.breakable
q.pp @data.keys
unless @api_endpoints.empty? then
q.breakable
q.text 'API endpoints:'
q.breakable
q.pp @api_endpoints.keys
end
end
end

View file

@ -73,7 +73,7 @@ module Gem::Text
d[j+1] + 1, # insertion
e + 1, # deletion
d[j] + cost # substitution
)
)
d[j] = e
e = x
end

View file

@ -315,8 +315,8 @@ class Gem::Uninstaller
msg << ''
siblings = Gem::Specification.select do |s|
s.name == spec.name && s.full_name != spec.full_name
end
s.name == spec.name && s.full_name != spec.full_name
end
spec.dependent_gems.each do |dep_spec, dep, satlist|
unless siblings.any? { |s| s.satisfies_requirement? dep }

View file

@ -154,7 +154,7 @@ class Gem::Version
include Comparable
VERSION_PATTERN = '[0-9]+(?>\.[0-9a-zA-Z]+)*(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?' # :nodoc:
VERSION_PATTERN = '[0-9]+(?>\.[0-9a-zA-Z]+)*(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?'.freeze # :nodoc:
ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})?\s*\z/ # :nodoc:
##

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
SIMPLE_GEM = <<-GEMDATA
SIMPLE_GEM = <<-GEMDATA.freeze
MD5SUM = "989bf34a1cbecd52e0ea66b662b3a405"
if $0 == __FILE__
require 'optparse'

View file

@ -14,7 +14,7 @@ end
class TestGem < Gem::TestCase
PLUGINS_LOADED = []
PLUGINS_LOADED = [] # rubocop:disable Style/MutableConstant
def setup
super
@ -1494,7 +1494,7 @@ class TestGem < Gem::TestCase
if Gem::USE_BUNDLER_FOR_GEMDEPS
BUNDLER_LIB_PATH = File.expand_path $LOAD_PATH.find {|lp| File.file?(File.join(lp, "bundler.rb")) }.dup.untaint
BUNDLER_FULL_NAME = "bundler-#{Bundler::VERSION}"
BUNDLER_FULL_NAME = "bundler-#{Bundler::VERSION}".freeze
end
def add_bundler_full_name(names)
@ -1757,19 +1757,20 @@ class TestGem < Gem::TestCase
else
platform = " #{platform}"
end
expected = if Gem::USE_BUNDLER_FOR_GEMDEPS
<<-EXPECTED
expected =
if Gem::USE_BUNDLER_FOR_GEMDEPS
<<-EXPECTED
Could not find gem 'a#{platform}' in any of the gem sources listed in your Gemfile.
You may need to `gem install -g` to install missing gems
EXPECTED
else
<<-EXPECTED
EXPECTED
else
<<-EXPECTED
Unable to resolve dependency: user requested 'a (>= 0)'
You may need to `gem install -g` to install missing gems
EXPECTED
end
EXPECTED
end
assert_output nil, expected do
Gem.use_gemdeps

View file

@ -126,7 +126,7 @@ class TestGemCommandManager < Gem::TestCase
#check settings
check_options = nil
@command_manager.process_args %w[
install --force --local --rdoc --install-dir .
install --force --local --document=ri,rdoc --install-dir .
--version 3.0 --no-wrapper --bindir .
]
assert_equal %w[rdoc ri], check_options[:document].sort
@ -260,7 +260,7 @@ class TestGemCommandManager < Gem::TestCase
#check settings
check_options = nil
@command_manager.process_args %w[update --force --rdoc --install-dir .]
@command_manager.process_args %w[update --force --document=ri --install-dir .]
assert_includes check_options[:document], 'ri'
assert_equal true, check_options[:force]
assert_equal Dir.pwd, check_options[:install_dir]

View file

@ -6,6 +6,12 @@ require 'rubygems/package'
class TestGemCommandsBuildCommand < Gem::TestCase
CERT_FILE = cert_path 'public3072'
SIGNING_KEY = key_path 'private3072'
EXPIRED_CERT_FILE = cert_path 'expired'
PRIVATE_KEY_FILE = key_path 'private'
def setup
super
@ -50,6 +56,32 @@ class TestGemCommandsBuildCommand < Gem::TestCase
util_test_build_gem @gem
end
def test_execute_bad_name
[".", "-", "_"].each do |special_char|
gem = util_spec 'some_gem_with_bad_name' do |s|
s.name = "#{special_char}bad_gem_name"
s.license = 'AGPL-3.0'
s.files = ['README.md']
end
gemspec_file = File.join(@tempdir, gem.spec_name)
File.open gemspec_file, 'w' do |gs|
gs.write gem.to_ruby
end
@cmd.options[:args] = [gemspec_file]
use_ui @ui do
Dir.chdir @tempdir do
assert_raises Gem::InvalidSpecificationException do
@cmd.execute
end
end
end
end
end
def test_execute_strict_without_warnings
gemspec_file = File.join(@tempdir, @gem.spec_name)
@ -221,9 +253,6 @@ class TestGemCommandsBuildCommand < Gem::TestCase
util_test_build_gem @gem
end
CERT_FILE = cert_path 'public3072'
SIGNING_KEY = key_path 'private3072'
def test_build_signed_gem
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
@ -251,4 +280,48 @@ class TestGemCommandsBuildCommand < Gem::TestCase
assert gem.verify
end
def test_build_signed_gem_with_cert_expiration_length_days
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
gem_path = File.join Gem.user_home, ".gem"
Dir.mkdir gem_path
trust_dir = Gem::Security.trust_dir
tmp_expired_cert_file = File.join gem_path, "gem-public_cert.pem"
File.write(tmp_expired_cert_file, File.read(EXPIRED_CERT_FILE))
tmp_private_key_file = File.join gem_path, "gem-private_key.pem"
File.write(tmp_private_key_file, File.read(PRIVATE_KEY_FILE))
spec = util_spec 'some_gem' do |s|
s.signing_key = tmp_private_key_file
s.cert_chain = [tmp_expired_cert_file]
end
gemspec_file = File.join(@tempdir, spec.spec_name)
File.open gemspec_file, 'w' do |gs|
gs.write spec.to_ruby
end
@cmd.options[:args] = [gemspec_file]
Gem.configuration.cert_expiration_length_days = 28
use_ui @ui do
Dir.chdir @tempdir do
@cmd.execute
end
end
re_signed_cert = OpenSSL::X509::Certificate.new(File.read(tmp_expired_cert_file))
cert_days_to_expire = (re_signed_cert.not_after - re_signed_cert.not_before).to_i / (24 * 60 * 60)
gem_file = File.join @tempdir, File.basename(spec.cache_file)
assert File.exist?(gem_file)
assert_equal(28, cert_days_to_expire)
end
end

View file

@ -159,7 +159,7 @@ Added '/CN=alternate/DC=example'
@cmd.handle_options %W[
--build nobody@example.com
--days 26
]
]
@build_ui = Gem::MockGemUi.new "#{passphrase}\n#{passphrase}"
@ -615,6 +615,37 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
assert_equal '', @ui.error
end
def test_execute_re_sign_with_cert_expiration_length_days
gem_path = File.join Gem.user_home, ".gem"
Dir.mkdir gem_path
path = File.join @tempdir, 'cert.pem'
Gem::Security.write EXPIRED_PUBLIC_CERT, path, 0600
assert_equal '/CN=nobody/DC=example', EXPIRED_PUBLIC_CERT.issuer.to_s
tmp_expired_cert_file = File.join(Dir.tmpdir, File.basename(EXPIRED_PUBLIC_CERT_FILE))
File.write(tmp_expired_cert_file, File.read(EXPIRED_PUBLIC_CERT_FILE))
@cmd.handle_options %W[
--private-key #{PRIVATE_KEY_FILE}
--certificate #{tmp_expired_cert_file}
--re-sign
]
Gem.configuration.cert_expiration_length_days = 28
use_ui @ui do
@cmd.execute
end
re_signed_cert = OpenSSL::X509::Certificate.new(File.read(tmp_expired_cert_file))
cert_days_to_expire = (re_signed_cert.not_after - re_signed_cert.not_before).to_i / (24 * 60 * 60)
assert_equal(28, cert_days_to_expire)
assert_equal '', @ui.error
end
def test_handle_options
@cmd.handle_options %W[
--add #{PUBLIC_CERT_FILE}

View file

@ -55,7 +55,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase
a2_pre = specs['a-2.a']
@cmd.handle_options [a2_pre.name, '--version', a2_pre.version.to_s,
"--no-ri", "--no-rdoc"]
"--no-document"]
assert @cmd.options[:prerelease]
assert @cmd.options[:version].satisfied_by?(a2_pre.version)

View file

@ -495,11 +495,13 @@ class TestGemCommandsPristineCommand < Gem::TestCase
@cmd.execute
end
assert_equal([
"Restoring gems to pristine condition...",
"Skipped default-2.0.0.0, it is a default gem",
],
@ui.output.split("\n"))
assert_equal(
[
"Restoring gems to pristine condition...",
"Skipped default-2.0.0.0, it is a default gem",
],
@ui.output.split("\n")
)
assert_empty(@ui.error)
end

View file

@ -10,7 +10,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase
if File.exist?(bundler_gemspec)
BUNDLER_VERS = File.read(bundler_gemspec).match(/VERSION = "(#{Gem::Version::VERSION_PATTERN})"/)[1]
else
BUNDLER_VERS = "1.16.2"
BUNDLER_VERS = "1.16.2".freeze
end
def setup

View file

@ -44,6 +44,7 @@ class TestGemConfigFile < Gem::TestCase
assert_equal Gem::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold
assert_equal true, @cfg.verbose
assert_equal [@gem_repo], Gem.sources
assert_equal 365, @cfg.cert_expiration_length_days
File.open @temp_conf, 'w' do |fp|
fp.puts ":backtrace: true"
@ -58,6 +59,7 @@ class TestGemConfigFile < Gem::TestCase
fp.puts "- /var/ruby/1.8/gem_home"
fp.puts ":ssl_verify_mode: 0"
fp.puts ":ssl_ca_cert: /etc/ssl/certs"
fp.puts ":cert_expiration_length_days: 28"
end
util_config_file
@ -71,6 +73,7 @@ class TestGemConfigFile < Gem::TestCase
@cfg.path)
assert_equal 0, @cfg.ssl_verify_mode
assert_equal '/etc/ssl/certs', @cfg.ssl_ca_cert
assert_equal 28, @cfg.cert_expiration_length_days
end
def test_initialize_handle_arguments_config_file

View file

@ -136,8 +136,8 @@ class TestGemDependencyList < Gem::TestCase
exp = {
"b" => [
Gem::Dependency.new("a", ">= 1")
]
Gem::Dependency.new("a", ">= 1")
]
}
assert_equal exp, @deplist.why_not_ok?

View file

@ -26,7 +26,7 @@ class TestGemExtRakeBuilder < Gem::TestCase
refute_match %r%^rake failed:%, output
assert_match %r%^#{Regexp.escape @@ruby} mkrf_conf\.rb%, output
assert_match %r%^#{Regexp.escape rake} RUBYARCHDIR=#{Regexp.escape @dest_path} RUBYLIBDIR=#{Regexp.escape @dest_path}%, output
assert_match %r%^#{Regexp.escape rake} RUBYARCHDIR\\=#{Regexp.escape @dest_path} RUBYLIBDIR\\=#{Regexp.escape @dest_path}%, output
end
end
@ -47,7 +47,22 @@ class TestGemExtRakeBuilder < Gem::TestCase
refute_match %r%^rake failed:%, output
assert_match %r%^#{Regexp.escape @@ruby} mkrf_conf\.rb%, output
assert_match %r%^#{Regexp.escape rake} RUBYARCHDIR=#{Regexp.escape @dest_path} RUBYLIBDIR=#{Regexp.escape @dest_path}%, output
assert_match %r%^#{Regexp.escape rake} RUBYARCHDIR\\=#{Regexp.escape @dest_path} RUBYLIBDIR\\=#{Regexp.escape @dest_path}%, output
end
end
def test_class_build_no_mkrf_passes_args
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"
refute_match %r%^rake failed:%, output
assert_match %r%^#{Regexp.escape rake} RUBYARCHDIR\\=#{Regexp.escape @dest_path} RUBYLIBDIR\\=#{Regexp.escape @dest_path} test1 test2%, output
end
end

View file

@ -21,8 +21,7 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
--build-root build_root
--format-exec
--ignore-dependencies
--rdoc
--ri
--document
-E
-f
-i /install_to
@ -92,24 +91,6 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
assert_equal %w[ri], @cmd.options[:document]
end
def test_rdoc
@cmd.handle_options %w[--rdoc]
assert_equal %w[rdoc ri], @cmd.options[:document].sort
end
def test_rdoc_no
@cmd.handle_options %w[--no-rdoc]
assert_equal %w[ri], @cmd.options[:document]
end
def test_ri
@cmd.handle_options %w[--no-ri]
assert_equal %w[], @cmd.options[:document]
end
def test_security_policy
skip 'openssl is missing' unless defined?(OpenSSL::SSL)

View file

@ -44,10 +44,10 @@ class TestGemPathSupport < Gem::TestCase
assert_equal ENV["GEM_HOME"], ps.home
expected = [
File.join(@tempdir, 'foo'),
File.join(@tempdir, 'bar'),
ENV["GEM_HOME"],
]
File.join(@tempdir, 'foo'),
File.join(@tempdir, 'bar'),
ENV["GEM_HOME"],
]
assert_equal expected, ps.path
end
@ -63,9 +63,9 @@ class TestGemPathSupport < Gem::TestCase
assert_equal ENV["GEM_HOME"], ps.home
expected = [
File.join(@tempdir, 'foo'),
File.join(@tempdir, 'bar'),
] + Gem.default_path << ENV["GEM_HOME"]
File.join(@tempdir, 'foo'),
File.join(@tempdir, 'bar'),
] + Gem.default_path << ENV["GEM_HOME"]
assert_equal expected, ps.path
end
@ -81,9 +81,9 @@ class TestGemPathSupport < Gem::TestCase
assert_equal ENV["GEM_HOME"], ps.home
expected = [
File.join(@tempdir, 'foo'),
File.join(@tempdir, 'bar'),
] + Gem.default_path << ENV["GEM_HOME"]
File.join(@tempdir, 'foo'),
File.join(@tempdir, 'bar'),
] + Gem.default_path << ENV["GEM_HOME"]
assert_equal expected, ps.path
end

View file

@ -35,7 +35,7 @@ class TestGemRemoteFetcher < Gem::TestCase
include Gem::DefaultUserInteraction
SERVER_DATA = <<-EOY
SERVER_DATA = <<-EOY.freeze
--- !ruby/object:Gem::Cache
gems:
rake-0.4.11: !ruby/object:Gem::Specification
@ -185,106 +185,6 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
end
end
def test_api_endpoint
uri = URI.parse "http://example.com/foo"
target = MiniTest::Mock.new
target.expect :target, "gems.example.com"
dns = MiniTest::Mock.new
dns.expect :getresource, target, [String, Object]
fetch = Gem::RemoteFetcher.new nil, dns
assert_equal URI.parse("http://gems.example.com/foo"), fetch.api_endpoint(uri)
target.verify
dns.verify
end
def test_api_endpoint_ignores_trans_domain_values
uri = URI.parse "http://gems.example.com/foo"
target = MiniTest::Mock.new
target.expect :target, "blah.com"
dns = MiniTest::Mock.new
dns.expect :getresource, target, [String, Object]
fetch = Gem::RemoteFetcher.new nil, dns
assert_equal URI.parse("http://gems.example.com/foo"), fetch.api_endpoint(uri)
target.verify
dns.verify
end
def test_api_endpoint_ignores_trans_domain_values_that_starts_with_original
uri = URI.parse "http://example.com/foo"
target = MiniTest::Mock.new
target.expect :target, "example.combadguy.com"
dns = MiniTest::Mock.new
dns.expect :getresource, target, [String, Object]
fetch = Gem::RemoteFetcher.new nil, dns
assert_equal URI.parse("http://example.com/foo"), fetch.api_endpoint(uri)
target.verify
dns.verify
end
def test_api_endpoint_ignores_trans_domain_values_that_end_with_original
uri = URI.parse "http://example.com/foo"
target = MiniTest::Mock.new
target.expect :target, "badexample.com"
dns = MiniTest::Mock.new
dns.expect :getresource, target, [String, Object]
fetch = Gem::RemoteFetcher.new nil, dns
assert_equal URI.parse("http://example.com/foo"), fetch.api_endpoint(uri)
target.verify
dns.verify
end
def test_api_endpoint_ignores_trans_domain_values_that_end_with_original_in_path
uri = URI.parse "http://example.com/foo"
target = MiniTest::Mock.new
target.expect :target, "evil.com/a.example.com"
dns = MiniTest::Mock.new
dns.expect :getresource, target, [String, Object]
fetch = Gem::RemoteFetcher.new nil, dns
assert_equal URI.parse("http://example.com/foo"), fetch.api_endpoint(uri)
target.verify
dns.verify
end
def test_api_endpoint_timeout_warning
uri = URI.parse "http://gems.example.com/foo"
dns = MiniTest::Mock.new
def dns.getresource arg, *rest
raise Resolv::ResolvError.new('timeout!')
end
fetch = Gem::RemoteFetcher.new nil, dns
begin
old_verbose, Gem.configuration.verbose = Gem.configuration.verbose, 1
endpoint = use_ui @stub_ui do
fetch.api_endpoint(uri)
end
ensure
Gem.configuration.verbose = old_verbose
end
assert_equal uri, endpoint
assert_equal "Getting SRV record failed: timeout!\n", @stub_ui.output
dns.verify
end
def test_cache_update_path
uri = URI 'http://example/file'
path = File.join @tempdir, 'file'
@ -1064,7 +964,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
:DocumentRoot => nil,
:Logger => null_logger,
:AccessLog => null_logger
)
)
s.mount_proc("/kill") { |req, res| s.shutdown }
s.mount_proc("/yaml") { |req, res|
if req["X-Captain"]

View file

@ -36,18 +36,6 @@ class TestGemSource < Gem::TestCase
assert_equal repository, source.uri
end
def test_api_uri
assert_equal @source.api_uri, @source.uri
end
def test_api_uri_resolved_from_remote_fetcher
uri = URI.parse "http://gem.example/foo"
@fetcher.api_endpoints[uri] = URI.parse "http://api.blah"
src = Gem::Source.new uri
assert_equal URI.parse("http://api.blah"), src.api_uri
end
def test_cache_dir_escapes_windows_paths
uri = URI.parse("file:///C:/WINDOWS/Temp/gem_repo")
root = Gem.spec_cache_dir

View file

@ -9,7 +9,7 @@ require 'rubygems/installer'
class TestGemSpecification < Gem::TestCase
LEGACY_YAML_SPEC = <<-EOF
LEGACY_YAML_SPEC = <<-EOF.freeze
--- !ruby/object:Gem::Specification
rubygems_version: "1.0"
name: keyedlist
@ -28,7 +28,7 @@ email: flgr@ccan.de
has_rdoc: true
EOF
LEGACY_RUBY_SPEC = <<-EOF
LEGACY_RUBY_SPEC = <<-EOF.freeze
Gem::Specification.new do |s|
s.name = %q{keyedlist}
s.version = %q{0.4.0}
@ -3428,10 +3428,10 @@ Did you mean 'Ruby'?
end
expected = %W[
a-2
a-2-x86-my_platform-1
a-3-x86-other_platform-1
]
a-2
a-2-x86-my_platform-1
a-3-x86-other_platform-1
]
latest_specs = Gem::Specification.latest_specs.map(&:full_name).sort

View file

@ -5,7 +5,8 @@ require 'rubygems/util'
class TestGemUtil < Gem::TestCase
def test_class_popen
assert_equal "0\n", Gem::Util.popen(Gem.ruby, '-e', 'p 0')
skip "MJIT executes process and it's caught by Process.wait(-1)" if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
assert_equal "0\n", Gem::Util.popen(Gem.ruby, '-I', File.expand_path('../../../lib', __FILE__), '-e', 'p 0')
assert_raises Errno::ECHILD do
Process.wait(-1)
@ -14,7 +15,7 @@ class TestGemUtil < Gem::TestCase
def test_silent_system
assert_silent do
Gem::Util.silent_system Gem.ruby, '-e', 'puts "hello"; warn "hello"'
Gem::Util.silent_system Gem.ruby, '-I', File.expand_path('../../../lib', __FILE__), '-e', 'puts "hello"; warn "hello"'
end
end