libgems 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +5811 -0
- data/History.txt +887 -0
- data/LICENSE.txt +51 -0
- data/README.md +87 -0
- data/Rakefile +113 -0
- data/lib/gauntlet_libgems.rb +50 -0
- data/lib/libgems.rb +1246 -0
- data/lib/libgems/builder.rb +102 -0
- data/lib/libgems/command.rb +534 -0
- data/lib/libgems/command_manager.rb +182 -0
- data/lib/libgems/commands/build_command.rb +53 -0
- data/lib/libgems/commands/cert_command.rb +86 -0
- data/lib/libgems/commands/check_command.rb +80 -0
- data/lib/libgems/commands/cleanup_command.rb +106 -0
- data/lib/libgems/commands/contents_command.rb +98 -0
- data/lib/libgems/commands/dependency_command.rb +195 -0
- data/lib/libgems/commands/environment_command.rb +133 -0
- data/lib/libgems/commands/fetch_command.rb +67 -0
- data/lib/libgems/commands/generate_index_command.rb +133 -0
- data/lib/libgems/commands/help_command.rb +172 -0
- data/lib/libgems/commands/install_command.rb +178 -0
- data/lib/libgems/commands/list_command.rb +35 -0
- data/lib/libgems/commands/lock_command.rb +110 -0
- data/lib/libgems/commands/mirror_command.rb +111 -0
- data/lib/libgems/commands/outdated_command.rb +33 -0
- data/lib/libgems/commands/owner_command.rb +75 -0
- data/lib/libgems/commands/pristine_command.rb +93 -0
- data/lib/libgems/commands/push_command.rb +56 -0
- data/lib/libgems/commands/query_command.rb +280 -0
- data/lib/libgems/commands/rdoc_command.rb +91 -0
- data/lib/libgems/commands/search_command.rb +31 -0
- data/lib/libgems/commands/server_command.rb +86 -0
- data/lib/libgems/commands/sources_command.rb +157 -0
- data/lib/libgems/commands/specification_command.rb +125 -0
- data/lib/libgems/commands/stale_command.rb +27 -0
- data/lib/libgems/commands/uninstall_command.rb +83 -0
- data/lib/libgems/commands/unpack_command.rb +121 -0
- data/lib/libgems/commands/update_command.rb +160 -0
- data/lib/libgems/commands/which_command.rb +86 -0
- data/lib/libgems/config_file.rb +345 -0
- data/lib/libgems/custom_require.rb +44 -0
- data/lib/libgems/defaults.rb +101 -0
- data/lib/libgems/dependency.rb +227 -0
- data/lib/libgems/dependency_installer.rb +286 -0
- data/lib/libgems/dependency_list.rb +208 -0
- data/lib/libgems/doc_manager.rb +242 -0
- data/lib/libgems/errors.rb +35 -0
- data/lib/libgems/exceptions.rb +91 -0
- data/lib/libgems/ext.rb +18 -0
- data/lib/libgems/ext/builder.rb +56 -0
- data/lib/libgems/ext/configure_builder.rb +25 -0
- data/lib/libgems/ext/ext_conf_builder.rb +24 -0
- data/lib/libgems/ext/rake_builder.rb +39 -0
- data/lib/libgems/format.rb +81 -0
- data/lib/libgems/gem_openssl.rb +92 -0
- data/lib/libgems/gem_path_searcher.rb +100 -0
- data/lib/libgems/gem_runner.rb +79 -0
- data/lib/libgems/gemcutter_utilities.rb +49 -0
- data/lib/libgems/indexer.rb +720 -0
- data/lib/libgems/install_update_options.rb +125 -0
- data/lib/libgems/installer.rb +604 -0
- data/lib/libgems/local_remote_options.rb +135 -0
- data/lib/libgems/old_format.rb +153 -0
- data/lib/libgems/package.rb +97 -0
- data/lib/libgems/package/f_sync_dir.rb +23 -0
- data/lib/libgems/package/tar_header.rb +266 -0
- data/lib/libgems/package/tar_input.rb +222 -0
- data/lib/libgems/package/tar_output.rb +144 -0
- data/lib/libgems/package/tar_reader.rb +106 -0
- data/lib/libgems/package/tar_reader/entry.rb +141 -0
- data/lib/libgems/package/tar_writer.rb +241 -0
- data/lib/libgems/package_task.rb +126 -0
- data/lib/libgems/platform.rb +183 -0
- data/lib/libgems/remote_fetcher.rb +414 -0
- data/lib/libgems/require_paths_builder.rb +18 -0
- data/lib/libgems/requirement.rb +153 -0
- data/lib/libgems/security.rb +814 -0
- data/lib/libgems/server.rb +872 -0
- data/lib/libgems/source_index.rb +597 -0
- data/lib/libgems/source_info_cache.rb +395 -0
- data/lib/libgems/source_info_cache_entry.rb +56 -0
- data/lib/libgems/spec_fetcher.rb +337 -0
- data/lib/libgems/specification.rb +1487 -0
- data/lib/libgems/test_utilities.rb +147 -0
- data/lib/libgems/text.rb +65 -0
- data/lib/libgems/uninstaller.rb +278 -0
- data/lib/libgems/user_interaction.rb +527 -0
- data/lib/libgems/validator.rb +240 -0
- data/lib/libgems/version.rb +316 -0
- data/lib/libgems/version_option.rb +65 -0
- data/lib/rbconfig/datadir.rb +20 -0
- data/test/bogussources.rb +8 -0
- data/test/data/gem-private_key.pem +27 -0
- data/test/data/gem-public_cert.pem +20 -0
- data/test/fake_certlib/openssl.rb +7 -0
- data/test/foo/discover.rb +0 -0
- data/test/gem_installer_test_case.rb +97 -0
- data/test/gem_package_tar_test_case.rb +132 -0
- data/test/gemutilities.rb +605 -0
- data/test/insure_session.rb +43 -0
- data/test/mockgemui.rb +56 -0
- data/test/plugin/exception/libgems_plugin.rb +2 -0
- data/test/plugin/load/libgems_plugin.rb +1 -0
- data/test/plugin/standarderror/libgems_plugin.rb +2 -0
- data/test/private_key.pem +27 -0
- data/test/public_cert.pem +20 -0
- data/test/rubygems_plugin.rb +21 -0
- data/test/simple_gem.rb +66 -0
- data/test/test_config.rb +12 -0
- data/test/test_gem.rb +780 -0
- data/test/test_gem_builder.rb +27 -0
- data/test/test_gem_command.rb +178 -0
- data/test/test_gem_command_manager.rb +207 -0
- data/test/test_gem_commands_build_command.rb +74 -0
- data/test/test_gem_commands_cert_command.rb +124 -0
- data/test/test_gem_commands_check_command.rb +18 -0
- data/test/test_gem_commands_contents_command.rb +156 -0
- data/test/test_gem_commands_dependency_command.rb +216 -0
- data/test/test_gem_commands_environment_command.rb +144 -0
- data/test/test_gem_commands_fetch_command.rb +76 -0
- data/test/test_gem_commands_generate_index_command.rb +135 -0
- data/test/test_gem_commands_install_command.rb +315 -0
- data/test/test_gem_commands_list_command.rb +36 -0
- data/test/test_gem_commands_lock_command.rb +68 -0
- data/test/test_gem_commands_mirror_command.rb +60 -0
- data/test/test_gem_commands_outdated_command.rb +40 -0
- data/test/test_gem_commands_owner_command.rb +105 -0
- data/test/test_gem_commands_pristine_command.rb +108 -0
- data/test/test_gem_commands_push_command.rb +81 -0
- data/test/test_gem_commands_query_command.rb +426 -0
- data/test/test_gem_commands_server_command.rb +59 -0
- data/test/test_gem_commands_sources_command.rb +209 -0
- data/test/test_gem_commands_specification_command.rb +139 -0
- data/test/test_gem_commands_stale_command.rb +38 -0
- data/test/test_gem_commands_uninstall_command.rb +83 -0
- data/test/test_gem_commands_unpack_command.rb +199 -0
- data/test/test_gem_commands_update_command.rb +207 -0
- data/test/test_gem_commands_which_command.rb +66 -0
- data/test/test_gem_config_file.rb +287 -0
- data/test/test_gem_dependency.rb +149 -0
- data/test/test_gem_dependency_installer.rb +661 -0
- data/test/test_gem_dependency_list.rb +230 -0
- data/test/test_gem_doc_manager.rb +31 -0
- data/test/test_gem_ext_configure_builder.rb +84 -0
- data/test/test_gem_ext_ext_conf_builder.rb +173 -0
- data/test/test_gem_ext_rake_builder.rb +81 -0
- data/test/test_gem_format.rb +70 -0
- data/test/test_gem_gem_path_searcher.rb +78 -0
- data/test/test_gem_gem_runner.rb +45 -0
- data/test/test_gem_gemcutter_utilities.rb +103 -0
- data/test/test_gem_indexer.rb +673 -0
- data/test/test_gem_install_update_options.rb +68 -0
- data/test/test_gem_installer.rb +857 -0
- data/test/test_gem_local_remote_options.rb +97 -0
- data/test/test_gem_package_tar_header.rb +130 -0
- data/test/test_gem_package_tar_input.rb +112 -0
- data/test/test_gem_package_tar_output.rb +97 -0
- data/test/test_gem_package_tar_reader.rb +46 -0
- data/test/test_gem_package_tar_reader_entry.rb +109 -0
- data/test/test_gem_package_tar_writer.rb +144 -0
- data/test/test_gem_package_task.rb +59 -0
- data/test/test_gem_platform.rb +264 -0
- data/test/test_gem_remote_fetcher.rb +740 -0
- data/test/test_gem_requirement.rb +292 -0
- data/test/test_gem_server.rb +356 -0
- data/test/test_gem_silent_ui.rb +113 -0
- data/test/test_gem_source_index.rb +461 -0
- data/test/test_gem_spec_fetcher.rb +410 -0
- data/test/test_gem_specification.rb +1334 -0
- data/test/test_gem_stream_ui.rb +218 -0
- data/test/test_gem_text.rb +43 -0
- data/test/test_gem_uninstaller.rb +146 -0
- data/test/test_gem_validator.rb +63 -0
- data/test/test_gem_version.rb +181 -0
- data/test/test_gem_version_option.rb +89 -0
- data/test/test_kernel.rb +59 -0
- metadata +402 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
require File.expand_path('../gemutilities', __FILE__)
|
2
|
+
require 'libgems/local_remote_options'
|
3
|
+
require 'libgems/command'
|
4
|
+
|
5
|
+
class TestGemLocalRemoteOptions < RubyGemTestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
super
|
9
|
+
|
10
|
+
@cmd = LibGems::Command.new 'dummy', 'dummy'
|
11
|
+
@cmd.extend LibGems::LocalRemoteOptions
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_add_local_remote_options
|
15
|
+
@cmd.add_local_remote_options
|
16
|
+
|
17
|
+
args = %w[-l -r -b -B 10 --source http://gems.example.com -p --update-sources]
|
18
|
+
assert @cmd.handles?(args)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_both_eh
|
22
|
+
assert_equal false, @cmd.both?
|
23
|
+
|
24
|
+
@cmd.options[:domain] = :local
|
25
|
+
|
26
|
+
assert_equal false, @cmd.both?
|
27
|
+
|
28
|
+
@cmd.options[:domain] = :both
|
29
|
+
|
30
|
+
assert_equal true, @cmd.both?
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_local_eh
|
34
|
+
assert_equal false, @cmd.local?
|
35
|
+
|
36
|
+
@cmd.options[:domain] = :local
|
37
|
+
|
38
|
+
assert_equal true, @cmd.local?
|
39
|
+
|
40
|
+
@cmd.options[:domain] = :both
|
41
|
+
|
42
|
+
assert_equal true, @cmd.local?
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_remote_eh
|
46
|
+
assert_equal false, @cmd.remote?
|
47
|
+
|
48
|
+
@cmd.options[:domain] = :remote
|
49
|
+
|
50
|
+
assert_equal true, @cmd.remote?
|
51
|
+
|
52
|
+
@cmd.options[:domain] = :both
|
53
|
+
|
54
|
+
assert_equal true, @cmd.remote?
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_source_option
|
58
|
+
@cmd.add_source_option
|
59
|
+
|
60
|
+
s1 = URI.parse 'http://more-gems.example.com/'
|
61
|
+
s2 = URI.parse 'http://even-more-gems.example.com/'
|
62
|
+
s3 = URI.parse 'http://other-gems.example.com/some_subdir'
|
63
|
+
s4 = URI.parse 'http://more-gems.example.com/' # Intentional duplicate
|
64
|
+
|
65
|
+
@cmd.handle_options %W[--source #{s1} --source #{s2} --source #{s3} --source #{s4}]
|
66
|
+
|
67
|
+
assert_equal [s1.to_s, s2.to_s, "#{s3}/"], LibGems.sources
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_update_sources_option
|
71
|
+
@cmd.add_update_sources_option
|
72
|
+
|
73
|
+
LibGems.configuration.update_sources = false
|
74
|
+
|
75
|
+
@cmd.handle_options %W[--update-sources]
|
76
|
+
|
77
|
+
assert_equal true, LibGems.configuration.update_sources
|
78
|
+
|
79
|
+
@cmd.handle_options %W[--no-update-sources]
|
80
|
+
|
81
|
+
assert_equal false, LibGems.configuration.update_sources
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_source_option_bad
|
85
|
+
@cmd.add_source_option
|
86
|
+
|
87
|
+
s1 = 'htp://more-gems.example.com'
|
88
|
+
|
89
|
+
assert_raises OptionParser::InvalidArgument do
|
90
|
+
@cmd.handle_options %W[--source #{s1}]
|
91
|
+
end
|
92
|
+
|
93
|
+
assert_equal [@gem_repo], LibGems.sources
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require File.expand_path('../gem_package_tar_test_case', __FILE__)
|
2
|
+
require 'libgems/package'
|
3
|
+
|
4
|
+
class TestGemPackageTarHeader < TarTestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
|
9
|
+
header = {
|
10
|
+
:name => 'x',
|
11
|
+
:mode => 0644,
|
12
|
+
:uid => 1000,
|
13
|
+
:gid => 10000,
|
14
|
+
:size => 100,
|
15
|
+
:mtime => 12345,
|
16
|
+
:typeflag => '0',
|
17
|
+
:linkname => 'link',
|
18
|
+
:uname => 'user',
|
19
|
+
:gname => 'group',
|
20
|
+
:devmajor => 1,
|
21
|
+
:devminor => 2,
|
22
|
+
:prefix => 'y',
|
23
|
+
}
|
24
|
+
|
25
|
+
@tar_header = LibGems::Package::TarHeader.new header
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_self_from
|
29
|
+
io = TempIO.new @tar_header.to_s
|
30
|
+
|
31
|
+
new_header = LibGems::Package::TarHeader.from io
|
32
|
+
|
33
|
+
assert_headers_equal @tar_header, new_header
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_initialize
|
37
|
+
assert_equal '', @tar_header.checksum, 'checksum'
|
38
|
+
assert_equal 1, @tar_header.devmajor, 'devmajor'
|
39
|
+
assert_equal 2, @tar_header.devminor, 'devminor'
|
40
|
+
assert_equal 10000, @tar_header.gid, 'gid'
|
41
|
+
assert_equal 'group', @tar_header.gname, 'gname'
|
42
|
+
assert_equal 'link', @tar_header.linkname, 'linkname'
|
43
|
+
assert_equal 'ustar', @tar_header.magic, 'magic'
|
44
|
+
assert_equal 0644, @tar_header.mode, 'mode'
|
45
|
+
assert_equal 12345, @tar_header.mtime, 'mtime'
|
46
|
+
assert_equal 'x', @tar_header.name, 'name'
|
47
|
+
assert_equal 'y', @tar_header.prefix, 'prefix'
|
48
|
+
assert_equal 100, @tar_header.size, 'size'
|
49
|
+
assert_equal '0', @tar_header.typeflag, 'typeflag'
|
50
|
+
assert_equal 1000, @tar_header.uid, 'uid'
|
51
|
+
assert_equal 'user', @tar_header.uname, 'uname'
|
52
|
+
assert_equal '00', @tar_header.version, 'version'
|
53
|
+
|
54
|
+
refute_empty @tar_header, 'empty'
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_initialize_bad
|
58
|
+
assert_raises ArgumentError do
|
59
|
+
LibGems::Package::TarHeader.new :name => '', :size => '', :mode => ''
|
60
|
+
end
|
61
|
+
|
62
|
+
assert_raises ArgumentError do
|
63
|
+
LibGems::Package::TarHeader.new :name => '', :size => '', :prefix => ''
|
64
|
+
end
|
65
|
+
|
66
|
+
assert_raises ArgumentError do
|
67
|
+
LibGems::Package::TarHeader.new :name => '', :prefix => '', :mode => ''
|
68
|
+
end
|
69
|
+
|
70
|
+
assert_raises ArgumentError do
|
71
|
+
LibGems::Package::TarHeader.new :prefix => '', :size => '', :mode => ''
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_empty_eh
|
76
|
+
refute_empty @tar_header
|
77
|
+
|
78
|
+
@tar_header = LibGems::Package::TarHeader.new :name => 'x', :prefix => '',
|
79
|
+
:mode => 0, :size => 0,
|
80
|
+
:empty => true
|
81
|
+
|
82
|
+
assert_empty @tar_header
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_equals2
|
86
|
+
assert_equal @tar_header, @tar_header
|
87
|
+
assert_equal @tar_header, @tar_header.dup
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_to_s
|
91
|
+
expected = <<-EOF.split("\n").join
|
92
|
+
x\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
93
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
94
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
95
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
96
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
97
|
+
\000\000\000\0000000644\0000001750\0000023420\00000000000144\00000000030071
|
98
|
+
\000012467\000 0link\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
99
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
100
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
101
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
102
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
103
|
+
\000\000\000\000\000\000ustar\00000user\000\000\000\000\000\000\000\000\000
|
104
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
105
|
+
group\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
106
|
+
\000\000\000\000\000\000\000\000\0000000001\0000000002\000y\000\000\000\000
|
107
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
108
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
109
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
110
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
111
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
112
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
113
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
114
|
+
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
|
115
|
+
\000\000\000\000\000\000\000\000\000\000
|
116
|
+
EOF
|
117
|
+
|
118
|
+
assert_headers_equal expected, @tar_header
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_update_checksum
|
122
|
+
assert_equal '', @tar_header.checksum
|
123
|
+
|
124
|
+
@tar_header.update_checksum
|
125
|
+
|
126
|
+
assert_equal '012467', @tar_header.checksum
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require File.expand_path('../gem_package_tar_test_case', __FILE__)
|
2
|
+
require 'libgems/package/tar_input'
|
3
|
+
|
4
|
+
class TestGemPackageTarInput < TarTestCase
|
5
|
+
|
6
|
+
# Sometimes the setgid bit doesn't take. Don't know if this is a problem on
|
7
|
+
# all systems, or just some. But for now, we will ignore it in the tests.
|
8
|
+
SETGID_BIT = 02000
|
9
|
+
|
10
|
+
def setup
|
11
|
+
super
|
12
|
+
|
13
|
+
inner_tar = tar_file_header("bla", "", 0612, 10)
|
14
|
+
inner_tar += "0123456789" + "\0" * 502
|
15
|
+
inner_tar += tar_file_header("foo", "", 0636, 5)
|
16
|
+
inner_tar += "01234" + "\0" * 507
|
17
|
+
inner_tar += tar_dir_header("__dir__", "", 0600)
|
18
|
+
inner_tar += "\0" * 1024
|
19
|
+
str = TempIO.new
|
20
|
+
|
21
|
+
begin
|
22
|
+
os = Zlib::GzipWriter.new str
|
23
|
+
os.write inner_tar
|
24
|
+
ensure
|
25
|
+
os.finish
|
26
|
+
end
|
27
|
+
|
28
|
+
str.rewind
|
29
|
+
|
30
|
+
@file = File.join @tempdir, 'bla.tar'
|
31
|
+
|
32
|
+
File.open @file, 'wb' do |f|
|
33
|
+
f.write tar_file_header("data.tar.gz", "", 0644, str.string.size)
|
34
|
+
f.write str.string
|
35
|
+
f.write "\0" * ((512 - (str.string.size % 512)) % 512 )
|
36
|
+
|
37
|
+
@spec = LibGems::Specification.new do |spec|
|
38
|
+
spec.author = "Mauricio :)"
|
39
|
+
end
|
40
|
+
|
41
|
+
meta = @spec.to_yaml
|
42
|
+
|
43
|
+
f.write tar_file_header("metadata", "", 0644, meta.size)
|
44
|
+
f.write meta + "\0" * (1024 - meta.size)
|
45
|
+
f.write "\0" * 1024
|
46
|
+
end
|
47
|
+
|
48
|
+
@entry_names = %w{bla foo __dir__}
|
49
|
+
@entry_sizes = [10, 5, 0]
|
50
|
+
#FIXME: are these modes system dependent?
|
51
|
+
@entry_modes = [0100612, 0100636, 040600]
|
52
|
+
@entry_files = %W[#{@tempdir}/bla #{@tempdir}/foo]
|
53
|
+
@entry_contents = %w[0123456789 01234]
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_each_works
|
57
|
+
open @file, 'rb' do |io|
|
58
|
+
LibGems::Package::TarInput.open io do |tar_input|
|
59
|
+
count = 0
|
60
|
+
|
61
|
+
tar_input.each_with_index do |entry, i|
|
62
|
+
count = i
|
63
|
+
|
64
|
+
assert_kind_of LibGems::Package::TarReader::Entry, entry
|
65
|
+
assert_equal @entry_names[i], entry.header.name
|
66
|
+
assert_equal @entry_sizes[i], entry.header.size
|
67
|
+
end
|
68
|
+
|
69
|
+
assert_equal 2, count
|
70
|
+
|
71
|
+
assert_equal @spec, tar_input.metadata
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_extract_entry_works
|
77
|
+
open @file, 'rb' do |io|
|
78
|
+
LibGems::Package::TarInput.open io do |tar_input|
|
79
|
+
assert_equal @spec, tar_input.metadata
|
80
|
+
|
81
|
+
count = 0
|
82
|
+
|
83
|
+
tar_input.each_with_index do |entry, i|
|
84
|
+
count = i
|
85
|
+
tar_input.extract_entry @tempdir, entry
|
86
|
+
name = File.join @tempdir, entry.header.name
|
87
|
+
|
88
|
+
if entry.directory? then
|
89
|
+
assert File.directory?(name)
|
90
|
+
else
|
91
|
+
assert File.file?(name)
|
92
|
+
assert_equal @entry_sizes[i], File.stat(name).size
|
93
|
+
#FIXME: win32? !!
|
94
|
+
end
|
95
|
+
|
96
|
+
unless LibGems.win_platform? then
|
97
|
+
assert_equal @entry_modes[i], File.stat(name).mode & (~SETGID_BIT)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
assert_equal 2, count
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
@entry_files.each_with_index do |x, i|
|
106
|
+
assert File.file?(x)
|
107
|
+
assert_equal @entry_contents[i], LibGems.read_binary(x)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require File.expand_path('../gem_package_tar_test_case', __FILE__)
|
2
|
+
require 'libgems/package/tar_output'
|
3
|
+
|
4
|
+
class TestGemPackageTarOutput < TarTestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
|
9
|
+
@file = File.join @tempdir, 'bla2.tar'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_self_open
|
13
|
+
open @file, 'wb' do |tar_io|
|
14
|
+
LibGems::Package::TarOutput.open tar_io do |tar_writer|
|
15
|
+
tar_writer.add_file_simple 'README', 0, 17 do |io|
|
16
|
+
io.write "This is a README\n"
|
17
|
+
end
|
18
|
+
|
19
|
+
tar_writer.metadata = "This is some metadata\n"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
files = util_extract
|
24
|
+
|
25
|
+
name, data = files.shift
|
26
|
+
assert_equal 'data.tar.gz', name
|
27
|
+
|
28
|
+
gz = Zlib::GzipReader.new StringIO.new(data)
|
29
|
+
|
30
|
+
LibGems::Package::TarReader.new gz do |tar_reader|
|
31
|
+
tar_reader.each do |entry|
|
32
|
+
assert_equal 'README', entry.full_name
|
33
|
+
assert_equal "This is a README\n", entry.read
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
gz.close
|
38
|
+
|
39
|
+
name, data = files.shift
|
40
|
+
assert_equal 'metadata.gz', name
|
41
|
+
|
42
|
+
gz = Zlib::GzipReader.new StringIO.new(data)
|
43
|
+
assert_equal "This is some metadata\n", gz.read
|
44
|
+
|
45
|
+
assert_empty files
|
46
|
+
ensure
|
47
|
+
gz.close if gz
|
48
|
+
end
|
49
|
+
|
50
|
+
if defined? OpenSSL then
|
51
|
+
def test_self_open_signed
|
52
|
+
signer = LibGems::Security::Signer.new @private_key, [@public_cert]
|
53
|
+
|
54
|
+
open @file, 'wb' do |tar_io|
|
55
|
+
LibGems::Package::TarOutput.open tar_io, signer do |tar_writer|
|
56
|
+
tar_writer.add_file_simple 'README', 0, 17 do |io|
|
57
|
+
io.write "This is a README\n"
|
58
|
+
end
|
59
|
+
|
60
|
+
tar_writer.metadata = "This is some metadata\n"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
files = util_extract
|
65
|
+
|
66
|
+
name, data = files.shift
|
67
|
+
assert_equal 'data.tar.gz', name
|
68
|
+
|
69
|
+
name, data = files.shift
|
70
|
+
assert_equal 'metadata.gz', name
|
71
|
+
|
72
|
+
name, data = files.shift
|
73
|
+
assert_equal 'data.tar.gz.sig', name
|
74
|
+
|
75
|
+
name, data = files.shift
|
76
|
+
assert_equal 'metadata.gz.sig', name
|
77
|
+
|
78
|
+
assert_empty files
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def util_extract
|
83
|
+
files = []
|
84
|
+
|
85
|
+
open @file, 'rb' do |io|
|
86
|
+
LibGems::Package::TarReader.new io do |tar_reader|
|
87
|
+
tar_reader.each do |entry|
|
88
|
+
files << [entry.full_name, entry.read]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
files
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path('../gem_package_tar_test_case', __FILE__)
|
2
|
+
require 'libgems/package'
|
3
|
+
|
4
|
+
class TestGemPackageTarReader < TarTestCase
|
5
|
+
|
6
|
+
def test_each_entry
|
7
|
+
tar = tar_dir_header "foo", "bar", 0
|
8
|
+
tar << tar_file_header("bar", "baz", 0, 0)
|
9
|
+
|
10
|
+
io = TempIO.new tar
|
11
|
+
|
12
|
+
entries = 0
|
13
|
+
|
14
|
+
LibGems::Package::TarReader.new io do |tar_reader|
|
15
|
+
tar_reader.each_entry do |entry|
|
16
|
+
assert_kind_of LibGems::Package::TarReader::Entry, entry
|
17
|
+
|
18
|
+
entries += 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_equal 2, entries
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_rewind
|
26
|
+
content = ('a'..'z').to_a.join(" ")
|
27
|
+
|
28
|
+
str = tar_file_header("lib/foo", "", 010644, content.size) + content +
|
29
|
+
"\0" * (512 - content.size)
|
30
|
+
str << "\0" * 1024
|
31
|
+
|
32
|
+
LibGems::Package::TarReader.new(TempIO.new(str)) do |tar_reader|
|
33
|
+
3.times do
|
34
|
+
tar_reader.rewind
|
35
|
+
i = 0
|
36
|
+
tar_reader.each_entry do |entry|
|
37
|
+
assert_equal(content, entry.read)
|
38
|
+
i += 1
|
39
|
+
end
|
40
|
+
assert_equal(1, i)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|