rubyzip 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +89 -35
- data/lib/zip/central_directory.rb +3 -3
- data/lib/zip/compressor.rb +1 -2
- data/lib/zip/constants.rb +3 -3
- data/lib/zip/crypto/null_encryption.rb +2 -4
- data/lib/zip/decompressor.rb +1 -1
- data/lib/zip/dos_time.rb +1 -1
- data/lib/zip/entry.rb +67 -57
- data/lib/zip/entry_set.rb +3 -3
- data/lib/zip/errors.rb +1 -0
- data/lib/zip/extra_field/generic.rb +1 -1
- data/lib/zip/extra_field/zip64_placeholder.rb +1 -2
- data/lib/zip/extra_field.rb +2 -2
- data/lib/zip/file.rb +47 -27
- data/lib/zip/filesystem.rb +17 -13
- data/lib/zip/inflater.rb +2 -2
- data/lib/zip/input_stream.rb +10 -7
- data/lib/zip/ioextras/abstract_input_stream.rb +1 -1
- data/lib/zip/ioextras/abstract_output_stream.rb +1 -1
- data/lib/zip/output_stream.rb +5 -5
- data/lib/zip/pass_thru_decompressor.rb +1 -1
- data/lib/zip/streamable_stream.rb +1 -1
- data/lib/zip/version.rb +1 -1
- data/lib/zip.rb +11 -1
- data/samples/example_recursive.rb +14 -15
- data/samples/gtk_ruby_zip.rb +1 -1
- data/samples/qtzip.rb +1 -1
- data/samples/zipfind.rb +2 -2
- data/test/central_directory_entry_test.rb +1 -1
- data/test/data/gpbit3stored.zip +0 -0
- data/test/data/path_traversal/Makefile +10 -0
- data/test/data/path_traversal/jwilk/README.md +5 -0
- data/test/data/path_traversal/jwilk/absolute1.zip +0 -0
- data/test/data/path_traversal/jwilk/absolute2.zip +0 -0
- data/test/data/path_traversal/jwilk/dirsymlink.zip +0 -0
- data/test/data/path_traversal/jwilk/dirsymlink2a.zip +0 -0
- data/test/data/path_traversal/jwilk/dirsymlink2b.zip +0 -0
- data/test/data/path_traversal/jwilk/relative0.zip +0 -0
- data/test/data/path_traversal/jwilk/relative2.zip +0 -0
- data/test/data/path_traversal/jwilk/symlink.zip +0 -0
- data/test/data/path_traversal/relative1.zip +0 -0
- data/test/data/path_traversal/tilde.zip +0 -0
- data/test/data/path_traversal/tuzovakaoff/README.md +3 -0
- data/test/data/path_traversal/tuzovakaoff/absolutepath.zip +0 -0
- data/test/data/path_traversal/tuzovakaoff/symlink.zip +0 -0
- data/test/data/rubycode.zip +0 -0
- data/test/errors_test.rb +1 -0
- data/test/file_extract_test.rb +62 -0
- data/test/file_permissions_test.rb +11 -15
- data/test/file_test.rb +92 -9
- data/test/filesystem/dir_iterator_test.rb +1 -1
- data/test/filesystem/directory_test.rb +29 -11
- data/test/filesystem/file_mutating_test.rb +3 -4
- data/test/filesystem/file_nonmutating_test.rb +31 -31
- data/test/filesystem/file_stat_test.rb +4 -4
- data/test/gentestfiles.rb +13 -13
- data/test/input_stream_test.rb +6 -6
- data/test/ioextras/abstract_output_stream_test.rb +2 -2
- data/test/path_traversal_test.rb +141 -0
- data/test/test_helper.rb +2 -2
- data/test/unicode_file_names_and_comments_test.rb +12 -0
- data/test/zip64_full_test.rb +2 -2
- metadata +103 -51
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class FilePermissionsTest < MiniTest::Test
|
4
|
-
|
5
|
-
|
6
|
-
FILENAME = File.join(File.dirname(__FILE__), "umask.txt")
|
4
|
+
ZIPNAME = File.join(File.dirname(__FILE__), 'umask.zip')
|
5
|
+
FILENAME = File.join(File.dirname(__FILE__), 'umask.txt')
|
7
6
|
|
8
7
|
def teardown
|
9
8
|
::File.unlink(ZIPNAME)
|
@@ -16,7 +15,7 @@ class FilePermissionsTest < MiniTest::Test
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def test_umask_000
|
19
|
-
set_umask(
|
18
|
+
set_umask(0o000) do
|
20
19
|
create_files
|
21
20
|
end
|
22
21
|
|
@@ -24,7 +23,7 @@ class FilePermissionsTest < MiniTest::Test
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def test_umask_066
|
27
|
-
set_umask(
|
26
|
+
set_umask(0o066) do
|
28
27
|
create_files
|
29
28
|
end
|
30
29
|
|
@@ -32,7 +31,7 @@ class FilePermissionsTest < MiniTest::Test
|
|
32
31
|
end
|
33
32
|
|
34
33
|
def test_umask_027
|
35
|
-
set_umask(
|
34
|
+
set_umask(0o027) do
|
36
35
|
create_files
|
37
36
|
end
|
38
37
|
|
@@ -48,7 +47,7 @@ class FilePermissionsTest < MiniTest::Test
|
|
48
47
|
|
49
48
|
def create_files
|
50
49
|
::Zip::File.open(ZIPNAME, ::Zip::File::CREATE) do |zip|
|
51
|
-
zip.comment =
|
50
|
+
zip.comment = 'test'
|
52
51
|
end
|
53
52
|
|
54
53
|
::File.open(FILENAME, 'w') do |file|
|
@@ -57,13 +56,10 @@ class FilePermissionsTest < MiniTest::Test
|
|
57
56
|
end
|
58
57
|
|
59
58
|
# If anything goes wrong, make sure the umask is restored.
|
60
|
-
def set_umask(umask
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
::File.umask(saved_umask)
|
66
|
-
end
|
59
|
+
def set_umask(umask)
|
60
|
+
saved_umask = ::File.umask(umask)
|
61
|
+
yield
|
62
|
+
ensure
|
63
|
+
::File.umask(saved_umask)
|
67
64
|
end
|
68
|
-
|
69
65
|
end
|
data/test/file_test.rb
CHANGED
@@ -55,6 +55,12 @@ class ZipFileTest < MiniTest::Test
|
|
55
55
|
assert_equal(2, zfRead.entries.length)
|
56
56
|
end
|
57
57
|
|
58
|
+
def test_get_input_stream_stored_with_gpflag_bit3
|
59
|
+
::Zip::File.open('test/data/gpbit3stored.zip') do |zf|
|
60
|
+
assert_equal("foo\n", zf.read("foo.txt"))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
58
64
|
def test_get_output_stream
|
59
65
|
entryCount = nil
|
60
66
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
@@ -97,6 +103,13 @@ class ZipFileTest < MiniTest::Test
|
|
97
103
|
end
|
98
104
|
end
|
99
105
|
|
106
|
+
def test_open_buffer_with_string
|
107
|
+
string = File.read('test/data/rubycode.zip')
|
108
|
+
::Zip::File.open_buffer string do |zf|
|
109
|
+
assert zf.entries.map { |e| e.name }.include?('zippedruby1.rb')
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
100
113
|
def test_open_buffer_with_stringio
|
101
114
|
string_io = StringIO.new File.read('test/data/rubycode.zip')
|
102
115
|
::Zip::File.open_buffer string_io do |zf|
|
@@ -104,6 +117,57 @@ class ZipFileTest < MiniTest::Test
|
|
104
117
|
end
|
105
118
|
end
|
106
119
|
|
120
|
+
def test_close_buffer_with_stringio
|
121
|
+
string_io = StringIO.new File.read('test/data/rubycode.zip')
|
122
|
+
zf = ::Zip::File.open_buffer string_io
|
123
|
+
assert_nil zf.close
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_open_buffer_no_op_does_not_change_file
|
127
|
+
Dir.mktmpdir do |tmp|
|
128
|
+
test_zip = File.join(tmp, 'test.zip')
|
129
|
+
FileUtils.cp 'test/data/rubycode.zip', test_zip
|
130
|
+
|
131
|
+
# Note: this may change the file if it is opened with r+b instead of rb.
|
132
|
+
# The 'extra fields' in this particular zip file get reordered.
|
133
|
+
File.open(test_zip, 'rb') do |file|
|
134
|
+
Zip::File.open_buffer(file) do |zf|
|
135
|
+
nil # do nothing
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
assert_equal \
|
140
|
+
File.binread('test/data/rubycode.zip'),
|
141
|
+
File.binread(test_zip)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_open_buffer_close_does_not_change_file
|
146
|
+
Dir.mktmpdir do |tmp|
|
147
|
+
test_zip = File.join(tmp, 'test.zip')
|
148
|
+
FileUtils.cp 'test/data/rubycode.zip', test_zip
|
149
|
+
|
150
|
+
File.open(test_zip, 'rb') do |file|
|
151
|
+
zf = Zip::File.open_buffer(file)
|
152
|
+
refute zf.commit_required?
|
153
|
+
assert_nil zf.close
|
154
|
+
end
|
155
|
+
|
156
|
+
assert_equal \
|
157
|
+
File.binread('test/data/rubycode.zip'),
|
158
|
+
File.binread(test_zip)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_open_buffer_with_io_and_block
|
163
|
+
File.open('test/data/rubycode.zip') do |io|
|
164
|
+
io.set_encoding(Encoding::BINARY) # not strictly required but can be set
|
165
|
+
Zip::File.open_buffer(io) do |zip_io|
|
166
|
+
# left empty on purpose
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
107
171
|
def test_open_buffer_without_block
|
108
172
|
string_io = StringIO.new File.read('test/data/rubycode.zip')
|
109
173
|
zf = ::Zip::File.open_buffer string_io
|
@@ -140,17 +204,37 @@ class ZipFileTest < MiniTest::Test
|
|
140
204
|
zfRead.get_input_stream(entryName) { |zis| zis.read })
|
141
205
|
end
|
142
206
|
|
207
|
+
def test_add_stored
|
208
|
+
srcFile = 'test/data/file2.txt'
|
209
|
+
entryName = 'newEntryName.rb'
|
210
|
+
assert(::File.exist?(srcFile))
|
211
|
+
zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
|
212
|
+
zf.add_stored(entryName, srcFile)
|
213
|
+
zf.close
|
214
|
+
|
215
|
+
zfRead = ::Zip::File.new(EMPTY_FILENAME)
|
216
|
+
entry = zfRead.entries.first
|
217
|
+
assert_equal('', zfRead.comment)
|
218
|
+
assert_equal(1, zfRead.entries.length)
|
219
|
+
assert_equal(entryName, entry.name)
|
220
|
+
assert_equal(File.size(srcFile), entry.size)
|
221
|
+
assert_equal(entry.size, entry.compressed_size)
|
222
|
+
assert_equal(::Zip::Entry::STORED, entry.compression_method)
|
223
|
+
AssertEntry.assert_contents(srcFile,
|
224
|
+
zfRead.get_input_stream(entryName) { |zis| zis.read })
|
225
|
+
end
|
226
|
+
|
143
227
|
def test_recover_permissions_after_add_files_to_archive
|
144
228
|
srcZip = TEST_ZIP.zip_name
|
145
|
-
::File.chmod(
|
229
|
+
::File.chmod(0o664, srcZip)
|
146
230
|
srcFile = 'test/data/file2.txt'
|
147
231
|
entryName = 'newEntryName.rb'
|
148
|
-
assert_equal(::File.stat(srcZip).mode,
|
232
|
+
assert_equal(::File.stat(srcZip).mode, 0o100664)
|
149
233
|
assert(::File.exist?(srcZip))
|
150
234
|
zf = ::Zip::File.new(srcZip, ::Zip::File::CREATE)
|
151
235
|
zf.add(entryName, srcFile)
|
152
236
|
zf.close
|
153
|
-
assert_equal(::File.stat(srcZip).mode,
|
237
|
+
assert_equal(::File.stat(srcZip).mode, 0o100664)
|
154
238
|
end
|
155
239
|
|
156
240
|
def test_add_existing_entry_name
|
@@ -234,7 +318,7 @@ class ZipFileTest < MiniTest::Test
|
|
234
318
|
zf.mkdir('test')
|
235
319
|
arr << 'test/'
|
236
320
|
arr_renamed << 'Ztest/'
|
237
|
-
%w
|
321
|
+
%w[a b c d].each do |f|
|
238
322
|
zf.get_output_stream("test/#{f}") { |file| file.puts 'aaaa' }
|
239
323
|
arr << "test/#{f}"
|
240
324
|
arr_renamed << "Ztest/#{f}"
|
@@ -329,7 +413,7 @@ class ZipFileTest < MiniTest::Test
|
|
329
413
|
|
330
414
|
def test_replace_non_entry
|
331
415
|
entryToReplace = 'nonExistingEntryname'
|
332
|
-
::Zip::File.open(TEST_ZIP.zip_name) do
|
416
|
+
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
333
417
|
assert_raises(Errno::ENOENT) { zf.replace(entryToReplace, 'test/data/file2.txt') }
|
334
418
|
end
|
335
419
|
end
|
@@ -347,7 +431,7 @@ class ZipFileTest < MiniTest::Test
|
|
347
431
|
zfRead.close
|
348
432
|
|
349
433
|
zf.close
|
350
|
-
res = system("unzip -
|
434
|
+
res = system("unzip -tqq #{TEST_ZIP.zip_name}")
|
351
435
|
assert_equal(res, true)
|
352
436
|
end
|
353
437
|
|
@@ -363,7 +447,7 @@ class ZipFileTest < MiniTest::Test
|
|
363
447
|
zf2 = ::Zip::File.open(filename)
|
364
448
|
assert(zf2.entries.detect { |e| e.name == 'test1.txt' } != nil)
|
365
449
|
assert(zf2.entries.detect { |e| e.name == 'test2.txt' } != nil)
|
366
|
-
res = system("unzip -
|
450
|
+
res = system("unzip -tqq #{filename}")
|
367
451
|
assert_equal(res, true)
|
368
452
|
end
|
369
453
|
|
@@ -434,7 +518,6 @@ class ZipFileTest < MiniTest::Test
|
|
434
518
|
filename_to_remove = originalEntries.map(&:to_s).find { |name| name.match('longBinary') }
|
435
519
|
zf.remove(filename_to_remove)
|
436
520
|
assert_not_contains(zf, filename_to_remove)
|
437
|
-
|
438
521
|
ensure
|
439
522
|
zf.close
|
440
523
|
end
|
@@ -558,7 +641,7 @@ class ZipFileTest < MiniTest::Test
|
|
558
641
|
entry_count = 0
|
559
642
|
File.open 'test/data/oddExtraField.zip', 'rb' do |zip_io|
|
560
643
|
Zip::File.open_buffer zip_io.read do |zip|
|
561
|
-
zip.each do |
|
644
|
+
zip.each do |_zip_entry|
|
562
645
|
entry_count += 1
|
563
646
|
end
|
564
647
|
end
|
@@ -3,6 +3,7 @@ require 'zip/filesystem'
|
|
3
3
|
|
4
4
|
class ZipFsDirectoryTest < MiniTest::Test
|
5
5
|
TEST_ZIP = 'test/data/generated/zipWithDirs_copy.zip'
|
6
|
+
GLOB_TEST_ZIP = 'test/data/globTest.zip'
|
6
7
|
|
7
8
|
def setup
|
8
9
|
FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP)
|
@@ -51,10 +52,10 @@ class ZipFsDirectoryTest < MiniTest::Test
|
|
51
52
|
zf.dir.chdir 'file1'
|
52
53
|
end
|
53
54
|
|
54
|
-
assert_equal(%w
|
55
|
+
assert_equal(%w[dir1 dir2 file1].sort, zf.dir.entries('.').sort)
|
55
56
|
zf.dir.chdir 'dir1'
|
56
57
|
assert_equal('/dir1', zf.dir.pwd)
|
57
|
-
assert_equal(%w
|
58
|
+
assert_equal(%w[dir11 file11 file12], zf.dir.entries('.').sort)
|
58
59
|
|
59
60
|
zf.dir.chdir '../dir2/dir21'
|
60
61
|
assert_equal('/dir2/dir21', zf.dir.pwd)
|
@@ -77,11 +78,11 @@ class ZipFsDirectoryTest < MiniTest::Test
|
|
77
78
|
|
78
79
|
entries = []
|
79
80
|
zf.dir.foreach('.') { |e| entries << e }
|
80
|
-
assert_equal(%w
|
81
|
+
assert_equal(%w[dir1 dir2 file1].sort, entries.sort)
|
81
82
|
|
82
83
|
entries = []
|
83
84
|
zf.dir.foreach('dir1') { |e| entries << e }
|
84
|
-
assert_equal(%w
|
85
|
+
assert_equal(%w[dir11 file11 file12], entries.sort)
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
@@ -93,11 +94,28 @@ class ZipFsDirectoryTest < MiniTest::Test
|
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
def test_glob
|
98
|
+
globbed_files = [
|
99
|
+
'globTest/foo/bar/baz/foo.txt',
|
100
|
+
'globTest/foo.txt',
|
101
|
+
'globTest/food.txt'
|
102
|
+
]
|
103
|
+
|
104
|
+
::Zip::File.open(GLOB_TEST_ZIP) do |zf|
|
105
|
+
zf.dir.glob('**/*.txt') do |f|
|
106
|
+
assert globbed_files.include?(f.name)
|
107
|
+
end
|
108
|
+
|
109
|
+
zf.dir.glob('globTest/foo/**/*.txt') do |f|
|
110
|
+
assert_equal globbed_files[0], f.name
|
111
|
+
end
|
112
|
+
|
113
|
+
zf.dir.chdir('globTest/foo')
|
114
|
+
zf.dir.glob('**/*.txt') do |f|
|
115
|
+
assert_equal globbed_files[0], f.name
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
101
119
|
|
102
120
|
def test_open_new
|
103
121
|
::Zip::File.open(TEST_ZIP) do |zf|
|
@@ -110,11 +128,11 @@ class ZipFsDirectoryTest < MiniTest::Test
|
|
110
128
|
end
|
111
129
|
|
112
130
|
d = zf.dir.new('.')
|
113
|
-
assert_equal(%w
|
131
|
+
assert_equal(%w[file1 dir1 dir2].sort, d.entries.sort)
|
114
132
|
d.close
|
115
133
|
|
116
134
|
zf.dir.open('dir1') do |dir|
|
117
|
-
assert_equal(%w
|
135
|
+
assert_equal(%w[dir11 file11 file12].sort, dir.entries.sort)
|
118
136
|
end
|
119
137
|
end
|
120
138
|
end
|
@@ -7,8 +7,7 @@ class ZipFsFileMutatingTest < MiniTest::Test
|
|
7
7
|
FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP)
|
8
8
|
end
|
9
9
|
|
10
|
-
def teardown
|
11
|
-
end
|
10
|
+
def teardown; end
|
12
11
|
|
13
12
|
def test_delete
|
14
13
|
do_test_delete_or_unlink(:delete)
|
@@ -51,11 +50,11 @@ class ZipFsFileMutatingTest < MiniTest::Test
|
|
51
50
|
|
52
51
|
def test_chmod
|
53
52
|
::Zip::File.open(TEST_ZIP) do |zf|
|
54
|
-
zf.file.chmod(
|
53
|
+
zf.file.chmod(0o765, 'file1')
|
55
54
|
end
|
56
55
|
|
57
56
|
::Zip::File.open(TEST_ZIP) do |zf|
|
58
|
-
assert_equal(
|
57
|
+
assert_equal(0o100765, zf.file.stat('file1').mode)
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
@@ -14,11 +14,11 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
14
14
|
|
15
15
|
def test_umask
|
16
16
|
assert_equal(::File.umask, @zip_file.file.umask)
|
17
|
-
@zip_file.file.umask(
|
17
|
+
@zip_file.file.umask(0o006)
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_exists?
|
21
|
-
assert(
|
21
|
+
assert(!@zip_file.file.exists?('notAFile'))
|
22
22
|
assert(@zip_file.file.exists?('file1'))
|
23
23
|
assert(@zip_file.file.exists?('dir1'))
|
24
24
|
assert(@zip_file.file.exists?('dir1/'))
|
@@ -114,13 +114,13 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
114
114
|
def test_file?
|
115
115
|
assert(@zip_file.file.file?('file1'))
|
116
116
|
assert(@zip_file.file.file?('dir2/file21'))
|
117
|
-
assert(
|
118
|
-
assert(
|
117
|
+
assert(!@zip_file.file.file?('dir1'))
|
118
|
+
assert(!@zip_file.file.file?('dir1/dir11'))
|
119
119
|
|
120
120
|
assert(@zip_file.file.stat('file1').file?)
|
121
121
|
assert(@zip_file.file.stat('dir2/file21').file?)
|
122
|
-
assert(
|
123
|
-
assert(
|
122
|
+
assert(!@zip_file.file.stat('dir1').file?)
|
123
|
+
assert(!@zip_file.file.stat('dir1/dir11').file?)
|
124
124
|
end
|
125
125
|
|
126
126
|
include ExtraAssertions
|
@@ -160,15 +160,15 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
160
160
|
end
|
161
161
|
|
162
162
|
def assert_always_false(operation)
|
163
|
-
assert(
|
164
|
-
assert(
|
165
|
-
assert(
|
166
|
-
assert(
|
167
|
-
assert(
|
163
|
+
assert(!@zip_file.file.send(operation, 'noSuchFile'))
|
164
|
+
assert(!@zip_file.file.send(operation, 'file1'))
|
165
|
+
assert(!@zip_file.file.send(operation, 'dir1'))
|
166
|
+
assert(!@zip_file.file.stat('file1').send(operation))
|
167
|
+
assert(!@zip_file.file.stat('dir1').send(operation))
|
168
168
|
end
|
169
169
|
|
170
170
|
def assert_true_if_entry_exists(operation)
|
171
|
-
assert(
|
171
|
+
assert(!@zip_file.file.send(operation, 'noSuchFile'))
|
172
172
|
assert(@zip_file.file.send(operation, 'file1'))
|
173
173
|
assert(@zip_file.file.send(operation, 'dir1'))
|
174
174
|
assert(@zip_file.file.stat('file1').send(operation))
|
@@ -221,15 +221,15 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
221
221
|
end
|
222
222
|
|
223
223
|
def test_directory?
|
224
|
-
assert(
|
225
|
-
assert(
|
226
|
-
assert(
|
224
|
+
assert(!@zip_file.file.directory?('notAFile'))
|
225
|
+
assert(!@zip_file.file.directory?('file1'))
|
226
|
+
assert(!@zip_file.file.directory?('dir1/file11'))
|
227
227
|
assert(@zip_file.file.directory?('dir1'))
|
228
228
|
assert(@zip_file.file.directory?('dir1/'))
|
229
229
|
assert(@zip_file.file.directory?('dir2/dir21'))
|
230
230
|
|
231
|
-
assert(
|
232
|
-
assert(
|
231
|
+
assert(!@zip_file.file.stat('file1').directory?)
|
232
|
+
assert(!@zip_file.file.stat('dir1/file11').directory?)
|
233
233
|
assert(@zip_file.file.stat('dir1').directory?)
|
234
234
|
assert(@zip_file.file.stat('dir1/').directory?)
|
235
235
|
assert(@zip_file.file.stat('dir2/dir21').directory?)
|
@@ -243,8 +243,8 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
243
243
|
end
|
244
244
|
|
245
245
|
def test_zero?
|
246
|
-
assert(
|
247
|
-
assert(
|
246
|
+
assert(!@zip_file.file.zero?('notAFile'))
|
247
|
+
assert(!@zip_file.file.zero?('file1'))
|
248
248
|
assert(@zip_file.file.zero?('dir1'))
|
249
249
|
blockCalled = false
|
250
250
|
::Zip::File.open('test/data/generated/5entry.zip') do |zf|
|
@@ -253,7 +253,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
253
253
|
end
|
254
254
|
assert(blockCalled)
|
255
255
|
|
256
|
-
assert(
|
256
|
+
assert(!@zip_file.file.stat('file1').zero?)
|
257
257
|
assert(@zip_file.file.stat('dir1').zero?)
|
258
258
|
blockCalled = false
|
259
259
|
::Zip::File.open('test/data/generated/5entry.zip') do |zf|
|
@@ -309,7 +309,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
309
309
|
end
|
310
310
|
|
311
311
|
def test_readable?
|
312
|
-
assert(
|
312
|
+
assert(!@zip_file.file.readable?('noSuchFile'))
|
313
313
|
assert(@zip_file.file.readable?('file1'))
|
314
314
|
assert(@zip_file.file.readable?('dir1'))
|
315
315
|
assert(@zip_file.file.stat('file1').readable?)
|
@@ -317,7 +317,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
317
317
|
end
|
318
318
|
|
319
319
|
def test_readable_real?
|
320
|
-
assert(
|
320
|
+
assert(!@zip_file.file.readable_real?('noSuchFile'))
|
321
321
|
assert(@zip_file.file.readable_real?('file1'))
|
322
322
|
assert(@zip_file.file.readable_real?('dir1'))
|
323
323
|
assert(@zip_file.file.stat('file1').readable_real?)
|
@@ -325,7 +325,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
325
325
|
end
|
326
326
|
|
327
327
|
def test_writable?
|
328
|
-
assert(
|
328
|
+
assert(!@zip_file.file.writable?('noSuchFile'))
|
329
329
|
assert(@zip_file.file.writable?('file1'))
|
330
330
|
assert(@zip_file.file.writable?('dir1'))
|
331
331
|
assert(@zip_file.file.stat('file1').writable?)
|
@@ -333,7 +333,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
333
333
|
end
|
334
334
|
|
335
335
|
def test_writable_real?
|
336
|
-
assert(
|
336
|
+
assert(!@zip_file.file.writable_real?('noSuchFile'))
|
337
337
|
assert(@zip_file.file.writable_real?('file1'))
|
338
338
|
assert(@zip_file.file.writable_real?('dir1'))
|
339
339
|
assert(@zip_file.file.stat('file1').writable_real?)
|
@@ -341,18 +341,18 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
341
341
|
end
|
342
342
|
|
343
343
|
def test_executable?
|
344
|
-
assert(
|
345
|
-
assert(
|
344
|
+
assert(!@zip_file.file.executable?('noSuchFile'))
|
345
|
+
assert(!@zip_file.file.executable?('file1'))
|
346
346
|
assert(@zip_file.file.executable?('dir1'))
|
347
|
-
assert(
|
347
|
+
assert(!@zip_file.file.stat('file1').executable?)
|
348
348
|
assert(@zip_file.file.stat('dir1').executable?)
|
349
349
|
end
|
350
350
|
|
351
351
|
def test_executable_real?
|
352
|
-
assert(
|
353
|
-
assert(
|
352
|
+
assert(!@zip_file.file.executable_real?('noSuchFile'))
|
353
|
+
assert(!@zip_file.file.executable_real?('file1'))
|
354
354
|
assert(@zip_file.file.executable_real?('dir1'))
|
355
|
-
assert(
|
355
|
+
assert(!@zip_file.file.stat('file1').executable_real?)
|
356
356
|
assert(@zip_file.file.stat('dir1').executable_real?)
|
357
357
|
end
|
358
358
|
|
@@ -455,7 +455,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
455
455
|
zf.glob('**/foo.txt') do |match|
|
456
456
|
results << "<#{match.class.name}: #{match}>"
|
457
457
|
end
|
458
|
-
assert(
|
458
|
+
assert(!results.empty?, 'block not run, or run out of context')
|
459
459
|
assert_equal 2, results.size
|
460
460
|
assert_operator results, :include?, '<Zip::Entry: globTest/foo.txt>'
|
461
461
|
assert_operator results, :include?, '<Zip::Entry: globTest/foo/bar/baz/foo.txt>'
|
@@ -32,10 +32,10 @@ class ZipFsFileStatTest < MiniTest::Test
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_mode
|
35
|
-
assert_equal(
|
36
|
-
assert_equal(
|
37
|
-
assert_equal(
|
38
|
-
assert_equal(
|
35
|
+
assert_equal(0o600, @zip_file.file.stat('file1').mode & 0o777)
|
36
|
+
assert_equal(0o600, @zip_file.file.stat('file1').mode & 0o777)
|
37
|
+
assert_equal(0o755, @zip_file.file.stat('dir1').mode & 0o777)
|
38
|
+
assert_equal(0o755, @zip_file.file.stat('dir1').mode & 0o777)
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_dev
|
data/test/gentestfiles.rb
CHANGED
@@ -71,12 +71,12 @@ class TestZipFile
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def self.create_test_zips
|
74
|
-
raise "failed to create test zip '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} test/data/file2.txt")
|
75
|
-
raise "failed to remove entry from '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} -d test/data/file2.txt")
|
74
|
+
raise "failed to create test zip '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP1.zip_name} test/data/file2.txt")
|
75
|
+
raise "failed to remove entry from '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP1.zip_name} -d test/data/file2.txt")
|
76
76
|
|
77
77
|
File.open('test/data/generated/empty.txt', 'w') {}
|
78
78
|
File.open('test/data/generated/empty_chmod640.txt', 'w') {}
|
79
|
-
::File.chmod(
|
79
|
+
::File.chmod(0o640, 'test/data/generated/empty_chmod640.txt')
|
80
80
|
|
81
81
|
File.open('test/data/generated/short.txt', 'w') { |file| file << 'ABCDEF' }
|
82
82
|
ziptestTxt = ''
|
@@ -93,34 +93,34 @@ class TestZipFile
|
|
93
93
|
file << testBinaryPattern << rand << "\0" while file.tell < 6E5
|
94
94
|
end
|
95
95
|
|
96
|
-
raise "failed to create test zip '#{TEST_ZIP2.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP2.zip_name} #{TEST_ZIP2.entry_names.join(' ')}")
|
96
|
+
raise "failed to create test zip '#{TEST_ZIP2.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP2.zip_name} #{TEST_ZIP2.entry_names.join(' ')}")
|
97
97
|
|
98
98
|
if RUBY_PLATFORM =~ /mswin|mingw|cygwin/
|
99
|
-
raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("echo #{TEST_ZIP2.comment}| /usr/bin/zip -
|
99
|
+
raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("echo #{TEST_ZIP2.comment}| /usr/bin/zip -zq #{TEST_ZIP2.zip_name}\"")
|
100
100
|
else
|
101
101
|
# without bash system interprets everything after echo as parameters to
|
102
102
|
# echo including | zip -z ...
|
103
|
-
raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("bash -c \"echo #{TEST_ZIP2.comment} | /usr/bin/zip -
|
103
|
+
raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("bash -c \"echo #{TEST_ZIP2.comment} | /usr/bin/zip -zq #{TEST_ZIP2.zip_name}\"")
|
104
104
|
end
|
105
105
|
|
106
|
-
raise "failed to create test zip '#{TEST_ZIP3.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP3.zip_name} #{TEST_ZIP3.entry_names.join(' ')}")
|
106
|
+
raise "failed to create test zip '#{TEST_ZIP3.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP3.zip_name} #{TEST_ZIP3.entry_names.join(' ')}")
|
107
107
|
|
108
|
-
raise "failed to create test zip '#{TEST_ZIP4.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP4.zip_name} #{TEST_ZIP4.entry_names.join(' ')}")
|
108
|
+
raise "failed to create test zip '#{TEST_ZIP4.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP4.zip_name} #{TEST_ZIP4.entry_names.join(' ')}")
|
109
109
|
rescue
|
110
110
|
# If there are any Windows developers wanting to use a command line zip.exe
|
111
111
|
# to help create the following files, there's a free one available from
|
112
112
|
# http://stahlworks.com/dev/index.php?tool=zipunzip
|
113
113
|
# that works with the above code
|
114
114
|
raise $!.to_s +
|
115
|
-
|
116
|
-
|
117
|
-
|
115
|
+
"\n\nziptest.rb requires the Info-ZIP program 'zip' in the path\n" \
|
116
|
+
"to create test data. If you don't have it you can download\n" \
|
117
|
+
'the necessary test files at http://sf.net/projects/rubyzip.'
|
118
118
|
end
|
119
119
|
|
120
120
|
TEST_ZIP1 = TestZipFile.new('test/data/generated/empty.zip', [])
|
121
|
-
TEST_ZIP2 = TestZipFile.new('test/data/generated/5entry.zip', %w
|
121
|
+
TEST_ZIP2 = TestZipFile.new('test/data/generated/5entry.zip', %w[test/data/generated/longAscii.txt test/data/generated/empty.txt test/data/generated/empty_chmod640.txt test/data/generated/short.txt test/data/generated/longBinary.bin],
|
122
122
|
'my zip comment')
|
123
|
-
TEST_ZIP3 = TestZipFile.new('test/data/generated/test1.zip', %w
|
123
|
+
TEST_ZIP3 = TestZipFile.new('test/data/generated/test1.zip', %w[test/data/file1.txt])
|
124
124
|
TEST_ZIP4 = TestZipFile.new('test/data/generated/zipWithDir.zip', ['test/data/file1.txt',
|
125
125
|
TestFiles::EMPTY_TEST_DIR])
|
126
126
|
end
|
data/test/input_stream_test.rb
CHANGED
@@ -70,7 +70,7 @@ class ZipInputStreamTest < MiniTest::Test
|
|
70
70
|
entry = zis.get_next_entry # longAscii.txt
|
71
71
|
assert_equal(false, zis.eof?)
|
72
72
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
|
73
|
-
assert zis.gets.
|
73
|
+
assert !zis.gets.empty?
|
74
74
|
assert_equal(false, zis.eof?)
|
75
75
|
entry = zis.get_next_entry # empty.txt
|
76
76
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
|
@@ -84,10 +84,10 @@ class ZipInputStreamTest < MiniTest::Test
|
|
84
84
|
assert_equal(true, zis.eof?)
|
85
85
|
entry = zis.get_next_entry # short.txt
|
86
86
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
|
87
|
-
assert zis.gets.
|
87
|
+
assert !zis.gets.empty?
|
88
88
|
entry = zis.get_next_entry # longBinary.bin
|
89
89
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
|
90
|
-
assert zis.gets.
|
90
|
+
assert !zis.gets.empty?
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -97,7 +97,7 @@ class ZipInputStreamTest < MiniTest::Test
|
|
97
97
|
entry = zis.get_next_entry # longAscii.txt
|
98
98
|
assert_equal(false, zis.eof?)
|
99
99
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
|
100
|
-
assert zis.gets.
|
100
|
+
assert !zis.gets.empty?
|
101
101
|
assert_equal(false, zis.eof?)
|
102
102
|
entry = zis.get_next_entry # empty.txt
|
103
103
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
|
@@ -111,10 +111,10 @@ class ZipInputStreamTest < MiniTest::Test
|
|
111
111
|
assert_equal(true, zis.eof?)
|
112
112
|
entry = zis.get_next_entry # short.txt
|
113
113
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
|
114
|
-
assert zis.gets.
|
114
|
+
assert !zis.gets.empty?
|
115
115
|
entry = zis.get_next_entry # longBinary.bin
|
116
116
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
|
117
|
-
assert zis.gets.
|
117
|
+
assert !zis.gets.empty?
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
@@ -92,11 +92,11 @@ class AbstractOutputStreamTest < MiniTest::Test
|
|
92
92
|
assert_equal("hello\nworld\n", @output_stream.buffer)
|
93
93
|
|
94
94
|
@output_stream.buffer = ''
|
95
|
-
@output_stream.puts([
|
95
|
+
@output_stream.puts(%W[hello\n world\n])
|
96
96
|
assert_equal("hello\nworld\n", @output_stream.buffer)
|
97
97
|
|
98
98
|
@output_stream.buffer = ''
|
99
|
-
@output_stream.puts([
|
99
|
+
@output_stream.puts(%W[hello\n world\n], 'bingo')
|
100
100
|
assert_equal("hello\nworld\nbingo\n", @output_stream.buffer)
|
101
101
|
|
102
102
|
@output_stream.buffer = ''
|