rubygems-update 1.0.1 → 1.1.0

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 (172) hide show
  1. data.tar.gz.sig +0 -0
  2. data/ChangeLog +248 -0
  3. data/README +2 -0
  4. data/Rakefile +47 -23
  5. data/bin/gem +9 -4
  6. data/bin/update_rubygems +15 -1
  7. data/examples/application/bin/myapp +0 -0
  8. data/lib/rubygems.rb +506 -373
  9. data/lib/rubygems/builder.rb +14 -7
  10. data/lib/rubygems/command.rb +9 -9
  11. data/lib/rubygems/command_manager.rb +1 -0
  12. data/lib/rubygems/commands/cleanup_command.rb +67 -69
  13. data/lib/rubygems/commands/environment_command.rb +16 -10
  14. data/lib/rubygems/commands/fetch_command.rb +7 -9
  15. data/lib/rubygems/commands/install_command.rb +9 -3
  16. data/lib/rubygems/commands/list_command.rb +2 -4
  17. data/lib/rubygems/commands/mirror_command.rb +1 -1
  18. data/lib/rubygems/commands/query_command.rb +52 -5
  19. data/lib/rubygems/commands/sources_command.rb +19 -10
  20. data/lib/rubygems/commands/specification_command.rb +10 -6
  21. data/lib/rubygems/commands/uninstall_command.rb +23 -6
  22. data/lib/rubygems/commands/unpack_command.rb +15 -3
  23. data/lib/rubygems/commands/update_command.rb +27 -25
  24. data/lib/rubygems/custom_require.rb +1 -1
  25. data/lib/rubygems/defaults.rb +8 -1
  26. data/lib/rubygems/dependency_installer.rb +72 -104
  27. data/lib/rubygems/digest/digest_adapter.rb +0 -0
  28. data/lib/rubygems/digest/md5.rb +0 -0
  29. data/lib/rubygems/digest/sha1.rb +0 -0
  30. data/lib/rubygems/digest/sha2.rb +0 -0
  31. data/lib/rubygems/exceptions.rb +22 -1
  32. data/lib/rubygems/format.rb +16 -10
  33. data/lib/rubygems/indexer.rb +46 -33
  34. data/lib/rubygems/indexer/abstract_index_builder.rb +10 -2
  35. data/lib/rubygems/indexer/latest_index_builder.rb +35 -0
  36. data/lib/rubygems/indexer/master_index_builder.rb +9 -8
  37. data/lib/rubygems/indexer/quick_index_builder.rb +5 -3
  38. data/lib/rubygems/install_update_options.rb +7 -1
  39. data/lib/rubygems/installer.rb +8 -5
  40. data/lib/rubygems/package.rb +17 -774
  41. data/lib/rubygems/package/f_sync_dir.rb +24 -0
  42. data/lib/rubygems/package/tar_header.rb +245 -0
  43. data/lib/rubygems/package/tar_input.rb +219 -0
  44. data/lib/rubygems/package/tar_output.rb +143 -0
  45. data/lib/rubygems/package/tar_reader.rb +86 -0
  46. data/lib/rubygems/package/tar_reader/entry.rb +99 -0
  47. data/lib/rubygems/package/tar_writer.rb +180 -0
  48. data/lib/rubygems/remote_fetcher.rb +131 -16
  49. data/lib/rubygems/requirement.rb +2 -0
  50. data/lib/rubygems/rubygems_version.rb +1 -1
  51. data/lib/rubygems/security.rb +1 -0
  52. data/lib/rubygems/server.rb +85 -104
  53. data/lib/rubygems/source_index.rb +412 -329
  54. data/lib/rubygems/source_info_cache.rb +232 -99
  55. data/lib/rubygems/source_info_cache_entry.rb +14 -4
  56. data/lib/rubygems/specification.rb +9 -10
  57. data/lib/rubygems/timer.rb +0 -0
  58. data/lib/rubygems/uninstaller.rb +56 -32
  59. data/lib/rubygems/user_interaction.rb +4 -10
  60. data/lib/rubygems/validator.rb +0 -0
  61. data/scripts/gemdoc.rb +0 -0
  62. data/scripts/specdoc.rb +0 -0
  63. data/setup.rb +56 -19
  64. data/test/gem_installer_test_case.rb +86 -0
  65. data/test/gem_installer_test_case.rbc +0 -0
  66. data/test/gem_package_tar_test_case.rb +146 -0
  67. data/test/gem_package_tar_test_case.rbc +0 -0
  68. data/test/gemutilities.rb +123 -38
  69. data/test/gemutilities.rbc +0 -0
  70. data/test/mockgemui.rb +5 -13
  71. data/test/mockgemui.rbc +0 -0
  72. data/test/private_key.pem +27 -0
  73. data/test/public_cert.pem +20 -0
  74. data/test/simple_gem.rbc +0 -0
  75. data/test/test_config.rbc +0 -0
  76. data/test/test_gem.rb +46 -4
  77. data/test/test_gem.rbc +0 -0
  78. data/test/test_gem_builder.rbc +0 -0
  79. data/test/test_gem_command.rbc +0 -0
  80. data/test/test_gem_command_manager.rb +4 -2
  81. data/test/test_gem_command_manager.rbc +0 -0
  82. data/test/test_gem_commands_build_command.rbc +0 -0
  83. data/test/test_gem_commands_cert_command.rb +5 -1
  84. data/test/test_gem_commands_cert_command.rbc +0 -0
  85. data/test/test_gem_commands_check_command.rbc +0 -0
  86. data/test/test_gem_commands_contents_command.rbc +0 -0
  87. data/test/test_gem_commands_dependency_command.rbc +0 -0
  88. data/test/test_gem_commands_environment_command.rb +17 -1
  89. data/test/test_gem_commands_environment_command.rbc +0 -0
  90. data/test/test_gem_commands_fetch_command.rb +6 -5
  91. data/test/test_gem_commands_fetch_command.rbc +0 -0
  92. data/test/test_gem_commands_generate_index_command.rbc +0 -0
  93. data/test/test_gem_commands_install_command.rb +36 -28
  94. data/test/test_gem_commands_install_command.rbc +0 -0
  95. data/test/test_gem_commands_mirror_command.rbc +0 -0
  96. data/test/test_gem_commands_pristine_command.rbc +0 -0
  97. data/test/test_gem_commands_query_command.rb +143 -19
  98. data/test/test_gem_commands_query_command.rbc +0 -0
  99. data/test/test_gem_commands_server_command.rb +1 -1
  100. data/test/test_gem_commands_server_command.rbc +0 -0
  101. data/test/test_gem_commands_sources_command.rb +67 -9
  102. data/test/test_gem_commands_sources_command.rbc +0 -0
  103. data/test/test_gem_commands_specification_command.rb +3 -2
  104. data/test/test_gem_commands_specification_command.rbc +0 -0
  105. data/test/test_gem_commands_unpack_command.rb +46 -4
  106. data/test/test_gem_commands_unpack_command.rbc +0 -0
  107. data/test/test_gem_commands_update_command.rb +174 -0
  108. data/test/test_gem_commands_update_command.rbc +0 -0
  109. data/test/test_gem_config_file.rbc +0 -0
  110. data/test/test_gem_dependency.rbc +0 -0
  111. data/test/test_gem_dependency_installer.rb +172 -187
  112. data/test/test_gem_dependency_installer.rbc +0 -0
  113. data/test/test_gem_dependency_list.rbc +0 -0
  114. data/test/test_gem_digest.rb +0 -0
  115. data/test/test_gem_digest.rbc +0 -0
  116. data/test/test_gem_doc_manager.rbc +0 -0
  117. data/test/test_gem_ext_configure_builder.rb +9 -6
  118. data/test/test_gem_ext_configure_builder.rbc +0 -0
  119. data/test/test_gem_ext_ext_conf_builder.rbc +0 -0
  120. data/test/test_gem_ext_rake_builder.rbc +0 -0
  121. data/test/test_gem_format.rb +1 -1
  122. data/test/test_gem_format.rbc +0 -0
  123. data/test/test_gem_gem_path_searcher.rbc +0 -0
  124. data/test/test_gem_gem_runner.rbc +0 -0
  125. data/test/test_gem_indexer.rb +7 -2
  126. data/test/test_gem_indexer.rbc +0 -0
  127. data/test/test_gem_install_update_options.rbc +0 -0
  128. data/test/test_gem_installer.rb +5 -84
  129. data/test/test_gem_installer.rbc +0 -0
  130. data/test/test_gem_local_remote_options.rbc +0 -0
  131. data/test/test_gem_outdated_command.rbc +0 -0
  132. data/test/test_gem_package_tar_header.rb +137 -0
  133. data/test/test_gem_package_tar_header.rbc +0 -0
  134. data/test/test_gem_package_tar_input.rb +119 -0
  135. data/test/test_gem_package_tar_input.rbc +0 -0
  136. data/test/test_gem_package_tar_output.rb +104 -0
  137. data/test/test_gem_package_tar_output.rbc +0 -0
  138. data/test/test_gem_package_tar_reader.rb +53 -0
  139. data/test/test_gem_package_tar_reader.rbc +0 -0
  140. data/test/test_gem_package_tar_reader_entry.rb +116 -0
  141. data/test/test_gem_package_tar_reader_entry.rbc +0 -0
  142. data/test/test_gem_package_tar_writer.rb +151 -0
  143. data/test/test_gem_package_tar_writer.rbc +0 -0
  144. data/test/test_gem_platform.rbc +0 -0
  145. data/test/test_gem_remote_fetcher.rb +189 -17
  146. data/test/test_gem_remote_fetcher.rbc +0 -0
  147. data/test/test_gem_requirement.rbc +0 -0
  148. data/test/test_gem_server.rb +13 -12
  149. data/test/test_gem_server.rbc +0 -0
  150. data/test/test_gem_source_index.rb +305 -56
  151. data/test/test_gem_source_index.rbc +0 -0
  152. data/test/test_gem_source_info_cache.rb +179 -53
  153. data/test/test_gem_source_info_cache.rbc +0 -0
  154. data/test/test_gem_source_info_cache_entry.rb +41 -10
  155. data/test/test_gem_source_info_cache_entry.rbc +0 -0
  156. data/test/test_gem_specification.rb +7 -7
  157. data/test/test_gem_specification.rbc +0 -0
  158. data/test/test_gem_stream_ui.rbc +0 -0
  159. data/test/test_gem_uninstaller.rb +43 -0
  160. data/test/test_gem_uninstaller.rbc +0 -0
  161. data/test/test_gem_validator.rbc +0 -0
  162. data/test/test_gem_version.rb +1 -1
  163. data/test/test_gem_version.rbc +0 -0
  164. data/test/test_gem_version_option.rbc +0 -0
  165. data/test/test_kernel.rb +1 -0
  166. data/test/test_kernel.rbc +0 -0
  167. metadata +85 -8
  168. metadata.gz.sig +0 -0
  169. data/lib/rubygems/gem_open_uri.rb +0 -7
  170. data/lib/rubygems/open-uri.rb +0 -773
  171. data/test/test_open_uri.rb +0 -13
  172. data/test/test_package.rb +0 -608
@@ -0,0 +1,104 @@
1
+ #--
2
+ # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+ require File.join(File.expand_path(File.dirname(__FILE__)),
8
+ 'gem_package_tar_test_case')
9
+ require 'rubygems/package/tar_output'
10
+
11
+ class TestGemPackageTarOutput < TarTestCase
12
+
13
+ def setup
14
+ super
15
+
16
+ @file = File.join @tempdir, 'bla2.tar'
17
+ end
18
+
19
+ def test_self_open
20
+ open @file, 'wb' do |tar_io|
21
+ Gem::Package::TarOutput.open tar_io do |tar_writer|
22
+ tar_writer.add_file_simple 'README', 0, 17 do |io|
23
+ io.write "This is a README\n"
24
+ end
25
+
26
+ tar_writer.metadata = "This is some metadata\n"
27
+ end
28
+ end
29
+
30
+ files = util_extract
31
+
32
+ name, data = files.shift
33
+ assert_equal 'data.tar.gz', name
34
+
35
+ gz = Zlib::GzipReader.new StringIO.new(data)
36
+
37
+ Gem::Package::TarReader.new gz do |tar_reader|
38
+ tar_reader.each do |entry|
39
+ assert_equal 'README', entry.full_name
40
+ assert_equal "This is a README\n", entry.read
41
+ end
42
+ end
43
+
44
+ gz.close
45
+
46
+ name, data = files.shift
47
+ assert_equal 'metadata.gz', name
48
+
49
+ gz = Zlib::GzipReader.new StringIO.new(data)
50
+ assert_equal "This is some metadata\n", gz.read
51
+
52
+ assert files.empty?
53
+ ensure
54
+ gz.close if gz
55
+ end
56
+
57
+ if defined? OpenSSL then
58
+ def test_self_open_signed
59
+ signer = Gem::Security::Signer.new @private_key, [@public_cert]
60
+
61
+ open @file, 'wb' do |tar_io|
62
+ Gem::Package::TarOutput.open tar_io, signer do |tar_writer|
63
+ tar_writer.add_file_simple 'README', 0, 17 do |io|
64
+ io.write "This is a README\n"
65
+ end
66
+
67
+ tar_writer.metadata = "This is some metadata\n"
68
+ end
69
+ end
70
+
71
+ files = util_extract
72
+
73
+ name, data = files.shift
74
+ assert_equal 'data.tar.gz', name
75
+
76
+ name, data = files.shift
77
+ assert_equal 'metadata.gz', name
78
+
79
+ name, data = files.shift
80
+ assert_equal 'data.tar.gz.sig', name
81
+
82
+ name, data = files.shift
83
+ assert_equal 'metadata.gz.sig', name
84
+
85
+ assert files.empty?
86
+ end
87
+ end
88
+
89
+ def util_extract
90
+ files = []
91
+
92
+ open @file, 'rb' do |io|
93
+ Gem::Package::TarReader.new io do |tar_reader|
94
+ tar_reader.each do |entry|
95
+ files << [entry.full_name, entry.read]
96
+ end
97
+ end
98
+ end
99
+
100
+ files
101
+ end
102
+
103
+ end
104
+
@@ -0,0 +1,53 @@
1
+ #--
2
+ # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+ require File.join(File.expand_path(File.dirname(__FILE__)),
8
+ 'gem_package_tar_test_case')
9
+ require 'rubygems/package'
10
+
11
+ class TestGemPackageTarReader < TarTestCase
12
+
13
+ def test_each_entry
14
+ tar = tar_dir_header "foo", "bar", 0
15
+ tar << tar_file_header("bar", "baz", 0, 0)
16
+
17
+ io = TempIO.new tar
18
+
19
+ entries = 0
20
+
21
+ Gem::Package::TarReader.new io do |tar_reader|
22
+ tar_reader.each_entry do |entry|
23
+ assert_kind_of Gem::Package::TarReader::Entry, entry
24
+
25
+ entries += 1
26
+ end
27
+ end
28
+
29
+ assert_equal 2, entries
30
+ end
31
+
32
+ def test_rewind
33
+ content = ('a'..'z').to_a.join(" ")
34
+
35
+ str = tar_file_header("lib/foo", "", 010644, content.size) + content +
36
+ "\0" * (512 - content.size)
37
+ str << "\0" * 1024
38
+
39
+ Gem::Package::TarReader.new(TempIO.new(str)) do |tar_reader|
40
+ 3.times do
41
+ tar_reader.rewind
42
+ i = 0
43
+ tar_reader.each_entry do |entry|
44
+ assert_equal(content, entry.read)
45
+ i += 1
46
+ end
47
+ assert_equal(1, i)
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+
@@ -0,0 +1,116 @@
1
+ #--
2
+ # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+ require File.join(File.expand_path(File.dirname(__FILE__)),
8
+ 'gem_package_tar_test_case')
9
+ require 'rubygems/package'
10
+
11
+ class TestGemPackageTarReaderEntry < TarTestCase
12
+
13
+ def setup
14
+ super
15
+
16
+ @contents = ('a'..'z').to_a.join * 100
17
+
18
+ @tar = ''
19
+ @tar << tar_file_header("lib/foo", "", 0, @contents.size)
20
+ @tar << @contents
21
+ @tar << "\0" * (512 - (@tar.size % 512))
22
+
23
+ @entry = util_entry @tar
24
+ end
25
+
26
+ def test_bytes_read
27
+ assert_equal 0, @entry.bytes_read
28
+
29
+ @entry.getc
30
+
31
+ assert_equal 1, @entry.bytes_read
32
+ end
33
+
34
+ def test_close
35
+ @entry.close
36
+
37
+ assert @entry.bytes_read
38
+
39
+ e = assert_raise IOError do @entry.eof? end
40
+ assert_equal 'closed Gem::Package::TarReader::Entry', e.message
41
+
42
+ e = assert_raise IOError do @entry.getc end
43
+ assert_equal 'closed Gem::Package::TarReader::Entry', e.message
44
+
45
+ e = assert_raise IOError do @entry.pos end
46
+ assert_equal 'closed Gem::Package::TarReader::Entry', e.message
47
+
48
+ e = assert_raise IOError do @entry.read end
49
+ assert_equal 'closed Gem::Package::TarReader::Entry', e.message
50
+
51
+ e = assert_raise IOError do @entry.rewind end
52
+ assert_equal 'closed Gem::Package::TarReader::Entry', e.message
53
+ end
54
+
55
+ def test_closed_eh
56
+ @entry.close
57
+
58
+ assert @entry.closed?
59
+ end
60
+
61
+ def test_eof_eh
62
+ @entry.read
63
+
64
+ assert @entry.eof?
65
+ end
66
+
67
+ def test_full_name
68
+ assert_equal 'lib/foo', @entry.full_name
69
+ end
70
+
71
+ def test_getc
72
+ assert_equal ?a, @entry.getc
73
+ end
74
+
75
+ def test_directory_eh
76
+ assert_equal false, @entry.directory?
77
+ assert_equal true, util_dir_entry.directory?
78
+ end
79
+
80
+ def test_file_eh
81
+ assert_equal true, @entry.file?
82
+ assert_equal false, util_dir_entry.file?
83
+ end
84
+
85
+ def test_pos
86
+ assert_equal 0, @entry.pos
87
+
88
+ @entry.getc
89
+
90
+ assert_equal 1, @entry.pos
91
+ end
92
+
93
+ def test_read
94
+ assert_equal @contents, @entry.read
95
+ end
96
+
97
+ def test_read_big
98
+ assert_equal @contents, @entry.read(@contents.size * 2)
99
+ end
100
+
101
+ def test_read_small
102
+ assert_equal @contents[0...100], @entry.read(100)
103
+ end
104
+
105
+ def test_rewind
106
+ char = @entry.getc
107
+
108
+ @entry.rewind
109
+
110
+ assert_equal 0, @entry.pos
111
+
112
+ assert_equal char, @entry.getc
113
+ end
114
+
115
+ end
116
+
@@ -0,0 +1,151 @@
1
+ #--
2
+ # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+ require File.join(File.expand_path(File.dirname(__FILE__)),
8
+ 'gem_package_tar_test_case')
9
+ require 'rubygems/package/tar_writer'
10
+
11
+ class TestTarWriter < TarTestCase
12
+
13
+ def setup
14
+ super
15
+
16
+ @data = 'abcde12345'
17
+ @io = TempIO.new
18
+ @tar_writer = Gem::Package::TarWriter.new @io
19
+ end
20
+
21
+ def teardown
22
+ @tar_writer.close unless @tar_writer.closed?
23
+
24
+ super
25
+ end
26
+
27
+ def test_add_file
28
+ @tar_writer.add_file 'x', 0644 do |f| f.write 'a' * 10 end
29
+
30
+ assert_headers_equal(tar_file_header('x', '', 0644, 10),
31
+ @io.string[0, 512])
32
+ assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
33
+ assert_equal 1024, @io.pos
34
+ end
35
+
36
+ def test_add_file_simple
37
+ @tar_writer.add_file_simple 'x', 0644, 10 do |io| io.write "a" * 10 end
38
+
39
+ assert_headers_equal(tar_file_header('x', '', 0644, 10),
40
+ @io.string[0, 512])
41
+
42
+ assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
43
+ assert_equal 1024, @io.pos
44
+ end
45
+
46
+ def test_add_file_simple_padding
47
+ @tar_writer.add_file_simple 'x', 0, 100
48
+
49
+ assert_headers_equal tar_file_header('x', '', 0, 100),
50
+ @io.string[0, 512]
51
+
52
+ assert_equal "\0" * 512, @io.string[512, 512]
53
+ end
54
+
55
+ def test_add_file_simple_data
56
+ @tar_writer.add_file_simple("lib/foo/bar", 0, 10) { |f| f.write @data }
57
+ @tar_writer.flush
58
+
59
+ assert_equal @data + ("\0" * (512-@data.size)),
60
+ @io.string[512, 512]
61
+ end
62
+
63
+ def test_add_file_simple_size
64
+ assert_raise Gem::Package::TarWriter::FileOverflow do
65
+ @tar_writer.add_file_simple("lib/foo/bar", 0, 10) do |io|
66
+ io.write "1" * 11
67
+ end
68
+ end
69
+ end
70
+
71
+ def test_add_file_unseekable
72
+ assert_raise Gem::Package::NonSeekableIO do
73
+ Gem::Package::TarWriter.new(Object.new).add_file 'x', 0
74
+ end
75
+ end
76
+
77
+ def test_close
78
+ @tar_writer.close
79
+
80
+ assert_equal "\0" * 1024, @io.string
81
+
82
+ e = assert_raise IOError do
83
+ @tar_writer.close
84
+ end
85
+ assert_equal 'closed Gem::Package::TarWriter', e.message
86
+
87
+ e = assert_raise IOError do
88
+ @tar_writer.flush
89
+ end
90
+ assert_equal 'closed Gem::Package::TarWriter', e.message
91
+
92
+ e = assert_raise IOError do
93
+ @tar_writer.add_file 'x', 0
94
+ end
95
+ assert_equal 'closed Gem::Package::TarWriter', e.message
96
+
97
+ e = assert_raise IOError do
98
+ @tar_writer.add_file_simple 'x', 0, 0
99
+ end
100
+ assert_equal 'closed Gem::Package::TarWriter', e.message
101
+
102
+ e = assert_raise IOError do
103
+ @tar_writer.mkdir 'x', 0
104
+ end
105
+ assert_equal 'closed Gem::Package::TarWriter', e.message
106
+ end
107
+
108
+ def test_mkdir
109
+ @tar_writer.mkdir 'foo', 0644
110
+
111
+ assert_headers_equal tar_dir_header('foo', '', 0644),
112
+ @io.string[0, 512]
113
+ assert_equal 512, @io.pos
114
+ end
115
+
116
+ def test_split_name
117
+ assert_equal ['b' * 100, 'a' * 155],
118
+ @tar_writer.split_name("#{'a' * 155}/#{'b' * 100}")
119
+
120
+ assert_equal ["#{'qwer/' * 19}bla", 'a' * 151],
121
+ @tar_writer.split_name("#{'a' * 151}/#{'qwer/' * 19}bla")
122
+ end
123
+
124
+ def test_split_name_too_long_name
125
+ name = File.join 'a', 'b' * 100
126
+ assert_equal ['b' * 100, 'a'], @tar_writer.split_name(name)
127
+
128
+ assert_raise Gem::Package::TooLongFileName do
129
+ name = File.join 'a', 'b' * 101
130
+ @tar_writer.split_name name
131
+ end
132
+ end
133
+
134
+ def test_split_name_too_long_prefix
135
+ name = File.join 'a' * 155, 'b'
136
+ assert_equal ['b', 'a' * 155], @tar_writer.split_name(name)
137
+
138
+ assert_raise Gem::Package::TooLongFileName do
139
+ name = File.join 'a' * 156, 'b'
140
+ @tar_writer.split_name name
141
+ end
142
+ end
143
+
144
+ def test_split_name_too_long_total
145
+ assert_raise Gem::Package::TooLongFileName do
146
+ @tar_writer.split_name 'a' * 257
147
+ end
148
+ end
149
+
150
+ end
151
+
@@ -97,6 +97,13 @@ gems:
97
97
  @server_uri = base_server_uri + "/yaml"
98
98
  @server_z_uri = base_server_uri + "/yaml.Z"
99
99
 
100
+ # REFACTOR: copied from test_gem_dependency_installer.rb
101
+ @gems_dir = File.join @tempdir, 'gems'
102
+ @cache_dir = File.join @gemhome, 'cache'
103
+ FileUtils.mkdir @gems_dir
104
+
105
+ @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end
106
+
100
107
  Gem::RemoteFetcher.instance_variable_set :@fetcher, nil
101
108
  end
102
109
 
@@ -156,6 +163,140 @@ gems:
156
163
  end
157
164
  end
158
165
 
166
+ def util_fuck_with_fetcher data, blow = false
167
+ fetcher = Gem::RemoteFetcher.fetcher
168
+ fetcher.instance_variable_set :@test_data, data
169
+
170
+ unless blow then
171
+ def fetcher.fetch_path arg
172
+ @test_arg = arg
173
+ @test_data
174
+ end
175
+ else
176
+ def fetcher.fetch_path arg
177
+ # OMG I'm such an ass
178
+ class << self; remove_method :fetch_path; end
179
+ def self.fetch_path arg
180
+ @test_arg = arg
181
+ @test_data
182
+ end
183
+
184
+ raise Gem::RemoteFetcher::FetchError, "haha!"
185
+ end
186
+ end
187
+
188
+ fetcher
189
+ end
190
+
191
+ def test_download
192
+ a1_data = nil
193
+ File.open @a1_gem, 'rb' do |fp|
194
+ a1_data = fp.read
195
+ end
196
+
197
+ fetcher = util_fuck_with_fetcher a1_data
198
+
199
+ a1_cache_gem = File.join(@gemhome, 'cache', "#{@a1.full_name}.gem")
200
+ assert_equal a1_cache_gem, fetcher.download(@a1, 'http://gems.example.com')
201
+ assert_equal("http://gems.example.com/gems/a-1.gem",
202
+ fetcher.instance_variable_get(:@test_arg).to_s)
203
+ assert File.exist?(a1_cache_gem)
204
+ end
205
+
206
+ def test_download_cached
207
+ FileUtils.mv @a1_gem, @cache_dir
208
+
209
+ inst = Gem::RemoteFetcher.fetcher
210
+
211
+ assert_equal File.join(@gemhome, 'cache', "#{@a1.full_name}.gem"),
212
+ inst.download(@a1, 'http://gems.example.com')
213
+ end
214
+
215
+ def test_download_local
216
+ FileUtils.mv @a1_gem, @tempdir
217
+ local_path = File.join @tempdir, "#{@a1.full_name}.gem"
218
+ inst = nil
219
+
220
+ Dir.chdir @tempdir do
221
+ inst = Gem::RemoteFetcher.fetcher
222
+ end
223
+
224
+ assert_equal File.join(@gemhome, 'cache', "#{@a1.full_name}.gem"),
225
+ inst.download(@a1, local_path)
226
+ end
227
+
228
+ def test_download_install_dir
229
+ a1_data = nil
230
+ File.open @a1_gem, 'rb' do |fp|
231
+ a1_data = fp.read
232
+ end
233
+
234
+ fetcher = util_fuck_with_fetcher a1_data
235
+
236
+ install_dir = File.join @tempdir, 'more_gems'
237
+
238
+ a1_cache_gem = File.join install_dir, 'cache', "#{@a1.full_name}.gem"
239
+ actual = fetcher.download(@a1, 'http://gems.example.com', install_dir)
240
+
241
+ assert_equal a1_cache_gem, actual
242
+ assert_equal("http://gems.example.com/gems/a-1.gem",
243
+ fetcher.instance_variable_get(:@test_arg).to_s)
244
+
245
+ assert File.exist?(a1_cache_gem)
246
+ end
247
+
248
+ unless win_platform? then # File.chmod doesn't work
249
+ def test_download_local_read_only
250
+ FileUtils.mv @a1_gem, @tempdir
251
+ local_path = File.join @tempdir, "#{@a1.full_name}.gem"
252
+ inst = nil
253
+ File.chmod 0555, File.join(@gemhome, 'cache')
254
+
255
+ Dir.chdir @tempdir do
256
+ inst = Gem::RemoteFetcher.fetcher
257
+ end
258
+
259
+ assert_equal File.join(@tempdir, "#{@a1.full_name}.gem"),
260
+ inst.download(@a1, local_path)
261
+ ensure
262
+ File.chmod 0755, File.join(@gemhome, 'cache')
263
+ end
264
+ end
265
+
266
+ def test_download_platform_legacy
267
+ original_platform = 'old-platform'
268
+
269
+ e1, e1_gem = util_gem 'e', '1' do |s|
270
+ s.platform = Gem::Platform::CURRENT
271
+ s.instance_variable_set :@original_platform, original_platform
272
+ end
273
+
274
+ e1_data = nil
275
+ File.open e1_gem, 'rb' do |fp|
276
+ e1_data = fp.read
277
+ end
278
+
279
+ fetcher = util_fuck_with_fetcher e1_data, :blow_chunks
280
+
281
+ e1_cache_gem = File.join(@gemhome, 'cache', "#{e1.full_name}.gem")
282
+
283
+ assert_equal e1_cache_gem, fetcher.download(e1, 'http://gems.example.com')
284
+
285
+ assert_equal("http://gems.example.com/gems/#{e1.original_name}.gem",
286
+ fetcher.instance_variable_get(:@test_arg).to_s)
287
+ assert File.exist?(e1_cache_gem)
288
+ end
289
+
290
+ def test_download_unsupported
291
+ inst = Gem::RemoteFetcher.fetcher
292
+
293
+ e = assert_raise Gem::InstallError do
294
+ inst.download @a1, 'ftp://gems.rubyforge.org'
295
+ end
296
+
297
+ assert_equal 'unsupported URI scheme ftp', e.message
298
+ end
299
+
159
300
  def test_explicit_proxy
160
301
  use_ui @ui do
161
302
  fetcher = Gem::RemoteFetcher.new @proxy_uri
@@ -232,22 +373,6 @@ gems:
232
373
  assert_equal 'EOFError: EOFError reading uri', e.message
233
374
  end
234
375
 
235
- def test_fetch_path_open_uri_http_error
236
- fetcher = Gem::RemoteFetcher.new nil
237
-
238
- def fetcher.open_uri_or_path(uri)
239
- io = StringIO.new 'went boom'
240
- err = OpenURI::HTTPError.new 'error', io
241
- raise err
242
- end
243
-
244
- e = assert_raise Gem::RemoteFetcher::FetchError do
245
- fetcher.fetch_path 'uri'
246
- end
247
-
248
- assert_equal "OpenURI::HTTPError: error reading uri\n\twent boom", e.message
249
- end
250
-
251
376
  def test_fetch_path_socket_error
252
377
  fetcher = Gem::RemoteFetcher.new nil
253
378
 
@@ -271,7 +396,7 @@ gems:
271
396
  fetcher.fetch_path 'uri'
272
397
  end
273
398
 
274
- assert_match %r|\AErrno::ECONNREFUSED: .* - connect\(2\) reading uri\z|,
399
+ assert_match %r|ECONNREFUSED:.*connect\(2\) reading uri\z|,
275
400
  e.message
276
401
  end
277
402
 
@@ -324,6 +449,53 @@ gems:
324
449
  end
325
450
  end
326
451
 
452
+ def test_open_uri_or_path
453
+ fetcher = Gem::RemoteFetcher.new nil
454
+
455
+ conn = Object.new
456
+ def conn.started?() true end
457
+ def conn.request(req)
458
+ unless defined? @requested then
459
+ @requested = true
460
+ res = Net::HTTPRedirection.new nil, 301, nil
461
+ res.add_field 'Location', 'http://gems.example.com/real_path'
462
+ res
463
+ else
464
+ res = Net::HTTPOK.new nil, 200, nil
465
+ def res.body() 'real_path' end
466
+ res
467
+ end
468
+ end
469
+
470
+ conn = { 'gems.example.com:80' => conn }
471
+ fetcher.instance_variable_set :@connections, conn
472
+
473
+ fetcher.send :open_uri_or_path, 'http://gems.example.com/redirect' do |io|
474
+ assert_equal 'real_path', io.read
475
+ end
476
+ end
477
+
478
+ def test_open_uri_or_path_limited_redirects
479
+ fetcher = Gem::RemoteFetcher.new nil
480
+
481
+ conn = Object.new
482
+ def conn.started?() true end
483
+ def conn.request(req)
484
+ res = Net::HTTPRedirection.new nil, 301, nil
485
+ res.add_field 'Location', 'http://gems.example.com/redirect'
486
+ res
487
+ end
488
+
489
+ conn = { 'gems.example.com:80' => conn }
490
+ fetcher.instance_variable_set :@connections, conn
491
+
492
+ e = assert_raise Gem::RemoteFetcher::FetchError do
493
+ fetcher.send :open_uri_or_path, 'http://gems.example.com/redirect'
494
+ end
495
+
496
+ assert_equal 'too many redirects', e.message
497
+ end
498
+
327
499
  def test_zip
328
500
  use_ui @ui do
329
501
  self.class.enable_zip = true