diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-08 01:32:18 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-08 01:32:18 +0000 |
commit | c00e84327f14845bd484e76b5ee5dfeb1fa9ce3d (patch) | |
tree | 9f558dafa363f4f0118d504a50cd4461e2821cd1 /test | |
parent | 6b05153a3a75b74b64553d6a46f501d9ee0f0376 (diff) | |
download | ruby-c00e84327f14845bd484e76b5ee5dfeb1fa9ce3d.tar.gz |
Merge rubygems master.
This is RC version of Rubygems 2.7.0.
https://github.com/rubygems/rubygems/commit/688fb7e83c13c3fe7c2bb03c49a2db4c82852aee
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
41 files changed, 967 insertions, 116 deletions
diff --git a/test/rubygems/private3072_key.pem b/test/rubygems/private3072_key.pem new file mode 100644 index 0000000000..e99abce69c --- /dev/null +++ b/test/rubygems/private3072_key.pem @@ -0,0 +1,40 @@ +-----BEGIN PRIVATE KEY----- +MIIG/gIBADANBgkqhkiG9w0BAQEFAASCBugwggbkAgEAAoIBgQDIl6Ne1eCreYAe +j+Qkbygv06KqtcarwjNpSPJFq+G/R6xzGfbiuJDGePnlzqyAN6sti8r/tDD8orMS +l3EUSQTvFAVJKxbBDnklHUozdaX+giw+fi7onRJ3sQE2j7GhjahXZB0vmx20wU9v +sazZ0IU/x7k8X7WbVRCYig99UVn28zsq586LN5u/w7qXo50156bfmeDS8tt+TKSK +PkQQYuO+AulWDVdwHycKSzCE7SPWiZ/scFUirN4Stfw0bJZbr8VQ6QBAhHcHgd6B +tcZ1vBDC656zsWgpGWNTCU9mSBWV3UMk8mdwkO/jz8mXYSBfbyLESkhc8slf47zd +dqs1iZZOmVVlz/TXYc9N9d8DTl3OR/YYy04mdrysf4ijB6HV9U7NrRbjcKqKwTjW +xMWsFDdc1d5WCTsXzKjvB582LspGYxv9zgs0KkhSChGTA0qCqGdl0ZVx1Q0suW5O +7XlcEWAp9gSww0RW3E1zkrUARcB4mQgyC89kvE4y9RW4/KzZDcsCAwEAAQKCAYEA +uhQJBkGLgCZe1nsO3UmMUwmVPZ0QpmapgIKd1EnFScb4T3IHl3w1ORgiYa9eUDbU +AZVLg/co9kMLsTRxPqsZ+5pr6Nsi6YY+lVJdce0yRi2FU5eEdl63MfcuM+oKkt4x +CpihhnbzkKk+wlNlEE2iPm9NA5eZhXXcxlRUWCEuPqqV+ZA+BuFYBwVPw7mQbd/t +6kD50VZejQQWIvPt+fFyaOKUiDIqKaWMdr0XTkgZ1bunchMmttr7ywms4wjUVktv +LWMmI8wEMXfxR+xOtigwolSuFn+djWgh02KEc4gSQD3KGKshps5cMrLxxkwIoaC8 +rDxKfdUtixBx6JzrN0Wmq7f/oLpvzxTXoQTu30BvpUOr9evZjE/3ZYXiGCxoSDEL +cvdZHvd+4r0TEkuxNBebq5106bJCBTuq6awwiwAodrsH5DCnqkkrv9tnkVi71NnV +UfnF/C4i5clpJK+Rx4bub9SiqJuyEfQBDlEHdCDwKVASk6B3gXD2mgkJu+EdShkp +AoHBAPx27s3iBN1gRGzD9GU0x2z7uMrgXzXh71kCvzzkfOli5fpIvCyoOR8CIfok +Ph8Kth4c+Bz4bmp6c859yxm5aBdQb3y34LDvCkqEeFCs9XX31QTMjJ1Y3R6Iyun5 +nJzzZ5BtJbLFTHw9/p/pCUmJscUP8nQLwBMLIk4HzmrVXVLKJyaakK4LbsCChBc5 +XwCqzWFKbMRZM3X8PaZp3DCo9iA5/TyzkQMTucLSYaxDDG+YNtYQPB8J5wkFWTD8 +5//WZQKBwQDLZr9CnPR8HcrG46+rDzoZO1nXqaaEQMZhmm25lpL5oSHLrm4elGDp +vH5SRcCPz986InRszMROI3xvYpGtFsAzff3UVY0M8uDQcEKucHtd4wmFHefzYmKo +cvR9PuGmotk6yYpb+cMITT6sCzC4OHPz3DQAclmswRZchHYd2Zkv7tjgE0dXS9nw +XKaH5vQC4wjWBc857scHz0WYJLlj8s8UM9Fludz7kuagXczrsFIONxvrFKNJXeYl +muFCQl8hOG8CgcEA4ZZkTBNpxWX/vjBacRR4HinPNXjHmp4IAMEzoHWKKAD2/m1/ +t2eZotuFAL7hw1sO4FmCWmCiSQKh+CDvGk1RdYOqGwcy/uaZi3xTBcOGkaKh9WfR +PcfpzR7uMaOZDaVxJNxikxs4/MtoefsBEXS4JB3bx1W4i0unm5HeIBgHC7MWyKfU +H7CXhe0Zmqbo/O+iFQ0ro0cRdJuvesOcvN49Dw7B+Tt6mAVIN41FOWev9QdN+HkJ +P7LZfnYI/Hz/0NsBAoHADm2+eZI6wac3YD58kqzk2S9doy/UsSMLL5dN21F0IaMt +i45XH3I1Ib+OUnXCQDFly3DwQ1uPPV/FDv22CcpIXh6859gdxmJgUkj0Yf12suVN +IpVJg/lhuENXVp8kULbSpBnx565jCG66WGf+z8Kpbw4a3kE+XUPhOzTmUB3EgSL3 +XYXglK+7yRI5egCHJMFIOi51Uc2/bq1kaXOJdy6dQ/idDRNPOsVj+NJOnBWI7Js6 +LsXrA2RW1CoVeqbMqsWfAoHAAabWXkQ74BuTo+P7lbfnFa6qLfTRnkWBkKKpWSAZ +ZBLfGsw2F5ZzrfwXtLriPcQJNA+3q3u1WPiGZkjV4QnFMt+Kgcg8ahW94vDEgfex +OSQyrlioT2m9DLJNXXHxo3+0ePNQkmoMQbNRUwdYjBuK7dqNDmFQ8Oo8SxtlV2sL +ntLc47NvFaxDlOvnj9ftQv6ZhdzXQmKGiuZWxtrrjFgHJm8KhMS8IF9xHM3d0uYb +sbykscVdmz3lOmUZrxCeIJvk +-----END PRIVATE KEY----- diff --git a/test/rubygems/public3072_cert.pem b/test/rubygems/public3072_cert.pem new file mode 100644 index 0000000000..8f769aa8b9 --- /dev/null +++ b/test/rubygems/public3072_cert.pem @@ -0,0 +1,25 @@ +-----BEGIN CERTIFICATE----- +MIIENDCCApygAwIBAgIBATANBgkqhkiG9w0BAQsFADAqMQ8wDQYDVQQDDAZub2Jv +ZHkxFzAVBgoJkiaJk/IsZAEZFgdleGFtcGxlMCAXDTE2MDEwMTAwMDAwMFoYDzk5 +OTkxMjMxMjM1OTU5WjAqMQ8wDQYDVQQDDAZub2JvZHkxFzAVBgoJkiaJk/IsZAEZ +FgdleGFtcGxlMIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAyJejXtXg +q3mAHo/kJG8oL9OiqrXGq8IzaUjyRavhv0escxn24riQxnj55c6sgDerLYvK/7Qw +/KKzEpdxFEkE7xQFSSsWwQ55JR1KM3Wl/oIsPn4u6J0Sd7EBNo+xoY2oV2QdL5sd +tMFPb7Gs2dCFP8e5PF+1m1UQmIoPfVFZ9vM7KufOizebv8O6l6OdNeem35ng0vLb +fkykij5EEGLjvgLpVg1XcB8nCkswhO0j1omf7HBVIqzeErX8NGyWW6/FUOkAQIR3 +B4HegbXGdbwQwuues7FoKRljUwlPZkgVld1DJPJncJDv48/Jl2EgX28ixEpIXPLJ +X+O83XarNYmWTplVZc/012HPTfXfA05dzkf2GMtOJna8rH+Ioweh1fVOza0W43Cq +isE41sTFrBQ3XNXeVgk7F8yo7wefNi7KRmMb/c4LNCpIUgoRkwNKgqhnZdGVcdUN +LLluTu15XBFgKfYEsMNEVtxNc5K1AEXAeJkIMgvPZLxOMvUVuPys2Q3LAgMBAAGj +YzBhMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgIEMB0GA1UdDgQWBBSf +hxDG5kMk4VhQNMcuLhULi3gMpTAfBgNVHSMEGDAWgBSfhxDG5kMk4VhQNMcuLhUL +i3gMpTANBgkqhkiG9w0BAQsFAAOCAYEAuvY1Nc8lkjCWEnVlAB0yfx85+xa/6zoQ +9w4cG/Nk+M2XNXRmp0c6FQgy7Y/aRxIobJnJfo2S1yJIPfzBuxb/oOy4ikYGmrYV +JUJFs4KaMPz8nM13YVI+KtskNEs0Pb8kcb0ZO640f0ptkgFDN/rvezu2uxqTlaD+ +NSy+O+2Xr5T1Qq2eT2ui3mint26sA2g2cZqkqIdeEWHz/wf5ECMANvgCvE4efduI +oSwFbdb32UKKzppGW+usUbCgEH++EVNWN7VG8F7bvsnPDmuW2J2p2jjvg76H5eK2 +OtnI180JV2Qb80d2lKOS24Mq9edhCzh9AUFsTAfaQ1iBUE4P353G67RF88ZNvV1A +n9DIgbMBf97bByUmp+5MWMXWJ9AcqyXQFsQutEQMudor8P9UqwpCVUkxijpfFxvM +HOBVArYRsdhbjNRGpVAVHdzpJ2AQNTQVeSS7YdzHAzGIVksKHL3K5QJuUJCgNa52 +9H5201wSTxSAhlhoPTT06OHmIGiTvXZS +-----END CERTIFICATE----- diff --git a/test/rubygems/test_config.rb b/test/rubygems/test_config.rb index 79f300fd9c..f8aadb4a23 100644 --- a/test/rubygems/test_config.rb +++ b/test/rubygems/test_config.rb @@ -8,7 +8,7 @@ class TestConfig < Gem::TestCase util_make_gems spec = Gem::Specification.find_by_name("a") spec.activate - assert_equal "#{spec.full_gem_path}/data/a", Gem.datadir('a') + assert_equal "#{spec.full_gem_path}/data/a", spec.datadir end def test_good_rake_path_is_escaped diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 8b15debb49..2ec7044d7a 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -180,6 +180,35 @@ class TestGem < Gem::TestCase assert_match 'a-2/bin/exec', Gem.bin_path('a', 'exec', '>= 0') end + def test_activate_bin_path_resolves_eagerly + a1 = util_spec 'a', '1' do |s| + s.executables = ['exec'] + s.add_dependency 'b' + end + + b1 = util_spec 'b', '1' do |s| + s.add_dependency 'c', '2' + end + + b2 = util_spec 'b', '2' do |s| + s.add_dependency 'c', '1' + end + + c1 = util_spec 'c', '1' + c2 = util_spec 'c', '2' + + install_specs c1, c2, b1, b2, a1 + + Gem.activate_bin_path("a", "exec", ">= 0") + + # If we didn't eagerly resolve, this would activate c-2 and then the + # finish_resolve would cause a conflict + gem 'c' + Gem.finish_resolve + + assert_equal %w(a-1 b-2 c-1), loaded_spec_names + end + def test_self_bin_path_no_exec_name e = assert_raises ArgumentError do Gem.bin_path 'a' @@ -275,11 +304,13 @@ class TestGem < Gem::TestCase expected = File.join @gemhome, 'gems', foo.full_name, 'data', 'foo' - assert_equal expected, Gem.datadir('foo') + assert_equal expected, Gem::Specification.find_by_name("foo").datadir end def test_self_datadir_nonexistent_package - assert_nil Gem.datadir('xyzzy') + assert_raises(Gem::MissingSpecError) do + Gem::Specification.find_by_name("xyzzy").datadir + end end def test_self_default_exec_format @@ -368,7 +399,7 @@ class TestGem < Gem::TestCase begin Dir.chdir 'detect/a/b' - assert_empty Gem.detect_gemdeps + assert_equal add_bundler_full_name([]), Gem.detect_gemdeps.map(&:full_name) ensure Dir.chdir @tempdir end @@ -1068,7 +1099,7 @@ class TestGem < Gem::TestCase refute Gem.try_activate 'nonexistent' end - expected = "Ignoring ext-1 because its extensions are not built. " + + expected = "Ignoring ext-1 because its extensions are not built. " + "Try: gem pristine ext --version 1\n" assert_equal expected, err @@ -1079,7 +1110,8 @@ class TestGem < Gem::TestCase orig_path = ENV.delete 'GEM_PATH' Gem.use_paths nil, nil assert_equal Gem.default_dir, Gem.paths.home - assert_equal (Gem.default_path + [Gem.paths.home]).uniq, Gem.paths.path + path = (Gem.default_path + [Gem.paths.home]).uniq + assert_equal path, Gem.paths.path ensure ENV['GEM_HOME'] = orig_home ENV['GEM_PATH'] = orig_path @@ -1420,7 +1452,7 @@ class TestGem < Gem::TestCase Gem.detect_gemdeps - assert_equal %w!a-1 b-1 c-1!, loaded_spec_names + assert_equal add_bundler_full_name(%W(a-1 b-1 c-1)), loaded_spec_names end def test_auto_activation_of_detected_gemdeps_file @@ -1443,10 +1475,20 @@ class TestGem < Gem::TestCase ENV['RUBYGEMS_GEMDEPS'] = "-" - assert_equal [a,b,c], Gem.detect_gemdeps.sort_by { |s| s.name } + expected_specs = [a, b, (Gem::USE_BUNDLER_FOR_GEMDEPS || nil) && util_spec("bundler", Bundler::VERSION), c].compact + assert_equal expected_specs, Gem.detect_gemdeps.sort_by { |s| s.name } end LIB_PATH = File.expand_path "../../../lib".dup.untaint, __FILE__.dup.untaint + 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}" + + def add_bundler_full_name(names) + return names unless Gem::USE_BUNDLER_FOR_GEMDEPS + names << BUNDLER_FULL_NAME + names.sort! + names + end def test_looks_for_gemdeps_files_automatically_on_start util_clear_gems @@ -1466,7 +1508,8 @@ class TestGem < Gem::TestCase ENV['RUBYGEMS_GEMDEPS'] = "-" path = File.join @tempdir, "gem.deps.rb" - cmd = [Gem.ruby.dup.untaint, "-I#{LIB_PATH.untaint}", "-rrubygems"] + cmd = [Gem.ruby.dup.untaint, "-I#{LIB_PATH.untaint}", + "-I#{BUNDLER_LIB_PATH.untaint}", "-rrubygems"] if RUBY_VERSION < '1.9' cmd << "-e 'puts Gem.loaded_specs.values.map(&:full_name).sort'" cmd = cmd.join(' ') @@ -1508,7 +1551,8 @@ class TestGem < Gem::TestCase Dir.mkdir "sub1" path = File.join @tempdir, "gem.deps.rb" - cmd = [Gem.ruby.dup.untaint, "-Csub1", "-I#{LIB_PATH.untaint}", "-rrubygems"] + cmd = [Gem.ruby.dup.untaint, "-Csub1", "-I#{LIB_PATH.untaint}", + "-I#{BUNDLER_LIB_PATH.untaint}", "-rrubygems"] if RUBY_VERSION < '1.9' cmd << "-e 'puts Gem.loaded_specs.values.map(&:full_name).sort'" cmd = cmd.join(' ') @@ -1603,7 +1647,7 @@ class TestGem < Gem::TestCase Gem.use_gemdeps gem_deps_file - assert spec.activated? + assert_equal add_bundler_full_name(%W(a-1)), loaded_spec_names refute_nil Gem.gemdeps end @@ -1664,7 +1708,7 @@ class TestGem < Gem::TestCase Gem.use_gemdeps - assert spec.activated? + assert_equal add_bundler_full_name(%W(a-1)), loaded_spec_names ensure ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps end @@ -1706,11 +1750,25 @@ class TestGem < Gem::TestCase io.write 'gem "a"' end - expected = <<-EXPECTED + platform = Bundler::GemHelpers.generic_local_platform + if platform == Gem::Platform::RUBY + platform = '' + else + platform = " #{platform}" + end + 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 Unable to resolve dependency: user requested 'a (>= 0)' You may need to `gem install -g` to install missing gems - EXPECTED + EXPECTED + end assert_output nil, expected do Gem.use_gemdeps @@ -1735,7 +1793,7 @@ You may need to `gem install -g` to install missing gems Gem.use_gemdeps - assert spec.activated? + assert_equal add_bundler_full_name(%W(a-1)), loaded_spec_names ensure ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps end diff --git a/test/rubygems/test_gem_bundler_version_finder.rb b/test/rubygems/test_gem_bundler_version_finder.rb new file mode 100644 index 0000000000..fff52e8186 --- /dev/null +++ b/test/rubygems/test_gem_bundler_version_finder.rb @@ -0,0 +1,125 @@ +# frozen_string_literal: true +require 'rubygems/test_case' + +class TestGemBundlerVersionFinder < Gem::TestCase + def setup + @argv = ARGV.dup + @env = ENV.to_hash.clone + ENV.delete("BUNDLER_VERSION") + @dollar_0 = $0 + end + + def teardown + ARGV.replace @argv + ENV.replace @env + $0 = @dollar_0 + end + + def bvf + Gem::BundlerVersionFinder + end + + def test_bundler_version_defaults_to_nil + assert_nil bvf.bundler_version + end + + def test_bundler_version_with_env_var + ENV["BUNDLER_VERSION"] = "1.1.1.1" + assert_equal v("1.1.1.1"), bvf.bundler_version + end + + def test_bundler_version_with_bundle_update_bundler + ARGV.replace %w[update --bundler] + assert_nil bvf.bundler_version + $0 = "/foo/bar/bundle" + assert_nil bvf.bundler_version + ARGV.replace %w[update --bundler=1.1.1.1 gem_name] + assert_equal v("1.1.1.1"), bvf.bundler_version + ARGV.replace %w[update --bundler 1.1.1.1 gem_name] + assert_equal v("1.1.1.1"), bvf.bundler_version + ARGV.replace %w[update --bundler\ 1.1.1.1 gem_name] + assert_equal v("1.1.1.1"), bvf.bundler_version + ARGV.replace %w[update --bundler\ 1.1.1.2 --bundler --bundler 1.1.1.1 gem_name] + assert_equal v("1.1.1.1"), bvf.bundler_version + $0 = "other" + assert_nil bvf.bundler_version + end + + def test_bundler_version_with_lockfile + bvf.stub(:lockfile_contents, [nil, ""]) do + assert_nil bvf.bundler_version + end + bvf.stub(:lockfile_contents, [nil, "\n\nBUNDLED WITH\n 1.1.1.1\n"]) do + assert_equal v("1.1.1.1"), bvf.bundler_version + end + bvf.stub(:lockfile_contents, [nil, "\n\nBUNDLED WITH\n fjdkslfjdkslfjsldk\n"]) do + assert_nil bvf.bundler_version + end + end + + def test_bundler_version_with_reason + assert_nil bvf.bundler_version_with_reason + bvf.stub(:lockfile_contents, [nil, "\n\nBUNDLED WITH\n 1.1.1.1\n"]) do + assert_equal ["1.1.1.1", "your lockfile"], bvf.bundler_version_with_reason + + $0 = "bundle" + ARGV.replace %w[update --bundler] + assert_nil bvf.bundler_version_with_reason + ARGV.replace %w[update --bundler=1.1.1.2] + assert_equal ["1.1.1.2", "`bundle update --bundler`"], bvf.bundler_version_with_reason + + ENV["BUNDLER_VERSION"] = "1.1.1.3" + assert_equal ["1.1.1.3", "`$BUNDLER_VERSION`"], bvf.bundler_version_with_reason + end + end + + def test_compatible + assert bvf.compatible?(util_spec("foo")) + assert bvf.compatible?(util_spec("bundler", 1.1)) + + bvf.stub(:bundler_version, v("1.1.1.1")) do + assert bvf.compatible?(util_spec("foo")) + assert bvf.compatible?(util_spec("bundler", "1.1.1.1")) + assert bvf.compatible?(util_spec("bundler", "1.1.1.a")) + assert bvf.compatible?(util_spec("bundler", "1.999")) + refute bvf.compatible?(util_spec("bundler", "2.999")) + end + + bvf.stub(:bundler_version, v("2.1.1.1")) do + assert bvf.compatible?(util_spec("foo")) + assert bvf.compatible?(util_spec("bundler", "2.1.1.1")) + refute bvf.compatible?(util_spec("bundler", "2.1.1.a")) + refute bvf.compatible?(util_spec("bundler", "1.999")) + refute bvf.compatible?(util_spec("bundler", "2.999")) + end + end + + def test_filter + versions = %w[1 1.0 1.0.1.1 2.a 3 3.0] + specs = versions.map { |v| util_spec("bundler", v) } + + assert_equal %w[1 1.0 1.0.1.1 2.a 3 3.0], util_filter_specs(specs).map(&:version).map(&:to_s) + + bvf.stub(:bundler_version, v("2.1.1.1")) do + assert_empty util_filter_specs(specs).map(&:version).map(&:to_s) + end + bvf.stub(:bundler_version, v("1.1.1.1")) do + assert_equal %w[1 1.0 1.0.1.1], util_filter_specs(specs).map(&:version).map(&:to_s) + end + bvf.stub(:bundler_version, v("1")) do + assert_equal %w[1 1.0 1.0.1.1], util_filter_specs(specs).map(&:version).map(&:to_s) + end + bvf.stub(:bundler_version, v("2.a")) do + assert_equal %w[2.a], util_filter_specs(specs).map(&:version).map(&:to_s) + end + bvf.stub(:bundler_version, v("3")) do + assert_equal %w[3 3.0], util_filter_specs(specs).map(&:version).map(&:to_s) + end + end + + def util_filter_specs(specs) + specs = specs.dup + bvf.filter!(specs) + specs + end +end
\ No newline at end of file diff --git a/test/rubygems/test_gem_command.rb b/test/rubygems/test_gem_command.rb index 8100a34c25..913cd72aa0 100644 --- a/test/rubygems/test_gem_command.rb +++ b/test/rubygems/test_gem_command.rb @@ -170,7 +170,7 @@ class TestGemCommand < Gem::TestCase @cmd.add_option('-f', '--file FILE', 'File option') do |value, options| options[:help] = true end - @cmd.add_option('--silent', 'Silence rubygems output') do |value, options| + @cmd.add_option('--silent', 'Silence RubyGems output') do |value, options| options[:silent] = true end assert @cmd.handles?(['-x']) diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb index 703512ecba..08854f0bf1 100644 --- a/test/rubygems/test_gem_commands_build_command.rb +++ b/test/rubygems/test_gem_commands_build_command.rb @@ -1,3 +1,4 @@ + # frozen_string_literal: true require 'rubygems/test_case' require 'rubygems/commands/build_command' @@ -117,5 +118,30 @@ class TestGemCommandsBuildCommand < Gem::TestCase util_test_build_gem @gem, gemspec_file, false end -end + CERT_FILE = cert_path 'public3072' + SIGNING_KEY = key_path 'private3072' + + def test_build_signed_gem + trust_dir = Gem::Security.trust_dir + + spec = util_spec 'some_gem' do |s| + s.signing_key = SIGNING_KEY + s.cert_chain = [CERT_FILE] + end + + gemspec_file = File.join(@tempdir, spec.spec_name) + + File.open gemspec_file, 'w' do |gs| + gs.write spec.to_ruby + end + + util_test_build_gem spec, gemspec_file + + trust_dir.trust_cert OpenSSL::X509::Certificate.new(File.read(CERT_FILE)) + gem = Gem::Package.new(File.join(@tempdir, spec.file_name), + Gem::Security::HighSecurity) + assert gem.verify + end + +end diff --git a/test/rubygems/test_gem_commands_cert_command.rb b/test/rubygems/test_gem_commands_cert_command.rb index a9a78336aa..2d38a57bc4 100644 --- a/test/rubygems/test_gem_commands_cert_command.rb +++ b/test/rubygems/test_gem_commands_cert_command.rb @@ -130,6 +130,70 @@ Added '/CN=alternate/DC=example' assert_path_exists File.join(@tempdir, 'gem-public_cert.pem') end + def test_execute_build_bad_email_address + passphrase = 'Foo bar' + email = "nobody@" + + @cmd.handle_options %W[--build #{email}] + + @build_ui = Gem::MockGemUi.new "#{passphrase}\n#{passphrase}" + + use_ui @build_ui do + + e = assert_raises Gem::CommandLineError do + @cmd.execute + end + + assert_equal "Invalid email address #{email}", + e.message + + refute_path_exists File.join(@tempdir, 'gem-private_key.pem') + refute_path_exists File.join(@tempdir, 'gem-public_cert.pem') + end + end + + def test_execute_build_expiration_days + passphrase = 'Foo bar' + + @cmd.handle_options %W[ + --build nobody@example.com + --days 26 + ] + + @build_ui = Gem::MockGemUi.new "#{passphrase}\n#{passphrase}" + + use_ui @build_ui do + @cmd.execute + end + + output = @build_ui.output.squeeze("\n").split "\n" + + assert_equal "Passphrase for your Private Key: ", + output.shift + assert_equal "Please repeat the passphrase for your Private Key: ", + output.shift + assert_equal "Certificate: #{File.join @tempdir, 'gem-public_cert.pem'}", + output.shift + assert_equal "Private Key: #{File.join @tempdir, 'gem-private_key.pem'}", + output.shift + + assert_equal "Don't forget to move the key file to somewhere private!", + output.shift + + assert_empty output + assert_empty @build_ui.error + + assert_path_exists File.join(@tempdir, 'gem-private_key.pem') + assert_path_exists File.join(@tempdir, 'gem-public_cert.pem') + + pem = File.read("#{@tempdir}/gem-public_cert.pem") + cert = OpenSSL::X509::Certificate.new(pem) + + test = (cert.not_after - cert.not_before).to_i / (24 * 60 * 60) + assert_equal(test, 26) + + end + def test_execute_build_bad_passphrase_confirmation passphrase = 'Foo bar' passphrase_confirmation = 'Fu bar' diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index 13b9a7bbad..dd86a85038 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -96,6 +96,39 @@ class TestGemCommandsInstallCommand < Gem::TestCase assert_match "1 gem installed", @ui.output end + def test_execute_local_transitive_prerelease + specs = spec_fetcher do |fetcher| + fetcher.download 'a', 2, 'b' => "2.a", 'c' => '3' + fetcher.download 'b', '2.a' + fetcher.download 'c', '3' + end + + @cmd.options[:domain] = :local + + FileUtils.mv specs['a-2'].cache_file, @tempdir + FileUtils.mv specs['b-2.a'].cache_file, @tempdir + FileUtils.mv specs['c-3'].cache_file, @tempdir + + @cmd.options[:args] = %w[a] + + use_ui @ui do + orig_dir = Dir.pwd + begin + Dir.chdir @tempdir + FileUtils.rm_r [@gemhome, "gems"] + assert_raises Gem::MockGemUi::SystemExitException, @ui.error do + @cmd.execute + end + ensure + Dir.chdir orig_dir + end + end + + assert_equal %w[a-2 b-2.a c-3], @cmd.installed_specs.map { |spec| spec.full_name }.sort + + assert_match "3 gems installed", @ui.output + end + def test_execute_no_user_install skip 'skipped on MS Windows (chmod has no effect)' if win_platform? @@ -588,7 +621,7 @@ ERROR: Possible alternatives: non_existent_with_hint done_installing = true end - spec = quick_spec 'a', 2 + spec = util_spec 'a', 2 util_build_gem spec @@ -616,7 +649,7 @@ ERROR: Possible alternatives: non_existent_with_hint end def test_install_gem_ignore_dependencies_specific_file - spec = quick_spec 'a', 2 + spec = util_spec 'a', 2 util_build_gem spec diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb index dfec78b848..d2f8b10bb8 100644 --- a/test/rubygems/test_gem_commands_pristine_command.rb +++ b/test/rubygems/test_gem_commands_pristine_command.rb @@ -145,7 +145,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase out = @ui.output.split "\n" assert_equal 'Restoring gems to pristine condition...', out.shift - assert_equal 'Building native extensions. This could take a while...', + assert_equal 'Building native extensions. This could take a while...', out.shift assert_equal "Restored #{a.full_name}", out.shift assert_empty out, out.inspect diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb index 469223c6c0..5471ecadcc 100644 --- a/test/rubygems/test_gem_commands_query_command.rb +++ b/test/rubygems/test_gem_commands_query_command.rb @@ -637,6 +637,25 @@ EOF assert_equal expected, @ui.output end + def test_execute_show_default_gems_with_platform + a1 = new_default_spec 'a', 1 + a1.platform = 'java' + install_default_specs a1 + + use_ui @ui do + @cmd.execute + end + + expected = <<-EOF + +*** LOCAL GEMS *** + +a (default: 1 java) +EOF + + assert_equal expected, @ui.output + end + def test_execute_default_details spec_fetcher do |fetcher| fetcher.spec 'a', 2 diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb index ae3d0500dc..22c831fa5e 100644 --- a/test/rubygems/test_gem_commands_setup_command.rb +++ b/test/rubygems/test_gem_commands_setup_command.rb @@ -20,6 +20,13 @@ class TestGemCommandsSetupCommand < Gem::TestCase open 'lib/rubygems.rb', 'w' do |io| io.puts '# rubygems.rb' end open 'lib/rubygems/test_case.rb', 'w' do |io| io.puts '# test_case.rb' end open 'lib/rubygems/ssl_certs/rubygems.org/foo.pem', 'w' do |io| io.puts 'PEM' end + + FileUtils.mkdir_p 'bundler/exe' + FileUtils.mkdir_p 'bundler/lib/bundler' + + open 'bundler/exe/bundle', 'w' do |io| io.puts '# bundle' end + open 'bundler/lib/bundler.rb', 'w' do |io| io.puts '# bundler.rb' end + open 'bundler/lib/bundler/b.rb', 'w' do |io| io.puts '# b.rb' end end def test_pem_files_in @@ -40,12 +47,18 @@ class TestGemCommandsSetupCommand < Gem::TestCase assert_path_exists File.join(dir, 'rubygems.rb') assert_path_exists File.join(dir, 'rubygems/ssl_certs/rubygems.org/foo.pem') + + if Gem::USE_BUNDLER_FOR_GEMDEPS + assert_path_exists File.join(dir, 'bundler.rb') + assert_path_exists File.join(dir, 'bundler/b.rb') + end end end def test_remove_old_lib_files lib = File.join @install_dir, 'lib' lib_rubygems = File.join lib, 'rubygems' + lib_bundler = File.join lib, 'bundler' lib_rubygems_defaults = File.join lib_rubygems, 'defaults' securerandom_rb = File.join lib, 'securerandom.rb' @@ -55,13 +68,16 @@ class TestGemCommandsSetupCommand < Gem::TestCase old_builder_rb = File.join lib_rubygems, 'builder.rb' old_format_rb = File.join lib_rubygems, 'format.rb' + old_bundler_c_rb = File.join lib_bundler, 'c.rb' FileUtils.mkdir_p lib_rubygems_defaults + FileUtils.mkdir_p lib_bundler 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 old_bundler_c_rb, 'w' do |io| io.puts '# c.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 @@ -70,6 +86,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase refute_path_exists old_builder_rb refute_path_exists old_format_rb + refute_path_exists old_bundler_c_rb if Gem::USE_BUNDLER_FOR_GEMDEPS assert_path_exists securerandom_rb assert_path_exists engine_defaults_rb diff --git a/test/rubygems/test_gem_commands_signin_command.rb b/test/rubygems/test_gem_commands_signin_command.rb new file mode 100644 index 0000000000..ec40b71ada --- /dev/null +++ b/test/rubygems/test_gem_commands_signin_command.rb @@ -0,0 +1,95 @@ +# frozen_string_literal: true +require 'rubygems/test_case' +require 'rubygems/commands/signin_command' +require 'rubygems/installer' + +class TestGemCommandsSigninCommand < Gem::TestCase + + def setup + super + + Gem.configuration.rubygems_api_key = nil + Gem.configuration.api_keys.clear + + @cmd = Gem::Commands::SigninCommand.new + end + + def teardown + credentials_path = Gem.configuration.credentials_path + File.delete(credentials_path) if File.exist?(credentials_path) + super + end + + def test_execute_when_not_already_signed_in + sign_in_ui = util_capture() { @cmd.execute } + assert_match %r{Signed in.}, sign_in_ui.output + end + + def test_execute_when_already_signed_in_with_same_host + host = 'http://some-gemcutter-compatible-host.org' + sign_in_ui = util_capture(nil, host) { @cmd.execute } + old_credentials = YAML.load_file Gem.configuration.credentials_path + + sign_in_ui = util_capture(nil, host) { @cmd.execute } + new_credentials = YAML.load_file Gem.configuration.credentials_path + + assert_equal old_credentials[host], new_credentials[host] + end + + def test_execute_when_already_signed_in_with_different_host + api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf04045xxxx' + sign_in_ui = util_capture(nil, nil, api_key) { @cmd.execute } + host = 'http://some-gemcutter-compatible-host.org' + sign_in_ui = util_capture(nil, host, api_key) { @cmd.execute } + credentials = YAML.load_file Gem.configuration.credentials_path + + assert_equal credentials[:rubygems_api_key], api_key + + assert_equal credentials[host], nil + end + + def test_execute_with_host_supplied + host = 'http://some-gemcutter-compatible-host.org' + + sign_in_ui = util_capture(nil, host) { @cmd.execute } + assert_match %r{Enter your #{host} credentials.}, sign_in_ui.output + assert_match %r{Signed in.}, sign_in_ui.output + + api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' + credentials = YAML.load_file Gem.configuration.credentials_path + assert_equal api_key, credentials[host] + end + + def test_execute_with_valid_creds_set_for_default_host + util_capture {@cmd.execute} + + api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' + credentials = YAML.load_file Gem.configuration.credentials_path + + assert_equal api_key, credentials[:rubygems_api_key] + end + + # Utility method to capture IO/UI within the block passed + + def util_capture ui_stub = nil, host = nil, api_key = nil + api_key ||= 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' + response = [api_key, 200, 'OK'] + email = 'you@example.com' + password = 'secret' + fetcher = Gem::FakeFetcher.new + + # Set the expected response for the Web-API supplied + ENV['RUBYGEMS_HOST'] = host || Gem::DEFAULT_HOST + data_key = "#{ENV['RUBYGEMS_HOST']}/api/v1/api_key" + fetcher.data[data_key] = response + Gem::RemoteFetcher.fetcher = fetcher + + sign_in_ui = ui_stub || Gem::MockGemUi.new("#{email}\n#{password}\n") + + use_ui sign_in_ui do + yield + end + + sign_in_ui + end +end diff --git a/test/rubygems/test_gem_commands_signout_command.rb b/test/rubygems/test_gem_commands_signout_command.rb new file mode 100644 index 0000000000..814b55cf4f --- /dev/null +++ b/test/rubygems/test_gem_commands_signout_command.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'rubygems/test_case' +require 'rubygems/commands/signout_command' +require 'rubygems/installer' + +class TestGemCommandsSignoutCommand < Gem::TestCase + + def setup + super + @cmd = Gem::Commands::SignoutCommand.new + end + + def teardown + super + File.delete Gem.configuration.credentials_path if File.exist?(Gem.configuration.credentials_path) + end + + def test_execute_when_user_is_signed_in + FileUtils.mkdir_p File.dirname(Gem.configuration.credentials_path) + FileUtils::touch Gem.configuration.credentials_path + + @sign_out_ui = Gem::MockGemUi.new + use_ui(@sign_out_ui) { @cmd.execute } + + assert_match %r{You have successfully signed out}, @sign_out_ui.output + assert_equal false, File.exist?(Gem.configuration.credentials_path) + end + + def test_execute_when_not_signed_in # i.e. no credential file created + @sign_out_ui = Gem::MockGemUi.new + use_ui(@sign_out_ui) { @cmd.execute } + + assert_match %r{You are not currently signed in}, @sign_out_ui.error + end + +end diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb index e64bc77123..cca135afde 100644 --- a/test/rubygems/test_gem_commands_uninstall_command.rb +++ b/test/rubygems/test_gem_commands_uninstall_command.rb @@ -279,5 +279,17 @@ WARNING: Use your OS package manager to uninstall vendor gems RbConfig::CONFIG['vendordir'] = orig_vendordir end + def test_execute_with_gem_not_installed + @cmd.options[:args] = ['d'] + + use_ui ui do + @cmd.execute + end + + output = ui.output.split "\n" + + assert_equal output.first, "Gem 'd' is not installed" + end + end diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb index 4a9f496cbe..245d05727d 100644 --- a/test/rubygems/test_gem_commands_update_command.rb +++ b/test/rubygems/test_gem_commands_update_command.rb @@ -107,7 +107,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase end out = @ui.output.split "\n" - assert_equal "Latest version currently installed. Aborting.", out.shift + assert_equal "Latest version already installed. Done.", out.shift assert_empty out end diff --git a/test/rubygems/test_gem_commands_which_command.rb b/test/rubygems/test_gem_commands_which_command.rb index c55bb370cd..0c2b177273 100644 --- a/test/rubygems/test_gem_commands_which_command.rb +++ b/test/rubygems/test_gem_commands_which_command.rb @@ -33,7 +33,7 @@ class TestGemCommandsWhichCommand < Gem::TestCase end assert_equal '', @ui.output - assert_match %r%Can.t find ruby library file or shared library directory\n%, + assert_match %r%Can.t find Ruby library file or shared library directory\n%, @ui.error end @@ -51,7 +51,7 @@ class TestGemCommandsWhichCommand < Gem::TestCase end assert_equal "#{@foo_bar.full_gem_path}/lib/foo_bar.rb\n", @ui.output - assert_match %r%Can.t find ruby library file or shared library missinglib\n%, + assert_match %r%Can.t find Ruby library file or shared library missinglib\n%, @ui.error end @@ -65,7 +65,7 @@ class TestGemCommandsWhichCommand < Gem::TestCase end assert_equal '', @ui.output - assert_match %r%Can.t find ruby library file or shared library missinglib\n%, + assert_match %r%Can.t find Ruby library file or shared library missinglib\n%, @ui.error end diff --git a/test/rubygems/test_gem_dependency.rb b/test/rubygems/test_gem_dependency.rb index 0d501f567f..d7eec3c090 100644 --- a/test/rubygems/test_gem_dependency.rb +++ b/test/rubygems/test_gem_dependency.rb @@ -338,6 +338,34 @@ class TestGemDependency < Gem::TestCase assert_match "Could not find 'a' (= 2.0) - did find: [a-1.0]", e.message end + def test_to_specs_respects_bundler_version + b = util_spec 'bundler', '2.0.0.pre.1' + b_1 = util_spec 'bundler', '1' + install_specs b, b_1 + + b_file = File.join b.gem_dir, 'lib', 'bundler', 'setup.rb' + + write_file b_file do |io| + io.puts '# setup.rb' + end + + dep = Gem::Dependency.new "bundler", ">= 0.a" + + assert_equal [b, b_1], dep.to_specs + + Gem::BundlerVersionFinder.stub(:bundler_version_with_reason, ["3.5", "reason"]) do + e = assert_raises Gem::MissingSpecVersionError do + dep.to_specs + end + + assert_match "Could not find 'bundler' (3.5) required by reason.\nTo update to the lastest version installed on your system, run `bundle update --bundler`.\nTo install the missing version, run `gem install bundler:3.5`\n", e.message + end + + Gem::BundlerVersionFinder.stub(:bundler_version_with_reason, ["2.0.0.pre.1", "reason"]) do + assert_equal [b], dep.to_specs + end + end + def test_to_specs_indicates_total_gem_set_size a = util_spec 'a', '1.0' install_specs a diff --git a/test/rubygems/test_gem_ext_builder.rb b/test/rubygems/test_gem_ext_builder.rb index 370ebf8d14..d142ef28da 100644 --- a/test/rubygems/test_gem_ext_builder.rb +++ b/test/rubygems/test_gem_ext_builder.rb @@ -239,7 +239,7 @@ install: assert_match(/\AERROR: Failed to build gem native extension.$/, e.message) - assert_equal "Building native extensions. This could take a while...\n", + assert_equal "Building native extensions. This could take a while...\n", @ui.output assert_equal '', @ui.error @@ -272,7 +272,7 @@ install: assert_match(/^\s*No builder for extension ''$/, e.message) - assert_equal "Building native extensions. This could take a while...\n", + assert_equal "Building native extensions. This could take a while...\n", @ui.output assert_equal '', @ui.error diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb index e25259f4d1..e2d546307d 100644 --- a/test/rubygems/test_gem_install_update_options.rb +++ b/test/rubygems/test_gem_install_update_options.rb @@ -121,9 +121,10 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase def test_security_policy_unknown @cmd.add_install_update_options - assert_raises OptionParser::InvalidArgument do + e = assert_raises OptionParser::InvalidArgument do @cmd.handle_options %w[-P UnknownSecurity] end + assert_includes e.message, "UnknownSecurity" end def test_user_install_enabled diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index dd049214fb..39095c7dee 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -87,7 +87,7 @@ end end util_make_exec - @installer.gem_dir = util_gem_dir @spec + @installer.gem_dir = @spec.gem_dir @installer.wrappers = true @installer.generate_bin @@ -304,7 +304,7 @@ gem 'other', version def test_extract_files @installer.extract_files - assert_path_exists File.join util_gem_dir, 'bin/executable' + assert_path_exists File.join @spec.gem_dir, 'bin/executable' end def test_generate_bin_bindir @@ -314,12 +314,12 @@ gem 'other', version @spec.bindir = '.' exec_file = @installer.formatted_program_filename 'executable' - exec_path = File.join util_gem_dir(@spec), exec_file + exec_path = File.join @spec.gem_dir, exec_file File.open exec_path, 'w' do |f| f.puts '#!/usr/bin/ruby' end - @installer.gem_dir = util_gem_dir + @installer.gem_dir = @spec.gem_dir @installer.generate_bin @@ -355,7 +355,7 @@ gem 'other', version def test_generate_bin_script @installer.wrappers = true util_make_exec - @installer.gem_dir = util_gem_dir + @installer.gem_dir = @spec.gem_dir @installer.generate_bin assert File.directory? util_inst_bindir @@ -371,7 +371,7 @@ gem 'other', version @installer.format_executable = true @installer.wrappers = true util_make_exec - @installer.gem_dir = util_gem_dir + @installer.gem_dir = @spec.gem_dir Gem::Installer.exec_format = 'foo-%s-bar' @installer.generate_bin @@ -385,7 +385,7 @@ gem 'other', version def test_generate_bin_script_format_disabled @installer.wrappers = true util_make_exec - @installer.gem_dir = util_gem_dir + @installer.gem_dir = @spec.gem_dir Gem::Installer.exec_format = 'foo-%s-bar' @installer.generate_bin @@ -474,10 +474,10 @@ gem 'other', version def test_generate_bin_script_wrappers @installer.wrappers = true util_make_exec - @installer.gem_dir = util_gem_dir + @installer.gem_dir = @spec.gem_dir installed_exec = File.join(util_inst_bindir, 'executable') - real_exec = File.join util_gem_dir, 'bin', 'executable' + real_exec = File.join @spec.gem_dir, 'bin', 'executable' # fake --no-wrappers for previous install unless Gem.win_platform? then @@ -501,13 +501,13 @@ gem 'other', version @installer.wrappers = false util_make_exec - @installer.gem_dir = util_gem_dir + @installer.gem_dir = @spec.gem_dir @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) installed_exec = File.join util_inst_bindir, 'executable' assert_equal true, File.symlink?(installed_exec) - assert_equal(File.join(util_gem_dir, 'bin', 'executable'), + assert_equal(File.join(@spec.gem_dir, 'bin', 'executable'), File.readlink(installed_exec)) end @@ -523,7 +523,7 @@ gem 'other', version def test_generate_bin_symlink_no_perms @installer.wrappers = false util_make_exec - @installer.gem_dir = util_gem_dir + @installer.gem_dir = @spec.gem_dir Dir.mkdir util_inst_bindir @@ -545,11 +545,11 @@ gem 'other', version @installer.wrappers = false util_make_exec - @installer.gem_dir = util_gem_dir + @installer.gem_dir = @spec.gem_dir @installer.generate_bin installed_exec = File.join(util_inst_bindir, 'executable') - assert_equal(File.join(util_gem_dir, 'bin', 'executable'), + assert_equal(File.join(@spec.gem_dir, 'bin', 'executable'), File.readlink(installed_exec)) @spec = Gem::Specification.new do |s| @@ -562,7 +562,7 @@ gem 'other', version end util_make_exec - @installer.gem_dir = util_gem_dir @spec + @installer.gem_dir = @spec.gem_dir @installer.generate_bin installed_exec = File.join(util_inst_bindir, 'executable') assert_equal(@spec.bin_file('executable'), @@ -575,11 +575,11 @@ gem 'other', version @installer.wrappers = false util_make_exec - @installer.gem_dir = util_gem_dir + @installer.gem_dir = @spec.gem_dir @installer.generate_bin installed_exec = File.join(util_inst_bindir, 'executable') - assert_equal(File.join(util_gem_dir, 'bin', 'executable'), + assert_equal(File.join(@spec.gem_dir, 'bin', 'executable'), File.readlink(installed_exec)) spec = Gem::Specification.new do |s| @@ -595,12 +595,12 @@ gem 'other', version one = @spec.dup one.version = 1 @installer = Gem::Installer.for_spec spec - @installer.gem_dir = util_gem_dir one + @installer.gem_dir = one.gem_dir @installer.generate_bin installed_exec = File.join util_inst_bindir, 'executable' - expected = File.join util_gem_dir, 'bin', 'executable' + expected = File.join @spec.gem_dir, 'bin', 'executable' assert_equal(expected, File.readlink(installed_exec), "Ensure symlink not moved") @@ -611,7 +611,7 @@ gem 'other', version @installer.wrappers = true util_make_exec - @installer.gem_dir = util_gem_dir + @installer.gem_dir = @spec.gem_dir @installer.generate_bin @@ -630,7 +630,7 @@ gem 'other', version util_installer @spec, @gemhome @installer.wrappers = false - @installer.gem_dir = util_gem_dir + @installer.gem_dir = @spec.gem_dir @installer.generate_bin @@ -648,7 +648,7 @@ gem 'other', version File.const_set(:ALT_SEPARATOR, '\\') @installer.wrappers = false util_make_exec - @installer.gem_dir = util_gem_dir + @installer.gem_dir = @spec.gem_dir use_ui @ui do @installer.generate_bin @@ -1421,10 +1421,11 @@ gem 'other', version def test_pre_install_checks_ruby_version use_ui @ui do installer = Gem::Installer.at old_ruby_required - e = assert_raises Gem::InstallError do + e = assert_raises Gem::RuntimeRequirementNotMetError do installer.pre_install_checks end - assert_equal 'old_ruby_required requires Ruby version = 1.4.6.', + rv = Gem.ruby_api_version + assert_equal "old_ruby_required requires Ruby version = 1.4.6. The current ruby version is #{rv}.", e.message end end @@ -1440,10 +1441,11 @@ gem 'other', version use_ui @ui do @installer = Gem::Installer.at gem - e = assert_raises Gem::InstallError do + e = assert_raises Gem::RuntimeRequirementNotMetError do @installer.pre_install_checks end - assert_equal 'old_rubygems_required requires RubyGems version < 0. ' + + rgv = Gem::VERSION + assert_equal "old_rubygems_required requires RubyGems version < 0. The current RubyGems version is #{rgv}. " + "Try 'gem update --system' to update RubyGems itself.", e.message end end @@ -1739,7 +1741,7 @@ gem 'other', version @installer.wrappers = true @installer.options[:install_as_default] = true - @installer.gem_dir = util_gem_dir @spec + @installer.gem_dir = @spec.gem_dir @installer.generate_bin use_ui @ui do diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb index 9d47f0dea4..cec1981c4c 100644 --- a/test/rubygems/test_gem_package.rb +++ b/test/rubygems/test_gem_package.rb @@ -1,4 +1,4 @@ -# coding: UTF-8 +# coding: utf-8 # frozen_string_literal: true require 'rubygems/package/tar_test_case' @@ -84,7 +84,7 @@ class TestGemPackage < Gem::Package::TarTestCase io.write spec.to_yaml end - metadata_sha1 = Digest::SHA1.hexdigest s.string + metadata_sha256 = Digest::SHA256.hexdigest s.string metadata_sha512 = Digest::SHA512.hexdigest s.string expected = { @@ -95,9 +95,9 @@ class TestGemPackage < Gem::Package::TarTestCase } if defined?(OpenSSL::Digest) then - expected['SHA1'] = { - 'metadata.gz' => metadata_sha1, - 'data.tar.gz' => Digest::SHA1.hexdigest(tar), + expected['SHA256'] = { + 'metadata.gz' => metadata_sha256, + 'data.tar.gz' => Digest::SHA256.hexdigest(tar), } end diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index fbb7d89019..ee5ac77717 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -555,7 +555,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== nil end - assert_equal nil, fetcher.fetch_path(@uri + 'foo.gz', Time.at(0)) + assert_nil fetcher.fetch_path(@uri + 'foo.gz', Time.at(0)) end def test_fetch_path_io_error @@ -621,7 +621,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== nil end - assert_equal nil, fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0)) + assert_nil fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0)) end def test_implicit_no_proxy diff --git a/test/rubygems/test_gem_request_set_gem_dependency_api.rb b/test/rubygems/test_gem_request_set_gem_dependency_api.rb index 509d49890d..e8bb1d4a6d 100644 --- a/test/rubygems/test_gem_request_set_gem_dependency_api.rb +++ b/test/rubygems/test_gem_request_set_gem_dependency_api.rb @@ -753,7 +753,7 @@ end @gda.ruby RUBY_VERSION, :engine => 'jruby', :engine_version => '1.7.4' end - assert_equal 'Your ruby engine is ruby, but your gem.deps.rb requires jruby', + assert_equal 'Your Ruby engine is ruby, but your gem.deps.rb requires jruby', e.message end end @@ -764,7 +764,7 @@ end @gda.ruby RUBY_VERSION, :engine => 'jruby', :engine_version => '1.7.4' end - assert_equal 'Your ruby engine version is jruby 1.7.6, but your gem.deps.rb requires jruby 1.7.4', + assert_equal 'Your Ruby engine version is jruby 1.7.6, but your gem.deps.rb requires jruby 1.7.4', e.message end end @@ -774,7 +774,7 @@ end @gda.ruby RUBY_VERSION, :engine => 'jruby' end - assert_equal 'you must specify engine_version along with the ruby engine', + assert_equal 'You must specify engine_version along with the Ruby engine', e.message end diff --git a/test/rubygems/test_gem_requirement.rb b/test/rubygems/test_gem_requirement.rb index c110009840..ea354f7b1d 100644 --- a/test/rubygems/test_gem_requirement.rb +++ b/test/rubygems/test_gem_requirement.rb @@ -30,6 +30,12 @@ class TestGemRequirement < Gem::TestCase assert_requirement_equal "= 2", v(2) end + def test_create + assert_equal req("= 1"), Gem::Requirement.create("= 1") + assert_equal req(">= 1.2", "<= 1.3"), Gem::Requirement.create([">= 1.2", "<= 1.3"]) + assert_equal req(">= 1.2", "<= 1.3"), Gem::Requirement.create(">= 1.2", "<= 1.3") + end + def test_empty_requirements_is_none r = Gem::Requirement.new assert_equal true, r.none? diff --git a/test/rubygems/test_gem_resolver.rb b/test/rubygems/test_gem_resolver.rb index e95a37162d..417f0580f7 100644 --- a/test/rubygems/test_gem_resolver.rb +++ b/test/rubygems/test_gem_resolver.rb @@ -683,6 +683,32 @@ class TestGemResolver < Gem::TestCase assert_resolves_to [b1, c1, d2], r end + def test_sorts_by_source_then_version + sourceA = Gem::Source.new 'http://example.com/a' + sourceB = Gem::Source.new 'http://example.com/b' + sourceC = Gem::Source.new 'http://example.com/c' + + spec_A_1 = new_spec 'some-dep', '0.0.1' + spec_A_2 = new_spec 'some-dep', '1.0.0' + spec_B_1 = new_spec 'some-dep', '0.0.1' + spec_B_2 = new_spec 'some-dep', '0.0.2' + spec_C_1 = new_spec 'some-dep', '0.1.0' + + set = StaticSet.new [ + Gem::Resolver::SpecSpecification.new(nil, spec_B_1, sourceB), + Gem::Resolver::SpecSpecification.new(nil, spec_B_2, sourceB), + Gem::Resolver::SpecSpecification.new(nil, spec_C_1, sourceC), + Gem::Resolver::SpecSpecification.new(nil, spec_A_2, sourceA), + Gem::Resolver::SpecSpecification.new(nil, spec_A_1, sourceA), + ] + + dependency = make_dep 'some-dep', '> 0' + + resolver = Gem::Resolver.new [dependency], set + + assert_resolves_to [spec_B_2], resolver + end + def test_select_local_platforms r = Gem::Resolver.new nil, nil diff --git a/test/rubygems/test_gem_resolver_conflict.rb b/test/rubygems/test_gem_resolver_conflict.rb index 56f048d91b..d4b3455570 100644 --- a/test/rubygems/test_gem_resolver_conflict.rb +++ b/test/rubygems/test_gem_resolver_conflict.rb @@ -15,7 +15,7 @@ class TestGemResolverConflict < Gem::TestCase dep = Gem::Resolver::DependencyRequest.new dep('net-ssh', '>= 2.0.13'), nil - spec = quick_spec 'net-ssh', '2.2.2' + spec = util_spec 'net-ssh', '2.2.2' active = Gem::Resolver::ActivationRequest.new spec, dep diff --git a/test/rubygems/test_gem_security.rb b/test/rubygems/test_gem_security.rb index acd83f4dca..47010e088c 100644 --- a/test/rubygems/test_gem_security.rb +++ b/test/rubygems/test_gem_security.rb @@ -61,6 +61,7 @@ class TestGemSecurity < Gem::TestCase cert = @SEC.create_cert_self_signed subject, PRIVATE_KEY, 60 assert_equal '/CN=nobody/DC=example', cert.issuer.to_s + assert_equal "sha256WithRSAEncryption", cert.signature_algorithm end def test_class_create_cert_email @@ -120,6 +121,7 @@ class TestGemSecurity < Gem::TestCase end def test_class_re_sign + assert_equal "sha1WithRSAEncryption", EXPIRED_CERT.signature_algorithm re_signed = Gem::Security.re_sign EXPIRED_CERT, PRIVATE_KEY, 60 assert_in_delta Time.now, re_signed.not_before, 10 @@ -127,6 +129,7 @@ class TestGemSecurity < Gem::TestCase assert_equal EXPIRED_CERT.serial + 1, re_signed.serial assert re_signed.verify PUBLIC_KEY + assert_equal "sha256WithRSAEncryption", re_signed.signature_algorithm end def test_class_re_sign_not_self_signed @@ -218,6 +221,8 @@ class TestGemSecurity < Gem::TestCase assert_in_delta Time.now, signed.not_before, 10 assert_in_delta Time.now + 60, signed.not_after, 10 + assert_equal "sha256WithRSAEncryption", signed.signature_algorithm + assert_equal 5, signed.extensions.length, signed.extensions.map { |e| e.to_a.first } diff --git a/test/rubygems/test_gem_security_policy.rb b/test/rubygems/test_gem_security_policy.rb index bee0973f64..4108551dca 100644 --- a/test/rubygems/test_gem_security_policy.rb +++ b/test/rubygems/test_gem_security_policy.rb @@ -1,4 +1,4 @@ -# coding: UTF-8 +# coding: utf-8 # frozen_string_literal: true require 'rubygems/test_case' @@ -34,7 +34,7 @@ class TestGemSecurityPolicy < Gem::TestCase s.files = %w[lib/code.rb] end - @sha1 = OpenSSL::Digest::SHA1 + @digest = Gem::Security::DIGEST_ALGORITHM @trust_dir = Gem::Security.trust_dir.dir # HACK use the object @no = Gem::Security::NoSecurity @@ -69,7 +69,7 @@ class TestGemSecurityPolicy < Gem::TestCase signature = sign data - assert @almost_no.check_data(PUBLIC_KEY, @sha1, signature, data) + assert @almost_no.check_data(PUBLIC_KEY, @digest, signature, data) end def test_check_data_invalid @@ -80,7 +80,7 @@ class TestGemSecurityPolicy < Gem::TestCase invalid = digest 'hello!' e = assert_raises Gem::Security::Exception do - @almost_no.check_data PUBLIC_KEY, @sha1, signature, invalid + @almost_no.check_data PUBLIC_KEY, @digest, signature, invalid end assert_equal 'invalid signature', e.message @@ -238,18 +238,18 @@ class TestGemSecurityPolicy < Gem::TestCase def test_check_trust Gem::Security.trust_dir.trust_cert PUBLIC_CERT - assert @high.check_trust [PUBLIC_CERT], @sha1, @trust_dir + assert @high.check_trust [PUBLIC_CERT], @digest, @trust_dir end def test_check_trust_child Gem::Security.trust_dir.trust_cert PUBLIC_CERT - assert @high.check_trust [PUBLIC_CERT, CHILD_CERT], @sha1, @trust_dir + assert @high.check_trust [PUBLIC_CERT, CHILD_CERT], @digest, @trust_dir end def test_check_trust_empty_chain e = assert_raises Gem::Security::Exception do - @chain.check_trust [], @sha1, @trust_dir + @chain.check_trust [], @digest, @trust_dir end assert_equal 'missing root certificate', e.message @@ -259,7 +259,7 @@ class TestGemSecurityPolicy < Gem::TestCase Gem::Security.trust_dir.trust_cert PUBLIC_CERT e = assert_raises Gem::Security::Exception do - @high.check_trust [WRONG_KEY_CERT], @sha1, @trust_dir + @high.check_trust [WRONG_KEY_CERT], @digest, @trust_dir end assert_equal "trusted root certificate #{PUBLIC_CERT.subject} checksum " + @@ -268,7 +268,7 @@ class TestGemSecurityPolicy < Gem::TestCase def test_check_trust_no_chain e = assert_raises Gem::Security::Exception do - @chain.check_trust nil, @sha1, @trust_dir + @chain.check_trust nil, @digest, @trust_dir end assert_equal 'missing signing chain', e.message @@ -276,7 +276,7 @@ class TestGemSecurityPolicy < Gem::TestCase def test_check_trust_no_trust e = assert_raises Gem::Security::Exception do - @high.check_trust [PUBLIC_CERT], @sha1, @trust_dir + @high.check_trust [PUBLIC_CERT], @digest, @trust_dir end assert_equal "root cert #{PUBLIC_CERT.subject} is not trusted", e.message @@ -284,7 +284,7 @@ class TestGemSecurityPolicy < Gem::TestCase def test_check_trust_no_trust_child e = assert_raises Gem::Security::Exception do - @high.check_trust [PUBLIC_CERT, CHILD_CERT], @sha1, @trust_dir + @high.check_trust [PUBLIC_CERT, CHILD_CERT], @digest, @trust_dir end assert_equal "root cert #{PUBLIC_CERT.subject} is not trusted " + @@ -370,7 +370,7 @@ class TestGemSecurityPolicy < Gem::TestCase data = digest 'goodbye' - signatures[1] = PRIVATE_KEY.sign @sha1.new, data.digest + signatures[1] = PRIVATE_KEY.sign @digest.new, data.digest e = assert_raises Gem::Security::Exception do @almost_no.verify [PUBLIC_CERT], nil, digests, signatures @@ -453,17 +453,17 @@ class TestGemSecurityPolicy < Gem::TestCase metadata_gz = Gem.gzip @spec.to_yaml package = Gem::Package.new 'nonexistent.gem' - package.checksums['SHA1'] = {} + package.checksums[Gem::Security::DIGEST_NAME] = {} s = StringIO.new metadata_gz def s.full_name() 'metadata.gz' end digests = package.digest s - metadata_gz_digest = digests['SHA1']['metadata.gz'] + metadata_gz_digest = digests[Gem::Security::DIGEST_NAME]['metadata.gz'] signatures = {} signatures['metadata.gz'] = - PRIVATE_KEY.sign @sha1.new, metadata_gz_digest.digest + PRIVATE_KEY.sign @digest.new, metadata_gz_digest.digest assert @high.verify_signatures @spec, digests, signatures end @@ -476,19 +476,19 @@ class TestGemSecurityPolicy < Gem::TestCase metadata_gz = Gem.gzip @spec.to_yaml package = Gem::Package.new 'nonexistent.gem' - package.checksums['SHA1'] = {} + package.checksums[Gem::Security::DIGEST_NAME] = {} s = StringIO.new metadata_gz def s.full_name() 'metadata.gz' end digests = package.digest s - digests['SHA1']['data.tar.gz'] = OpenSSL::Digest.new 'SHA1', 'hello' + digests[Gem::Security::DIGEST_NAME]['data.tar.gz'] = @digest.new 'hello' - metadata_gz_digest = digests['SHA1']['metadata.gz'] + metadata_gz_digest = digests[Gem::Security::DIGEST_NAME]['metadata.gz'] signatures = {} signatures['metadata.gz'] = - PRIVATE_KEY.sign @sha1.new, metadata_gz_digest.digest + PRIVATE_KEY.sign @digest.new, metadata_gz_digest.digest e = assert_raises Gem::Security::Exception do @high.verify_signatures @spec, digests, signatures @@ -505,13 +505,13 @@ class TestGemSecurityPolicy < Gem::TestCase metadata_gz = Gem.gzip @spec.to_yaml package = Gem::Package.new 'nonexistent.gem' - package.checksums['SHA1'] = {} + package.checksums[Gem::Security::DIGEST_NAME] = {} s = StringIO.new metadata_gz def s.full_name() 'metadata.gz' end digests = package.digest s - digests['SHA1']['data.tar.gz'] = OpenSSL::Digest.new 'SHA1', 'hello' + digests[Gem::Security::DIGEST_NAME]['data.tar.gz'] = @digest.new 'hello' assert_raises Gem::Security::Exception do @high.verify_signatures @spec, digests, {} @@ -519,19 +519,19 @@ class TestGemSecurityPolicy < Gem::TestCase end def digest data - digester = @sha1.new + digester = @digest.new digester << data digester end def sign data, key = PRIVATE_KEY - key.sign @sha1.new, data.digest + key.sign @digest.new, data.digest end def dummy_signatures key = PRIVATE_KEY data = digest 'hello' - digests = { 'SHA1' => { 0 => data } } + digests = { Gem::Security::DIGEST_NAME => { 0 => data } } signatures = { 0 => sign(data, key) } return digests, signatures diff --git a/test/rubygems/test_gem_security_signer.rb b/test/rubygems/test_gem_security_signer.rb index 685a13949e..79dfea099d 100644 --- a/test/rubygems/test_gem_security_signer.rb +++ b/test/rubygems/test_gem_security_signer.rb @@ -121,12 +121,12 @@ class TestGemSecuritySigner < Gem::TestCase signature = signer.sign 'hello' expected = <<-EXPECTED -pxSf9ScaghbMNmNp8fqSJj7BiIGpbuoOVYCOM3TJNH9STLILA5z3xKp3gM6w -VJ7aGsh9KCP485ftS3J9Kb/lKJsyoSkkRSQ5QG+LnyZwMuWlThPDR5o7q6al -0oxE7vvbbqxFqcT4ojWIkwxJxOluFWmt2D8I6QTX2vLAn09y+Kl66AOrT7R5 -UinbXkz04VwcNvkBqJyko3yWxFKiGNpntZQg4jIw4L+h97EOaZp8H96udzQH -Da3K0YZ6FsqLDFNnWAFhve3kmpE3CludpvDqH0piq0zKqnOiqAcvICIpPaJP -c7NM7KZZjj7G++SXjYTEI1PHSA7aFQ/i/+qSUvx+Pg== +cHze2sEfRysoUMCfGVAx/7o8jxj5liJJ2ptNxe2jf3l+EZvyjdqpXo9Ndzxx +6xLp2rxLG4K2//ip4aCH5Sh7hnia+F5u6iuLBETPlklPrmw5dnuKZxolz+vM +0O1aOZsQHcVzQoESTGjkms3KZk+gn3lg0sSBbAV5/LyDYoHCEjxlcA5D+Olb +rDmRyBMOnMS+q489OZ5Hr6B2YJJ3QbUwIZNhUeNmOxIBEYTrrKkZ92qkxbRN +qhlqFP4jR6zXFeyBCOr0KpTiWBNuxBFXDsxmhGyt2BOIjD6qmKn7RSIfYg/U +toqvglr0kdbknSRRjBVLK6tsgr07aLT9gNP7mTW2PA== EXPECTED assert_equal expected, [signature].pack('m') diff --git a/test/rubygems/test_gem_security_trust_dir.rb b/test/rubygems/test_gem_security_trust_dir.rb index a0fbef809a..ab02ceb772 100644 --- a/test/rubygems/test_gem_security_trust_dir.rb +++ b/test/rubygems/test_gem_security_trust_dir.rb @@ -18,7 +18,7 @@ class TestGemSecurityTrustDir < Gem::TestCase end def test_cert_path - digest = OpenSSL::Digest::SHA1.hexdigest PUBLIC_CERT.subject.to_s + digest = Gem::Security::DIGEST_ALGORITHM.hexdigest PUBLIC_CERT.subject.to_s expected = File.join @dest_dir, "cert-#{digest}.pem" @@ -42,7 +42,7 @@ class TestGemSecurityTrustDir < Gem::TestCase end def test_name_path - digest = OpenSSL::Digest::SHA1.hexdigest PUBLIC_CERT.subject.to_s + digest = Gem::Security::DIGEST_ALGORITHM.hexdigest PUBLIC_CERT.subject.to_s expected = File.join @dest_dir, "cert-#{digest}.pem" diff --git a/test/rubygems/test_gem_server.rb b/test/rubygems/test_gem_server.rb index 4873fac5b6..6fe02e480f 100644 --- a/test/rubygems/test_gem_server.rb +++ b/test/rubygems/test_gem_server.rb @@ -222,7 +222,7 @@ class TestGemServer < Gem::TestCase assert_equal 404, @res.status, @res.body assert_match %r| \d\d:\d\d:\d\d |, @res['date'] assert_equal 'text/plain', @res['content-type'] - assert_equal 'No gems found matching "z" "9" nil', @res.body + assert_equal 'No gems found matching "z-9"', @res.body assert_equal 404, @res.status end @@ -291,6 +291,23 @@ class TestGemServer < Gem::TestCase assert_equal v('3.a'), spec.version end + def test_quick_marshal_a_b_1_3_a_gemspec_rz + quick_gem 'a-b-1', '3.a' + + data = StringIO.new "GET /quick/Marshal.#{Gem.marshal_version}/a-b-1-3.a.gemspec.rz HTTP/1.0\r\n\r\n" + @req.parse data + + @server.quick @req, @res + + assert_equal 200, @res.status, @res.body + assert @res['date'] + assert_equal 'application/x-deflate', @res['content-type'] + + spec = Marshal.load Gem.inflate(@res.body) + assert_equal 'a-b-1', spec.name + assert_equal v('3.a'), spec.version + end + def test_rdoc data = StringIO.new "GET /rdoc?q=a HTTP/1.0\r\n\r\n" @req.parse data diff --git a/test/rubygems/test_gem_source.rb b/test/rubygems/test_gem_source.rb index 64dfa42468..4a93e222f8 100644 --- a/test/rubygems/test_gem_source.rb +++ b/test/rubygems/test_gem_source.rb @@ -228,6 +228,15 @@ class TestGemSource < Gem::TestCase assert_equal(-1, remote. <=>(no_uri), 'remote <=> no_uri') end + def test_spaceship_order_is_preserved_when_uri_differs + sourceA = Gem::Source.new "http://example.com/a" + sourceB = Gem::Source.new "http://example.com/b" + + assert_equal( 0, sourceA. <=>(sourceA), 'sourceA <=> sourceA') + assert_equal( 1, sourceA. <=>(sourceB), 'sourceA <=> sourceB') + assert_equal( 1, sourceB. <=>(sourceA), 'sourceB <=> sourceA') + end + def test_update_cache_eh assert @source.update_cache? end diff --git a/test/rubygems/test_gem_spec_fetcher.rb b/test/rubygems/test_gem_spec_fetcher.rb index 53bb31a910..558869fe99 100644 --- a/test/rubygems/test_gem_spec_fetcher.rb +++ b/test/rubygems/test_gem_spec_fetcher.rb @@ -169,6 +169,26 @@ class TestGemSpecFetcher < Gem::TestCase assert_equal "bad news from the internet (#{@gem_repo})", sfp.error.message end + def test_suggest_gems_from_name_latest + spec_fetcher do|fetcher| + fetcher.spec 'example', 1 + fetcher.spec 'other-example', 1 + end + + suggestions = @sf.suggest_gems_from_name('examplw') + assert_equal ['example'], suggestions + end + + def test_suggest_gems_from_name_prerelease + spec_fetcher do|fetcher| + fetcher.spec 'example', '1.a' + fetcher.spec 'other-example', 1 + end + + suggestions = @sf.suggest_gems_from_name('examplw') + assert_equal ['example'], suggestions + end + def test_available_specs_latest spec_fetcher do |fetcher| fetcher.spec 'a', 1 diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 0fcc11e78f..bb6acbc7de 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -1586,7 +1586,7 @@ dependencies: [] refute @ext.contains_requirable_file? 'nonexistent' end - expected = "Ignoring ext-1 because its extensions are not built. " + + expected = "Ignoring ext-1 because its extensions are not built. " + "Try: gem pristine ext --version 1\n" assert_equal expected, err @@ -2748,14 +2748,6 @@ duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use: util_setup_validate Dir.chdir @tempdir do - @a1.email = "" - - use_ui @ui do - @a1.validate - end - - assert_match "#{w}: no email specified\n", @ui.error, "error" - @a1.email = "FIxxxXME (your e-mail)".sub(/xxx/, "") e = assert_raises Gem::InvalidSpecificationException do @@ -2977,6 +2969,43 @@ Did you mean 'Ruby'? warning end + def test_validate_empty_files + util_setup_validate + + use_ui @ui do + # we have to set all of these for #files to be empty + @a1.files = [] + @a1.test_files = [] + @a1.executables = [] + + @a1.validate + end + + assert_match "no files specified", @ui.error + end + + def test_validate_empty_homepage + util_setup_validate + + use_ui @ui do + @a1.homepage = nil + @a1.validate + end + + assert_match "no homepage specified", @ui.error + end + + def test_validate_empty_summary + util_setup_validate + + use_ui @ui do + @a1.summary = nil + @a1.validate + end + + assert_match "no summary specified", @ui.error + end + def test_validate_name util_setup_validate @@ -3252,7 +3281,11 @@ Did you mean 'Ruby'? Dir.chdir @tempdir do @m1 = quick_gem 'm', '1' do |s| s.files = %w[lib/code.rb] - s.metadata = { 'one' => "two", 'two' => "three" } + s.metadata = { + "one" => "two", + "home" => "three", + "homepage_uri" => "https://example.com/user/repo" + } end use_ui @ui do @@ -3329,6 +3362,23 @@ Did you mean 'Ruby'? end end + def test_metadata_link_validation_fails + util_setup_validate + + Dir.chdir @tempdir do + @m2 = quick_gem 'm', '2' do |s| + s.files = %w[lib/code.rb] + s.metadata = { 'homepage_uri' => 'http:/example.com' } + end + + e = assert_raises Gem::InvalidSpecificationException do + @m2.validate + end + + assert_equal "metadata['homepage_uri'] has invalid link: \"http:/example.com\"", e.message + end + end + def test_metadata_specs valid_ruby_spec = <<-EOF # -*- encoding: utf-8 -*- @@ -3406,6 +3456,31 @@ end refute @a1.missing_extensions? end + def test_find_all_by_full_name + pl = Gem::Platform.new 'i386-linux' + + a1 = util_spec "a", "1" + a1_pre = util_spec "a", "1.0.0.pre.1" + a_1_platform = util_spec("a", "1") {|s| s.platform = pl } + a_b_1 = util_spec "a-b", "1" + a_b_1_platform = util_spec("a-b", "1") {|s| s.platform = pl } + + a_b_1_1 = util_spec "a-b-1", "1" + a_b_1_1_platform = util_spec("a-b-1", "1") {|s| s.platform = pl } + + install_specs(a1, a1_pre, a_1_platform, a_b_1, a_b_1_platform, + a_b_1_1, a_b_1_1_platform) + + assert_equal [a1], Gem::Specification.find_all_by_full_name("a-1") + assert_equal [a1_pre], Gem::Specification.find_all_by_full_name("a-1.0.0.pre.1") + assert_equal [a_1_platform], Gem::Specification.find_all_by_full_name("a-1-x86-linux") + assert_equal [a_b_1_1], Gem::Specification.find_all_by_full_name("a-b-1-1") + assert_equal [a_b_1_1_platform], Gem::Specification.find_all_by_full_name("a-b-1-1-x86-linux") + + assert_equal [], Gem::Specification.find_all_by_full_name("monkeys") + assert_equal [], Gem::Specification.find_all_by_full_name("a-1-foo") + end + def test_find_by_name install_specs util_spec "a" install_specs util_spec "a", 1 diff --git a/test/rubygems/test_gem_stub_specification.rb b/test/rubygems/test_gem_stub_specification.rb index 5316449fba..53b9dab02d 100644 --- a/test/rubygems/test_gem_stub_specification.rb +++ b/test/rubygems/test_gem_stub_specification.rb @@ -71,7 +71,7 @@ class TestStubSpecification < Gem::TestCase refute stub.contains_requirable_file? 'nonexistent' end - expected = "Ignoring stub_e-2 because its extensions are not built. " + + expected = "Ignoring stub_e-2 because its extensions are not built. " + "Try: gem pristine stub_e --version 2\n" assert_equal expected, err @@ -95,6 +95,12 @@ class TestStubSpecification < Gem::TestCase assert_equal File.join(stub.full_gem_path, 'lib'), stub.lib_dirs_glob end + def test_lib_dirs_glob_with_extension + stub = stub_with_extension + + assert_equal File.join(stub.full_gem_path, 'lib'), stub.lib_dirs_glob + end + def test_matches_for_glob stub = stub_without_extension code_rb = File.join stub.gem_dir, 'lib', 'code.rb' diff --git a/test/rubygems/test_gem_util.rb b/test/rubygems/test_gem_util.rb index eb974427aa..b85db44d51 100644 --- a/test/rubygems/test_gem_util.rb +++ b/test/rubygems/test_gem_util.rb @@ -26,6 +26,7 @@ class TestGemUtil < Gem::TestCase assert_equal File.join(@tempdir, 'a/b/c'), enum.next assert_equal File.join(@tempdir, 'a/b'), enum.next assert_equal File.join(@tempdir, 'a'), enum.next + loop { break if enum.next.nil? } # exhaust the enumerator end def test_linked_list_find diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb index 1897d44905..56c818663e 100644 --- a/test/rubygems/test_gem_version.rb +++ b/test/rubygems/test_gem_version.rb @@ -41,6 +41,11 @@ class TestGemVersion < Gem::TestCase assert_equal v('1.1'), Gem::Version.create(ver) end + def test_class_correct + assert_equal true, Gem::Version.correct?("5.1") + assert_equal false, Gem::Version.correct?("an incorrect version") + end + def test_class_new_subclass v1 = Gem::Version.new '1' v2 = V.new '1' @@ -65,7 +70,8 @@ class TestGemVersion < Gem::TestCase def test_hash assert_equal v("1.2").hash, v("1.2").hash refute_equal v("1.2").hash, v("1.3").hash - refute_equal v("1.2").hash, v("1.2.0").hash + assert_equal v("1.2").hash, v("1.2.0").hash + assert_equal v("1.2.pre.1").hash, v("1.2.0.pre.1.0").hash end def test_initialize @@ -76,18 +82,23 @@ class TestGemVersion < Gem::TestCase assert_version_equal "1", 1 end - def test_initialize_bad - %W[ + def test_initialize_invalid + invalid_versions = %W[ junk 1.0\n2.0 1..2 1.2\ 3.4 - ].each do |bad| - e = assert_raises ArgumentError, bad do - Gem::Version.new bad + ] + + # DON'T TOUCH THIS WITHOUT CHECKING CVE-2013-4287 + invalid_versions << "2.3422222.222.222222222.22222.ads0as.dasd0.ddd2222.2.qd3e." + + invalid_versions.each do |invalid| + e = assert_raises ArgumentError, invalid do + Gem::Version.new invalid end - assert_equal "Malformed version number string #{bad}", e.message, bad + assert_equal "Malformed version number string #{invalid}", e.message, invalid end end @@ -105,6 +116,9 @@ class TestGemVersion < Gem::TestCase assert_prerelease '1.A' + assert_prerelease '1-1' + assert_prerelease '1-a' + refute_prerelease "1.2.0" refute_prerelease "2.9" refute_prerelease "22.1.50.0" @@ -160,6 +174,12 @@ class TestGemVersion < Gem::TestCase assert_equal [9,8,7], v("9.8.7").segments end + def test_canonical_segments + assert_equal [1], v("1.0.0").canonical_segments + assert_equal [1, "a", 1], v("1.0.0.a.1.0").canonical_segments + assert_equal [1, 2, 3, "pre", 1], v("1.2.3-1").canonical_segments + end + # Asserts that +version+ is a prerelease. def assert_prerelease version @@ -189,6 +209,7 @@ class TestGemVersion < Gem::TestCase def assert_version_equal expected, actual assert_equal v(expected), v(actual) + assert_equal v(expected).hash, v(actual).hash, "since #{actual} == #{expected}, they must have the same hash" end # Assert that two versions are eql?. Checks both directions. diff --git a/test/rubygems/test_gem_version_option.rb b/test/rubygems/test_gem_version_option.rb index d4699313c2..c06c716616 100644 --- a/test/rubygems/test_gem_version_option.rb +++ b/test/rubygems/test_gem_version_option.rb @@ -106,6 +106,21 @@ class TestGemVersionOption < Gem::TestCase assert_equal expected, @cmd.options end + def test_multiple_version_operator_option_compound + @cmd.add_version_option + + @cmd.handle_options ['--version', '< 1', '--version', '> 0.9'] + + expected = { + :args => [], + :explicit_prerelease => false, + :prerelease => false, + :version => Gem::Requirement.new('< 1', '> 0.9'), + } + + assert_equal expected, @cmd.options + end + def test_version_option_explicit_prerelease @cmd.add_prerelease_option @cmd.add_version_option diff --git a/test/rubygems/test_kernel.rb b/test/rubygems/test_kernel.rb index b565c62f4a..f7d3988ce3 100644 --- a/test/rubygems/test_kernel.rb +++ b/test/rubygems/test_kernel.rb @@ -90,4 +90,34 @@ class TestKernel < Gem::TestCase assert gem('a', '= 1'), "Should load" refute $:.any? { |p| %r{a-1/bin} =~ p } end + + def test_gem_bundler + quick_gem 'bundler', '1' + quick_gem 'bundler', '2.a' + + assert gem('bundler') + assert $:.any? { |p| %r{bundler-1/lib} =~ p } + end + + def test_gem_bundler_missing_bundler_version + Gem::BundlerVersionFinder.stub(:bundler_version_with_reason, ["55", "reason"]) do + quick_gem 'bundler', '1' + quick_gem 'bundler', '2.a' + + e = assert_raises Gem::MissingSpecVersionError do + gem('bundler') + end + assert_match "Could not find 'bundler' (55) required by reason.", e.message + end + end + + def test_gem_bundler_inferred_bundler_version + Gem::BundlerVersionFinder.stub(:bundler_version_with_reason, ["1", "reason"]) do + quick_gem 'bundler', '1' + quick_gem 'bundler', '2.a' + + assert gem('bundler', '>= 0.a') + assert $:.any? { |p| %r{bundler-1/lib} =~ p } + end + end end diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index edb36f1f32..a846f46833 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -383,6 +383,44 @@ class TestGemRequire < Gem::TestCase assert_equal %w(a-1), loaded_spec_names end + + def test_require_bundler + b1 = new_spec('bundler', '1', nil, "lib/bundler/setup.rb") + b2a = new_spec('bundler', '2.a', nil, "lib/bundler/setup.rb") + install_specs b1, b2a + + require "rubygems/bundler_version_finder" + $:.clear + assert_require 'bundler/setup' + assert_equal %w[bundler-2.a], loaded_spec_names + assert_empty unresolved_names + end + + def test_require_bundler_missing_bundler_version + Gem::BundlerVersionFinder.stub(:bundler_version_with_reason, ["55", "reason"]) do + b1 = new_spec('bundler', '1.999999999', nil, "lib/bundler/setup.rb") + b2a = new_spec('bundler', '2.a', nil, "lib/bundler/setup.rb") + install_specs b1, b2a + + e = assert_raises Gem::MissingSpecVersionError do + gem('bundler') + end + assert_match "Could not find 'bundler' (55) required by reason.", e.message + end + end + + def test_require_bundler_with_bundler_version + Gem::BundlerVersionFinder.stub(:bundler_version_with_reason, ["1", "reason"]) do + b1 = new_spec('bundler', '1.999999999', nil, "lib/bundler/setup.rb") + b2 = new_spec('bundler', '2', nil, "lib/bundler/setup.rb") + install_specs b1, b2 + + $:.clear + assert_require 'bundler/setup' + assert_equal %w[bundler-1.999999999], loaded_spec_names + end + end + def silence_warnings old_verbose, $VERBOSE = $VERBOSE, false yield |