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
@@ -0,0 +1,239 @@
1
+ require 'rubygems/test_case'
2
+ require 'rubygems/request'
3
+ require 'ostruct'
4
+
5
+ class TestGemRequest < Gem::TestCase
6
+
7
+ def setup
8
+ @proxies = %w[http_proxy HTTP_PROXY http_proxy_user HTTP_PROXY_USER http_proxy_pass HTTP_PROXY_PASS no_proxy NO_PROXY]
9
+ @old_proxies = @proxies.map {|k| ENV[k] }
10
+ @proxies.each {|k| ENV[k] = nil }
11
+
12
+ super
13
+
14
+ @proxy_uri = "http://localhost:1234"
15
+
16
+ @request = Gem::Request.new nil, nil, nil, nil
17
+ end
18
+
19
+ def teardown
20
+ super
21
+ Gem.configuration[:http_proxy] = nil
22
+ @proxies.each_with_index {|k, i| ENV[k] = @old_proxies[i] }
23
+ end
24
+
25
+ def test_initialize_proxy
26
+ proxy_uri = 'http://proxy.example.com'
27
+
28
+ request = Gem::Request.new nil, nil, nil, proxy_uri
29
+
30
+ assert_equal proxy_uri, request.proxy_uri.to_s
31
+ end
32
+
33
+ def test_initialize_proxy_URI
34
+ proxy_uri = 'http://proxy.example.com'
35
+
36
+ request = Gem::Request.new nil, nil, nil, URI(proxy_uri)
37
+
38
+ assert_equal proxy_uri, request.proxy_uri.to_s
39
+ end
40
+
41
+ def test_initialize_proxy_ENV
42
+ ENV['http_proxy'] = @proxy_uri
43
+ ENV['http_proxy_user'] = 'foo'
44
+ ENV['http_proxy_pass'] = 'bar'
45
+
46
+ request = Gem::Request.new nil, nil, nil, nil
47
+
48
+ proxy = request.proxy_uri
49
+
50
+ assert_equal 'foo', proxy.user
51
+ assert_equal 'bar', proxy.password
52
+ end
53
+
54
+ def test_get_proxy_from_env_domain
55
+ ENV['http_proxy'] = @proxy_uri
56
+ ENV['http_proxy_user'] = 'foo\user'
57
+ ENV['http_proxy_pass'] = 'my bar'
58
+
59
+ proxy = @request.get_proxy_from_env
60
+
61
+ assert_equal 'foo\user', Gem::UriFormatter.new(proxy.user).unescape
62
+ assert_equal 'my bar', Gem::UriFormatter.new(proxy.password).unescape
63
+ end
64
+
65
+ def test_get_proxy_from_env_normalize
66
+ ENV['HTTP_PROXY'] = 'fakeurl:12345'
67
+
68
+ assert_equal 'http://fakeurl:12345', @request.get_proxy_from_env.to_s
69
+ end
70
+
71
+ def test_get_proxy_from_env_empty
72
+ ENV['HTTP_PROXY'] = ''
73
+ ENV.delete 'http_proxy'
74
+
75
+ assert_nil @request.get_proxy_from_env
76
+ end
77
+
78
+ def test_fetch
79
+ uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
80
+ @request = Gem::Request.new(uri, Net::HTTP::Get, nil, nil)
81
+ util_stub_connection_for :body => :junk, :code => 200
82
+
83
+ response = @request.fetch
84
+
85
+ assert_equal 200, response.code
86
+ assert_equal :junk, response.body
87
+ end
88
+
89
+ def test_fetch_head
90
+ uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
91
+ @request = Gem::Request.new(uri, Net::HTTP::Get, nil, nil)
92
+ util_stub_connection_for :body => '', :code => 200
93
+
94
+ response = @request.fetch
95
+
96
+ assert_equal 200, response.code
97
+ assert_equal '', response.body
98
+ end
99
+
100
+ def test_fetch_unmodified
101
+ uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
102
+ t = Time.now
103
+ @request = Gem::Request.new(uri, Net::HTTP::Get, t, nil)
104
+ conn = util_stub_connection_for :body => '', :code => 304
105
+
106
+ response = @request.fetch
107
+
108
+ assert_equal 304, response.code
109
+ assert_equal '', response.body
110
+
111
+ assert_equal t.rfc2822, conn.payload['if-modified-since']
112
+ end
113
+
114
+ def test_user_agent
115
+ ua = Gem::Request.new(nil, nil, nil, nil).user_agent
116
+
117
+ assert_match %r%^RubyGems/\S+ \S+ Ruby/\S+ \(.*?\)%, ua
118
+ assert_match %r%RubyGems/#{Regexp.escape Gem::VERSION}%, ua
119
+ assert_match %r% #{Regexp.escape Gem::Platform.local.to_s} %, ua
120
+ assert_match %r%Ruby/#{Regexp.escape RUBY_VERSION}%, ua
121
+ assert_match %r%\(#{Regexp.escape RUBY_RELEASE_DATE} %, ua
122
+ end
123
+
124
+ def test_user_agent_engine
125
+ util_save_version
126
+
127
+ Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE)
128
+ Object.send :const_set, :RUBY_ENGINE, 'vroom'
129
+
130
+ ua = Gem::Request.new(nil, nil, nil, nil).user_agent
131
+
132
+ assert_match %r%\) vroom%, ua
133
+ ensure
134
+ util_restore_version
135
+ end
136
+
137
+ def test_user_agent_engine_ruby
138
+ util_save_version
139
+
140
+ Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE)
141
+ Object.send :const_set, :RUBY_ENGINE, 'ruby'
142
+
143
+ ua = Gem::Request.new(nil, nil, nil, nil).user_agent
144
+
145
+ assert_match %r%\)%, ua
146
+ ensure
147
+ util_restore_version
148
+ end
149
+
150
+ def test_user_agent_patchlevel
151
+ util_save_version
152
+
153
+ Object.send :remove_const, :RUBY_PATCHLEVEL
154
+ Object.send :const_set, :RUBY_PATCHLEVEL, 5
155
+
156
+ ua = Gem::Request.new(nil, nil, nil, nil).user_agent
157
+
158
+ assert_match %r% patchlevel 5\)%, ua
159
+ ensure
160
+ util_restore_version
161
+ end
162
+
163
+ def test_user_agent_revision
164
+ util_save_version
165
+
166
+ Object.send :remove_const, :RUBY_PATCHLEVEL
167
+ Object.send :const_set, :RUBY_PATCHLEVEL, -1
168
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
169
+ Object.send :const_set, :RUBY_REVISION, 6
170
+
171
+ ua = Gem::Request.new(nil, nil, nil, nil).user_agent
172
+
173
+ assert_match %r% revision 6\)%, ua
174
+ assert_match %r%Ruby/#{Regexp.escape RUBY_VERSION}dev%, ua
175
+ ensure
176
+ util_restore_version
177
+ end
178
+
179
+ def test_user_agent_revision_missing
180
+ util_save_version
181
+
182
+ Object.send :remove_const, :RUBY_PATCHLEVEL
183
+ Object.send :const_set, :RUBY_PATCHLEVEL, -1
184
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
185
+
186
+ ua = Gem::Request.new(nil, nil, nil, nil).user_agent
187
+
188
+ assert_match %r%\(#{Regexp.escape RUBY_RELEASE_DATE}\)%, ua
189
+ ensure
190
+ util_restore_version
191
+ end
192
+
193
+ def util_restore_version
194
+ Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE)
195
+ Object.send :const_set, :RUBY_ENGINE, @orig_RUBY_ENGINE if
196
+ defined?(@orig_RUBY_ENGINE)
197
+
198
+ Object.send :remove_const, :RUBY_PATCHLEVEL
199
+ Object.send :const_set, :RUBY_PATCHLEVEL, @orig_RUBY_PATCHLEVEL
200
+
201
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
202
+ Object.send :const_set, :RUBY_REVISION, @orig_RUBY_REVISION if
203
+ defined?(@orig_RUBY_REVISION)
204
+ end
205
+
206
+ def util_save_version
207
+ @orig_RUBY_ENGINE = RUBY_ENGINE if defined? RUBY_ENGINE
208
+ @orig_RUBY_PATCHLEVEL = RUBY_PATCHLEVEL
209
+ @orig_RUBY_REVISION = RUBY_REVISION if defined? RUBY_REVISION
210
+ end
211
+
212
+ def util_stub_connection_for hash
213
+ def @request.connection= conn
214
+ @conn = conn
215
+ end
216
+
217
+ def @request.connection_for uri
218
+ @conn
219
+ end
220
+
221
+ @request.connection = Conn.new OpenStruct.new(hash)
222
+ end
223
+
224
+ class Conn
225
+ attr_accessor :payload
226
+
227
+ def initialize(response)
228
+ @response = response
229
+ self.payload = nil
230
+ end
231
+
232
+ def request(req)
233
+ self.payload = req
234
+ @response
235
+ end
236
+ end
237
+
238
+ end
239
+
@@ -47,20 +47,18 @@ class TestGemRequirement < Gem::TestCase
47
47
  end
48
48
 
49
49
  def test_parse_bad
50
- [
51
- nil,
52
- '',
53
- '! 1',
54
- '= junk',
55
- '1..2',
56
- ].each do |bad|
57
- e = assert_raises Gem::Requirement::BadRequirementError do
58
- Gem::Requirement.parse bad
59
- end
50
+ e = assert_raises Gem::Requirement::BadRequirementError do
51
+ Gem::Requirement.parse nil
52
+ end
60
53
 
61
- assert_equal "Illformed requirement [#{bad.inspect}]", e.message
54
+ assert_equal 'Illformed requirement [nil]', e.message
55
+
56
+ e = assert_raises Gem::Requirement::BadRequirementError do
57
+ Gem::Requirement.parse ""
62
58
  end
63
59
 
60
+ assert_equal 'Illformed requirement [""]', e.message
61
+
64
62
  assert_equal Gem::Requirement::BadRequirementError.superclass, ArgumentError
65
63
  end
66
64
 
@@ -2,6 +2,10 @@ require 'rubygems/test_case'
2
2
  require 'rubygems/security'
3
3
  require 'rubygems/fix_openssl_warnings' if RUBY_VERSION < "1.9"
4
4
 
5
+ unless defined?(OpenSSL::SSL) then
6
+ warn 'Skipping Gem::Security tests. openssl not found.'
7
+ end
8
+
5
9
  class TestGemSecurity < Gem::TestCase
6
10
 
7
11
  CHILD_KEY = load_key 'child'
@@ -95,7 +99,7 @@ class TestGemSecurity < Gem::TestCase
95
99
  end
96
100
 
97
101
  def test_class_create_key
98
- key = @SEC.create_key 256
102
+ key = @SEC.create_key 1024
99
103
 
100
104
  assert_kind_of OpenSSL::PKey::RSA, key
101
105
  end
@@ -246,5 +250,57 @@ class TestGemSecurity < Gem::TestCase
246
250
  assert_equal expected, trust_dir.dir
247
251
  end
248
252
 
249
- end
253
+ def test_class_write
254
+ key = @SEC.create_key 1024
255
+
256
+ path = File.join @tempdir, 'test-private_key.pem'
257
+
258
+ @SEC.write key, path
259
+
260
+ assert_path_exists path
261
+
262
+ key_from_file = File.read path
263
+
264
+ assert_equal key.to_pem, key_from_file
265
+ end
266
+
267
+ def test_class_write_encrypted
268
+ key = @SEC.create_key 1024
269
+
270
+ path = File.join @tempdir, 'test-private_encrypted_key.pem'
271
+
272
+ passphrase = 'It should be long.'
273
+
274
+ @SEC.write key, path, 0600, passphrase
275
+
276
+ assert_path_exists path
277
+
278
+ key_from_file = OpenSSL::PKey::RSA.new File.read(path), passphrase
279
+
280
+ assert_equal key.to_pem, key_from_file.to_pem
281
+ end
282
+
283
+ def test_class_write_encrypted_cipher
284
+ key = @SEC.create_key 1024
285
+
286
+ path = File.join @tempdir, 'test-private_encrypted__with_non_default_cipher_key.pem'
287
+
288
+ passphrase = 'It should be long.'
289
+
290
+ cipher = OpenSSL::Cipher.new 'AES-192-CBC'
291
+
292
+ @SEC.write key, path, 0600, passphrase, cipher
293
+
294
+ assert_path_exists path
295
+
296
+ key_file_contents = File.read(path)
297
+
298
+ assert key_file_contents.split("\n")[2].match(cipher.name)
299
+
300
+ key_from_file = OpenSSL::PKey::RSA.new key_file_contents, passphrase
301
+
302
+ assert_equal key.to_pem, key_from_file.to_pem
303
+ end
304
+
305
+ end if defined?(OpenSSL::SSL)
250
306
 
@@ -2,6 +2,10 @@
2
2
 
3
3
  require 'rubygems/test_case'
4
4
 
5
+ unless defined?(OpenSSL::SSL) then
6
+ warn 'Skipping Gem::Security::Policy tests. openssl not found.'
7
+ end
8
+
5
9
  class TestGemSecurityPolicy < Gem::TestCase
6
10
 
7
11
  ALTERNATE_KEY = load_key 'alternate'
@@ -11,6 +15,7 @@ class TestGemSecurityPolicy < Gem::TestCase
11
15
  INVALIDCHILD_KEY = load_key 'invalidchild'
12
16
 
13
17
  ALTERNATE_CERT = load_cert 'alternate'
18
+ CA_CERT = load_cert 'ca'
14
19
  CHILD_CERT = load_cert 'child'
15
20
  EXPIRED_CERT = load_cert 'expired'
16
21
  FUTURE_CERT = load_cert 'future'
@@ -285,6 +290,11 @@ class TestGemSecurityPolicy < Gem::TestCase
285
290
  "(root of signing cert #{CHILD_CERT.subject})", e.message
286
291
  end
287
292
 
293
+ def test_subject
294
+ assert_equal 'email:nobody@example', @no.subject(PUBLIC_CERT)
295
+ assert_equal '/C=JP/O=JIN.GR.JP/OU=RRR/CN=CA', @no.subject(CA_CERT)
296
+ end
297
+
288
298
  def test_verify
289
299
  Gem::Security.trust_dir.trust_cert PUBLIC_CERT
290
300
 
@@ -325,6 +335,22 @@ class TestGemSecurityPolicy < Gem::TestCase
325
335
  assert_equal 'missing digest for 0', e.message
326
336
  end
327
337
 
338
+ def test_verify_no_signatures
339
+ Gem::Security.trust_dir.trust_cert PUBLIC_CERT
340
+
341
+ digests, = dummy_signatures
342
+
343
+ use_ui @ui do
344
+ @no.verify [PUBLIC_CERT], nil, digests, {}, 'some_gem'
345
+ end
346
+
347
+ assert_match "WARNING: some_gem is not signed\n", @ui.error
348
+
349
+ assert_raises Gem::Security::Exception do
350
+ @almost_no.verify [PUBLIC_CERT], nil, digests, {}
351
+ end
352
+ end
353
+
328
354
  def test_verify_not_enough_signatures
329
355
  Gem::Security.trust_dir.trust_cert PUBLIC_CERT
330
356
 
@@ -341,6 +367,21 @@ class TestGemSecurityPolicy < Gem::TestCase
341
367
  assert_equal 'missing digest for 1', e.message
342
368
  end
343
369
 
370
+ def test_verify_no_trust
371
+ digests, signatures = dummy_signatures
372
+
373
+ use_ui @ui do
374
+ @low.verify [PUBLIC_CERT], nil, digests, signatures, 'some_gem'
375
+ end
376
+
377
+ assert_equal "WARNING: email:nobody@example is not trusted for some_gem\n",
378
+ @ui.error
379
+
380
+ assert_raises Gem::Security::Exception do
381
+ @medium.verify [PUBLIC_CERT], nil, digests, signatures
382
+ end
383
+ end
384
+
344
385
  def test_verify_wrong_digest_type
345
386
  Gem::Security.trust_dir.trust_cert PUBLIC_CERT
346
387
 
@@ -484,5 +525,5 @@ class TestGemSecurityPolicy < Gem::TestCase
484
525
  return digests, signatures
485
526
  end
486
527
 
487
- end
528
+ end if defined?(OpenSSL::SSL)
488
529
 
@@ -1,5 +1,9 @@
1
1
  require 'rubygems/test_case'
2
2
 
3
+ unless defined?(OpenSSL::SSL) then
4
+ warn 'Skipping Gem::Security::Signer tests. openssl not found.'
5
+ end
6
+
3
7
  class TestGemSecuritySigner < Gem::TestCase
4
8
 
5
9
  ALTERNATE_KEY = load_key 'alternate'
@@ -72,6 +76,14 @@ class TestGemSecuritySigner < Gem::TestCase
72
76
  assert_equal PRIVATE_KEY.to_s, signer.key.to_s
73
77
  end
74
78
 
79
+ def test_initialize_encrypted_key_path
80
+ key_file = ENCRYPTED_PRIVATE_KEY_PATH
81
+
82
+ signer = Gem::Security::Signer.new key_file, nil, PRIVATE_KEY_PASSPHRASE
83
+
84
+ assert_equal ENCRYPTED_PRIVATE_KEY.to_s, signer.key.to_s
85
+ end
86
+
75
87
  def test_load_cert_chain
76
88
  Gem::Security.trust_dir.trust_cert PUBLIC_CERT
77
89
 
@@ -186,5 +198,5 @@ c7NM7KZZjj7G++SXjYTEI1PHSA7aFQ/i/+qSUvx+Pg==
186
198
  end
187
199
  end
188
200
 
189
- end
201
+ end if defined?(OpenSSL::SSL)
190
202