rubygems-update 1.8.30 → 2.0.0.preview2

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 (241) hide show
  1. checksums.yaml +6 -6
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +3 -0
  4. data/.autotest +6 -3
  5. data/History.txt +137 -63
  6. data/LICENSE.txt +1 -5
  7. data/Manifest.txt +69 -32
  8. data/README.rdoc +11 -9
  9. data/Rakefile +24 -38
  10. data/bin/gem +0 -9
  11. data/bin/update_rubygems +1 -0
  12. data/lib/rubygems.rb +193 -405
  13. data/lib/rubygems/available_set.rb +95 -0
  14. data/lib/rubygems/command.rb +88 -45
  15. data/lib/rubygems/command_manager.rb +67 -40
  16. data/lib/rubygems/commands/build_command.rb +5 -23
  17. data/lib/rubygems/commands/cert_command.rb +199 -57
  18. data/lib/rubygems/commands/check_command.rb +14 -39
  19. data/lib/rubygems/commands/cleanup_command.rb +9 -1
  20. data/lib/rubygems/commands/contents_command.rb +30 -12
  21. data/lib/rubygems/commands/dependency_command.rb +3 -8
  22. data/lib/rubygems/commands/environment_command.rb +13 -8
  23. data/lib/rubygems/commands/fetch_command.rb +3 -16
  24. data/lib/rubygems/commands/generate_index_command.rb +7 -47
  25. data/lib/rubygems/commands/help_command.rb +1 -1
  26. data/lib/rubygems/commands/install_command.rb +69 -36
  27. data/lib/rubygems/commands/list_command.rb +6 -4
  28. data/lib/rubygems/commands/lock_command.rb +1 -1
  29. data/lib/rubygems/commands/mirror_command.rb +17 -0
  30. data/lib/rubygems/commands/outdated_command.rb +6 -3
  31. data/lib/rubygems/commands/owner_command.rb +13 -5
  32. data/lib/rubygems/commands/pristine_command.rb +19 -4
  33. data/lib/rubygems/commands/push_command.rb +12 -1
  34. data/lib/rubygems/commands/query_command.rb +43 -27
  35. data/lib/rubygems/commands/rdoc_command.rb +23 -28
  36. data/lib/rubygems/commands/search_command.rb +4 -18
  37. data/lib/rubygems/commands/server_command.rb +1 -1
  38. data/lib/rubygems/commands/setup_command.rb +124 -38
  39. data/lib/rubygems/commands/sources_command.rb +16 -16
  40. data/lib/rubygems/commands/specification_command.rb +11 -13
  41. data/lib/rubygems/commands/uninstall_command.rb +24 -7
  42. data/lib/rubygems/commands/unpack_command.rb +7 -3
  43. data/lib/rubygems/commands/update_command.rb +22 -36
  44. data/lib/rubygems/commands/yank_command.rb +98 -0
  45. data/lib/rubygems/compatibility.rb +51 -0
  46. data/lib/rubygems/config_file.rb +82 -54
  47. data/lib/rubygems/core_ext/kernel_gem.rb +53 -0
  48. data/lib/rubygems/core_ext/kernel_require.rb +119 -0
  49. data/lib/rubygems/defaults.rb +10 -21
  50. data/lib/rubygems/dependency.rb +61 -10
  51. data/lib/rubygems/dependency_installer.rb +157 -69
  52. data/lib/rubygems/dependency_list.rb +11 -19
  53. data/lib/rubygems/dependency_resolver.rb +562 -0
  54. data/lib/rubygems/deprecate.rb +40 -40
  55. data/lib/rubygems/errors.rb +77 -24
  56. data/lib/rubygems/exceptions.rb +25 -7
  57. data/lib/rubygems/ext/builder.rb +20 -23
  58. data/lib/rubygems/ext/configure_builder.rb +2 -2
  59. data/lib/rubygems/ext/ext_conf_builder.rb +5 -45
  60. data/lib/rubygems/ext/rake_builder.rb +2 -2
  61. data/lib/rubygems/gem_runner.rb +3 -16
  62. data/lib/rubygems/gemcutter_utilities.rb +22 -7
  63. data/lib/rubygems/indexer.rb +6 -159
  64. data/lib/rubygems/install_message.rb +12 -0
  65. data/lib/rubygems/install_update_options.rb +56 -18
  66. data/lib/rubygems/installer.rb +244 -134
  67. data/lib/rubygems/installer_test_case.rb +71 -19
  68. data/lib/rubygems/mock_gem_ui.rb +17 -0
  69. data/lib/rubygems/name_tuple.rb +110 -0
  70. data/lib/rubygems/package.rb +514 -43
  71. data/lib/rubygems/package/digest_io.rb +64 -0
  72. data/lib/rubygems/package/old.rb +147 -0
  73. data/lib/rubygems/package/tar_header.rb +18 -55
  74. data/lib/rubygems/package/tar_reader.rb +20 -3
  75. data/lib/rubygems/package/tar_writer.rb +63 -7
  76. data/lib/rubygems/package_task.rb +3 -4
  77. data/lib/rubygems/path_support.rb +14 -7
  78. data/lib/rubygems/platform.rb +19 -26
  79. data/lib/rubygems/rdoc.rb +316 -0
  80. data/lib/rubygems/remote_fetcher.rb +117 -54
  81. data/lib/rubygems/request_set.rb +182 -0
  82. data/lib/rubygems/requirement.rb +63 -26
  83. data/lib/rubygems/security.rb +295 -555
  84. data/lib/rubygems/security/policies.rb +115 -0
  85. data/lib/rubygems/security/policy.rb +227 -0
  86. data/lib/rubygems/security/signer.rb +136 -0
  87. data/lib/rubygems/security/trust_dir.rb +104 -0
  88. data/lib/rubygems/server.rb +45 -55
  89. data/lib/rubygems/source.rb +144 -0
  90. data/lib/rubygems/source_list.rb +87 -0
  91. data/lib/rubygems/source_local.rb +92 -0
  92. data/lib/rubygems/source_specific_file.rb +28 -0
  93. data/lib/rubygems/spec_fetcher.rb +116 -184
  94. data/lib/rubygems/specification.rb +731 -335
  95. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot.pem +88 -30
  96. data/lib/rubygems/ssl_certs/Entrust_net-Secure-Server-Certification-Authority.pem +90 -0
  97. data/lib/rubygems/ssl_certs/VerisignClass3PublicPrimaryCertificationAuthority-G2.pem +57 -0
  98. data/lib/rubygems/syck_hack.rb +2 -0
  99. data/lib/rubygems/test_case.rb +199 -109
  100. data/lib/rubygems/test_utilities.rb +25 -5
  101. data/lib/rubygems/uninstaller.rb +62 -20
  102. data/lib/rubygems/user_interaction.rb +10 -0
  103. data/lib/rubygems/validator.rb +33 -40
  104. data/lib/rubygems/version.rb +19 -8
  105. data/setup.rb +8 -1
  106. data/test/rubygems/alternate_cert.pem +9 -0
  107. data/test/rubygems/alternate_cert_32.pem +9 -0
  108. data/test/rubygems/alternate_key.pem +9 -0
  109. data/test/rubygems/bad_rake.rb +1 -0
  110. data/test/rubygems/child_cert.pem +9 -0
  111. data/test/rubygems/child_cert_32.pem +9 -0
  112. data/test/rubygems/child_key.pem +9 -0
  113. data/test/rubygems/data/null-type.gemspec.rz +0 -0
  114. data/test/rubygems/expired_cert.pem +9 -0
  115. data/test/rubygems/future_cert.pem +9 -0
  116. data/test/rubygems/future_cert_32.pem +9 -0
  117. data/test/rubygems/good_rake.rb +1 -0
  118. data/test/rubygems/grandchild_cert.pem +9 -0
  119. data/test/rubygems/grandchild_cert_32.pem +9 -0
  120. data/test/rubygems/grandchild_key.pem +9 -0
  121. data/test/rubygems/invalid_issuer_cert.pem +9 -0
  122. data/test/rubygems/invalid_issuer_cert_32.pem +9 -0
  123. data/test/rubygems/invalid_key.pem +9 -0
  124. data/test/rubygems/invalid_signer_cert.pem +9 -0
  125. data/test/rubygems/invalid_signer_cert_32.pem +9 -0
  126. data/test/rubygems/invalidchild_cert.pem +9 -0
  127. data/test/rubygems/invalidchild_cert_32.pem +9 -0
  128. data/test/rubygems/invalidchild_key.pem +9 -0
  129. data/test/rubygems/plugin/exception/rubygems_plugin.rb +1 -1
  130. data/test/rubygems/plugin/standarderror/rubygems_plugin.rb +1 -1
  131. data/test/rubygems/private_key.pem +7 -25
  132. data/test/rubygems/public_cert.pem +8 -18
  133. data/test/rubygems/public_cert_32.pem +10 -0
  134. data/test/rubygems/public_key.pem +4 -0
  135. data/test/rubygems/rubygems/commands/crash_command.rb +1 -1
  136. data/test/rubygems/test_config.rb +4 -6
  137. data/test/rubygems/test_deprecate.rb +76 -0
  138. data/test/rubygems/test_gem.rb +318 -83
  139. data/test/rubygems/test_gem_available_set.rb +106 -0
  140. data/test/rubygems/test_gem_command.rb +10 -0
  141. data/test/rubygems/test_gem_command_manager.rb +55 -9
  142. data/test/rubygems/test_gem_commands_build_command.rb +11 -19
  143. data/test/rubygems/test_gem_commands_cert_command.rb +441 -42
  144. data/test/rubygems/test_gem_commands_cleanup_command.rb +29 -1
  145. data/test/rubygems/test_gem_commands_contents_command.rb +23 -0
  146. data/test/rubygems/test_gem_commands_dependency_command.rb +5 -0
  147. data/test/rubygems/test_gem_commands_fetch_command.rb +19 -20
  148. data/test/rubygems/test_gem_commands_generate_index_command.rb +2 -83
  149. data/test/rubygems/test_gem_commands_help_command.rb +2 -1
  150. data/test/rubygems/test_gem_commands_install_command.rb +647 -48
  151. data/test/rubygems/test_gem_commands_mirror.rb +32 -0
  152. data/test/rubygems/test_gem_commands_owner_command.rb +4 -8
  153. data/test/rubygems/test_gem_commands_pristine_command.rb +99 -4
  154. data/test/rubygems/test_gem_commands_push_command.rb +62 -8
  155. data/test/rubygems/test_gem_commands_query_command.rb +51 -0
  156. data/test/rubygems/test_gem_commands_search_command.rb +25 -0
  157. data/test/rubygems/test_gem_commands_setup_command.rb +45 -0
  158. data/test/rubygems/test_gem_commands_sources_command.rb +21 -6
  159. data/test/rubygems/test_gem_commands_specification_command.rb +33 -1
  160. data/test/rubygems/test_gem_commands_uninstall_command.rb +91 -31
  161. data/test/rubygems/test_gem_commands_unpack_command.rb +3 -3
  162. data/test/rubygems/test_gem_commands_update_command.rb +56 -38
  163. data/test/rubygems/test_gem_commands_which_command.rb +4 -4
  164. data/test/rubygems/test_gem_commands_yank_command.rb +97 -0
  165. data/test/rubygems/test_gem_config_file.rb +66 -21
  166. data/test/rubygems/test_gem_dependency.rb +46 -0
  167. data/test/rubygems/test_gem_dependency_installer.rb +228 -18
  168. data/test/rubygems/test_gem_dependency_list.rb +0 -9
  169. data/test/rubygems/test_gem_dependency_resolver.rb +327 -0
  170. data/test/rubygems/test_gem_ext_configure_builder.rb +4 -4
  171. data/test/rubygems/test_gem_ext_ext_conf_builder.rb +21 -49
  172. data/test/rubygems/test_gem_ext_rake_builder.rb +13 -13
  173. data/test/rubygems/test_gem_gem_runner.rb +27 -5
  174. data/test/rubygems/test_gem_gemcutter_utilities.rb +19 -0
  175. data/test/rubygems/test_gem_indexer.rb +14 -227
  176. data/test/rubygems/test_gem_install_update_options.rb +83 -3
  177. data/test/rubygems/test_gem_installer.rb +211 -236
  178. data/test/rubygems/test_gem_local_remote_options.rb +8 -2
  179. data/test/rubygems/test_gem_name_tuple.rb +15 -0
  180. data/test/rubygems/test_gem_package.rb +547 -0
  181. data/test/rubygems/test_gem_package_old.rb +37 -0
  182. data/test/rubygems/test_gem_package_tar_reader.rb +32 -0
  183. data/test/rubygems/test_gem_package_tar_writer.rb +84 -1
  184. data/test/rubygems/test_gem_path_support.rb +4 -30
  185. data/test/rubygems/test_gem_platform.rb +3 -6
  186. data/test/rubygems/test_gem_rdoc.rb +245 -0
  187. data/test/rubygems/test_gem_remote_fetcher.rb +51 -5
  188. data/test/rubygems/test_gem_request_set.rb +70 -0
  189. data/test/rubygems/test_gem_requirement.rb +53 -24
  190. data/test/rubygems/test_gem_security.rb +189 -43
  191. data/test/rubygems/test_gem_security_policy.rb +376 -0
  192. data/test/rubygems/test_gem_security_signer.rb +184 -0
  193. data/test/rubygems/test_gem_security_trust_dir.rb +94 -0
  194. data/test/rubygems/test_gem_server.rb +31 -36
  195. data/test/rubygems/test_gem_silent_ui.rb +2 -2
  196. data/test/rubygems/test_gem_source.rb +188 -0
  197. data/test/rubygems/test_gem_source_list.rb +87 -0
  198. data/test/rubygems/test_gem_source_local.rb +83 -0
  199. data/test/rubygems/test_gem_source_specific_file.rb +33 -0
  200. data/test/rubygems/test_gem_spec_fetcher.rb +91 -255
  201. data/test/rubygems/test_gem_specification.rb +293 -39
  202. data/test/rubygems/test_gem_uninstaller.rb +136 -13
  203. data/test/rubygems/test_gem_validator.rb +14 -41
  204. data/test/rubygems/test_gem_version.rb +15 -21
  205. data/test/rubygems/test_require.rb +193 -0
  206. data/test/rubygems/wrong_key_cert.pem +9 -0
  207. data/test/rubygems/wrong_key_cert_32.pem +9 -0
  208. metadata +171 -83
  209. metadata.gz.sig +1 -0
  210. data/CVE-2013-4287.txt +0 -36
  211. data/CVE-2013-4363.txt +0 -45
  212. data/ci_build.sh +0 -27
  213. data/cruise_config.rb +0 -32
  214. data/lib/rbconfig/datadir.rb +0 -13
  215. data/lib/rubygems/builder.rb +0 -99
  216. data/lib/rubygems/custom_require.rb +0 -69
  217. data/lib/rubygems/doc_manager.rb +0 -243
  218. data/lib/rubygems/format.rb +0 -82
  219. data/lib/rubygems/gem_openssl.rb +0 -90
  220. data/lib/rubygems/gem_path_searcher.rb +0 -172
  221. data/lib/rubygems/old_format.rb +0 -153
  222. data/lib/rubygems/package/f_sync_dir.rb +0 -23
  223. data/lib/rubygems/package/tar_input.rb +0 -234
  224. data/lib/rubygems/package/tar_output.rb +0 -146
  225. data/lib/rubygems/require_paths_builder.rb +0 -18
  226. data/lib/rubygems/source_index.rb +0 -406
  227. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot-2048.pem +0 -25
  228. data/lib/rubygems/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem +0 -14
  229. data/lib/rubygems/ssl_certs/DigiCertHighAssuranceEVRootCA.pem +0 -23
  230. data/lib/rubygems/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem +0 -28
  231. data/lib/rubygems/ssl_certs/GeoTrustGlobalCA.pem +0 -20
  232. data/test/rubygems/test_bundled_ca.rb +0 -59
  233. data/test/rubygems/test_gem_builder.rb +0 -44
  234. data/test/rubygems/test_gem_doc_manager.rb +0 -32
  235. data/test/rubygems/test_gem_ext_builder.rb +0 -58
  236. data/test/rubygems/test_gem_format.rb +0 -88
  237. data/test/rubygems/test_gem_gem_path_searcher.rb +0 -94
  238. data/test/rubygems/test_gem_package_tar_input.rb +0 -129
  239. data/test/rubygems/test_gem_package_tar_output.rb +0 -101
  240. data/test/rubygems/test_gem_source_index.rb +0 -250
  241. data/util/update_bundled_ca_certificates.rb +0 -103
@@ -40,6 +40,8 @@ class TestGemLocalRemoteOptions < Gem::TestCase
40
40
  end
41
41
 
42
42
  def test_clear_sources_option_idiot_proof
43
+ util_setup_fake_fetcher
44
+
43
45
  @cmd.add_local_remote_options
44
46
  @cmd.handle_options %W[--clear-sources]
45
47
  assert_equal Gem.default_sources, Gem.sources
@@ -78,10 +80,14 @@ class TestGemLocalRemoteOptions < Gem::TestCase
78
80
  s4 = URI.parse 'http://more-gems.example.com/' # Intentional duplicate
79
81
 
80
82
  original_sources = Gem.sources.dup
83
+
81
84
  @cmd.handle_options %W[--source #{s1} --source #{s2} --source #{s3} --source #{s4}]
82
85
 
83
- assert_equal [original_sources, s1.to_s, s2.to_s, "#{s3}/"].flatten,
84
- Gem.sources
86
+ original_sources << s1.to_s
87
+ original_sources << s2.to_s
88
+ original_sources << "#{s3}/"
89
+
90
+ assert_equal original_sources, Gem.sources
85
91
  end
86
92
 
87
93
  def test_update_sources_option
@@ -0,0 +1,15 @@
1
+ require 'rubygems/test_case'
2
+ require 'rubygems/name_tuple'
3
+
4
+ class TestGemNameTuple < Gem::TestCase
5
+ def test_platform_normalization
6
+ n = Gem::NameTuple.new "a", Gem::Version.new(0), "ruby"
7
+ assert_equal "ruby", n.platform
8
+
9
+ n = Gem::NameTuple.new "a", Gem::Version.new(0), nil
10
+ assert_equal "ruby", n.platform
11
+
12
+ n = Gem::NameTuple.new "a", Gem::Version.new(0), ""
13
+ assert_equal "ruby", n.platform
14
+ end
15
+ end
@@ -0,0 +1,547 @@
1
+ # coding: UTF-8
2
+
3
+ require 'rubygems/package/tar_test_case'
4
+ require 'rubygems/simple_gem'
5
+
6
+ class TestGemPackage < Gem::Package::TarTestCase
7
+
8
+ def setup
9
+ super
10
+
11
+ @spec = quick_gem 'a' do |s|
12
+ s.description = 'π'
13
+ s.files = %w[lib/code.rb]
14
+ end
15
+
16
+ util_build_gem @spec
17
+
18
+ @gem = @spec.cache_file
19
+
20
+ @destination = File.join @tempdir, 'extract'
21
+ end
22
+
23
+ def test_class_new_old_format
24
+ open 'old_format.gem', 'wb' do |io|
25
+ io.write SIMPLE_GEM
26
+ end
27
+
28
+ package = Gem::Package.new 'old_format.gem'
29
+
30
+ assert package.spec
31
+ end
32
+
33
+ def test_add_checksums
34
+ gem_io = StringIO.new
35
+
36
+ spec = Gem::Specification.new 'build', '1'
37
+ spec.summary = 'build'
38
+ spec.authors = 'build'
39
+ spec.files = ['lib/code.rb']
40
+ spec.date = Time.at 0
41
+ spec.rubygems_version = Gem::Version.new '0'
42
+
43
+ FileUtils.mkdir 'lib'
44
+
45
+ open 'lib/code.rb', 'w' do |io|
46
+ io.write '# lib/code.rb'
47
+ end
48
+
49
+ package = Gem::Package.new spec.file_name
50
+ package.spec = spec
51
+ package.build_time = 1 # 0 uses current time
52
+ package.setup_signer
53
+
54
+ Gem::Package::TarWriter.new gem_io do |gem|
55
+ package.add_metadata gem
56
+ package.add_contents gem
57
+ package.add_checksums gem
58
+ end
59
+
60
+ gem_io.rewind
61
+
62
+ reader = Gem::Package::TarReader.new gem_io
63
+
64
+ checksums = nil
65
+
66
+ reader.each_entry do |entry|
67
+ case entry.full_name
68
+ when 'checksums.yaml.gz'
69
+ Zlib::GzipReader.wrap entry do |io|
70
+ checksums = io.read
71
+ end
72
+ end
73
+ end
74
+
75
+ s = StringIO.new
76
+
77
+ package.gzip_to s do |io|
78
+ io.write spec.to_yaml
79
+ end
80
+
81
+ metadata_sha1 = Digest::SHA1.hexdigest s.string
82
+ metadata_sha512 = Digest::SHA512.hexdigest s.string
83
+
84
+ data_digests = nil
85
+ util_tar do |tar|
86
+ data_digests = package.add_contents tar
87
+ end
88
+
89
+ expected = {
90
+ 'SHA1' => {
91
+ 'metadata.gz' => metadata_sha1,
92
+ 'data.tar.gz' => data_digests['SHA1'].hexdigest,
93
+ },
94
+ 'SHA512' => {
95
+ 'metadata.gz' => metadata_sha512,
96
+ 'data.tar.gz' => data_digests['SHA512'].hexdigest,
97
+ }
98
+ }
99
+
100
+ assert_equal expected, YAML.load(checksums)
101
+ end
102
+
103
+ def test_add_files
104
+ spec = Gem::Specification.new
105
+ spec.files = 'lib/code.rb'
106
+
107
+ FileUtils.mkdir 'lib'
108
+ open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end
109
+ open 'lib/extra.rb', 'w' do |io| io.write '# lib/extra.rb' end
110
+
111
+ package = Gem::Package.new 'bogus.gem'
112
+ package.spec = spec
113
+
114
+ tar = util_tar do |tar_io|
115
+ package.add_files tar_io
116
+ end
117
+
118
+ tar.rewind
119
+
120
+ files = []
121
+
122
+ Gem::Package::TarReader.new tar do |tar_io|
123
+ tar_io.each_entry do |entry|
124
+ files << entry.full_name
125
+ end
126
+ end
127
+
128
+ assert_equal %w[lib/code.rb], files
129
+ end
130
+
131
+ def test_build
132
+ spec = Gem::Specification.new 'build', '1'
133
+ spec.summary = 'build'
134
+ spec.authors = 'build'
135
+ spec.files = ['lib/code.rb']
136
+
137
+ FileUtils.mkdir 'lib'
138
+
139
+ open 'lib/code.rb', 'w' do |io|
140
+ io.write '# lib/code.rb'
141
+ end
142
+
143
+ package = Gem::Package.new spec.file_name
144
+ package.spec = spec
145
+
146
+ package.build
147
+
148
+ assert_equal Gem::VERSION, spec.rubygems_version
149
+ assert_path_exists spec.file_name
150
+
151
+ reader = Gem::Package.new spec.file_name
152
+ assert_equal spec, reader.spec
153
+
154
+ assert_equal %w[metadata.gz data.tar.gz checksums.yaml.gz],
155
+ reader.files
156
+
157
+ assert_equal %w[lib/code.rb], reader.contents
158
+ end
159
+
160
+ def test_build_auto_signed
161
+ private_key_path = File.join Gem.user_home, 'gem-private_key.pem'
162
+ Gem::Security.write PRIVATE_KEY, private_key_path
163
+
164
+ public_cert_path = File.join Gem.user_home, 'gem-public_cert.pem'
165
+ Gem::Security.write PUBLIC_CERT, public_cert_path
166
+
167
+ spec = Gem::Specification.new 'build', '1'
168
+ spec.summary = 'build'
169
+ spec.authors = 'build'
170
+ spec.files = ['lib/code.rb']
171
+
172
+ FileUtils.mkdir 'lib'
173
+
174
+ open 'lib/code.rb', 'w' do |io|
175
+ io.write '# lib/code.rb'
176
+ end
177
+
178
+ package = Gem::Package.new spec.file_name
179
+ package.spec = spec
180
+
181
+ package.build
182
+
183
+ assert_equal Gem::VERSION, spec.rubygems_version
184
+ assert_path_exists spec.file_name
185
+
186
+ reader = Gem::Package.new spec.file_name
187
+ assert reader.verify
188
+
189
+ assert_equal [PUBLIC_CERT.to_pem], reader.spec.cert_chain
190
+
191
+ assert_equal %w[metadata.gz metadata.gz.sig
192
+ data.tar.gz data.tar.gz.sig
193
+ checksums.yaml.gz checksums.yaml.gz.sig],
194
+ reader.files
195
+
196
+ assert_equal %w[lib/code.rb], reader.contents
197
+ end
198
+
199
+ def test_build_invalid
200
+ spec = Gem::Specification.new 'build', '1'
201
+
202
+ package = Gem::Package.new spec.file_name
203
+ package.spec = spec
204
+
205
+ e = assert_raises Gem::InvalidSpecificationException do
206
+ package.build
207
+ end
208
+
209
+ assert_equal 'missing value for attribute summary', e.message
210
+ end
211
+
212
+ def test_build_signed
213
+ spec = Gem::Specification.new 'build', '1'
214
+ spec.summary = 'build'
215
+ spec.authors = 'build'
216
+ spec.files = ['lib/code.rb']
217
+ spec.cert_chain = [PUBLIC_CERT.to_pem]
218
+ spec.signing_key = PRIVATE_KEY
219
+
220
+ FileUtils.mkdir 'lib'
221
+
222
+ open 'lib/code.rb', 'w' do |io|
223
+ io.write '# lib/code.rb'
224
+ end
225
+
226
+ package = Gem::Package.new spec.file_name
227
+ package.spec = spec
228
+
229
+ package.build
230
+
231
+ assert_equal Gem::VERSION, spec.rubygems_version
232
+ assert_path_exists spec.file_name
233
+
234
+ reader = Gem::Package.new spec.file_name
235
+ assert reader.verify
236
+
237
+ assert_equal spec, reader.spec
238
+
239
+ assert_equal %w[metadata.gz metadata.gz.sig
240
+ data.tar.gz data.tar.gz.sig
241
+ checksums.yaml.gz checksums.yaml.gz.sig],
242
+ reader.files
243
+
244
+ assert_equal %w[lib/code.rb], reader.contents
245
+ end
246
+
247
+ def test_contents
248
+ package = Gem::Package.new @gem
249
+
250
+ assert_equal %w[lib/code.rb], package.contents
251
+ end
252
+
253
+ def test_extract_files
254
+ package = Gem::Package.new @gem
255
+
256
+ package.extract_files @destination
257
+
258
+ extracted = File.join @destination, 'lib/code.rb'
259
+ assert_path_exists extracted
260
+
261
+ mask = 0100666 & (~File.umask)
262
+
263
+ assert_equal mask.to_s(8), File.stat(extracted).mode.to_s(8) unless
264
+ win_platform?
265
+ end
266
+
267
+ def test_extract_files_empty
268
+ data_tgz = util_tar_gz do end
269
+
270
+ gem = util_tar do |tar|
271
+ tar.add_file 'data.tar.gz', 0644 do |io|
272
+ io.write data_tgz.string
273
+ end
274
+
275
+ tar.add_file 'metadata.gz', 0644 do |io|
276
+ Zlib::GzipWriter.wrap io do |gzio|
277
+ gzio.write @spec.to_yaml
278
+ end
279
+ end
280
+ end
281
+
282
+ open 'empty.gem', 'wb' do |io|
283
+ io.write gem.string
284
+ end
285
+
286
+ package = Gem::Package.new 'empty.gem'
287
+
288
+ package.extract_files @destination
289
+
290
+ assert_path_exists @destination
291
+ end
292
+
293
+ def test_extract_tar_gz_absolute
294
+ package = Gem::Package.new @gem
295
+
296
+ tgz_io = util_tar_gz do |tar|
297
+ tar.add_file '/absolute.rb', 0644 do |io| io.write 'hi' end
298
+ end
299
+
300
+ e = assert_raises Gem::Package::PathError do
301
+ package.extract_tar_gz tgz_io, @destination
302
+ end
303
+
304
+ assert_equal("installing into parent path /absolute.rb of " \
305
+ "#{@destination} is not allowed", e.message)
306
+ end
307
+
308
+ def test_install_location
309
+ package = Gem::Package.new @gem
310
+
311
+ file = 'file.rb'
312
+ file.taint
313
+
314
+ destination = package.install_location file, @destination
315
+
316
+ assert_equal File.join(@destination, 'file.rb'), destination
317
+ refute destination.tainted?
318
+ end
319
+
320
+ def test_install_location_absolute
321
+ package = Gem::Package.new @gem
322
+
323
+ e = assert_raises Gem::Package::PathError do
324
+ package.install_location '/absolute.rb', @destination
325
+ end
326
+
327
+ assert_equal("installing into parent path /absolute.rb of " \
328
+ "#{@destination} is not allowed", e.message)
329
+ end
330
+
331
+ def test_install_location_relative
332
+ package = Gem::Package.new @gem
333
+
334
+ e = assert_raises Gem::Package::PathError do
335
+ package.install_location '../relative.rb', @destination
336
+ end
337
+
338
+ parent = File.expand_path File.join @destination, "../relative.rb"
339
+
340
+ assert_equal("installing into parent path #{parent} of " \
341
+ "#{@destination} is not allowed", e.message)
342
+ end
343
+
344
+ def test_load_spec
345
+ entry = StringIO.new Gem.gzip @spec.to_yaml
346
+ def entry.full_name() 'metadata.gz' end
347
+
348
+ package = Gem::Package.new 'nonexistent.gem'
349
+
350
+ spec = package.load_spec entry
351
+
352
+ assert_equal @spec, spec
353
+ end
354
+
355
+ def test_verify
356
+ package = Gem::Package.new @gem
357
+
358
+ package.verify
359
+
360
+ assert_equal @spec, package.spec
361
+ assert_equal %w[checksums.yaml.gz data.tar.gz metadata.gz],
362
+ package.files.sort
363
+ end
364
+
365
+ def test_verify_checksum_bad
366
+ data_tgz = util_tar_gz do |tar|
367
+ tar.add_file 'lib/code.rb', 0444 do |io|
368
+ io.write '# lib/code.rb'
369
+ end
370
+ end
371
+
372
+ data_tgz = data_tgz.string
373
+
374
+ gem = util_tar do |tar|
375
+ metadata_gz = Gem.gzip @spec.to_yaml
376
+
377
+ tar.add_file 'metadata.gz', 0444 do |io|
378
+ io.write metadata_gz
379
+ end
380
+
381
+ tar.add_file 'data.tar.gz', 0444 do |io|
382
+ io.write data_tgz
383
+ end
384
+
385
+ bogus_checksums = {
386
+ 'SHA1' => {
387
+ 'data.tar.gz' => 'bogus',
388
+ 'metadata.gz' => 'bogus',
389
+ },
390
+ }
391
+ tar.add_file 'checksums.yaml.gz', 0444 do |io|
392
+ Zlib::GzipWriter.wrap io do |gz_io|
393
+ gz_io.write YAML.dump bogus_checksums
394
+ end
395
+ end
396
+ end
397
+
398
+ open 'mismatch.gem', 'wb' do |io|
399
+ io.write gem.string
400
+ end
401
+
402
+ package = Gem::Package.new 'mismatch.gem'
403
+
404
+ e = assert_raises Gem::Package::FormatError do
405
+ package.verify
406
+ end
407
+
408
+ assert_equal 'SHA1 checksum mismatch for data.tar.gz in mismatch.gem',
409
+ e.message
410
+ end
411
+
412
+ def test_verify_checksum_missing
413
+ data_tgz = util_tar_gz do |tar|
414
+ tar.add_file 'lib/code.rb', 0444 do |io|
415
+ io.write '# lib/code.rb'
416
+ end
417
+ end
418
+
419
+ data_tgz = data_tgz.string
420
+
421
+ gem = util_tar do |tar|
422
+ metadata_gz = Gem.gzip @spec.to_yaml
423
+
424
+ tar.add_file 'metadata.gz', 0444 do |io|
425
+ io.write metadata_gz
426
+ end
427
+
428
+ digest = OpenSSL::Digest::SHA1.new
429
+ digest << metadata_gz
430
+ checksum = "#{digest.name}\t#{digest.hexdigest}\n"
431
+
432
+ tar.add_file 'metadata.gz.sum', 0444 do |io|
433
+ io.write checksum
434
+ end
435
+
436
+ tar.add_file 'data.tar.gz', 0444 do |io|
437
+ io.write data_tgz
438
+ end
439
+ end
440
+
441
+ open 'data_checksum_missing.gem', 'wb' do |io|
442
+ io.write gem.string
443
+ end
444
+
445
+ package = Gem::Package.new 'data_checksum_missing.gem'
446
+
447
+ assert package.verify
448
+ end
449
+
450
+ def test_verify_corrupt
451
+ Tempfile.open 'corrupt' do |io|
452
+ data = Gem.gzip 'a' * 10
453
+ io.write tar_file_header('metadata.gz', "\000x", 0644, data.length)
454
+ io.write data
455
+ io.rewind
456
+
457
+ package = Gem::Package.new io.path
458
+
459
+ e = assert_raises Gem::Package::FormatError do
460
+ package.verify
461
+ end
462
+
463
+ assert_equal "tar is corrupt, name contains null byte in #{io.path}",
464
+ e.message
465
+ end
466
+ end
467
+
468
+ def test_verify_empty
469
+ FileUtils.touch 'empty.gem'
470
+
471
+ package = Gem::Package.new 'empty.gem'
472
+
473
+ e = assert_raises Gem::Package::FormatError do
474
+ package.verify
475
+ end
476
+
477
+ assert_equal 'package metadata is missing in empty.gem', e.message
478
+ end
479
+
480
+ def test_verify_nonexistent
481
+ package = Gem::Package.new 'nonexistent.gem'
482
+
483
+ e = assert_raises Gem::Package::FormatError do
484
+ package.verify
485
+ end
486
+
487
+ assert_equal 'No such file or directory - nonexistent.gem', e.message
488
+ end
489
+
490
+ def test_verify_security_policy
491
+ package = Gem::Package.new @gem
492
+ package.security_policy = Gem::Security::HighSecurity
493
+
494
+ e = assert_raises Gem::Security::Exception do
495
+ package.verify
496
+ end
497
+
498
+ assert_equal 'unsigned gems are not allowed by the High Security policy',
499
+ e.message
500
+ end
501
+
502
+ def test_verify_truncate
503
+ open 'bad.gem', 'wb' do |io|
504
+ io.write File.read(@gem, 1024) # don't care about newlines
505
+ end
506
+
507
+ package = Gem::Package.new 'bad.gem'
508
+
509
+ e = assert_raises Gem::Package::FormatError do
510
+ package.verify
511
+ end
512
+
513
+ assert_equal 'package content (data.tar.gz) is missing in bad.gem',
514
+ e.message
515
+ end
516
+
517
+ def test_spec
518
+ package = Gem::Package.new @gem
519
+
520
+ assert_equal @spec, package.spec
521
+ end
522
+
523
+ def util_tar
524
+ tar_io = StringIO.new
525
+
526
+ Gem::Package::TarWriter.new tar_io do |tar|
527
+ yield tar
528
+ end
529
+
530
+ tar_io.rewind
531
+
532
+ tar_io
533
+ end
534
+
535
+ def util_tar_gz(&block)
536
+ tar_io = util_tar(&block)
537
+
538
+ tgz_io = StringIO.new
539
+
540
+ # can't wrap TarWriter because it seeks
541
+ Zlib::GzipWriter.wrap tgz_io do |io| io.write tar_io.string end
542
+
543
+ StringIO.new tgz_io.string
544
+ end
545
+
546
+ end
547
+