diff --git a/ChangeLog b/ChangeLog index 8fc848d0ca..42cef5a0f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +Tue Mar 12 06:27:59 2013 Eric Hodel + + * lib/rubygems/commands/setup_command.rb: Don't delete non-rubygems + files when installing RubyGems. + * test/rubygems/test_gem_commands_setup_command.rb: Test for the + above. + + * lib/rubygems/ext/ext_conf_builder.rb: Use full path to siteconf.rb + in case the extconf.rb changes directories (like memcached does). + + * lib/rubygems/package.rb: Remove double slash from path. + * test/rubygems/test_gem_package.rb: Test for the above. + * test/rubygems/test_gem_package_old.rb: ditto. + + * lib/rubygems/source.rb: Revert automatic HTTPS upgrade + * lib/rubygems/spec_fetcher.rb: ditto. + * test/rubygems/test_gem_remote_fetcher.rb: ditto. + * test/rubygems/test_gem_source.rb: ditto. + * test/rubygems/test_gem_spec_fetcher.rb: ditto. + Tue Mar 12 02:25:19 2013 Eric Hodel * lib/net/smtp.rb: Added Net::SMTP#rset method to implement the SMTP diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index 12e60109aa..1cdc9f4c57 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -437,13 +437,18 @@ abort "#{deprecation_message}" end def remove_old_lib_files lib_dir - lib_files = rb_files_in 'lib' + rubygems_dir = File.join lib_dir, 'rubygems' + lib_files = rb_files_in 'lib/rubygems' - old_lib_files = rb_files_in lib_dir + old_lib_files = rb_files_in rubygems_dir to_remove = old_lib_files - lib_files - Dir.chdir lib_dir do + to_remove.delete_if do |file| + file.start_with? 'defaults' + end + + Dir.chdir rubygems_dir do to_remove.each do |file| FileUtils.rm_f file diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb index a172afa7db..d09cb5266f 100644 --- a/lib/rubygems/ext/ext_conf_builder.rb +++ b/lib/rubygems/ext/ext_conf_builder.rb @@ -25,11 +25,13 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder siteconf.flush + siteconf_path = File.expand_path siteconf.path + rubyopt = ENV["RUBYOPT"] destdir = ENV["DESTDIR"] begin - ENV["RUBYOPT"] = ["-r#{siteconf.path}", rubyopt].compact.join(' ') + ENV["RUBYOPT"] = ["-r#{siteconf_path}", rubyopt].compact.join(' ') cmd = [Gem.ruby, File.basename(extension), *args].join ' ' run cmd, results diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index 7e2458c3b6..1a064e12a6 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -368,6 +368,9 @@ EOM raise Gem::Package::PathError.new(filename, destination_dir) if filename.start_with? '/' + destination_dir = File.realpath destination_dir if + File.respond_to? :realpath + destination = File.join destination_dir, filename destination = File.expand_path destination diff --git a/lib/rubygems/source.rb b/lib/rubygems/source.rb index 8f39cb1464..96d57870e2 100644 --- a/lib/rubygems/source.rb +++ b/lib/rubygems/source.rb @@ -141,14 +141,4 @@ class Gem::Source fetcher = Gem::RemoteFetcher.fetcher fetcher.download spec, @uri.to_s, dir end - - ## - # Replaces the URI for this source with +uri+. Used for upgrading this - # source to HTTPS - - def uri= uri # :nodoc: - @api_uri = nil - @uri = uri - end - end diff --git a/lib/rubygems/spec_fetcher.rb b/lib/rubygems/spec_fetcher.rb index 31205b9a06..3d484d1c13 100644 --- a/lib/rubygems/spec_fetcher.rb +++ b/lib/rubygems/spec_fetcher.rb @@ -188,8 +188,6 @@ class Gem::SpecFetcher list = {} Gem.sources.each_source do |source| - source = upgrade_http_source source - begin names = case type when :latest @@ -228,40 +226,5 @@ 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' && - uri.host.downcase == 'rubygems.org' - - https_uri = uri.dup - https_uri.scheme = 'https' - https_uri += '/' - - https_uri = URI https_uri.to_s # cast to URI::HTTPS - - begin - Gem::RemoteFetcher.fetcher.fetch_path https_uri, nil, true - rescue Gem::RemoteFetcher::FetchError => e - raise unless e.message =~ / Not Allowed 405 / - end - - say "Upgraded #{uri} to HTTPS" - - https_uri += uri.request_uri - - source.uri = URI https_uri.to_s # cast to URI::HTTPS - - source - rescue Gem::RemoteFetcher::FetchError - say "Upgrading #{uri} to HTTPS failed, continuing" if - Gem.configuration.really_verbose - - source - end - end diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb index 86d5d0d4db..16298c9393 100644 --- a/test/rubygems/test_gem_commands_setup_command.rb +++ b/test/rubygems/test_gem_commands_setup_command.rb @@ -41,21 +41,36 @@ class TestGemCommandsSetupCommand < Gem::TestCase end def test_remove_old_lib_files - lib = File.join @install_dir, 'lib' - lib_rubygems = File.join lib, 'rubygems' + lib = File.join @install_dir, 'lib' + lib_rubygems = File.join lib, 'rubygems' + lib_rubygems_defaults = File.join lib_rubygems, 'defaults' - old_builder_rb = File.join lib_rubygems, 'builder.rb' - old_format_rb = File.join lib_rubygems, 'format.rb' + securerandom_rb = File.join lib, 'securerandom.rb' - FileUtils.mkdir_p lib_rubygems + engine_defaults_rb = File.join lib_rubygems_defaults, 'jruby.rb' + os_defaults_rb = File.join lib_rubygems_defaults, 'operating_system.rb' - open old_builder_rb, 'w' do |io| io.puts '# builder.rb' end - open old_format_rb, 'w' do |io| io.puts '# format.rb' end + old_builder_rb = File.join lib_rubygems, 'builder.rb' + old_format_rb = File.join lib_rubygems, 'format.rb' + + FileUtils.mkdir_p lib_rubygems_defaults + + open securerandom_rb, 'w' do |io| io.puts '# securerandom.rb' end + + open old_builder_rb, 'w' do |io| io.puts '# builder.rb' end + open old_format_rb, 'w' do |io| io.puts '# format.rb' end + + open engine_defaults_rb, 'w' do |io| io.puts '# jruby.rb' end + open os_defaults_rb, 'w' do |io| io.puts '# operating_system.rb' end @cmd.remove_old_lib_files lib refute_path_exists old_builder_rb refute_path_exists old_format_rb + + assert_path_exists securerandom_rb + assert_path_exists engine_defaults_rb + assert_path_exists os_defaults_rb end end diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb index 1e9603c6c7..87e7274051 100644 --- a/test/rubygems/test_gem_package.rb +++ b/test/rubygems/test_gem_package.rb @@ -18,6 +18,8 @@ class TestGemPackage < Gem::Package::TarTestCase @gem = @spec.cache_file @destination = File.join @tempdir, 'extract' + + FileUtils.mkdir_p @destination end def test_class_new_old_format @@ -330,6 +332,20 @@ class TestGemPackage < Gem::Package::TarTestCase "#{@destination} is not allowed", e.message) end + def test_install_location_extra_slash + package = Gem::Package.new @gem + + file = 'foo//file.rb' + file.taint + + destination = @destination.sub '/', '//' + + destination = package.install_location file, destination + + assert_equal File.join(@destination, 'foo', 'file.rb'), destination + refute destination.tainted? + end + def test_install_location_relative package = Gem::Package.new @gem diff --git a/test/rubygems/test_gem_package_old.rb b/test/rubygems/test_gem_package_old.rb index e0884348e5..05f7ae3dec 100644 --- a/test/rubygems/test_gem_package_old.rb +++ b/test/rubygems/test_gem_package_old.rb @@ -12,6 +12,8 @@ class TestGemPackageOld < Gem::TestCase @package = Gem::Package::Old.new 'old_format.gem' @destination = File.join @tempdir, 'extract' + + FileUtils.mkdir_p @destination end def test_contents diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index c178edc0d9..d3cc388db4 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -399,9 +399,6 @@ gems: @fetcher.instance_variable_set :@a1, @a1 @fetcher.instance_variable_set :@a2, @a2 def @fetcher.fetch_path uri, mtime = nil, head = false - raise Gem::RemoteFetcher::FetchError.new 'no http upgrade', uri if - uri.scheme != 'http' - case uri.request_uri when /#{@a1.spec_name}/ then Gem.deflate Marshal.dump @a1 diff --git a/test/rubygems/test_gem_source.rb b/test/rubygems/test_gem_source.rb index 3de9073f96..2629f180a9 100644 --- a/test/rubygems/test_gem_source.rb +++ b/test/rubygems/test_gem_source.rb @@ -184,16 +184,5 @@ class TestGemSource < Gem::TestCase end end - def test_uri_equals - @source.api_uri # cached - - refute_equal URI('https://secure.example'), @source.api_uri - - @source.uri = URI 'https://secure.example' - - assert_equal URI('https://secure.example'), @source.uri - assert_equal URI('https://secure.example'), @source.api_uri - end - end diff --git a/test/rubygems/test_gem_spec_fetcher.rb b/test/rubygems/test_gem_spec_fetcher.rb index 41d0ce4e26..b4aff095c0 100644 --- a/test/rubygems/test_gem_spec_fetcher.rb +++ b/test/rubygems/test_gem_spec_fetcher.rb @@ -32,14 +32,13 @@ class TestGemSpecFetcher < Gem::TestCase Gem::NameTuple.new(spec.name, spec.version, spec.original_platform) } - @v = Gem.marshal_version - @s_zip = util_gzip(Marshal.dump(Gem::NameTuple.to_basic(@specs))) - @l_zip = util_gzip(Marshal.dump(Gem::NameTuple.to_basic(@latest_specs))) - @p_zip = util_gzip(Marshal.dump(Gem::NameTuple.to_basic(@prerelease_specs))) - - @fetcher.data["#{@gem_repo}specs.#{@v}.gz"] = @s_zip - @fetcher.data["#{@gem_repo}latest_specs.#{@v}.gz"] = @l_zip - @fetcher.data["#{@gem_repo}prerelease_specs.#{@v}.gz"] = @p_zip + v = Gem.marshal_version + s_zip = util_gzip(Marshal.dump(Gem::NameTuple.to_basic(@specs))) + l_zip = util_gzip(Marshal.dump(Gem::NameTuple.to_basic(@latest_specs))) + p_zip = util_gzip(Marshal.dump(Gem::NameTuple.to_basic(@prerelease_specs))) + @fetcher.data["#{@gem_repo}specs.#{v}.gz"] = s_zip + @fetcher.data["#{@gem_repo}latest_specs.#{v}.gz"] = l_zip + @fetcher.data["#{@gem_repo}prerelease_specs.#{v}.gz"] = p_zip @sf = Gem::SpecFetcher.new @@ -201,6 +200,7 @@ class TestGemSpecFetcher < Gem::TestCase assert_equal comp.sort, specs[@source].sort end + def test_available_specs_cache specs, _ = @sf.available_specs(:latest) @@ -240,77 +240,5 @@ class TestGemSpecFetcher < Gem::TestCase assert_kind_of Gem::SourceFetchProblem, errors.first end - def test_upgrade_http_source - Gem.configuration.verbose = :really - - source = Gem::Source.new URI 'http://example' - same_source = nil - - use_ui @ui do - same_source = @sf.upgrade_http_source source - end - - assert_equal URI('http://example'), same_source.uri - - assert_empty @ui.output - assert_empty @ui.error - end - - def test_upgrade_http_source_rubygems - Gem.configuration.verbose = :really - - source = Gem::Source.new URI 'http://rubygems.org' - same_source = nil - https_source = nil - - use_ui @ui do - same_source = @sf.upgrade_http_source source - end - - assert_equal URI('http://rubygems.org'), same_source.uri - - @fetcher.data['https://rubygems.org/'] = 'hello' - - use_ui @ui do - https_source = @sf.upgrade_http_source source - end - - assert_equal URI('https://rubygems.org'), https_source.uri - - assert_empty @ui.error - - expected = <<-EXPECTED -Upgrading http://rubygems.org to HTTPS failed, continuing -Upgraded http://rubygems.org to HTTPS - EXPECTED - - assert_equal expected, @ui.output - end - - def test_upgrade_http_source_rubygems_405 - Gem.configuration.verbose = :really - - source = Gem::Source.new URI 'http://rubygems.org' - https_source = nil - - @fetcher.data['https://rubygems.org/'] = proc do - raise Gem::RemoteFetcher::FetchError.new ' Not Allowed 405 ', nil - end - - use_ui @ui do - https_source = @sf.upgrade_http_source source - end - - assert_equal URI('https://rubygems.org'), https_source.uri - - assert_empty @ui.error - - expected = <<-EXPECTED -Upgraded http://rubygems.org to HTTPS - EXPECTED - - assert_equal expected, @ui.output - end - end