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
@@ -0,0 +1,106 @@
1
+ require 'rubygems/test_case'
2
+ require 'rubygems/available_set'
3
+ require 'rubygems/security'
4
+
5
+ class TestGemAvailableSet < Gem::TestCase
6
+ def setup
7
+ super
8
+
9
+ @source = Gem::Source.new(@gem_repo)
10
+ end
11
+
12
+ def test_add_and_empty
13
+ a1, _ = util_gem 'a', '1'
14
+
15
+ set = Gem::AvailableSet.new
16
+ assert set.empty?
17
+
18
+ set.add a1, @source
19
+
20
+ refute set.empty?
21
+
22
+ assert_equal [a1], set.all_specs
23
+ end
24
+
25
+ def test_match_platform
26
+ a1, _ = util_gem 'a', '1' do |g|
27
+ g.platform = "something-weird-yep"
28
+ end
29
+
30
+ a1c, _ = util_gem 'a', '2' do |g|
31
+ g.platform = Gem::Platform.local
32
+ end
33
+
34
+ a2, _ = util_gem 'a', '2'
35
+
36
+ set = Gem::AvailableSet.new
37
+ set.add a1, @source
38
+ set.add a1c, @source
39
+ set.add a2, @source
40
+
41
+ set.match_platform!
42
+
43
+ assert_equal [a1c, a2], set.all_specs
44
+ end
45
+
46
+ def test_best
47
+ a1, _ = util_gem 'a', '1'
48
+ a2, _ = util_gem 'a', '2'
49
+
50
+ set = Gem::AvailableSet.new
51
+ set.add a1, @source
52
+ set.add a2, @source
53
+
54
+ set.pick_best!
55
+
56
+ assert_equal [a2], set.all_specs
57
+ end
58
+
59
+ def test_remove_installed_bang
60
+ a1, _ = util_gem 'a', '1'
61
+
62
+ a1.activate
63
+
64
+ set = Gem::AvailableSet.new
65
+ set.add a1, @source
66
+
67
+ dep = Gem::Dependency.new "a", ">= 0"
68
+
69
+ set.remove_installed! dep
70
+
71
+ assert set.empty?
72
+ end
73
+
74
+ def test_sorted_normal_versions
75
+ a1, _ = util_gem 'a', '1'
76
+ a2, _ = util_gem 'a', '2'
77
+
78
+ set = Gem::AvailableSet.new
79
+ set.add a1, @source
80
+ set.add a2, @source
81
+
82
+ g = set.sorted
83
+
84
+ assert_equal a2, g[0].spec
85
+ assert_equal a1, g[1].spec
86
+ end
87
+
88
+ def test_sorted_respect_pre
89
+ a1a, _ = util_gem 'a', '1.a'
90
+ a1, _ = util_gem 'a', '1'
91
+ a2a, _ = util_gem 'a', '2.a'
92
+ a2, _ = util_gem 'a', '2'
93
+ a3a, _ = util_gem 'a', '3.a'
94
+
95
+ set = Gem::AvailableSet.new
96
+ set.add a1, @source
97
+ set.add a1a, @source
98
+ set.add a3a, @source
99
+ set.add a2a, @source
100
+ set.add a2, @source
101
+
102
+ g = set.sorted.map { |t| t.spec }
103
+
104
+ assert_equal [a3a, a2, a2a, a1, a1a], g
105
+ end
106
+ end
@@ -109,6 +109,16 @@ class TestGemCommand < Gem::TestCase
109
109
  assert @xopt, "Should have done xopt"
110
110
  end
111
111
 
112
+ def test_invoke_with_build_args
113
+ @cmd.when_invoked { true }
114
+
115
+ use_ui @ui do
116
+ @cmd.invoke_with_build_args ["-x"], ["--awesome=true"]
117
+ end
118
+
119
+ assert_equal ["--awesome=true"], @cmd.options[:build_args]
120
+ end
121
+
112
122
  # Returning false from the command handler invokes the usage output.
113
123
  def test_invoke_with_help
114
124
  done = false
@@ -6,7 +6,47 @@ class TestGemCommandManager < Gem::TestCase
6
6
  def setup
7
7
  super
8
8
 
9
- @command_manager = Gem::CommandManager.instance
9
+ @command_manager = Gem::CommandManager.new
10
+ end
11
+
12
+ def test_find_command
13
+ command = @command_manager.find_command 'install'
14
+
15
+ assert_kind_of Gem::Commands::InstallCommand, command
16
+
17
+ command = @command_manager.find_command 'ins'
18
+
19
+ assert_kind_of Gem::Commands::InstallCommand, command
20
+ end
21
+
22
+ def test_find_command_ambiguous
23
+ e = assert_raises Gem::CommandLineError do
24
+ @command_manager.find_command 'u'
25
+ end
26
+
27
+ assert_equal 'Ambiguous command u matches [uninstall, unpack, update]',
28
+ e.message
29
+ end
30
+
31
+ def test_find_command_ambiguous_exact
32
+ ins_command = Class.new
33
+ Gem::Commands.send :const_set, :InsCommand, ins_command
34
+
35
+ @command_manager.register_command :ins
36
+
37
+ command = @command_manager.find_command 'ins'
38
+
39
+ assert_kind_of ins_command, command
40
+ ensure
41
+ Gem::Commands.send :remove_const, :InsCommand
42
+ end
43
+
44
+ def test_find_command_unknown
45
+ e = assert_raises Gem::CommandLineError do
46
+ @command_manager.find_command 'xyz'
47
+ end
48
+
49
+ assert_equal 'Unknown command xyz', e.message
10
50
  end
11
51
 
12
52
  def test_run_interrupt
@@ -14,6 +54,8 @@ class TestGemCommandManager < Gem::TestCase
14
54
  $: << File.expand_path("test/rubygems", @@project_dir)
15
55
  Gem.load_env_plugins
16
56
 
57
+ @command_manager.register_command :interrupt
58
+
17
59
  use_ui @ui do
18
60
  assert_raises Gem::MockGemUi::TermError do
19
61
  @command_manager.run 'interrupt'
@@ -54,6 +96,7 @@ class TestGemCommandManager < Gem::TestCase
54
96
  assert_match(/invalid option: --bad-arg/i, @ui.error)
55
97
  end
56
98
 
99
+ # HACK move to install command test
57
100
  def test_process_args_install
58
101
  #capture all install options
59
102
  use_ui @ui do
@@ -65,7 +108,7 @@ class TestGemCommandManager < Gem::TestCase
65
108
 
66
109
  #check defaults
67
110
  @command_manager.process_args("install")
68
- assert_equal true, check_options[:generate_rdoc]
111
+ assert_equal %w[ri], check_options[:document].sort
69
112
  assert_equal false, check_options[:force]
70
113
  assert_equal :both, check_options[:domain]
71
114
  assert_equal true, check_options[:wrappers]
@@ -77,7 +120,7 @@ class TestGemCommandManager < Gem::TestCase
77
120
  check_options = nil
78
121
  @command_manager.process_args(
79
122
  "install --force --local --rdoc --install-dir . --version 3.0 --no-wrapper --bindir . ")
80
- assert_equal true, check_options[:generate_rdoc]
123
+ assert_equal %w[rdoc ri], check_options[:document].sort
81
124
  assert_equal true, check_options[:force]
82
125
  assert_equal :local, check_options[:domain]
83
126
  assert_equal false, check_options[:wrappers]
@@ -102,6 +145,7 @@ class TestGemCommandManager < Gem::TestCase
102
145
  end
103
146
  end
104
147
 
148
+ # HACK move to uninstall command test
105
149
  def test_process_args_uninstall
106
150
  #capture all uninstall options
107
151
  check_options = nil
@@ -121,6 +165,7 @@ class TestGemCommandManager < Gem::TestCase
121
165
  assert_equal Gem::Requirement.new('3.0'), check_options[:version]
122
166
  end
123
167
 
168
+ # HACK move to check command test
124
169
  def test_process_args_check
125
170
  #capture all check options
126
171
  check_options = nil
@@ -131,16 +176,15 @@ class TestGemCommandManager < Gem::TestCase
131
176
 
132
177
  #check defaults
133
178
  @command_manager.process_args("check")
134
- assert_equal false, check_options[:verify]
135
- assert_equal false, check_options[:alien]
179
+ assert_equal true, check_options[:alien]
136
180
 
137
181
  #check settings
138
182
  check_options = nil
139
- @command_manager.process_args("check --verify foobar --alien")
140
- assert_equal "foobar", check_options[:verify]
183
+ @command_manager.process_args("check foobar --alien")
141
184
  assert_equal true, check_options[:alien]
142
185
  end
143
186
 
187
+ # HACK move to build command test
144
188
  def test_process_args_build
145
189
  #capture all build options
146
190
  check_options = nil
@@ -159,6 +203,7 @@ class TestGemCommandManager < Gem::TestCase
159
203
  assert_equal 'foobar.rb', check_options[:args].first
160
204
  end
161
205
 
206
+ # HACK move to query command test
162
207
  def test_process_args_query
163
208
  #capture all query options
164
209
  check_options = nil
@@ -191,6 +236,7 @@ class TestGemCommandManager < Gem::TestCase
191
236
  assert_equal :both, check_options[:domain]
192
237
  end
193
238
 
239
+ # HACK move to update command test
194
240
  def test_process_args_update
195
241
  #capture all update options
196
242
  check_options = nil
@@ -201,12 +247,12 @@ class TestGemCommandManager < Gem::TestCase
201
247
 
202
248
  #check defaults
203
249
  @command_manager.process_args("update")
204
- assert_equal true, check_options[:generate_rdoc]
250
+ assert_includes check_options[:document], 'rdoc'
205
251
 
206
252
  #check settings
207
253
  check_options = nil
208
254
  @command_manager.process_args("update --force --rdoc --install-dir .")
209
- assert_equal true, check_options[:generate_rdoc]
255
+ assert_includes check_options[:document], 'ri'
210
256
  assert_equal true, check_options[:force]
211
257
  assert_equal Dir.pwd, check_options[:install_dir]
212
258
  end
@@ -1,6 +1,6 @@
1
1
  require 'rubygems/test_case'
2
2
  require 'rubygems/commands/build_command'
3
- require 'rubygems/format'
3
+ require 'rubygems/package'
4
4
 
5
5
  class TestGemCommandsBuildCommand < Gem::TestCase
6
6
 
@@ -24,16 +24,6 @@ class TestGemCommandsBuildCommand < Gem::TestCase
24
24
  util_test_build_gem @gem, gemspec_file
25
25
  end
26
26
 
27
- def test_execute_yaml
28
- gemspec_file = File.join(@tempdir, @gem.spec_name)
29
-
30
- File.open gemspec_file, 'w' do |gs|
31
- gs.write @gem.to_yaml
32
- end
33
-
34
- util_test_build_gem @gem, gemspec_file
35
- end
36
-
37
27
  def test_execute_bad_spec
38
28
  @gem.date = "2010-11-08"
39
29
 
@@ -72,7 +62,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
72
62
  assert_equal "ERROR: Gemspec file not found: some_gem\n", @ui.error
73
63
  end
74
64
 
75
- def util_test_build_gem(gem, gemspec_file)
65
+ def util_test_build_gem(gem, gemspec_file, check_licenses=true)
76
66
  @cmd.options[:args] = [gemspec_file]
77
67
 
78
68
  use_ui @ui do
@@ -87,32 +77,34 @@ class TestGemCommandsBuildCommand < Gem::TestCase
87
77
  assert_equal " Version: 2", output.shift
88
78
  assert_equal " File: some_gem-2.gem", output.shift
89
79
  assert_equal [], output
90
- assert_equal '', @ui.error
80
+
81
+ if check_licenses
82
+ assert_equal "WARNING: licenses is empty\n", @ui.error
83
+ end
91
84
 
92
85
  gem_file = File.join @tempdir, File.basename(gem.cache_file)
93
86
  assert File.exist?(gem_file)
94
87
 
95
- spec = Gem::Format.from_file_by_path(gem_file).spec
88
+ spec = Gem::Package.new(gem_file).spec
96
89
 
97
90
  assert_equal "some_gem", spec.name
98
91
  assert_equal "this is a summary", spec.summary
99
92
  end
100
93
 
101
94
  def test_execute_force
102
- @gem.instance_variable_set :@required_rubygems_version, nil
103
-
104
95
  gemspec_file = File.join(@tempdir, @gem.spec_name)
105
96
 
97
+ @gem.send :remove_instance_variable, :@rubygems_version
98
+
106
99
  File.open gemspec_file, 'w' do |gs|
107
- gs.write @gem.to_yaml
100
+ gs.write @gem.to_ruby
108
101
  end
109
102
 
110
103
  @cmd.options[:args] = [gemspec_file]
111
104
  @cmd.options[:force] = true
112
105
 
113
- util_test_build_gem @gem, gemspec_file
106
+ util_test_build_gem @gem, gemspec_file, false
114
107
  end
115
108
 
116
-
117
109
  end
118
110
 
@@ -8,117 +8,516 @@ end
8
8
 
9
9
  class TestGemCommandsCertCommand < Gem::TestCase
10
10
 
11
+ ALTERNATE_CERT = load_cert 'alternate'
12
+
13
+ ALTERNATE_KEY_FILE = key_path 'alternate'
14
+ PRIVATE_KEY_FILE = key_path 'private'
15
+ PUBLIC_KEY_FILE = key_path 'public'
16
+
17
+ ALTERNATE_CERT_FILE = cert_path 'alternate'
18
+ CHILD_CERT_FILE = cert_path 'child'
19
+ PUBLIC_CERT_FILE = cert_path 'public'
20
+
11
21
  def setup
12
22
  super
13
23
 
14
- @orig_security_trust_dir = Gem::Security::OPT[:trust_dir]
15
- Gem::Security::OPT[:trust_dir] = @tempdir
16
-
17
24
  @cmd = Gem::Commands::CertCommand.new
18
25
 
19
- root = File.expand_path(File.dirname(__FILE__), @@project_dir)
26
+ @trust_dir = Gem::Security.trust_dir
27
+ end
28
+
29
+ def test_certificates_matching
30
+ @trust_dir.trust_cert PUBLIC_CERT
31
+ @trust_dir.trust_cert ALTERNATE_CERT
20
32
 
21
- FileUtils.cp File.join(root, 'data', 'gem-private_key.pem'), @tempdir
22
- FileUtils.cp File.join(root, 'data', 'gem-public_cert.pem'), @tempdir
33
+ matches = @cmd.certificates_matching ''
23
34
 
24
- @cert_file_name = File.join @tempdir, 'gem-public_cert.pem'
25
- @pkey_file_name = File.join @tempdir, 'gem-private_key.pem'
35
+ # HACK OpenSSL::X509::Certificate#== is Object#==, so do this the hard way
36
+ match = matches.next
37
+ assert_equal ALTERNATE_CERT.to_pem, match.first.to_pem
38
+ assert_equal @trust_dir.cert_path(ALTERNATE_CERT), match.last
39
+
40
+ match = matches.next
41
+ assert_equal PUBLIC_CERT.to_pem, match.first.to_pem
42
+ assert_equal @trust_dir.cert_path(PUBLIC_CERT), match.last
43
+
44
+ assert_raises StopIteration do
45
+ matches.next
46
+ end
26
47
  end
27
48
 
28
- def teardown
29
- Gem::Security::OPT[:trust_dir] = @orig_security_trust_dir
49
+ def test_certificates_matching_filter
50
+ @trust_dir.trust_cert PUBLIC_CERT
51
+ @trust_dir.trust_cert ALTERNATE_CERT
30
52
 
31
- super
53
+ matches = @cmd.certificates_matching 'alternate'
54
+
55
+ match = matches.next
56
+ assert_equal ALTERNATE_CERT.to_pem, match.first.to_pem
57
+ assert_equal @trust_dir.cert_path(ALTERNATE_CERT), match.last
58
+
59
+ assert_raises StopIteration do
60
+ matches.next
61
+ end
32
62
  end
33
63
 
34
64
  def test_execute_add
65
+ @cmd.handle_options %W[--add #{PUBLIC_CERT_FILE}]
66
+
35
67
  use_ui @ui do
36
- @cmd.send :handle_options, %W[--add #{@cert_file_name}]
68
+ @cmd.execute
37
69
  end
38
70
 
39
- assert_equal "Added '/CN=rubygems/DC=example/DC=com'\n", @ui.output
40
- assert_equal '', @ui.error
71
+ cert_path = @trust_dir.cert_path PUBLIC_CERT
72
+
73
+ assert_path_exists cert_path
74
+
75
+ assert_equal "Added '/CN=nobody/DC=example'\n", @ui.output
76
+ assert_empty @ui.error
77
+ end
78
+
79
+ def test_execute_add_twice
80
+ self.class.cert_path 'alternate'
81
+
82
+ @cmd.handle_options %W[
83
+ --add #{PUBLIC_CERT_FILE}
84
+ --add #{ALTERNATE_CERT_FILE}
85
+ ]
86
+
87
+ use_ui @ui do
88
+ @cmd.execute
89
+ end
90
+
91
+ expected = <<-EXPECTED
92
+ Added '/CN=nobody/DC=example'
93
+ Added '/CN=alternate/DC=example'
94
+ EXPECTED
95
+
96
+ assert_equal expected, @ui.output
97
+ assert_empty @ui.error
41
98
  end
42
99
 
43
100
  def test_execute_build
44
- FileUtils.rm @cert_file_name
45
- FileUtils.rm @pkey_file_name
101
+ @cmd.handle_options %W[--build nobody@example.com]
46
102
 
47
103
  use_ui @ui do
48
- Dir.chdir @tempdir do
49
- @cmd.send :handle_options, %W[--build nobody@example.com]
50
- end
104
+ @cmd.execute
51
105
  end
52
106
 
53
107
  output = @ui.output.split "\n"
54
108
 
55
- assert_equal 'Public Cert: gem-public_cert.pem', output.shift
56
- assert_equal 'Private Key: gem-private_key.pem', output.shift
57
- assert_equal 'Don\'t forget to move the key file to somewhere private...',
109
+ assert_equal "Certificate: #{File.join @tempdir, 'gem-public_cert.pem'}",
110
+ output.shift
111
+ assert_equal "Private Key: #{File.join @tempdir, 'gem-private_key.pem'}",
58
112
  output.shift
59
- assert_equal [], output
60
113
 
61
- assert_equal '', @ui.error
114
+ assert_equal "Don't forget to move the key file to somewhere private!",
115
+ output.shift
116
+
117
+ assert_empty output
118
+ assert_empty @ui.error
119
+
120
+ assert_path_exists File.join(@tempdir, 'gem-private_key.pem')
121
+ assert_path_exists File.join(@tempdir, 'gem-public_cert.pem')
122
+ end
123
+
124
+ def test_execute_build_key
125
+ @cmd.handle_options %W[
126
+ --build nobody@example.com
127
+ --private-key #{PRIVATE_KEY_FILE}
128
+ ]
129
+
130
+ use_ui @ui do
131
+ @cmd.execute
132
+ end
133
+
134
+ output = @ui.output.split "\n"
135
+
136
+ assert_equal "Certificate: #{File.join @tempdir, 'gem-public_cert.pem'}",
137
+ output.shift
138
+ assert_equal "Private Key: #{File.join @tempdir, 'gem-private_key.pem'}",
139
+ output.shift
140
+
141
+ assert_equal "Don't forget to move the key file to somewhere private!",
142
+ output.shift
143
+
144
+ assert_empty output
145
+ assert_empty @ui.error
146
+
147
+ assert_path_exists File.join(@tempdir, 'gem-public_cert.pem')
148
+
149
+ private_key_file = File.join @tempdir, 'gem-private_key.pem'
150
+ assert_path_exists private_key_file
62
151
 
63
- assert File.exist?(File.join(@tempdir, 'gem-private_key.pem'))
64
- assert File.exist?(File.join(@tempdir, 'gem-public_cert.pem'))
152
+ assert_equal PRIVATE_KEY.to_pem, File.read(private_key_file)
65
153
  end
66
154
 
67
155
  def test_execute_certificate
68
156
  use_ui @ui do
69
- @cmd.send :handle_options, %W[--certificate #{@cert_file_name}]
157
+ @cmd.handle_options %W[--certificate #{PUBLIC_CERT_FILE}]
70
158
  end
71
159
 
72
160
  assert_equal '', @ui.output
73
161
  assert_equal '', @ui.error
74
162
 
75
- assert_equal File.read(@cert_file_name),
76
- @cmd.options[:issuer_cert].to_s
163
+ assert_equal PUBLIC_CERT.to_pem, @cmd.options[:issuer_cert].to_pem
77
164
  end
78
165
 
79
166
  def test_execute_list
167
+ @trust_dir.trust_cert PUBLIC_CERT
168
+ @trust_dir.trust_cert ALTERNATE_CERT
169
+
170
+ @cmd.handle_options %W[--list]
171
+
80
172
  use_ui @ui do
81
- @cmd.send :handle_options, %W[--list]
173
+ @cmd.execute
82
174
  end
83
175
 
84
- assert_equal "/CN=rubygems/DC=example/DC=com\n", @ui.output
85
- assert_equal '', @ui.error
176
+ assert_equal "/CN=alternate/DC=example\n/CN=nobody/DC=example\n",
177
+ @ui.output
178
+ assert_empty @ui.error
179
+ end
180
+
181
+ def test_execute_list_filter
182
+ @trust_dir.trust_cert PUBLIC_CERT
183
+ @trust_dir.trust_cert ALTERNATE_CERT
184
+
185
+ @cmd.handle_options %W[--list nobody]
186
+
187
+ use_ui @ui do
188
+ @cmd.execute
189
+ end
190
+
191
+ assert_equal "/CN=nobody/DC=example\n", @ui.output
192
+ assert_empty @ui.error
86
193
  end
87
194
 
88
195
  def test_execute_private_key
89
196
  use_ui @ui do
90
- @cmd.send :handle_options, %W[--private-key #{@pkey_file_name}]
197
+ @cmd.send :handle_options, %W[--private-key #{PRIVATE_KEY_FILE}]
91
198
  end
92
199
 
93
200
  assert_equal '', @ui.output
94
201
  assert_equal '', @ui.error
95
202
 
96
- assert_equal File.read(@pkey_file_name),
97
- @cmd.options[:issuer_key].to_s
203
+ assert_equal PRIVATE_KEY.to_pem, @cmd.options[:key].to_pem
98
204
  end
99
205
 
100
206
  def test_execute_remove
207
+ @trust_dir.trust_cert PUBLIC_CERT
208
+
209
+ cert_path = @trust_dir.cert_path PUBLIC_CERT
210
+
211
+ assert_path_exists cert_path
212
+
213
+ @cmd.handle_options %W[--remove nobody]
214
+
215
+ use_ui @ui do
216
+ @cmd.execute
217
+ end
218
+
219
+ assert_equal "Removed '/CN=nobody/DC=example'\n", @ui.output
220
+ assert_equal '', @ui.error
221
+
222
+ refute_path_exists cert_path
223
+ end
224
+
225
+ def test_execute_remove_multiple
226
+ @trust_dir.trust_cert PUBLIC_CERT
227
+ @trust_dir.trust_cert ALTERNATE_CERT
228
+
229
+ public_path = @trust_dir.cert_path PUBLIC_CERT
230
+ alternate_path = @trust_dir.cert_path ALTERNATE_CERT
231
+
232
+ assert_path_exists public_path
233
+ assert_path_exists alternate_path
234
+
235
+ @cmd.handle_options %W[--remove example]
236
+
101
237
  use_ui @ui do
102
- @cmd.send :handle_options, %W[--remove rubygems]
238
+ @cmd.execute
103
239
  end
104
240
 
105
- assert_equal "Removed '/CN=rubygems/DC=example/DC=com'\n", @ui.output
241
+ expected = <<-EXPECTED
242
+ Removed '/CN=alternate/DC=example'
243
+ Removed '/CN=nobody/DC=example'
244
+ EXPECTED
245
+
246
+ assert_equal expected, @ui.output
106
247
  assert_equal '', @ui.error
107
248
 
108
- refute File.exist?(@cert_file_name)
249
+ refute_path_exists public_path
250
+ refute_path_exists alternate_path
251
+ end
252
+
253
+ def test_execute_remove_twice
254
+ @trust_dir.trust_cert PUBLIC_CERT
255
+ @trust_dir.trust_cert ALTERNATE_CERT
256
+
257
+ public_path = @trust_dir.cert_path PUBLIC_CERT
258
+ alternate_path = @trust_dir.cert_path ALTERNATE_CERT
259
+
260
+ assert_path_exists public_path
261
+ assert_path_exists alternate_path
262
+
263
+ @cmd.handle_options %W[--remove nobody --remove alternate]
264
+
265
+ use_ui @ui do
266
+ @cmd.execute
267
+ end
268
+
269
+ expected = <<-EXPECTED
270
+ Removed '/CN=nobody/DC=example'
271
+ Removed '/CN=alternate/DC=example'
272
+ EXPECTED
273
+
274
+ assert_equal expected, @ui.output
275
+ assert_equal '', @ui.error
276
+
277
+ refute_path_exists public_path
278
+ refute_path_exists alternate_path
109
279
  end
110
280
 
111
281
  def test_execute_sign
282
+ path = File.join @tempdir, 'cert.pem'
283
+ Gem::Security.write ALTERNATE_CERT, path, 0600
284
+
285
+ assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s
286
+
287
+ @cmd.handle_options %W[
288
+ --private-key #{PRIVATE_KEY_FILE}
289
+ --certificate #{PUBLIC_CERT_FILE}
290
+
291
+ --sign #{path}
292
+ ]
293
+
112
294
  use_ui @ui do
113
- @cmd.send :handle_options, %W[
114
- -K #{@pkey_file_name} -C #{@cert_file_name} --sign #{@cert_file_name}
115
- ]
295
+ @cmd.execute
116
296
  end
117
297
 
118
298
  assert_equal '', @ui.output
119
299
  assert_equal '', @ui.error
120
300
 
121
- # HACK this test sucks
301
+ cert = OpenSSL::X509::Certificate.new File.read path
302
+
303
+ assert_equal '/CN=nobody/DC=example', cert.issuer.to_s
304
+
305
+ mask = 0100600 & (~File.umask)
306
+
307
+ assert_equal mask, File.stat(path).mode unless win_platform?
308
+ end
309
+
310
+ def test_execute_sign_default
311
+ private_key_path = File.join Gem.user_home, 'gem-private_key.pem'
312
+ Gem::Security.write PRIVATE_KEY, private_key_path
313
+
314
+ public_cert_path = File.join Gem.user_home, 'gem-public_cert.pem'
315
+ Gem::Security.write PUBLIC_CERT, public_cert_path
316
+
317
+ path = File.join @tempdir, 'cert.pem'
318
+ Gem::Security.write ALTERNATE_CERT, path, 0600
319
+
320
+ assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s
321
+
322
+ @cmd.handle_options %W[--sign #{path}]
323
+
324
+ use_ui @ui do
325
+ @cmd.execute
326
+ end
327
+
328
+ assert_equal '', @ui.output
329
+ assert_equal '', @ui.error
330
+
331
+ cert = OpenSSL::X509::Certificate.new File.read path
332
+
333
+ assert_equal '/CN=nobody/DC=example', cert.issuer.to_s
334
+
335
+ mask = 0100600 & (~File.umask)
336
+
337
+ assert_equal mask, File.stat(path).mode unless win_platform?
338
+ end
339
+
340
+ def test_execute_sign_no_cert
341
+ private_key_path = File.join Gem.user_home, 'gem-private_key.pem'
342
+ Gem::Security.write PRIVATE_KEY, private_key_path
343
+
344
+ path = File.join @tempdir, 'cert.pem'
345
+ Gem::Security.write ALTERNATE_CERT, path, 0600
346
+
347
+ assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s
348
+
349
+ @cmd.handle_options %W[--sign #{path}]
350
+
351
+ use_ui @ui do
352
+ assert_raises Gem::MockGemUi::TermError do
353
+ @cmd.execute
354
+ end
355
+ end
356
+
357
+ assert_equal '', @ui.output
358
+
359
+ expected = <<-EXPECTED
360
+ ERROR: --certificate not specified and ~/.gem/gem-public_cert.pem does not exist
361
+ EXPECTED
362
+
363
+ assert_equal expected, @ui.error
364
+ end
365
+
366
+ def test_execute_sign_no_key
367
+ public_cert_path = File.join Gem.user_home, 'gem-public_cert.pem'
368
+ Gem::Security.write PUBLIC_CERT, public_cert_path
369
+
370
+ path = File.join @tempdir, 'cert.pem'
371
+ Gem::Security.write ALTERNATE_CERT, path, 0600
372
+
373
+ assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s
374
+
375
+ @cmd.handle_options %W[--sign #{path}]
376
+
377
+ use_ui @ui do
378
+ assert_raises Gem::MockGemUi::TermError do
379
+ @cmd.execute
380
+ end
381
+ end
382
+
383
+ assert_equal '', @ui.output
384
+
385
+ expected = <<-EXPECTED
386
+ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exist
387
+ EXPECTED
388
+
389
+ assert_equal expected, @ui.error
390
+ end
391
+
392
+ def test_handle_options
393
+ @cmd.handle_options %W[
394
+ --add #{PUBLIC_CERT_FILE}
395
+ --add #{ALTERNATE_CERT_FILE}
396
+
397
+ --remove nobody
398
+ --remove example
399
+
400
+ --list
401
+ --list example
402
+
403
+ --build nobody@example
404
+ --build other@example
405
+ ]
406
+
407
+ assert_equal [PUBLIC_CERT.to_pem, ALTERNATE_CERT.to_pem],
408
+ @cmd.options[:add].map { |cert| cert.to_pem }
409
+
410
+ assert_equal %w[nobody example], @cmd.options[:remove]
411
+
412
+ assert_equal %w[nobody@example other@example],
413
+ @cmd.options[:build].map { |name| name.to_s }
414
+
415
+ assert_equal ['', 'example'], @cmd.options[:list]
416
+ end
417
+
418
+ def test_handle_options_add_bad
419
+ nonexistent = File.join @tempdir, 'nonexistent'
420
+ e = assert_raises OptionParser::InvalidArgument do
421
+ @cmd.handle_options %W[--add #{nonexistent}]
422
+ end
423
+
424
+ assert_equal "invalid argument: --add #{nonexistent}: does not exist",
425
+ e.message
426
+
427
+ bad = File.join @tempdir, 'bad'
428
+ FileUtils.touch bad
429
+
430
+ e = assert_raises OptionParser::InvalidArgument do
431
+ @cmd.handle_options %W[--add #{bad}]
432
+ end
433
+
434
+ assert_equal "invalid argument: --add #{bad}: invalid X509 certificate",
435
+ e.message
436
+ end
437
+
438
+ def test_handle_options_certificate
439
+ nonexistent = File.join @tempdir, 'nonexistent'
440
+ e = assert_raises OptionParser::InvalidArgument do
441
+ @cmd.handle_options %W[--certificate #{nonexistent}]
442
+ end
443
+
444
+ assert_equal "invalid argument: " \
445
+ "--certificate #{nonexistent}: does not exist",
446
+ e.message
447
+
448
+ bad = File.join @tempdir, 'bad'
449
+ FileUtils.touch bad
450
+
451
+ e = assert_raises OptionParser::InvalidArgument do
452
+ @cmd.handle_options %W[--certificate #{bad}]
453
+ end
454
+
455
+ assert_equal "invalid argument: " \
456
+ "--certificate #{bad}: invalid X509 certificate",
457
+ e.message
458
+ end
459
+
460
+ def test_handle_options_key_bad
461
+ nonexistent = File.join @tempdir, 'nonexistent'
462
+ e = assert_raises OptionParser::InvalidArgument do
463
+ @cmd.handle_options %W[--private-key #{nonexistent}]
464
+ end
465
+
466
+ assert_equal "invalid argument: " \
467
+ "--private-key #{nonexistent}: does not exist",
468
+ e.message
469
+
470
+ bad = File.join @tempdir, 'bad'
471
+ FileUtils.touch bad
472
+
473
+ e = assert_raises OptionParser::InvalidArgument do
474
+ @cmd.handle_options %W[--private-key #{bad}]
475
+ end
476
+
477
+ assert_equal "invalid argument: --private-key #{bad}: invalid RSA key",
478
+ e.message
479
+
480
+ e = assert_raises OptionParser::InvalidArgument do
481
+ @cmd.handle_options %W[--private-key #{PUBLIC_KEY_FILE}]
482
+ end
483
+
484
+ assert_equal "invalid argument: " \
485
+ "--private-key #{PUBLIC_KEY_FILE}: private key not found",
486
+ e.message
487
+ end
488
+
489
+ def test_handle_options_sign
490
+ @cmd.handle_options %W[
491
+ --private-key #{ALTERNATE_KEY_FILE}
492
+ --private-key #{PRIVATE_KEY_FILE}
493
+
494
+ --certificate #{ALTERNATE_CERT_FILE}
495
+ --certificate #{PUBLIC_CERT_FILE}
496
+
497
+ --sign #{ALTERNATE_CERT_FILE}
498
+ --sign #{CHILD_CERT_FILE}
499
+ ]
500
+
501
+ assert_equal PRIVATE_KEY.to_pem, @cmd.options[:key].to_pem
502
+ assert_equal PUBLIC_CERT.to_pem, @cmd.options[:issuer_cert].to_pem
503
+
504
+ assert_equal [ALTERNATE_CERT_FILE, CHILD_CERT_FILE], @cmd.options[:sign]
505
+ end
506
+
507
+ def test_handle_options_sign_nonexistent
508
+ nonexistent = File.join @tempdir, 'nonexistent'
509
+ e = assert_raises OptionParser::InvalidArgument do
510
+ @cmd.handle_options %W[
511
+ --private-key #{ALTERNATE_KEY_FILE}
512
+
513
+ --certificate #{ALTERNATE_CERT_FILE}
514
+
515
+ --sign #{nonexistent}
516
+ ]
517
+ end
518
+
519
+ assert_equal "invalid argument: --sign #{nonexistent}: does not exist",
520
+ e.message
122
521
  end
123
522
 
124
523
  end if defined? OpenSSL