diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-27 10:05:04 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-27 10:05:04 +0000 |
commit | 85d461456c154d7b4a72b20369e0d65d7880ce02 (patch) | |
tree | 21e1be2c786c8040a426841768e046fb4dc365b1 /test/rubygems | |
parent | 3a83ba90c35833bab757998def36cfe872dec461 (diff) |
Merge master branch from rubygems upstream.
* It's preparation to release RubyGems 3.0.0.beta2 and Ruby 2.6.0
preview 3.
* https://github.com/rubygems/rubygems/compare/v3.0.0.beta1...fad2eb15a282b19dfcb4b48bc95b8b39ebb4511f
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64555 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems')
23 files changed, 539 insertions, 84 deletions
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index f383d5af58..ddf0f7e04c 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -1758,7 +1758,7 @@ class TestGem < Gem::TestCase platform = " #{platform}" end expected = if Gem::USE_BUNDLER_FOR_GEMDEPS - <<-EXPECTED + <<-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 diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb index c3aa01503a..51a14184ff 100644 --- a/test/rubygems/test_gem_command_manager.rb +++ b/test/rubygems/test_gem_command_manager.rb @@ -29,6 +29,12 @@ class TestGemCommandManager < Gem::TestCase e.message end + def test_find_alias_command + command = @command_manager.find_command 'i' + + assert_kind_of Gem::Commands::InstallCommand, command + end + def test_find_command_ambiguous_exact ins_command = Class.new Gem::Commands.send :const_set, :InsCommand, ins_command diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb index 19ca03bb70..8048f3e8f5 100644 --- a/test/rubygems/test_gem_commands_build_command.rb +++ b/test/rubygems/test_gem_commands_build_command.rb @@ -9,13 +9,35 @@ class TestGemCommandsBuildCommand < Gem::TestCase def setup super + readme_file = File.join(@tempdir, 'README.md') + + File.open readme_file, 'w' do |f| + f.write 'My awesome gem' + end + @gem = util_spec 'some_gem' do |s| s.rubyforge_project = 'example' + s.license = 'AGPL-3.0' + s.files = ['README.md'] end @cmd = Gem::Commands::BuildCommand.new end + def test_handle_options + @cmd.handle_options %w[--force --strict] + + assert @cmd.options[:force] + assert @cmd.options[:strict] + end + + def test_handle_options_defaults + @cmd.handle_options [] + + refute @cmd.options[:force] + refute @cmd.options[:strict] + end + def test_execute gemspec_file = File.join(@tempdir, @gem.spec_name) @@ -23,7 +45,55 @@ class TestGemCommandsBuildCommand < Gem::TestCase gs.write @gem.to_ruby end - util_test_build_gem @gem, gemspec_file + @cmd.options[:args] = [gemspec_file] + + util_test_build_gem @gem + end + + def test_execute_strict_without_warnings + gemspec_file = File.join(@tempdir, @gem.spec_name) + + File.open gemspec_file, 'w' do |gs| + gs.write @gem.to_ruby + end + + @cmd.options[:strict] = true + @cmd.options[:args] = [gemspec_file] + + util_test_build_gem @gem + end + + def test_execute_strict_with_warnings + bad_gem = util_spec 'some_bad_gem' do |s| + s.rubyforge_project = 'example' + s.files = ['README.md'] + end + + gemspec_file = File.join(@tempdir, bad_gem.spec_name) + + File.open gemspec_file, 'w' do |gs| + gs.write bad_gem.to_ruby + end + + @cmd.options[:args] = [gemspec_file] + @cmd.options[:strict] = true + + use_ui @ui do + Dir.chdir @tempdir do + assert_raises Gem::InvalidSpecificationException do + @cmd.execute + end + end + end + + error = @ui.error.split "\n" + assert_equal "WARNING: licenses is empty, but is recommended. Use a license identifier from", error.shift + assert_equal "http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.", error.shift + assert_equal "WARNING: See http://guides.rubygems.org/specification-reference/ for help", error.shift + assert_equal [], error + + gem_file = File.join @tempdir, File.basename(@gem.cache_file) + refute File.exist?(gem_file) end def test_execute_bad_spec @@ -67,9 +137,14 @@ class TestGemCommandsBuildCommand < Gem::TestCase def test_execute_outside_dir gemspec_dir = File.join @tempdir, 'build_command_gem' gemspec_file = File.join gemspec_dir, @gem.spec_name + readme_file = File.join gemspec_dir, 'README.md' FileUtils.mkdir_p gemspec_dir + File.open readme_file, 'w' do |f| + f.write "My awesome gem" + end + File.open gemspec_file, 'w' do |gs| gs.write @gem.to_ruby end @@ -103,12 +178,12 @@ class TestGemCommandsBuildCommand < Gem::TestCase gs.write @gem.to_ruby end - util_test_build_gem @gem, gemspec_file - end - - def util_test_build_gem(gem, gemspec_file, check_licenses=true) @cmd.options[:args] = [gemspec_file] + util_test_build_gem @gem + end + + def util_test_build_gem(gem) use_ui @ui do Dir.chdir @tempdir do @cmd.execute @@ -122,10 +197,6 @@ class TestGemCommandsBuildCommand < Gem::TestCase assert_equal " File: some_gem-2.gem", output.shift assert_equal [], output - if check_licenses - assert_match "WARNING: licenses is empty", @ui.error - end - gem_file = File.join @tempdir, File.basename(gem.cache_file) assert File.exist?(gem_file) @@ -147,7 +218,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase @cmd.options[:args] = [gemspec_file] @cmd.options[:force] = true - util_test_build_gem @gem, gemspec_file, false + util_test_build_gem @gem end CERT_FILE = cert_path 'public3072' @@ -169,7 +240,9 @@ class TestGemCommandsBuildCommand < Gem::TestCase gs.write spec.to_ruby end - util_test_build_gem spec, gemspec_file + @cmd.options[:args] = [gemspec_file] + + util_test_build_gem spec trust_dir.trust_cert OpenSSL::X509::Certificate.new(File.read(CERT_FILE)) diff --git a/test/rubygems/test_gem_commands_cleanup_command.rb b/test/rubygems/test_gem_commands_cleanup_command.rb index 60d208fcc0..7024e59fb9 100644 --- a/test/rubygems/test_gem_commands_cleanup_command.rb +++ b/test/rubygems/test_gem_commands_cleanup_command.rb @@ -236,5 +236,32 @@ class TestGemCommandsCleanupCommand < Gem::TestCase refute_path_exists d_1.gem_dir refute_path_exists e_1.gem_dir end + + def test_execute_user_install + c_1, = util_gem 'c', '1.0' + c_2, = util_gem 'c', '1.1' + + d_1, = util_gem 'd', '1.0' + d_2, = util_gem 'd', '1.1' + + c_1 = install_gem c_1, :user_install => true # pick up user install path + c_2 = install_gem c_2, :user_install => true # pick up user install path + + d_1 = install_gem d_1 + d_2 = install_gem d_2 + + Gem::Specification.dirs = [Gem.dir, Gem.user_dir] + + @cmd.handle_options %w[--user-install] + @cmd.options[:args] = [] + + @cmd.execute + + refute_path_exists c_1.gem_dir + assert_path_exists c_2.gem_dir + + assert_path_exists d_1.gem_dir + assert_path_exists d_2.gem_dir + end end diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index a0851fc288..03ceec94b4 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -229,7 +229,7 @@ ERROR: Could not find a valid gem 'bar' (= 0.5) (required by 'foo' (>= 0)) in a @cmd.handle_options %w[-p=foo.bar.com] end - assert_match "Invalid uri scheme for =foo.bar.com\nPreface URLs with one of [\"http://\", \"https://\", \"file://\", \"s3://\"]", e.message + assert_match "Invalid uri scheme for =foo.bar.com\nPreface URLs with one of [\"http://\", \"https://\", \"file://\", \"s3://\"]", e.message end end @@ -451,23 +451,23 @@ ERROR: Possible alternatives: non_existent_with_hint specs = spec_fetcher do |fetcher| fetcher.gem 'a', 2 end - + Gem.done_installing(&Gem::RDoc.method(:generation_hook)) - + @cmd.options[:document] = %w[rdoc ri] @cmd.options[:domain] = :local @cmd.options[:install_dir] = 'whatever' - + a2 = specs['a-2'] FileUtils.mv a2.cache_file, @tempdir - + @cmd.options[:args] = %w[a] - + use_ui @ui do # Don't use Dir.chdir with a block, it warnings a lot because # of a downstream Dir.chdir with a block old = Dir.getwd - + begin Dir.chdir @tempdir assert_raises Gem::MockGemUi::SystemExitException, @ui.error do @@ -477,9 +477,9 @@ ERROR: Possible alternatives: non_existent_with_hint Dir.chdir old end end - + wait_for_child_process_to_exit - + assert_path_exists 'whatever/doc/a-2', 'documentation not installed' end diff --git a/test/rubygems/test_gem_commands_open_command.rb b/test/rubygems/test_gem_commands_open_command.rb index a96fa6ea23..e73a138204 100644 --- a/test/rubygems/test_gem_commands_open_command.rb +++ b/test/rubygems/test_gem_commands_open_command.rb @@ -68,4 +68,33 @@ class TestGemCommandsOpenCommand < Gem::TestCase assert_equal "", @ui.error end + def test_default_gem + @cmd.options[:version] = "1.0" + @cmd.options[:args] = %w[foo] + + version = @cmd.options[:version] + @cmd.define_singleton_method(:spec_for) do |name| + spec = Gem::Specification.find_all_by_name(name, version).first + + spec.define_singleton_method(:default_gem?) do + true + end + + return spec if spec + + say "Unable to find gem '#{name}'" + end + + gem("foo", "1.0") + + assert_raises Gem::MockGemUi::TermError do + use_ui @ui do + @cmd.execute + end + end + + assert_match %r|'foo' is a default gem and can't be opened\.| , @ui.output + assert_equal "", @ui.error + end + end diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb index 806ed87007..4586159af6 100644 --- a/test/rubygems/test_gem_commands_pristine_command.rb +++ b/test/rubygems/test_gem_commands_pristine_command.rb @@ -433,6 +433,39 @@ class TestGemCommandsPristineCommand < Gem::TestCase refute File.exist? gem_lib end + def test_execute_bindir + a = util_spec 'a' do |s| + s.name = "test_gem" + s.executables = %w[foo] + s.files = %w[bin/foo] + end + + write_file File.join(@tempdir, 'bin', 'foo') do |fp| + fp.puts "#!/usr/bin/ruby" + end + + write_file File.join(@tempdir, 'test_bin', 'foo') do |fp| + fp.puts "#!/usr/bin/ruby" + end + + install_gem a + + gem_exec = File.join @gemhome, 'bin', 'foo' + gem_bindir = File.join @tempdir, 'test_bin', 'foo' + + FileUtils.rm gem_exec + FileUtils.rm gem_bindir + + @cmd.handle_options ["--all", "--only-executables", "--bindir", "#{gem_bindir}"] + + use_ui @ui do + @cmd.execute + end + + refute File.exist? gem_exec + assert File.exist? gem_bindir + end + def test_execute_unknown_gem_at_remote_source install_specs util_spec 'a' diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb index 1c5dbfe23e..ccc46d4f45 100644 --- a/test/rubygems/test_gem_commands_push_command.rb +++ b/test/rubygems/test_gem_commands_push_command.rb @@ -95,6 +95,26 @@ class TestGemCommandsPushCommand < Gem::TestCase @fetcher.last_request["Content-Type"] end + def test_execute_allowed_push_host + @spec, @path = util_gem "freebird", "1.0.1" do |spec| + spec.metadata['allowed_push_host'] = "https://privategemserver.example" + end + + @response = "Successfully registered gem: freewill (1.0.0)" + @fetcher.data["#{@spec.metadata['allowed_push_host']}/api/v1/gems"] = [@response, 200, 'OK'] + @fetcher.data["#{Gem.host}/api/v1/gems"] = + ['fail', 500, 'Internal Server Error'] + + @cmd.options[:args] = [@path] + + @cmd.execute + + assert_equal Net::HTTP::Post, @fetcher.last_request.class + assert_equal Gem.read_binary(@path), @fetcher.last_request.body + assert_equal "application/octet-stream", + @fetcher.last_request["Content-Type"] + end + def test_sending_when_default_host_disabled Gem.configuration.disable_default_gem_server = true response = "You must specify a gem server" diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb index 7957689db4..db6c16e91b 100644 --- a/test/rubygems/test_gem_commands_query_command.rb +++ b/test/rubygems/test_gem_commands_query_command.rb @@ -11,7 +11,7 @@ module TestGemCommandsQueryCommandSetup @specs = add_gems_to_fetcher @stub_ui = Gem::MockGemUi.new @stub_fetcher = Gem::FakeFetcher.new - + @stub_fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do raise Gem::RemoteFetcher::FetchError end diff --git a/test/rubygems/test_gem_ext_cmake_builder.rb b/test/rubygems/test_gem_ext_cmake_builder.rb index 76d3cb2afe..2d449fc2fd 100644 --- a/test/rubygems/test_gem_ext_cmake_builder.rb +++ b/test/rubygems/test_gem_ext_cmake_builder.rb @@ -25,6 +25,7 @@ class TestGemExtCmakeBuilder < Gem::TestCase File.open File.join(@ext, 'CMakeLists.txt'), 'w' do |cmakelists| cmakelists.write <<-eo_cmake cmake_minimum_required(VERSION 2.6) +project(self_build LANGUAGES NONE) install (FILES test.txt DESTINATION bin) eo_cmake end diff --git a/test/rubygems/test_gem_gemcutter_utilities.rb b/test/rubygems/test_gem_gemcutter_utilities.rb index 7b3e273957..90f9142171 100644 --- a/test/rubygems/test_gem_gemcutter_utilities.rb +++ b/test/rubygems/test_gem_gemcutter_utilities.rb @@ -179,8 +179,6 @@ class TestGemGemcutterUtilities < Gem::TestCase end def test_sign_in_with_bad_credentials - skip 'Always uses $stdin on windows' if Gem.win_platform? - assert_raises Gem::MockGemUi::TermError do util_sign_in ['Access Denied.', 403, 'Forbidden'] end @@ -190,8 +188,6 @@ class TestGemGemcutterUtilities < Gem::TestCase end def util_sign_in response, host = nil, args = [] - skip 'Always uses $stdin on windows' if Gem.win_platform? - email = 'you@example.com' password = 'secret' diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 062d366665..0ff4954d82 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -141,7 +141,7 @@ end end File.open File.join(util_inst_bindir, 'executable'), 'w' do |io| - io.write <<-EXEC + io.write <<-EXEC #!/usr/local/bin/ruby # # This file was generated by RubyGems @@ -336,6 +336,9 @@ gem 'other', version bin_dir = Gem.win_platform? ? File.expand_path(ENV["WINDIR"]).upcase : "/usr/bin" + old_path = ENV["PATH"] + ENV["PATH"] = [ENV["PATH"], bin_dir].compact.join(File::PATH_SEPARATOR) + options = { :bin_dir => bin_dir, :install_dir => "/non/existent" @@ -350,6 +353,9 @@ gem 'other', version end assert_equal "", @ui.error + + ensure + ENV["PATH"] = old_path end def test_generate_bin_script @@ -1409,7 +1415,7 @@ gem 'other', version def spec.full_name # so the spec is buildable "malicious-1" end - def spec.validate; end + def spec.validate packaging, strict; end util_build_gem spec diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb index 09ef27ee22..a53cda1274 100644 --- a/test/rubygems/test_gem_package.rb +++ b/test/rubygems/test_gem_package.rb @@ -150,7 +150,7 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_add_files_symlink - skip 'symlink not supported' if Gem.win_platform? + skip 'symlink not supported' if Gem.win_platform? && RUBY_VERSION < '2.3' spec = Gem::Specification.new spec.files = %w[lib/code.rb lib/code_sym.rb] @@ -159,7 +159,15 @@ class TestGemPackage < Gem::Package::TarTestCase File.open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end # NOTE: 'code.rb' is correct, because it's relative to lib/code_sym.rb - File.symlink('code.rb', 'lib/code_sym.rb') + begin + File.symlink('code.rb', 'lib/code_sym.rb') + rescue Errno::EACCES => e + if win_platform? + skip "symlink - must be admin with no UAC on Windows" + else + raise e + end + end package = Gem::Package.new 'bogus.gem' package.spec = spec @@ -315,6 +323,19 @@ class TestGemPackage < Gem::Package::TarTestCase assert_equal 'missing value for attribute summary', e.message end + def test_build_invalid_arguments + spec = Gem::Specification.new 'build', '1' + + package = Gem::Package.new spec.file_name + package.spec = spec + + e = assert_raises ArgumentError do + package.build true, true + end + + assert_equal "skip_validation = true and strict_validation = true are incompatible", e.message + end + def test_build_signed skip 'openssl is missing' unless defined?(OpenSSL::SSL) @@ -451,7 +472,7 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_extract_tar_gz_symlink_relative_path - skip 'symlink not supported' if Gem.win_platform? + skip 'symlink not supported' if Gem.win_platform? && RUBY_VERSION < '2.3' package = Gem::Package.new @gem @@ -461,7 +482,15 @@ class TestGemPackage < Gem::Package::TarTestCase tar.add_symlink 'lib/foo.rb', '../relative.rb', 0644 end - package.extract_tar_gz tgz_io, @destination + begin + package.extract_tar_gz tgz_io, @destination + rescue Errno::EACCES => e + if win_platform? + skip "symlink - must be admin with no UAC on Windows" + else + raise e + end + end extracted = File.join @destination, 'lib/foo.rb' assert_path_exists extracted @@ -472,28 +501,34 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_extract_symlink_parent - skip 'symlink not supported' if Gem.win_platform? + skip 'symlink not supported' if Gem.win_platform? && RUBY_VERSION < '2.3' - package = Gem::Package.new @gem + package = Gem::Package.new @gem - tgz_io = util_tar_gz do |tar| - tar.mkdir 'lib', 0755 - tar.add_symlink 'lib/link', '../..', 0644 - tar.add_file 'lib/link/outside.txt', 0644 do |io| io.write 'hi' end - end + tgz_io = util_tar_gz do |tar| + tar.mkdir 'lib', 0755 + tar.add_symlink 'lib/link', '../..', 0644 + tar.add_file 'lib/link/outside.txt', 0644 do |io| io.write 'hi' end + end - # Extract into a subdirectory of @destination; if this test fails it writes - # a file outside destination_subdir, but we want the file to remain inside - # @destination so it will be cleaned up. - destination_subdir = File.join @destination, 'subdir' - FileUtils.mkdir_p destination_subdir + # Extract into a subdirectory of @destination; if this test fails it writes + # a file outside destination_subdir, but we want the file to remain inside + # @destination so it will be cleaned up. + destination_subdir = File.join @destination, 'subdir' + FileUtils.mkdir_p destination_subdir - e = assert_raises Gem::Package::PathError do - package.extract_tar_gz tgz_io, destination_subdir - end + e = assert_raises(Gem::Package::PathError, Errno::EACCES) do + package.extract_tar_gz tgz_io, destination_subdir + end - assert_equal("installing into parent path lib/link/outside.txt of " + - "#{destination_subdir} is not allowed", e.message) + if Gem::Package::PathError === e + assert_equal("installing into parent path lib/link/outside.txt of " + + "#{destination_subdir} is not allowed", e.message) + elsif win_platform? + skip "symlink - must be admin with no UAC on Windows" + else + raise e + end end def test_extract_tar_gz_directory diff --git a/test/rubygems/test_gem_package_tar_reader_entry.rb b/test/rubygems/test_gem_package_tar_reader_entry.rb index dba1987d4d..ef088e32be 100644 --- a/test/rubygems/test_gem_package_tar_reader_entry.rb +++ b/test/rubygems/test_gem_package_tar_reader_entry.rb @@ -34,6 +34,10 @@ class TestGemPackageTarReaderEntry < Gem::Package::TarTestCase assert_equal 1, @entry.bytes_read end + def test_size + assert_equal @contents.size, @entry.size + end + def test_close @entry.close @@ -129,6 +133,13 @@ class TestGemPackageTarReaderEntry < Gem::Package::TarTestCase assert_equal @contents[0...100], @entry.read(100) end + def test_readpartial + assert_raises(EOFError) do + @entry.read(@contents.size) + @entry.readpartial(1) + end + end + def test_rewind char = @entry.getc diff --git a/test/rubygems/test_gem_path_support.rb b/test/rubygems/test_gem_path_support.rb index ccb46d6b8e..90d50a269f 100644 --- a/test/rubygems/test_gem_path_support.rb +++ b/test/rubygems/test_gem_path_support.rb @@ -118,4 +118,21 @@ class TestGemPathSupport < Gem::TestCase ps = Gem::PathSupport.new "GEM_SPEC_CACHE" => "foo" assert_equal "foo", ps.spec_cache_dir end + + def test_gem_paths_do_not_contain_symlinks + dir = "#{@tempdir}/realgemdir" + symlink = "#{@tempdir}/symdir" + Dir.mkdir dir + begin + File.symlink(dir, symlink) + rescue NotImplementedError, SystemCallError + skip 'symlinks not supported' + end + not_existing = "#{@tempdir}/does_not_exist" + path = "#{symlink}#{File::PATH_SEPARATOR}#{not_existing}" + + ps = Gem::PathSupport.new "GEM_PATH" => path, "GEM_HOME" => symlink + assert_equal dir, ps.home + assert_equal [dir, not_existing], ps.path + end end diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index 1eed0c7670..dfef55c7ca 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -731,10 +731,9 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== assert_equal "murphy", fetcher.fetch_path(@server_uri) end - def test_fetch_s3 + def assert_fetch_s3(url) fetcher = Gem::RemoteFetcher.new nil @fetcher = fetcher - url = 's3://testuser:testpass@my-bucket/gems/specs.4.8.gz' $fetched_uri = nil def fetcher.request(uri, request_class, last_modified = nil) @@ -756,15 +755,64 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== $fetched_uri = nil end - def test_fetch_s3_no_creds + def test_fetch_s3_config_creds + Gem.configuration[:s3_source] = { + 'my-bucket' => {:id => 'testuser', :secret => 'testpass'} + } + url = 's3://my-bucket/gems/specs.4.8.gz' + assert_fetch_s3 url + ensure + Gem.configuration[:s3_source] = nil + end + + def test_fetch_s3_url_creds + url = 's3://testuser:testpass@my-bucket/gems/specs.4.8.gz' + assert_fetch_s3 url + end + + def refute_fetch_s3(url, expected_message) fetcher = Gem::RemoteFetcher.new nil @fetcher = fetcher - url = 's3://my-bucket/gems/specs.4.8.gz' + e = assert_raises Gem::RemoteFetcher::FetchError do fetcher.fetch_s3 URI.parse(url) end - assert_match "credentials needed", e.message + assert_match expected_message, e.message + end + + def test_fetch_s3_no_source_key + url = 's3://my-bucket/gems/specs.4.8.gz' + refute_fetch_s3 url, 'no s3_source key exists in .gemrc' + end + + def test_fetch_s3_no_host + Gem.configuration[:s3_source] = { + 'my-bucket' => {:id => 'testuser', :secret => 'testpass'} + } + + url = 's3://other-bucket/gems/specs.4.8.gz' + refute_fetch_s3 url, 'no key for host other-bucket in s3_source in .gemrc' + ensure + Gem.configuration[:s3_source] = nil + end + + def test_fetch_s3_no_id + Gem.configuration[:s3_source] = { 'my-bucket' => {:secret => 'testpass'} } + + url = 's3://my-bucket/gems/specs.4.8.gz' + refute_fetch_s3 url, 's3_source for my-bucket missing id or secret' + ensure + Gem.configuration[:s3_source] = nil + end + + def test_fetch_s3_no_secret + Gem.configuration[:s3_source] = { 'my-bucket' => {:id => 'testuser'} } + + url = 's3://my-bucket/gems/specs.4.8.gz' + refute_fetch_s3 url, 's3_source for my-bucket missing id or secret' + ensure + Gem.configuration[:s3_source] = nil end def test_observe_no_proxy_env_single_host @@ -846,9 +894,9 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== with_configured_fetcher( ":ssl_ca_cert: #{temp_ca_cert}\n" + ":ssl_client_cert: #{temp_client_cert}\n") do |fetcher| - assert_raises Gem::RemoteFetcher::FetchError do - fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml") - end + assert_raises Gem::RemoteFetcher::FetchError do + fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml") + end end end diff --git a/test/rubygems/test_gem_resolver.rb b/test/rubygems/test_gem_resolver.rb index b083622da4..99cb77afaf 100644 --- a/test/rubygems/test_gem_resolver.rb +++ b/test/rubygems/test_gem_resolver.rb @@ -299,7 +299,7 @@ class TestGemResolver < Gem::TestCase a2_p1 = a3_p2 = nil spec_fetcher do |fetcher| - fetcher.spec 'a', 2 + fetcher.spec 'a', 2 a2_p1 = fetcher.spec 'a', 2 do |s| s.platform = Gem::Platform.local end a3_p2 = fetcher.spec 'a', 3 do |s| s.platform = unknown end end diff --git a/test/rubygems/test_gem_security_signer.rb b/test/rubygems/test_gem_security_signer.rb index 79dfea099d..8a0b7cfde9 100644 --- a/test/rubygems/test_gem_security_signer.rb +++ b/test/rubygems/test_gem_security_signer.rb @@ -135,9 +135,11 @@ toqvglr0kdbknSRRjBVLK6tsgr07aLT9gNP7mTW2PA== def test_sign_expired signer = Gem::Security::Signer.new PRIVATE_KEY, [EXPIRED_CERT] - assert_raises Gem::Security::Exception do + e = assert_raises Gem::Security::Exception do signer.sign 'hello' end + + assert_match "certificate /CN=nobody/DC=example not valid after 1970-01-01 00:00:00 UTC", e.message end def test_sign_expired_auto_update diff --git a/test/rubygems/test_gem_server.rb b/test/rubygems/test_gem_server.rb index 8a3e6410ae..6886ec4858 100644 --- a/test/rubygems/test_gem_server.rb +++ b/test/rubygems/test_gem_server.rb @@ -377,9 +377,9 @@ class TestGemServer < Gem::TestCase assert_equal 200, @res.status assert_match 'xsshomepagegem 1', @res.body - # This verifies that the homepage for this spec is not displayed and is set to ".", because it's not a + # This verifies that the homepage for this spec is not displayed and is set to ".", because it's not a # valid HTTP/HTTPS URL and could be unsafe in an HTML context. We would prefer to throw an exception here, - # but spec.homepage is currently free form and not currently required to be a URL, this behavior may be + # but spec.homepage is currently free form and not currently required to be a URL, this behavior may be # validated in future versions of Gem::Specification. # # There are two variant we're checking here, one where rdoc is not present, and one where rdoc is present in the same regex: @@ -432,9 +432,9 @@ class TestGemServer < Gem::TestCase assert_equal 200, @res.status assert_match 'invalidhomepagegem 1', @res.body - # This verifies that the homepage for this spec is not displayed and is set to ".", because it's not a + # This verifies that the homepage for this spec is not displayed and is set to ".", because it's not a # valid HTTP/HTTPS URL and could be unsafe in an HTML context. We would prefer to throw an exception here, - # but spec.homepage is currently free form and not currently required to be a URL, this behavior may be + # but spec.homepage is currently free form and not currently required to be a URL, this behavior may be # validated in future versions of Gem::Specification. # # There are two variant we're checking here, one where rdoc is not present, and one where rdoc is present in the same regex: diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 845914d33a..edf4d08d93 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -108,7 +108,7 @@ end # objects are present in the @stubs collection. This test verifies that # this scenario works correctly. Gem::Specification.all = [spec] - Gem::Specification.find_active_stub_by_path('foo') + assert_equal spec, Gem::Specification.find_active_stub_by_path('foo') end def test_self_activate @@ -387,8 +387,8 @@ end def test_self_activate_checks_dependencies a = util_spec 'a', '1.0' - a.add_dependency 'c', '= 1.0' - a.add_dependency 'b', '~> 1.0' + a.add_dependency 'c', '= 1.0' + a.add_dependency 'b', '~> 1.0' b1 = util_spec 'b', '1.0' b2 = util_spec 'b', '2.0' @@ -1126,6 +1126,88 @@ dependencies: [] refute_includes Gem::Specification.stubs.map { |s| s.full_name }, 'a-1' end + def test_self_stubs + Gem.loaded_specs.clear + Gem::Specification.class_variable_set(:@@stubs, nil) + + dir_standard_specs = File.join Gem.dir, 'specifications' + dir_default_specs = Gem::BasicSpecification.default_specifications_dir + + # Create gemspecs in three locations used in stubs + loaded_spec = Gem::Specification.new 'a', '3' + Gem.loaded_specs['a'] = loaded_spec + save_gemspec 'a', '2', dir_default_specs + save_gemspec 'a', '1', dir_standard_specs + + full_names = ['a-3', 'a-2', 'a-1'] + assert_equal full_names, Gem::Specification.stubs.map { |s| s.full_name } + + Gem.loaded_specs.delete 'a' + Gem::Specification.class_variable_set(:@@stubs, nil) + end + + def test_self_stubs_for + Gem.loaded_specs.clear + Gem::Specification.class_variable_set(:@@stubs, nil) + + dir_standard_specs = File.join Gem.dir, 'specifications' + dir_default_specs = Gem::BasicSpecification.default_specifications_dir + + # Create gemspecs in three locations used in stubs + loaded_spec = Gem::Specification.new 'a', '3' + Gem.loaded_specs['a'] = loaded_spec + save_gemspec 'a', '2', dir_default_specs + save_gemspec 'a', '1', dir_standard_specs + + full_names = ['a-3', 'a-2', 'a-1'] + + full_names = Gem::Specification.stubs_for('a').map { |s| s.full_name } + assert_equal full_names, Gem::Specification.stubs_for('a').map { |s| s.full_name } + assert_equal 1, Gem::Specification.class_variable_get(:@@stubs_by_name).length + + Gem.loaded_specs.delete 'a' + Gem::Specification.class_variable_set(:@@stubs, nil) + end + + def test_self_stubs_for_mult_platforms + # gems for two different platforms are installed with --user-install + # the correct one should be returned in the array + + orig_platform = Gem.platforms.dup + + # create user spec + user_spec_dir = File.join Gem.user_dir, 'specifications' + FileUtils.mkdir_p(user_spec_dir) unless Dir.exist? user_spec_dir + # dirs doesn't include user ? + Gem::Specification.dirs << user_spec_dir + + gem = 'mingw' + v = '1.1.1' + platforms = ['x86-mingw32', 'x64-mingw32'] + + #create specs + platforms.each do |plat| + spec = Gem::Specification.new(gem, v) { |s| s.platform = plat } + File.open File.join(user_spec_dir, "#{gem}-#{v}-#{plat}.gemspec"), 'w' do |io| + io.write spec.to_ruby + end + end + + platforms.each do |plat| + cur_plat = Gem::Platform.new plat + Gem.platforms = ['ruby', cur_plat] + + Gem::Specification.class_variable_set :@@stubs, nil + Gem::Specification.stubs if plat == platforms.last # test loading via stubs + t = Gem::Specification.stubs_for 'mingw' + + assert_equal 1, t.length + assert_equal cur_plat, t.first.platform + end + + Gem.platforms = orig_platform + end + DATA_PATH = File.expand_path "../data", __FILE__ def test_handles_private_null_type @@ -2615,16 +2697,6 @@ end expected = <<-EXPECTED #{w}: prerelease dependency on b (>= 1.0.rc1) is not recommended #{w}: prerelease dependency on c (>= 2.0.rc2, development) is not recommended -#{w}: pessimistic dependency on d (~> 1.2.3) may be overly strict - if d is semantically versioned, use: - add_runtime_dependency 'd', '~> 1.2', '>= 1.2.3' - if d is not semantically versioned, you can bypass this warning with: - add_runtime_dependency 'd', '>= 1.2.3', '< 1.3.a' -#{w}: pessimistic dependency on e (~> 1.2.3.4) may be overly strict - if e is semantically versioned, use: - add_runtime_dependency 'e', '~> 1.2', '>= 1.2.3.4' - if e is not semantically versioned, you can bypass this warning with: - add_runtime_dependency 'e', '>= 1.2.3.4', '< 1.2.4.a' #{w}: open-ended dependency on i (>= 1.2) is not recommended if i is semantically versioned, use: add_runtime_dependency 'i', '~> 1.2' @@ -2637,11 +2709,6 @@ end #{w}: open-ended dependency on l (> 1.2.3) is not recommended if l is semantically versioned, use: add_runtime_dependency 'l', '~> 1.2', '> 1.2.3' -#{w}: pessimistic dependency on m (~> 2.1.0) may be overly strict - if m is semantically versioned, use: - add_runtime_dependency 'm', '~> 2.1', '>= 2.1.0' - if m is not semantically versioned, you can bypass this warning with: - add_runtime_dependency 'm', '>= 2.1.0', '< 2.2.a' #{w}: See http://guides.rubygems.org/specification-reference/ for help EXPECTED @@ -2844,6 +2911,58 @@ duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use: @a1.files end + def test_unresolved_specs + specification = Gem::Specification.clone + + specification.define_singleton_method(:unresolved_deps) do + { b: Gem::Dependency.new("x","1") } + end + + specification.define_singleton_method(:find_all_by_name) do |dep_name| + [] + end + + expected = <<-EXPECTED +WARN: Unresolved or ambigious specs during Gem::Specification.reset: + x (= 1) +WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>' +Please report a bug if this causes problems. + EXPECTED + + assert_output nil, expected do + specification.reset + end + end + + def test_unresolved_specs_with_versions + specification = Gem::Specification.clone + + specification.define_singleton_method(:unresolved_deps) do + { b: Gem::Dependency.new("x","1") } + end + + specification.define_singleton_method(:find_all_by_name) do |dep_name| + [ + specification.new { |s| s.name = "z", s.version = Gem::Version.new("1") }, + specification.new { |s| s.name = "z", s.version = Gem::Version.new("2") } + ] + end + + expected = <<-EXPECTED +WARN: Unresolved or ambigious specs during Gem::Specification.reset: + x (= 1) + Available/installed versions of this gem: + - 1 + - 2 +WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>' +Please report a bug if this causes problems. + EXPECTED + + assert_output nil, expected do + specification.reset + end + end + def test_validate_files_recursive util_setup_validate FileUtils.touch @a1.file_name diff --git a/test/rubygems/test_gem_text.rb b/test/rubygems/test_gem_text.rb index 04f3f605e8..0249c47f83 100644 --- a/test/rubygems/test_gem_text.rb +++ b/test/rubygems/test_gem_text.rb @@ -21,6 +21,10 @@ class TestGemText < Gem::TestCase assert_equal " text to wrap", format_text("text to wrap", 40, 2) end + def test_format_text_no_space + assert_equal "texttowr\nap", format_text("texttowrap", 8) + end + def test_format_text_trailing # for two spaces after . text = <<-TEXT This line is really, really long. So long, in fact, that it is more than eighty characters long! The purpose of this line is for testing wrapping behavior because sometimes people don't wrap their text to eighty characters. Without the wrapping, the text might not look good in the RSS feed. diff --git a/test/rubygems/test_gem_util.rb b/test/rubygems/test_gem_util.rb index 71a26c06ae..205cd89611 100644 --- a/test/rubygems/test_gem_util.rb +++ b/test/rubygems/test_gem_util.rb @@ -38,6 +38,8 @@ class TestGemUtil < Gem::TestCase # impossible to cd into it and its children FileUtils.chmod(0666, 'd/e') + skip 'skipped in root privilege' if Process.uid.zero? + paths = Gem::Util.traverse_parents('d/e/f').to_a assert_equal File.join(@tempdir, 'd'), paths[0] diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb index bddae7fdc3..a2572fb611 100644 --- a/test/rubygems/test_gem_version.rb +++ b/test/rubygems/test_gem_version.rb @@ -46,7 +46,11 @@ class TestGemVersion < Gem::TestCase def test_class_correct assert_equal true, Gem::Version.correct?("5.1") assert_equal false, Gem::Version.correct?("an incorrect version") - assert_equal false, Gem::Version.correct?(nil) + + expected = "nil versions are discouraged and will be deprecated in Rubygems 4\n" + assert_output nil, expected do + Gem::Version.correct?(nil) + end end def test_class_new_subclass @@ -158,11 +162,25 @@ class TestGemVersion < Gem::TestCase def test_approximate_recommendation assert_approximate_equal "~> 1.0", "1" + assert_approximate_satisfies_itself "1" + assert_approximate_equal "~> 1.0", "1.0" + assert_approximate_satisfies_itself "1.0" + assert_approximate_equal "~> 1.2", "1.2" + assert_approximate_satisfies_itself "1.2" + assert_approximate_equal "~> 1.2", "1.2.0" + assert_approximate_satisfies_itself "1.2.0" + assert_approximate_equal "~> 1.2", "1.2.3" - assert_approximate_equal "~> 1.2", "1.2.3.a.4" + assert_approximate_satisfies_itself "1.2.3" + + assert_approximate_equal "~> 1.2.a", "1.2.3.a.4" + assert_approximate_satisfies_itself "1.2.3.a.4" + + assert_approximate_equal "~> 1.9.a", "1.9.0.dev" + assert_approximate_satisfies_itself "1.9.0.dev" end def test_to_s @@ -198,12 +216,20 @@ class TestGemVersion < Gem::TestCase assert v(version).prerelease?, "#{version} is a prerelease" end - # Assert that +expected+ is the "approximate" recommendation for +version". + # Assert that +expected+ is the "approximate" recommendation for +version+. def assert_approximate_equal expected, version assert_equal expected, v(version).approximate_recommendation end + # Assert that the "approximate" recommendation for +version+ satifies +version+. + + def assert_approximate_satisfies_itself version + gem_version = v(version) + + assert Gem::Requirement.new(gem_version.approximate_recommendation).satisfied_by?(gem_version) + end + # Assert that bumping the +unbumped+ version yields the +expected+. def assert_bumped_version_equal expected, unbumped |