rubygems-update 2.0.17 → 2.1.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -0
  4. data/.autotest +1 -1
  5. data/History.txt +82 -153
  6. data/Manifest.txt +35 -9
  7. data/Rakefile +35 -36
  8. data/lib/rubygems.rb +106 -18
  9. data/lib/rubygems/available_set.rb +68 -0
  10. data/lib/rubygems/basic_specification.rb +139 -0
  11. data/lib/rubygems/command_manager.rb +37 -40
  12. data/lib/rubygems/commands/cert_command.rb +78 -29
  13. data/lib/rubygems/commands/cleanup_command.rb +2 -2
  14. data/lib/rubygems/commands/contents_command.rb +101 -58
  15. data/lib/rubygems/commands/dependency_command.rb +94 -53
  16. data/lib/rubygems/commands/environment_command.rb +70 -53
  17. data/lib/rubygems/commands/fetch_command.rb +1 -2
  18. data/lib/rubygems/commands/help_command.rb +85 -55
  19. data/lib/rubygems/commands/install_command.rb +84 -42
  20. data/lib/rubygems/commands/outdated_command.rb +2 -12
  21. data/lib/rubygems/commands/owner_command.rb +6 -0
  22. data/lib/rubygems/commands/pristine_command.rb +26 -16
  23. data/lib/rubygems/commands/sources_command.rb +85 -70
  24. data/lib/rubygems/commands/uninstall_command.rb +32 -2
  25. data/lib/rubygems/commands/update_command.rb +111 -75
  26. data/lib/rubygems/config_file.rb +15 -3
  27. data/lib/rubygems/core_ext/kernel_require.rb +9 -31
  28. data/lib/rubygems/defaults.rb +8 -0
  29. data/lib/rubygems/dependency.rb +4 -2
  30. data/lib/rubygems/dependency_installer.rb +180 -170
  31. data/lib/rubygems/dependency_resolver.rb +191 -526
  32. data/lib/rubygems/dependency_resolver/activation_request.rb +109 -0
  33. data/lib/rubygems/dependency_resolver/api_set.rb +65 -0
  34. data/lib/rubygems/dependency_resolver/api_specification.rb +36 -0
  35. data/lib/rubygems/dependency_resolver/composed_set.rb +18 -0
  36. data/lib/rubygems/dependency_resolver/current_set.rb +16 -0
  37. data/lib/rubygems/dependency_resolver/dependency_conflict.rb +85 -0
  38. data/lib/rubygems/dependency_resolver/dependency_request.rb +51 -0
  39. data/lib/rubygems/dependency_resolver/index_set.rb +59 -0
  40. data/lib/rubygems/dependency_resolver/index_specification.rb +53 -0
  41. data/lib/rubygems/dependency_resolver/installed_specification.rb +38 -0
  42. data/lib/rubygems/dependency_resolver/installer_set.rb +130 -0
  43. data/lib/rubygems/exceptions.rb +88 -1
  44. data/lib/rubygems/ext/builder.rb +1 -1
  45. data/lib/rubygems/gem_runner.rb +17 -9
  46. data/lib/rubygems/gemcutter_utilities.rb +72 -42
  47. data/lib/rubygems/install_default_message.rb +12 -0
  48. data/lib/rubygems/install_update_options.rb +3 -0
  49. data/lib/rubygems/installer.rb +55 -30
  50. data/lib/rubygems/name_tuple.rb +18 -7
  51. data/lib/rubygems/package.rb +50 -25
  52. data/lib/rubygems/package/tar_test_case.rb +9 -9
  53. data/lib/rubygems/package/tar_writer.rb +35 -12
  54. data/lib/rubygems/package_task.rb +2 -5
  55. data/lib/rubygems/path_support.rb +10 -0
  56. data/lib/rubygems/platform.rb +9 -3
  57. data/lib/rubygems/psych_additions.rb +1 -1
  58. data/lib/rubygems/remote_fetcher.rb +9 -276
  59. data/lib/rubygems/request.rb +267 -0
  60. data/lib/rubygems/request_set.rb +123 -125
  61. data/lib/rubygems/request_set/gem_dependency_api.rb +39 -0
  62. data/lib/rubygems/security.rb +32 -23
  63. data/lib/rubygems/security/policy.rb +35 -9
  64. data/lib/rubygems/security/signer.rb +2 -2
  65. data/lib/rubygems/server.rb +8 -16
  66. data/lib/rubygems/source.rb +25 -14
  67. data/lib/rubygems/source/installed.rb +28 -0
  68. data/lib/rubygems/source/local.rb +122 -0
  69. data/lib/rubygems/source/specific_file.rb +28 -0
  70. data/lib/rubygems/source_local.rb +2 -89
  71. data/lib/rubygems/source_specific_file.rb +2 -26
  72. data/lib/rubygems/spec_fetcher.rb +11 -11
  73. data/lib/rubygems/specification.rb +186 -198
  74. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot.pem +88 -30
  75. data/lib/rubygems/ssl_certs/Entrust_net-Secure-Server-Certification-Authority.pem +90 -0
  76. data/lib/rubygems/ssl_certs/{GeoTrustGlobalCA.pem → GeoTrust_Global_CA.pem} +20 -20
  77. data/lib/rubygems/ssl_certs/VerisignClass3PublicPrimaryCertificationAuthority-G2.pem +57 -0
  78. data/lib/rubygems/stub_specification.rb +119 -0
  79. data/lib/rubygems/test_case.rb +117 -49
  80. data/lib/rubygems/uninstaller.rb +14 -9
  81. data/lib/rubygems/uri_formatter.rb +39 -0
  82. data/lib/rubygems/util/list.rb +44 -0
  83. data/lib/rubygems/version.rb +15 -5
  84. data/lib/rubygems/version_option.rb +8 -2
  85. data/test/rubygems/ca_cert.pem +23 -0
  86. data/test/rubygems/client.pem +49 -0
  87. data/test/rubygems/encrypted_private_key.pem +30 -0
  88. data/test/rubygems/invalid_client.pem +49 -0
  89. data/test/rubygems/specifications/bar-0.0.2.gemspec +9 -0
  90. data/test/rubygems/specifications/foo-0.0.1.gemspec +0 -0
  91. data/test/rubygems/test_gem.rb +76 -454
  92. data/test/rubygems/test_gem_command_manager.rb +23 -21
  93. data/test/rubygems/test_gem_commands_cert_command.rb +154 -14
  94. data/test/rubygems/test_gem_commands_cleanup_command.rb +15 -0
  95. data/test/rubygems/test_gem_commands_contents_command.rb +32 -4
  96. data/test/rubygems/test_gem_commands_environment_command.rb +9 -1
  97. data/test/rubygems/test_gem_commands_fetch_command.rb +2 -28
  98. data/test/rubygems/test_gem_commands_help_command.rb +6 -3
  99. data/test/rubygems/test_gem_commands_install_command.rb +2 -65
  100. data/test/rubygems/test_gem_commands_owner_command.rb +49 -0
  101. data/test/rubygems/test_gem_commands_pristine_command.rb +30 -0
  102. data/test/rubygems/test_gem_commands_sources_command.rb +1 -1
  103. data/test/rubygems/test_gem_commands_uninstall_command.rb +33 -0
  104. data/test/rubygems/test_gem_commands_update_command.rb +2 -1
  105. data/test/rubygems/test_gem_config_file.rb +12 -0
  106. data/test/rubygems/test_gem_dependency_installer.rb +58 -65
  107. data/test/rubygems/test_gem_dependency_resolver.rb +6 -3
  108. data/test/rubygems/test_gem_dependency_resolver_dependency_conflict.rb +36 -0
  109. data/test/rubygems/test_gem_ext_builder.rb +2 -4
  110. data/test/rubygems/test_gem_ext_ext_conf_builder.rb +7 -2
  111. data/test/rubygems/test_gem_gem_runner.rb +17 -13
  112. data/test/rubygems/test_gem_gemcutter_utilities.rb +6 -19
  113. data/test/rubygems/test_gem_impossible_dependencies_error.rb +41 -0
  114. data/test/rubygems/test_gem_install_update_options.rb +4 -1
  115. data/test/rubygems/test_gem_installer.rb +31 -2
  116. data/test/rubygems/test_gem_name_tuple.rb +22 -0
  117. data/test/rubygems/test_gem_package.rb +122 -11
  118. data/test/rubygems/test_gem_package_old.rb +8 -0
  119. data/test/rubygems/test_gem_package_tar_reader.rb +9 -8
  120. data/test/rubygems/test_gem_package_tar_reader_entry.rb +1 -1
  121. data/test/rubygems/test_gem_package_tar_writer.rb +78 -56
  122. data/test/rubygems/test_gem_package_task.rb +2 -23
  123. data/test/rubygems/test_gem_path_support.rb +17 -0
  124. data/test/rubygems/test_gem_platform.rb +18 -0
  125. data/test/rubygems/test_gem_remote_fetcher.rb +106 -385
  126. data/test/rubygems/test_gem_request.rb +239 -0
  127. data/test/rubygems/test_gem_requirement.rb +9 -11
  128. data/test/rubygems/test_gem_security.rb +58 -2
  129. data/test/rubygems/test_gem_security_policy.rb +42 -1
  130. data/test/rubygems/test_gem_security_signer.rb +13 -1
  131. data/test/rubygems/test_gem_security_trust_dir.rb +5 -1
  132. data/test/rubygems/test_gem_server.rb +1 -105
  133. data/test/rubygems/test_gem_source.rb +4 -14
  134. data/test/rubygems/test_gem_source_local.rb +4 -4
  135. data/test/rubygems/test_gem_source_specific_file.rb +1 -1
  136. data/test/rubygems/test_gem_spec_fetcher.rb +0 -12
  137. data/test/rubygems/test_gem_specification.rb +452 -28
  138. data/test/rubygems/test_gem_stub_specification.rb +30 -0
  139. data/test/rubygems/test_gem_uninstaller.rb +14 -0
  140. data/test/rubygems/test_gem_uri_formatter.rb +20 -0
  141. data/test/rubygems/test_gem_version.rb +23 -13
  142. data/test/rubygems/test_gem_version_option.rb +63 -1
  143. data/test/rubygems/test_require.rb +0 -12
  144. data/util/create_encrypted_key.rb +16 -0
  145. metadata +161 -23
  146. metadata.gz.sig +0 -0
  147. data/CVE-2013-4287.txt +0 -36
  148. data/CVE-2013-4363.txt +0 -45
  149. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot-2048.pem +0 -25
  150. data/lib/rubygems/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem +0 -14
  151. data/lib/rubygems/ssl_certs/DigiCertHighAssuranceEVRootCA.pem +0 -23
  152. data/lib/rubygems/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem +0 -28
  153. data/test/rubygems/test_bundled_ca.rb +0 -59
  154. data/util/update_bundled_ca_certificates.rb +0 -103
@@ -15,7 +15,9 @@ class TestGemDependencyResolver < Gem::TestCase
15
15
  exp = expected.sort_by { |s| s.full_name }
16
16
  act = actual.map { |a| a.spec }.sort_by { |s| s.full_name }
17
17
 
18
- assert_equal exp, act
18
+ msg = "Set of gems was not the same: #{exp.map { |x| x.full_name}.inspect} != #{act.map { |x| x.full_name}.inspect}"
19
+
20
+ assert_equal exp, act, msg
19
21
  end
20
22
 
21
23
  def test_no_overlap_specificly
@@ -177,7 +179,8 @@ class TestGemDependencyResolver < Gem::TestCase
177
179
  r.resolve
178
180
  end
179
181
 
180
- assert_equal "unable to find any gem matching dependency 'a (>= 0)'", e.message
182
+ assert_equal "Unable to resolve dependency: (unknown) requires a (>= 0)",
183
+ e.message
181
184
 
182
185
  assert_equal "a (>= 0)", e.dependency.to_s
183
186
  end
@@ -215,7 +218,7 @@ class TestGemDependencyResolver < Gem::TestCase
215
218
  r.resolve
216
219
  end
217
220
 
218
- assert_equal "detected 1 conflict with dependency 'c (>= 2)'", e.message
221
+ assert_match "a-1 requires c (>= 2) but it conflicted", e.message
219
222
 
220
223
  assert_equal "c (>= 2)", e.dependency.to_s
221
224
 
@@ -0,0 +1,36 @@
1
+ require 'rubygems/test_case'
2
+ require 'rubygems/dependency_resolver'
3
+
4
+ class TestGemDependencyResolverDependencyConflict < Gem::TestCase
5
+
6
+ def test_explanation
7
+ root =
8
+ dependency_request dep('net-ssh', '>= 2.0.13'), 'rye', '0.9.8'
9
+ child =
10
+ dependency_request dep('net-ssh', '>= 2.6.5'), 'net-ssh', '2.2.2', root
11
+
12
+ conflict =
13
+ Gem::DependencyResolver::DependencyConflict.new child, child.requester
14
+
15
+ expected = <<-EXPECTED
16
+ Activated net-ssh-2.2.2 instead of (>= 2.6.5) via:
17
+ net-ssh-2.2.2, rye-0.9.8
18
+ EXPECTED
19
+
20
+ assert_equal expected, conflict.explanation
21
+ end
22
+
23
+ def test_request_path
24
+ root =
25
+ dependency_request dep('net-ssh', '>= 2.0.13'), 'rye', '0.9.8'
26
+ child =
27
+ dependency_request dep('net-ssh', '>= 2.6.5'), 'net-ssh', '2.2.2', root
28
+
29
+ conflict =
30
+ Gem::DependencyResolver::DependencyConflict.new child, nil
31
+
32
+ assert_equal %w[net-ssh-2.2.2 rye-0.9.8], conflict.request_path
33
+ end
34
+
35
+ end
36
+
@@ -50,10 +50,8 @@ install:
50
50
  refute_match %r%"DESTDIR=#{ENV['DESTDIR']}" install$%, results
51
51
  end
52
52
 
53
- if /nmake/ !~ results
54
- assert_match %r%^all: destination$%, results
55
- assert_match %r%^install: destination$%, results
56
- end
53
+ assert_match %r%^all: destination$%, results
54
+ assert_match %r%^install: destination$%, results
57
55
  end
58
56
 
59
57
  end
@@ -120,8 +120,13 @@ checking for main\(\) in .*?nonexistent/m, error.message)
120
120
  extconf.puts <<-'EXTCONF'
121
121
  include RbConfig
122
122
 
123
- ruby_exe = "#{CONFIG['RUBY_INSTALL_NAME']}#{CONFIG['EXEEXT']}"
124
- ruby = File.join CONFIG['bindir'], ruby_exe
123
+ ruby =
124
+ if ENV['RUBY'] then
125
+ ENV['RUBY']
126
+ else
127
+ ruby_exe = "#{CONFIG['RUBY_INSTALL_NAME']}#{CONFIG['EXEEXT']}"
128
+ File.join CONFIG['bindir'], ruby_exe
129
+ end
125
130
 
126
131
  open 'Makefile', 'w' do |io|
127
132
  io.write <<-Makefile
@@ -7,6 +7,7 @@ class TestGemGemRunner < Gem::TestCase
7
7
  super
8
8
 
9
9
  @orig_args = Gem::Command.build_args
10
+ @runner = Gem::GemRunner.new
10
11
  end
11
12
 
12
13
  def teardown
@@ -41,23 +42,26 @@ class TestGemGemRunner < Gem::TestCase
41
42
  assert_equal %w[--commands], Gem::Command.extra_args
42
43
  end
43
44
 
44
- def test_build_args_are_handled
45
- Gem.clear_paths
46
-
47
- cls = Class.new(Gem::Command) do
48
- def execute
49
- end
50
- end
45
+ def test_extract_build_args
46
+ args = %w[]
47
+ assert_equal [], @runner.extract_build_args(args)
48
+ assert_equal %w[], args
51
49
 
52
- test_obj = cls.new :ba_test
50
+ args = %w[foo]
51
+ assert_equal [], @runner.extract_build_args(args)
52
+ assert_equal %w[foo], args
53
53
 
54
- cmds = Gem::CommandManager.new
55
- cmds.register_command :ba_test, test_obj
54
+ args = %w[--foo]
55
+ assert_equal [], @runner.extract_build_args(args)
56
+ assert_equal %w[--foo], args
56
57
 
57
- runner = Gem::GemRunner.new :command_manager => cmds
58
- runner.run(%W[ba_test -- --build_arg1 --build_arg2])
58
+ args = %w[--foo --]
59
+ assert_equal [], @runner.extract_build_args(args)
60
+ assert_equal %w[--foo], args
59
61
 
60
- assert_equal %w[--build_arg1 --build_arg2], test_obj.options[:build_args]
62
+ args = %w[--foo -- --bar]
63
+ assert_equal %w[--bar], @runner.extract_build_args(args)
64
+ assert_equal %w[--foo], args
61
65
  end
62
66
 
63
67
  end
@@ -101,7 +101,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
101
101
  def test_sign_in_with_host
102
102
  api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
103
103
 
104
- util_sign_in [api_key, 200, 'OK'], 'http://example.com', ['http://example.com']
104
+ util_sign_in [api_key, 200, 'OK'], 'http://example.com', :param
105
105
 
106
106
  assert_match "Enter your http://example.com credentials.",
107
107
  @sign_in_ui.output
@@ -112,20 +112,6 @@ class TestGemGemcutterUtilities < Gem::TestCase
112
112
  assert_equal api_key, credentials[:rubygems_api_key]
113
113
  end
114
114
 
115
- def test_sign_in_with_host_nil
116
- api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
117
-
118
- util_sign_in [api_key, 200, 'OK'], nil, [nil]
119
-
120
- assert_match "Enter your RubyGems.org credentials.",
121
- @sign_in_ui.output
122
- assert @fetcher.last_request["authorization"]
123
- assert_match %r{Signed in.}, @sign_in_ui.output
124
-
125
- credentials = YAML.load_file Gem.configuration.credentials_path
126
- assert_equal api_key, credentials[:rubygems_api_key]
127
- end
128
-
129
115
  def test_sign_in_with_host_ENV
130
116
  api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
131
117
  util_sign_in [api_key, 200, 'OK'], 'http://example.com'
@@ -177,14 +163,14 @@ class TestGemGemcutterUtilities < Gem::TestCase
177
163
  assert_match %r{Access Denied.}, @sign_in_ui.output
178
164
  end
179
165
 
180
- def util_sign_in response, host = nil, args = []
166
+ def util_sign_in response, host = nil, style = :ENV
181
167
  skip 'Always uses $stdin on windows' if Gem.win_platform?
182
168
 
183
169
  email = 'you@example.com'
184
170
  password = 'secret'
185
171
 
186
172
  if host
187
- ENV['RUBYGEMS_HOST'] = host
173
+ ENV['RUBYGEMS_HOST'] = host if style == :ENV
188
174
  else
189
175
  host = Gem.host
190
176
  end
@@ -196,8 +182,8 @@ class TestGemGemcutterUtilities < Gem::TestCase
196
182
  @sign_in_ui = Gem::MockGemUi.new "#{email}\n#{password}\n"
197
183
 
198
184
  use_ui @sign_in_ui do
199
- if args.length > 0 then
200
- @cmd.sign_in(*args)
185
+ if style == :param then
186
+ @cmd.sign_in host
201
187
  else
202
188
  @cmd.sign_in
203
189
  end
@@ -223,3 +209,4 @@ class TestGemGemcutterUtilities < Gem::TestCase
223
209
  end
224
210
 
225
211
  end
212
+
@@ -0,0 +1,41 @@
1
+ require 'rubygems/test_case'
2
+
3
+ class TestGemImpossibleDependenciesError < Gem::TestCase
4
+
5
+ def test_message_conflict
6
+ request = dependency_request dep('net-ssh', '>= 2.0.13'), 'rye', '0.9.8'
7
+
8
+ conflicts = []
9
+
10
+ # These conflicts are lies as their dependencies does not have the correct
11
+ # requested-by entries, but they are suitable for testing the message.
12
+ # See #485 to construct a correct conflict.
13
+ net_ssh_2_2_2 =
14
+ dependency_request dep('net-ssh', '>= 2.6.5'), 'net-ssh', '2.2.2', request
15
+ net_ssh_2_6_5 =
16
+ dependency_request dep('net-ssh', '~> 2.2.2'), 'net-ssh', '2.6.5', request
17
+
18
+ conflict1 = Gem::DependencyResolver::DependencyConflict.new \
19
+ net_ssh_2_6_5, net_ssh_2_6_5.requester
20
+
21
+ conflict2 = Gem::DependencyResolver::DependencyConflict.new \
22
+ net_ssh_2_2_2, net_ssh_2_2_2.requester
23
+
24
+ conflicts << [net_ssh_2_6_5.requester.spec, conflict1]
25
+ conflicts << [net_ssh_2_2_2.requester.spec, conflict2]
26
+
27
+ error = Gem::ImpossibleDependenciesError.new request, conflicts
28
+
29
+ expected = <<-EXPECTED
30
+ rye-0.9.8 requires net-ssh (>= 2.0.13) but it conflicted:
31
+ Activated net-ssh-2.6.5 instead of (~> 2.2.2) via:
32
+ net-ssh-2.6.5, rye-0.9.8
33
+ Activated net-ssh-2.2.2 instead of (>= 2.6.5) via:
34
+ net-ssh-2.2.2, rye-0.9.8
35
+ EXPECTED
36
+
37
+ assert_equal expected, error.message
38
+ end
39
+
40
+ end
41
+
@@ -22,12 +22,13 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
22
22
  --rdoc
23
23
  --ri
24
24
  -E
25
- -P HighSecurity
26
25
  -f
27
26
  -i /install_to
28
27
  -w
29
28
  ]
30
29
 
30
+ args.concat %w[-P HighSecurity] if defined?(OpenSSL::SSL)
31
+
31
32
  assert @cmd.handles?(args)
32
33
  end
33
34
 
@@ -100,6 +101,8 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
100
101
  end
101
102
 
102
103
  def test_security_policy
104
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
105
+
103
106
  @cmd.handle_options %w[-P HighSecurity]
104
107
 
105
108
  assert_equal Gem::Security::HighSecurity, @cmd.options[:security_policy]
@@ -4,6 +4,7 @@ class TestGemInstaller < Gem::InstallerTestCase
4
4
 
5
5
  def setup
6
6
  super
7
+ common_installer_setup
7
8
 
8
9
  if __name__ =~ /^test_install(_|$)/ then
9
10
  FileUtils.rm_r @spec.gem_dir
@@ -14,6 +15,8 @@ class TestGemInstaller < Gem::InstallerTestCase
14
15
  end
15
16
 
16
17
  def teardown
18
+ common_installer_teardown
19
+
17
20
  super
18
21
 
19
22
  Gem.configuration = @config
@@ -300,6 +303,8 @@ gem 'other', version
300
303
  end
301
304
 
302
305
  def test_ensure_loadable_spec_security_policy
306
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
307
+
303
308
  _, a_gem = util_gem 'a', 2 do |s|
304
309
  s.add_dependency 'garbage ~> 5'
305
310
  end
@@ -1341,7 +1346,7 @@ gem 'other', version
1341
1346
  assert File.exist?(File.join(dest, 'bin', 'executable'))
1342
1347
  end
1343
1348
 
1344
- def test_write_build_args
1349
+ def test_write_build_info_file
1345
1350
  refute_path_exists @spec.build_info_file
1346
1351
 
1347
1352
  @installer.build_args = %w[
@@ -1357,7 +1362,7 @@ gem 'other', version
1357
1362
  assert_equal expected, File.read(@spec.build_info_file)
1358
1363
  end
1359
1364
 
1360
- def test_write_build_args_empty
1365
+ def test_write_build_info_file_empty
1361
1366
  refute_path_exists @spec.build_info_file
1362
1367
 
1363
1368
  @installer.write_build_info_file
@@ -1429,6 +1434,30 @@ gem 'other', version
1429
1434
  assert_match %r!/gemhome/gems/a-2$!, @installer.dir
1430
1435
  end
1431
1436
 
1437
+ def test_default_gem
1438
+ FileUtils.rm_f File.join(Gem.dir, 'specifications')
1439
+
1440
+ @installer.wrappers = true
1441
+ @installer.options[:install_as_default] = true
1442
+ @installer.gem_dir = util_gem_dir @spec
1443
+ @installer.generate_bin
1444
+
1445
+ use_ui @ui do
1446
+ @installer.install
1447
+ end
1448
+
1449
+ assert File.directory? util_inst_bindir
1450
+ installed_exec = File.join util_inst_bindir, 'executable'
1451
+ assert File.exist? installed_exec
1452
+
1453
+ assert File.directory? File.join(Gem.dir, 'specifications')
1454
+ assert File.directory? File.join(Gem.dir, 'specifications', 'default')
1455
+
1456
+ default_spec = eval File.read File.join(Gem.dir, 'specifications', 'default', 'a-2.gemspec')
1457
+ assert_equal Gem::Version.new("2"), default_spec.version
1458
+ assert_equal ['bin/executable'], default_spec.files
1459
+ end
1460
+
1432
1461
  def old_ruby_required
1433
1462
  spec = quick_spec 'old_ruby_required', '1' do |s|
1434
1463
  s.required_ruby_version = '= 1.4.6'
@@ -2,6 +2,21 @@ require 'rubygems/test_case'
2
2
  require 'rubygems/name_tuple'
3
3
 
4
4
  class TestGemNameTuple < Gem::TestCase
5
+
6
+ def test_full_name
7
+ n = Gem::NameTuple.new "a", Gem::Version.new(0), "ruby"
8
+ assert_equal "a-0", n.full_name
9
+
10
+ n = Gem::NameTuple.new "a", Gem::Version.new(0), nil
11
+ assert_equal "a-0", n.full_name
12
+
13
+ n = Gem::NameTuple.new "a", Gem::Version.new(0), ""
14
+ assert_equal "a-0", n.full_name
15
+
16
+ n = Gem::NameTuple.new "a", Gem::Version.new(0), "other"
17
+ assert_equal "a-0-other", n.full_name
18
+ end
19
+
5
20
  def test_platform_normalization
6
21
  n = Gem::NameTuple.new "a", Gem::Version.new(0), "ruby"
7
22
  assert_equal "ruby", n.platform
@@ -12,4 +27,11 @@ class TestGemNameTuple < Gem::TestCase
12
27
  n = Gem::NameTuple.new "a", Gem::Version.new(0), ""
13
28
  assert_equal "ruby", n.platform
14
29
  end
30
+
31
+ def test_spec_name
32
+ n = Gem::NameTuple.new "a", Gem::Version.new(0), "ruby"
33
+ assert_equal "a-0.gemspec", n.spec_name
34
+ end
35
+
15
36
  end
37
+
@@ -64,16 +64,13 @@ class TestGemPackage < Gem::Package::TarTestCase
64
64
  reader = Gem::Package::TarReader.new gem_io
65
65
 
66
66
  checksums = nil
67
- tar = nil
68
67
 
69
68
  reader.each_entry do |entry|
70
69
  case entry.full_name
71
- when 'checksums.yaml.gz' then
70
+ when 'checksums.yaml.gz'
72
71
  Zlib::GzipReader.wrap entry do |io|
73
72
  checksums = io.read
74
73
  end
75
- when 'data.tar.gz' then
76
- tar = entry.read
77
74
  end
78
75
  end
79
76
 
@@ -86,17 +83,25 @@ class TestGemPackage < Gem::Package::TarTestCase
86
83
  metadata_sha1 = Digest::SHA1.hexdigest s.string
87
84
  metadata_sha512 = Digest::SHA512.hexdigest s.string
88
85
 
86
+ data_digests = nil
87
+ util_tar do |tar|
88
+ data_digests = package.add_contents tar
89
+ end
90
+
89
91
  expected = {
90
- 'SHA1' => {
91
- 'metadata.gz' => metadata_sha1,
92
- 'data.tar.gz' => Digest::SHA1.hexdigest(tar),
93
- },
94
92
  'SHA512' => {
95
93
  'metadata.gz' => metadata_sha512,
96
- 'data.tar.gz' => Digest::SHA512.hexdigest(tar),
94
+ 'data.tar.gz' => data_digests['SHA512'].hexdigest,
97
95
  }
98
96
  }
99
97
 
98
+ if defined?(OpenSSL::Digest) then
99
+ expected['SHA1'] = {
100
+ 'metadata.gz' => metadata_sha1,
101
+ 'data.tar.gz' => data_digests['SHA1'].hexdigest,
102
+ }
103
+ end
104
+
100
105
  assert_equal expected, YAML.load(checksums)
101
106
  end
102
107
 
@@ -160,11 +165,56 @@ class TestGemPackage < Gem::Package::TarTestCase
160
165
  end
161
166
 
162
167
  def test_build_auto_signed
168
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
169
+
163
170
  FileUtils.mkdir_p File.join(Gem.user_home, '.gem')
164
171
 
165
172
  private_key_path = File.join Gem.user_home, '.gem', 'gem-private_key.pem'
166
173
  Gem::Security.write PRIVATE_KEY, private_key_path
167
174
 
175
+ public_cert_path = File.join Gem.user_home, '.gem', 'gem-public_cert.pem'
176
+ FileUtils.cp PUBLIC_CERT_PATH, public_cert_path
177
+
178
+ spec = Gem::Specification.new 'build', '1'
179
+ spec.summary = 'build'
180
+ spec.authors = 'build'
181
+ spec.files = ['lib/code.rb']
182
+
183
+ FileUtils.mkdir 'lib'
184
+
185
+ open 'lib/code.rb', 'w' do |io|
186
+ io.write '# lib/code.rb'
187
+ end
188
+
189
+ package = Gem::Package.new spec.file_name
190
+ package.spec = spec
191
+
192
+ package.build
193
+
194
+ assert_equal Gem::VERSION, spec.rubygems_version
195
+ assert_path_exists spec.file_name
196
+
197
+ reader = Gem::Package.new spec.file_name
198
+ assert reader.verify
199
+
200
+ assert_equal [PUBLIC_CERT.to_pem], reader.spec.cert_chain
201
+
202
+ assert_equal %w[metadata.gz metadata.gz.sig
203
+ data.tar.gz data.tar.gz.sig
204
+ checksums.yaml.gz checksums.yaml.gz.sig],
205
+ reader.files
206
+
207
+ assert_equal %w[lib/code.rb], reader.contents
208
+ end
209
+
210
+ def test_build_auto_signed_encrypted_key
211
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
212
+
213
+ FileUtils.mkdir_p File.join(Gem.user_home, '.gem')
214
+
215
+ private_key_path = File.join Gem.user_home, '.gem', 'gem-private_key.pem'
216
+ FileUtils.cp ENCRYPTED_PRIVATE_KEY_PATH, private_key_path
217
+
168
218
  public_cert_path = File.join Gem.user_home, '.gem', 'gem-public_cert.pem'
169
219
  Gem::Security.write PUBLIC_CERT, public_cert_path
170
220
 
@@ -214,6 +264,8 @@ class TestGemPackage < Gem::Package::TarTestCase
214
264
  end
215
265
 
216
266
  def test_build_signed
267
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
268
+
217
269
  spec = Gem::Specification.new 'build', '1'
218
270
  spec.summary = 'build'
219
271
  spec.authors = 'build'
@@ -248,6 +300,43 @@ class TestGemPackage < Gem::Package::TarTestCase
248
300
  assert_equal %w[lib/code.rb], reader.contents
249
301
  end
250
302
 
303
+ def test_build_signed_encryped_key
304
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
305
+
306
+ spec = Gem::Specification.new 'build', '1'
307
+ spec.summary = 'build'
308
+ spec.authors = 'build'
309
+ spec.files = ['lib/code.rb']
310
+ spec.cert_chain = [PUBLIC_CERT.to_pem]
311
+ spec.signing_key = ENCRYPTED_PRIVATE_KEY
312
+
313
+ FileUtils.mkdir 'lib'
314
+
315
+ open 'lib/code.rb', 'w' do |io|
316
+ io.write '# lib/code.rb'
317
+ end
318
+
319
+ package = Gem::Package.new spec.file_name
320
+ package.spec = spec
321
+
322
+ package.build
323
+
324
+ assert_equal Gem::VERSION, spec.rubygems_version
325
+ assert_path_exists spec.file_name
326
+
327
+ reader = Gem::Package.new spec.file_name
328
+ assert reader.verify
329
+
330
+ assert_equal spec, reader.spec
331
+
332
+ assert_equal %w[metadata.gz metadata.gz.sig
333
+ data.tar.gz data.tar.gz.sig
334
+ checksums.yaml.gz checksums.yaml.gz.sig],
335
+ reader.files
336
+
337
+ assert_equal %w[lib/code.rb], reader.contents
338
+ end
339
+
251
340
  def test_contents
252
341
  package = Gem::Package.new @gem
253
342
 
@@ -444,7 +533,7 @@ class TestGemPackage < Gem::Package::TarTestCase
444
533
  io.write metadata_gz
445
534
  end
446
535
 
447
- digest = OpenSSL::Digest::SHA1.new
536
+ digest = Digest::SHA1.new
448
537
  digest << metadata_gz
449
538
 
450
539
  checksums = {
@@ -476,7 +565,8 @@ class TestGemPackage < Gem::Package::TarTestCase
476
565
  def test_verify_corrupt
477
566
  Tempfile.open 'corrupt' do |io|
478
567
  data = Gem.gzip 'a' * 10
479
- io.write tar_file_header('metadata.gz', "\000x", 0644, data.length)
568
+ io.write \
569
+ tar_file_header('metadata.gz', "\000x", 0644, data.length, Time.now)
480
570
  io.write data
481
571
  io.rewind
482
572
 
@@ -515,6 +605,8 @@ class TestGemPackage < Gem::Package::TarTestCase
515
605
  end
516
606
 
517
607
  def test_verify_security_policy
608
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
609
+
518
610
  package = Gem::Package.new @gem
519
611
  package.security_policy = Gem::Security::HighSecurity
520
612
 
@@ -530,6 +622,8 @@ class TestGemPackage < Gem::Package::TarTestCase
530
622
  end
531
623
 
532
624
  def test_verify_security_policy_low_security
625
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
626
+
533
627
  @spec.cert_chain = [PUBLIC_CERT.to_pem]
534
628
  @spec.signing_key = PRIVATE_KEY
535
629
 
@@ -548,6 +642,8 @@ class TestGemPackage < Gem::Package::TarTestCase
548
642
  end
549
643
 
550
644
  def test_verify_security_policy_checksum_missing
645
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
646
+
551
647
  @spec.cert_chain = [PUBLIC_CERT.to_pem]
552
648
  @spec.signing_key = PRIVATE_KEY
553
649
 
@@ -603,6 +699,21 @@ class TestGemPackage < Gem::Package::TarTestCase
603
699
  e.message
604
700
  end
605
701
 
702
+ # end #verify tests
703
+
704
+ def test_verify_entry
705
+ entry = Object.new
706
+ def entry.full_name() raise ArgumentError, 'whatever' end
707
+
708
+ package = Gem::Package.new @gem
709
+
710
+ e = assert_raises Gem::Package::FormatError do
711
+ package.verify_entry entry
712
+ end
713
+
714
+ assert_equal "package is corrupt, exception while verifying: whatever (ArgumentError) in #{@gem}", e.message
715
+ end
716
+
606
717
  def test_spec
607
718
  package = Gem::Package.new @gem
608
719