summaryrefslogtreecommitdiff
path: root/lib/rubygems
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-05 22:40:53 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-05 22:40:53 +0000
commit7a88ad0a42dffdbbcaf0192635ab64c636294cf6 (patch)
tree932538cb8e039ea6005ab1f783da5d8c0e957338 /lib/rubygems
parent32fa37f53c386bf8b6d9031a7c587772ee12430d (diff)
* lib/rubygems/commands/query_command.rb: Only fetch remote specs when
showing details. [ruby-trunk - Bug #8019] RubyGems bug #487 * lib/rubygems/remote_fetcher.rb: ditto. * lib/rubygems/security/policy.rb: ditto. * test/rubygems/test_gem_commands_query_command.rb: Test for the above. * lib/rubygems/security.rb: Make OpenSSL optional for RubyGems. * lib/rubygems/commands/cert_command.rb: ditto. * lib/rubygems/config_file.rb: Display file with YAML error, not ~/.gemrc * lib/rubygems/remote_fetcher.rb: Only create gem subdirectories when installing gems. * lib/rubygems/dependency_resolver.rb: ditto. * lib/rubygems/test_utilities.rb: ditto. * test/rubygems/test_gem_commands_fetch_command.rb: Test for the above. * lib/rubygems/spec_fetcher.rb: Only try to upgrade http://rubygems.org to HTTPS * test/rubygems/test_gem_spec_fetcher.rb: Test for the above. * lib/rubygems.rb: Update win_platform? check for JRuby compatibility. * test/rubygems/test_gem_installer.rb: Update for Ruby 1.9.2 compatibility git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems')
-rw-r--r--lib/rubygems/commands/cert_command.rb1
-rw-r--r--lib/rubygems/commands/query_command.rb14
-rw-r--r--lib/rubygems/config_file.rb6
-rw-r--r--lib/rubygems/dependency_resolver.rb2
-rw-r--r--lib/rubygems/remote_fetcher.rb11
-rw-r--r--lib/rubygems/security.rb22
-rw-r--r--lib/rubygems/security/policy.rb2
-rw-r--r--lib/rubygems/spec_fetcher.rb6
-rw-r--r--lib/rubygems/test_utilities.rb2
9 files changed, 49 insertions, 17 deletions
diff --git a/lib/rubygems/commands/cert_command.rb b/lib/rubygems/commands/cert_command.rb
index 371ab403c6..13e5e2c37c 100644
--- a/lib/rubygems/commands/cert_command.rb
+++ b/lib/rubygems/commands/cert_command.rb
@@ -1,5 +1,6 @@
require 'rubygems/command'
require 'rubygems/security'
+require 'openssl'
class Gem::Commands::CertCommand < Gem::Command
diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb
index 0ae7924564..7bda7383e2 100644
--- a/lib/rubygems/commands/query_command.rb
+++ b/lib/rubygems/commands/query_command.rb
@@ -192,9 +192,13 @@ class Gem::Commands::QueryCommand < Gem::Command
end
end
- def entry_details entry, spec, specs, platforms
+ def entry_details entry, detail_tuple, specs, platforms
return unless options[:details]
+ name_tuple, spec = detail_tuple
+
+ spec = spec.fetch_spec name_tuple unless Gem::Specification === spec
+
entry << "\n"
spec_platforms entry, platforms
@@ -228,19 +232,15 @@ class Gem::Commands::QueryCommand < Gem::Command
def make_entry entry_tuples, platforms
detail_tuple = entry_tuples.first
- name_tuple, latest_spec = detail_tuple
-
- latest_spec = latest_spec.fetch_spec name_tuple unless
- Gem::Specification === latest_spec
name_tuples, specs = entry_tuples.flatten.partition do |item|
Gem::NameTuple === item
end
- entry = [latest_spec.name]
+ entry = [name_tuples.first.name]
entry_versions entry, name_tuples, platforms
- entry_details entry, latest_spec, specs, platforms
+ entry_details entry, detail_tuple, specs, platforms
entry.join
end
diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb
index 8d86dc5a3f..244e845e6f 100644
--- a/lib/rubygems/config_file.rb
+++ b/lib/rubygems/config_file.rb
@@ -317,14 +317,14 @@ if you believe they were disclosed to a third party.
begin
content = YAML.load(File.read(filename))
unless content.kind_of? Hash
- warn "Failed to load #{config_file_name} because it doesn't contain valid YAML hash"
+ warn "Failed to load #{filename} because it doesn't contain valid YAML hash"
return {}
end
return content
rescue ArgumentError
- warn "Failed to load #{config_file_name}"
+ warn "Failed to load #{filename}"
rescue Errno::EACCES
- warn "Failed to load #{config_file_name} due to permissions problem."
+ warn "Failed to load #{filename} due to permissions problem."
end
{}
diff --git a/lib/rubygems/dependency_resolver.rb b/lib/rubygems/dependency_resolver.rb
index 2c651aff2e..e8b620f356 100644
--- a/lib/rubygems/dependency_resolver.rb
+++ b/lib/rubygems/dependency_resolver.rb
@@ -406,6 +406,8 @@ module Gem
source = Gem.sources.first
end
+ Gem.ensure_gem_subdirectories path
+
source.download full_spec, path
end
diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb
index cc3d3cf860..ec052b50da 100644
--- a/lib/rubygems/remote_fetcher.rb
+++ b/lib/rubygems/remote_fetcher.rb
@@ -127,8 +127,6 @@ class Gem::RemoteFetcher
# always replaced.
def download(spec, source_uri, install_dir = Gem.dir)
- Gem.ensure_gem_subdirectories(install_dir) rescue nil
-
cache_dir =
if Dir.pwd == install_dir then # see fetch_command
install_dir
@@ -403,7 +401,8 @@ class Gem::RemoteFetcher
connection.start unless connection.started?
connection
- rescue OpenSSL::SSL::SSLError, Errno::EHOSTDOWN => e
+ rescue defined?(OpenSSL::SSL) ? OpenSSL::SSL::SSLError : Errno::EHOSTDOWN,
+ Errno::EHOSTDOWN => e
raise FetchError.new(e.message, uri)
end
@@ -424,6 +423,12 @@ class Gem::RemoteFetcher
add_rubygems_trusted_certs(store)
end
connection.cert_store = store
+ rescue LoadError => e
+ raise unless (e.respond_to?(:path) && e.path == 'openssl') ||
+ e.message =~ / -- openssl$/
+
+ raise Gem::Exception.new(
+ 'Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources')
end
def add_rubygems_trusted_certs(store)
diff --git a/lib/rubygems/security.rb b/lib/rubygems/security.rb
index 2485729488..bed47ab9f3 100644
--- a/lib/rubygems/security.rb
+++ b/lib/rubygems/security.rb
@@ -5,9 +5,29 @@
#++
require 'rubygems/exceptions'
-require 'openssl'
require 'fileutils'
+begin
+ require 'openssl'
+rescue LoadError => e
+ raise unless (e.respond_to?(:path) && e.path == 'openssl') ||
+ e.message =~ / -- openssl$/
+
+ module OpenSSL # :nodoc:
+ class Digest # :nodoc:
+ class SHA1 # :nodoc:
+ def name
+ 'SHA1'
+ end
+ end
+ end
+ module PKey # :nodoc:
+ class RSA # :nodoc:
+ end
+ end
+ end
+end
+
##
# = Signing gems
#
diff --git a/lib/rubygems/security/policy.rb b/lib/rubygems/security/policy.rb
index f3e4568117..467ee932b5 100644
--- a/lib/rubygems/security/policy.rb
+++ b/lib/rubygems/security/policy.rb
@@ -20,6 +20,8 @@ class Gem::Security::Policy
# options.
def initialize name, policy = {}, opt = {}
+ require 'openssl'
+
@name = name
@opt = opt
diff --git a/lib/rubygems/spec_fetcher.rb b/lib/rubygems/spec_fetcher.rb
index aeed37ba5e..62613f7a51 100644
--- a/lib/rubygems/spec_fetcher.rb
+++ b/lib/rubygems/spec_fetcher.rb
@@ -228,10 +228,14 @@ class Gem::SpecFetcher
end
end
+ ##
+ # Attempts to upgrade +source+ to HTTPS if it is for http://rubygems.org
+
def upgrade_http_source source
uri = source.uri
- return source unless uri.scheme.downcase == 'http'
+ return source unless uri.scheme.downcase == 'http' &&
+ uri.host.downcase == 'rubygems.org'
https_uri = uri.dup
https_uri.scheme = 'https'
diff --git a/lib/rubygems/test_utilities.rb b/lib/rubygems/test_utilities.rb
index 3da0b4ebc2..cf96fca43a 100644
--- a/lib/rubygems/test_utilities.rb
+++ b/lib/rubygems/test_utilities.rb
@@ -121,8 +121,6 @@ class Gem::FakeFetcher
path = File.join path, name
- Gem.ensure_gem_subdirectories install_dir
-
if source_uri =~ /^http/ then
File.open(path, "wb") do |f|
f.write fetch_path(File.join(source_uri, "gems", name))