rubyzip 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -8
  3. data/lib/zip.rb +1 -1
  4. data/lib/zip/version.rb +1 -1
  5. metadata +6 -154
  6. data/test/basic_zip_file_test.rb +0 -60
  7. data/test/case_sensitivity_test.rb +0 -69
  8. data/test/central_directory_entry_test.rb +0 -69
  9. data/test/central_directory_test.rb +0 -100
  10. data/test/crypto/null_encryption_test.rb +0 -57
  11. data/test/crypto/traditional_encryption_test.rb +0 -80
  12. data/test/data/WarnInvalidDate.zip +0 -0
  13. data/test/data/file1.txt +0 -46
  14. data/test/data/file1.txt.deflatedData +0 -0
  15. data/test/data/file2.txt +0 -1504
  16. data/test/data/globTest.zip +0 -0
  17. data/test/data/globTest/foo.txt +0 -0
  18. data/test/data/globTest/foo/bar/baz/foo.txt +0 -0
  19. data/test/data/globTest/food.txt +0 -0
  20. data/test/data/gpbit3stored.zip +0 -0
  21. data/test/data/mimetype +0 -1
  22. data/test/data/notzippedruby.rb +0 -7
  23. data/test/data/ntfs.zip +0 -0
  24. data/test/data/oddExtraField.zip +0 -0
  25. data/test/data/path_traversal/Makefile +0 -10
  26. data/test/data/path_traversal/jwilk/README.md +0 -5
  27. data/test/data/path_traversal/jwilk/absolute1.zip +0 -0
  28. data/test/data/path_traversal/jwilk/absolute2.zip +0 -0
  29. data/test/data/path_traversal/jwilk/dirsymlink.zip +0 -0
  30. data/test/data/path_traversal/jwilk/dirsymlink2a.zip +0 -0
  31. data/test/data/path_traversal/jwilk/dirsymlink2b.zip +0 -0
  32. data/test/data/path_traversal/jwilk/relative0.zip +0 -0
  33. data/test/data/path_traversal/jwilk/relative2.zip +0 -0
  34. data/test/data/path_traversal/jwilk/symlink.zip +0 -0
  35. data/test/data/path_traversal/relative1.zip +0 -0
  36. data/test/data/path_traversal/tilde.zip +0 -0
  37. data/test/data/path_traversal/tuzovakaoff/README.md +0 -3
  38. data/test/data/path_traversal/tuzovakaoff/absolutepath.zip +0 -0
  39. data/test/data/path_traversal/tuzovakaoff/symlink.zip +0 -0
  40. data/test/data/rubycode.zip +0 -0
  41. data/test/data/rubycode2.zip +0 -0
  42. data/test/data/test.xls +0 -0
  43. data/test/data/testDirectory.bin +0 -0
  44. data/test/data/zip64-sample.zip +0 -0
  45. data/test/data/zipWithDirs.zip +0 -0
  46. data/test/data/zipWithEncryption.zip +0 -0
  47. data/test/deflater_test.rb +0 -65
  48. data/test/encryption_test.rb +0 -42
  49. data/test/entry_set_test.rb +0 -163
  50. data/test/entry_test.rb +0 -154
  51. data/test/errors_test.rb +0 -35
  52. data/test/extra_field_test.rb +0 -76
  53. data/test/file_extract_directory_test.rb +0 -54
  54. data/test/file_extract_test.rb +0 -145
  55. data/test/file_permissions_test.rb +0 -65
  56. data/test/file_split_test.rb +0 -57
  57. data/test/file_test.rb +0 -666
  58. data/test/filesystem/dir_iterator_test.rb +0 -58
  59. data/test/filesystem/directory_test.rb +0 -139
  60. data/test/filesystem/file_mutating_test.rb +0 -87
  61. data/test/filesystem/file_nonmutating_test.rb +0 -508
  62. data/test/filesystem/file_stat_test.rb +0 -64
  63. data/test/gentestfiles.rb +0 -126
  64. data/test/inflater_test.rb +0 -14
  65. data/test/input_stream_test.rb +0 -182
  66. data/test/ioextras/abstract_input_stream_test.rb +0 -102
  67. data/test/ioextras/abstract_output_stream_test.rb +0 -106
  68. data/test/ioextras/fake_io_test.rb +0 -18
  69. data/test/local_entry_test.rb +0 -154
  70. data/test/output_stream_test.rb +0 -128
  71. data/test/pass_thru_compressor_test.rb +0 -30
  72. data/test/pass_thru_decompressor_test.rb +0 -14
  73. data/test/path_traversal_test.rb +0 -141
  74. data/test/samples/example_recursive_test.rb +0 -37
  75. data/test/settings_test.rb +0 -95
  76. data/test/test_helper.rb +0 -234
  77. data/test/unicode_file_names_and_comments_test.rb +0 -62
  78. data/test/zip64_full_test.rb +0 -51
  79. data/test/zip64_support_test.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7861f60d52fbe54891831d9239df3e3e927a33f1f2d00abcb7b2693a8c01097d
4
- data.tar.gz: c04844369dbc75f40583f3d8aab34cbf2cfcce293b3c30570fa76208755a3157
3
+ metadata.gz: 4e2be8aa3dea85f1e99fa26b5b2530ede874228f35379181d5219eb3864a0e33
4
+ data.tar.gz: '0985b8cd0b421a0bdf83953ba907ddad52d236948a81a242f322f0f5fa2145a6'
5
5
  SHA512:
6
- metadata.gz: f9fa8a9f92c4789f06a1691eee6201918a753f1356eb6f2ef99fe9c777d46d661b7a8f96ce71b7a18406a4e1a4098f81b8a282babe2a7284ae0c8c04d03cf758
7
- data.tar.gz: e4650b6f572ef4bcdb33cff4bd0c7ddbd399b04278bd644d11ea29defe057510706d15d0b8ac918df28280d13f4bdfec28526aaad258ff52136ce209f29a35dd
6
+ metadata.gz: c870bef8352ddb4e706a847f66da596fe556938d1b1422c3541f8ab24aa10bbdb6be577cd031853459101e24a4290aa816436834d1cae66dd26238b451f41d15
7
+ data.tar.gz: bb5c8ca7d286346bfad64a6e1bd637cb8a40a99974bc62fbd76ea1a5ee139d16dcf52a8480cc219e48e311d84046feafab2c497cfbeb0721940a06a5c7a163a2
data/README.md CHANGED
@@ -20,7 +20,7 @@ gem 'zip-zip' # will load compatibility for old rubyzip API.
20
20
 
21
21
  ## Requirements
22
22
 
23
- - Ruby 1.9.2 or greater
23
+ - Ruby 2.4 or greater (for rubyzip 2.0; use 1.x for older rubies)
24
24
 
25
25
  ## Installation
26
26
 
@@ -265,13 +265,7 @@ Zip.warn_invalid_date = false
265
265
 
266
266
  ### Size Validation
267
267
 
268
- **This setting defaults to `false` in rubyzip 1.3 for backward compatibility, but it will default to `true` in rubyzip 2.0.**
269
-
270
- If you set
271
- ```
272
- Zip.validate_entry_sizes = true
273
- ```
274
- then `rubyzip`'s `extract` method checks that an entry's reported uncompressed size is not (significantly) smaller than its actual size. This is to help you protect your application against [zip bombs](https://en.wikipedia.org/wiki/Zip_bomb). Before `extract`ing an entry, you should check that its size is in the range you expect. For example, if your application supports processing up to 100 files at once, each up to 10MiB, your zip extraction code might look like:
268
+ By default (in rubyzip >= 2.0), rubyzip's `extract` method checks that an entry's reported uncompressed size is not (significantly) smaller than its actual size. This is to help you protect your application against [zip bombs](https://en.wikipedia.org/wiki/Zip_bomb). Before `extract`ing an entry, you should check that its size is in the range you expect. For example, if your application supports processing up to 100 files at once, each up to 10MiB, your zip extraction code might look like:
275
269
 
276
270
  ```ruby
277
271
  MAX_FILE_SIZE = 10 * 1024**2 # 10MiB
data/lib/zip.rb CHANGED
@@ -55,7 +55,7 @@ module Zip
55
55
  @write_zip64_support = false
56
56
  @warn_invalid_date = true
57
57
  @case_insensitive_match = false
58
- @validate_entry_sizes = false
58
+ @validate_entry_sizes = true
59
59
  end
60
60
 
61
61
  def setup
@@ -1,3 +1,3 @@
1
1
  module Zip
2
- VERSION = '1.3.0'
2
+ VERSION = '2.0.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyzip
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Simonov
@@ -134,88 +134,14 @@ files:
134
134
  - samples/qtzip.rb
135
135
  - samples/write_simple.rb
136
136
  - samples/zipfind.rb
137
- - test/basic_zip_file_test.rb
138
- - test/case_sensitivity_test.rb
139
- - test/central_directory_entry_test.rb
140
- - test/central_directory_test.rb
141
- - test/crypto/null_encryption_test.rb
142
- - test/crypto/traditional_encryption_test.rb
143
- - test/data/WarnInvalidDate.zip
144
- - test/data/file1.txt
145
- - test/data/file1.txt.deflatedData
146
- - test/data/file2.txt
147
- - test/data/globTest.zip
148
- - test/data/globTest/foo.txt
149
- - test/data/globTest/foo/bar/baz/foo.txt
150
- - test/data/globTest/food.txt
151
- - test/data/gpbit3stored.zip
152
- - test/data/mimetype
153
- - test/data/notzippedruby.rb
154
- - test/data/ntfs.zip
155
- - test/data/oddExtraField.zip
156
- - test/data/path_traversal/Makefile
157
- - test/data/path_traversal/jwilk/README.md
158
- - test/data/path_traversal/jwilk/absolute1.zip
159
- - test/data/path_traversal/jwilk/absolute2.zip
160
- - test/data/path_traversal/jwilk/dirsymlink.zip
161
- - test/data/path_traversal/jwilk/dirsymlink2a.zip
162
- - test/data/path_traversal/jwilk/dirsymlink2b.zip
163
- - test/data/path_traversal/jwilk/relative0.zip
164
- - test/data/path_traversal/jwilk/relative2.zip
165
- - test/data/path_traversal/jwilk/symlink.zip
166
- - test/data/path_traversal/relative1.zip
167
- - test/data/path_traversal/tilde.zip
168
- - test/data/path_traversal/tuzovakaoff/README.md
169
- - test/data/path_traversal/tuzovakaoff/absolutepath.zip
170
- - test/data/path_traversal/tuzovakaoff/symlink.zip
171
- - test/data/rubycode.zip
172
- - test/data/rubycode2.zip
173
- - test/data/test.xls
174
- - test/data/testDirectory.bin
175
- - test/data/zip64-sample.zip
176
- - test/data/zipWithDirs.zip
177
- - test/data/zipWithEncryption.zip
178
- - test/deflater_test.rb
179
- - test/encryption_test.rb
180
- - test/entry_set_test.rb
181
- - test/entry_test.rb
182
- - test/errors_test.rb
183
- - test/extra_field_test.rb
184
- - test/file_extract_directory_test.rb
185
- - test/file_extract_test.rb
186
- - test/file_permissions_test.rb
187
- - test/file_split_test.rb
188
- - test/file_test.rb
189
- - test/filesystem/dir_iterator_test.rb
190
- - test/filesystem/directory_test.rb
191
- - test/filesystem/file_mutating_test.rb
192
- - test/filesystem/file_nonmutating_test.rb
193
- - test/filesystem/file_stat_test.rb
194
- - test/gentestfiles.rb
195
- - test/inflater_test.rb
196
- - test/input_stream_test.rb
197
- - test/ioextras/abstract_input_stream_test.rb
198
- - test/ioextras/abstract_output_stream_test.rb
199
- - test/ioextras/fake_io_test.rb
200
- - test/local_entry_test.rb
201
- - test/output_stream_test.rb
202
- - test/pass_thru_compressor_test.rb
203
- - test/pass_thru_decompressor_test.rb
204
- - test/path_traversal_test.rb
205
- - test/samples/example_recursive_test.rb
206
- - test/settings_test.rb
207
- - test/test_helper.rb
208
- - test/unicode_file_names_and_comments_test.rb
209
- - test/zip64_full_test.rb
210
- - test/zip64_support_test.rb
211
137
  homepage: http://github.com/rubyzip/rubyzip
212
138
  licenses:
213
139
  - BSD 2-Clause
214
140
  metadata:
215
141
  bug_tracker_uri: https://github.com/rubyzip/rubyzip/issues
216
- changelog_uri: https://github.com/rubyzip/rubyzip/blob/v1.3.0/Changelog.md
217
- documentation_uri: https://www.rubydoc.info/gems/rubyzip/1.3.0
218
- source_code_uri: https://github.com/rubyzip/rubyzip/tree/v1.3.0
142
+ changelog_uri: https://github.com/rubyzip/rubyzip/blob/v2.0.0/Changelog.md
143
+ documentation_uri: https://www.rubydoc.info/gems/rubyzip/2.0.0
144
+ source_code_uri: https://github.com/rubyzip/rubyzip/tree/v2.0.0
219
145
  wiki_uri: https://github.com/rubyzip/rubyzip/wiki
220
146
  post_install_message:
221
147
  rdoc_options: []
@@ -225,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
151
  requirements:
226
152
  - - ">="
227
153
  - !ruby/object:Gem::Version
228
- version: 1.9.2
154
+ version: '2.4'
229
155
  required_rubygems_version: !ruby/object:Gem::Requirement
230
156
  requirements:
231
157
  - - ">="
@@ -236,78 +162,4 @@ rubygems_version: 3.0.3
236
162
  signing_key:
237
163
  specification_version: 4
238
164
  summary: rubyzip is a ruby module for reading and writing zip files
239
- test_files:
240
- - test/file_permissions_test.rb
241
- - test/path_traversal_test.rb
242
- - test/ioextras/abstract_input_stream_test.rb
243
- - test/ioextras/fake_io_test.rb
244
- - test/ioextras/abstract_output_stream_test.rb
245
- - test/central_directory_test.rb
246
- - test/central_directory_entry_test.rb
247
- - test/crypto/traditional_encryption_test.rb
248
- - test/crypto/null_encryption_test.rb
249
- - test/input_stream_test.rb
250
- - test/file_extract_directory_test.rb
251
- - test/basic_zip_file_test.rb
252
- - test/inflater_test.rb
253
- - test/file_extract_test.rb
254
- - test/pass_thru_compressor_test.rb
255
- - test/filesystem/file_nonmutating_test.rb
256
- - test/filesystem/file_stat_test.rb
257
- - test/filesystem/file_mutating_test.rb
258
- - test/filesystem/dir_iterator_test.rb
259
- - test/filesystem/directory_test.rb
260
- - test/extra_field_test.rb
261
- - test/zip64_support_test.rb
262
- - test/local_entry_test.rb
263
- - test/samples/example_recursive_test.rb
264
- - test/entry_test.rb
265
- - test/case_sensitivity_test.rb
266
- - test/zip64_full_test.rb
267
- - test/pass_thru_decompressor_test.rb
268
- - test/settings_test.rb
269
- - test/gentestfiles.rb
270
- - test/encryption_test.rb
271
- - test/file_test.rb
272
- - test/deflater_test.rb
273
- - test/test_helper.rb
274
- - test/errors_test.rb
275
- - test/file_split_test.rb
276
- - test/data/file2.txt
277
- - test/data/testDirectory.bin
278
- - test/data/globTest/foo.txt
279
- - test/data/globTest/foo/bar/baz/foo.txt
280
- - test/data/globTest/food.txt
281
- - test/data/file1.txt
282
- - test/data/rubycode.zip
283
- - test/data/WarnInvalidDate.zip
284
- - test/data/zipWithDirs.zip
285
- - test/data/rubycode2.zip
286
- - test/data/mimetype
287
- - test/data/zipWithEncryption.zip
288
- - test/data/path_traversal/tilde.zip
289
- - test/data/path_traversal/Makefile
290
- - test/data/path_traversal/relative1.zip
291
- - test/data/path_traversal/jwilk/dirsymlink.zip
292
- - test/data/path_traversal/jwilk/symlink.zip
293
- - test/data/path_traversal/jwilk/README.md
294
- - test/data/path_traversal/jwilk/relative2.zip
295
- - test/data/path_traversal/jwilk/relative0.zip
296
- - test/data/path_traversal/jwilk/absolute2.zip
297
- - test/data/path_traversal/jwilk/dirsymlink2b.zip
298
- - test/data/path_traversal/jwilk/absolute1.zip
299
- - test/data/path_traversal/jwilk/dirsymlink2a.zip
300
- - test/data/path_traversal/tuzovakaoff/symlink.zip
301
- - test/data/path_traversal/tuzovakaoff/README.md
302
- - test/data/path_traversal/tuzovakaoff/absolutepath.zip
303
- - test/data/oddExtraField.zip
304
- - test/data/gpbit3stored.zip
305
- - test/data/ntfs.zip
306
- - test/data/notzippedruby.rb
307
- - test/data/globTest.zip
308
- - test/data/file1.txt.deflatedData
309
- - test/data/test.xls
310
- - test/data/zip64-sample.zip
311
- - test/unicode_file_names_and_comments_test.rb
312
- - test/entry_set_test.rb
313
- - test/output_stream_test.rb
165
+ test_files: []
@@ -1,60 +0,0 @@
1
- require 'test_helper'
2
-
3
- class BasicZipFileTest < MiniTest::Test
4
- include AssertEntry
5
-
6
- def setup
7
- @zip_file = ::Zip::File.new(TestZipFile::TEST_ZIP2.zip_name)
8
- @testEntryNameIndex = 0
9
- end
10
-
11
- def test_entries
12
- assert_equal(TestZipFile::TEST_ZIP2.entry_names.sort,
13
- @zip_file.entries.entries.sort.map { |e| e.name })
14
- end
15
-
16
- def test_each
17
- count = 0
18
- visited = {}
19
- @zip_file.each do |entry|
20
- assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
21
- assert(!visited.include?(entry.name))
22
- visited[entry.name] = nil
23
- count = count.succ
24
- end
25
- assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
26
- end
27
-
28
- def test_foreach
29
- count = 0
30
- visited = {}
31
- ::Zip::File.foreach(TestZipFile::TEST_ZIP2.zip_name) do |entry|
32
- assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
33
- assert(!visited.include?(entry.name))
34
- visited[entry.name] = nil
35
- count = count.succ
36
- end
37
- assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
38
- end
39
-
40
- def test_get_input_stream
41
- count = 0
42
- visited = {}
43
- @zip_file.each do |entry|
44
- assert_entry(entry.name, @zip_file.get_input_stream(entry), entry.name)
45
- assert(!visited.include?(entry.name))
46
- visited[entry.name] = nil
47
- count = count.succ
48
- end
49
- assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
50
- end
51
-
52
- def test_get_input_stream_block
53
- fileAndEntryName = @zip_file.entries.first.name
54
- @zip_file.get_input_stream(fileAndEntryName) do |zis|
55
- assert_entry_contents_for_stream(fileAndEntryName,
56
- zis,
57
- fileAndEntryName)
58
- end
59
- end
60
- end
@@ -1,69 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ZipCaseSensitivityTest < MiniTest::Test
4
- include CommonZipFileFixture
5
-
6
- SRC_FILES = [['test/data/file1.txt', 'testfile.rb'],
7
- ['test/data/file2.txt', 'testFILE.rb']]
8
-
9
- def teardown
10
- ::Zip.case_insensitive_match = false
11
- end
12
-
13
- # Ensure that everything functions normally when +case_insensitive_match = false+
14
- def test_add_case_sensitive
15
- ::Zip.case_insensitive_match = false
16
-
17
- SRC_FILES.each { |fn, _en| assert(::File.exist?(fn)) }
18
- zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
19
-
20
- SRC_FILES.each { |fn, en| zf.add(en, fn) }
21
- zf.close
22
-
23
- zfRead = ::Zip::File.new(EMPTY_FILENAME)
24
- assert_equal(SRC_FILES.size, zfRead.entries.length)
25
- SRC_FILES.each_with_index { |a, i|
26
- assert_equal(a.last, zfRead.entries[i].name)
27
- AssertEntry.assert_contents(a.first,
28
- zfRead.get_input_stream(a.last) { |zis| zis.read })
29
- }
30
- end
31
-
32
- # Ensure that names are treated case insensitively when adding files and +case_insensitive_match = false+
33
- def test_add_case_insensitive
34
- ::Zip.case_insensitive_match = true
35
-
36
- SRC_FILES.each { |fn, _en| assert(::File.exist?(fn)) }
37
- zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
38
-
39
- assert_raises Zip::EntryExistsError do
40
- SRC_FILES.each { |fn, en| zf.add(en, fn) }
41
- end
42
- end
43
-
44
- # Ensure that names are treated case insensitively when reading files and +case_insensitive_match = true+
45
- def test_add_case_sensitive_read_case_insensitive
46
- ::Zip.case_insensitive_match = false
47
-
48
- SRC_FILES.each { |fn, _en| assert(::File.exist?(fn)) }
49
- zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
50
-
51
- SRC_FILES.each { |fn, en| zf.add(en, fn) }
52
- zf.close
53
-
54
- ::Zip.case_insensitive_match = true
55
-
56
- zfRead = ::Zip::File.new(EMPTY_FILENAME)
57
- assert_equal(SRC_FILES.collect { |_fn, en| en.downcase }.uniq.size, zfRead.entries.length)
58
- assert_equal(SRC_FILES.last.last.downcase, zfRead.entries.first.name.downcase)
59
- AssertEntry.assert_contents(SRC_FILES.last.first,
60
- zfRead.get_input_stream(SRC_FILES.last.last) { |zis| zis.read })
61
- end
62
-
63
- private
64
-
65
- def assert_contains(zf, entryName, filename = entryName)
66
- assert(zf.entries.detect { |e| e.name == entryName } != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}")
67
- assert_entry_contents(zf, entryName, filename) if File.exist?(filename)
68
- end
69
- end
@@ -1,69 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ZipCentralDirectoryEntryTest < MiniTest::Test
4
- def test_read_from_stream
5
- File.open('test/data/testDirectory.bin', 'rb') do |file|
6
- entry = ::Zip::Entry.read_c_dir_entry(file)
7
-
8
- assert_equal('longAscii.txt', entry.name)
9
- assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
10
- assert_equal(106_490, entry.size)
11
- assert_equal(3784, entry.compressed_size)
12
- assert_equal(0xfcd1799c, entry.crc)
13
- assert_equal('', entry.comment)
14
-
15
- entry = ::Zip::Entry.read_c_dir_entry(file)
16
- assert_equal('empty.txt', entry.name)
17
- assert_equal(::Zip::Entry::STORED, entry.compression_method)
18
- assert_equal(0, entry.size)
19
- assert_equal(0, entry.compressed_size)
20
- assert_equal(0x0, entry.crc)
21
- assert_equal('', entry.comment)
22
-
23
- entry = ::Zip::Entry.read_c_dir_entry(file)
24
- assert_equal('short.txt', entry.name)
25
- assert_equal(::Zip::Entry::STORED, entry.compression_method)
26
- assert_equal(6, entry.size)
27
- assert_equal(6, entry.compressed_size)
28
- assert_equal(0xbb76fe69, entry.crc)
29
- assert_equal('', entry.comment)
30
-
31
- entry = ::Zip::Entry.read_c_dir_entry(file)
32
- assert_equal('longBinary.bin', entry.name)
33
- assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
34
- assert_equal(1_000_024, entry.size)
35
- assert_equal(70_847, entry.compressed_size)
36
- assert_equal(0x10da7d59, entry.crc)
37
- assert_equal('', entry.comment)
38
-
39
- entry = ::Zip::Entry.read_c_dir_entry(file)
40
- assert_nil(entry)
41
- # Fields that are not check by this test:
42
- # version made by 2 bytes
43
- # version needed to extract 2 bytes
44
- # general purpose bit flag 2 bytes
45
- # last mod file time 2 bytes
46
- # last mod file date 2 bytes
47
- # compressed size 4 bytes
48
- # uncompressed size 4 bytes
49
- # disk number start 2 bytes
50
- # internal file attributes 2 bytes
51
- # external file attributes 4 bytes
52
- # relative offset of local header 4 bytes
53
-
54
- # file name (variable size)
55
- # extra field (variable size)
56
- # file comment (variable size)
57
- end
58
- end
59
-
60
- def test_read_entry_from_truncated_zip_file
61
- fragment = ''
62
- File.open('test/data/testDirectory.bin') { |f| fragment = f.read(12) } # cdir entry header is at least 46 bytes
63
- fragment.extend(IOizeString)
64
- entry = ::Zip::Entry.new
65
- entry.read_c_dir_entry(fragment)
66
- fail 'ZipError expected'
67
- rescue ::Zip::Error
68
- end
69
- end
@@ -1,100 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ZipCentralDirectoryTest < MiniTest::Test
4
- def teardown
5
- ::Zip.reset!
6
- end
7
-
8
- def test_read_from_stream
9
- ::File.open(TestZipFile::TEST_ZIP2.zip_name, 'rb') do |zipFile|
10
- cdir = ::Zip::CentralDirectory.read_from_stream(zipFile)
11
-
12
- assert_equal(TestZipFile::TEST_ZIP2.entry_names.size, cdir.size)
13
- assert(cdir.entries.sort.compare_enumerables(TestZipFile::TEST_ZIP2.entry_names.sort) do |cdirEntry, testEntryName|
14
- cdirEntry.name == testEntryName
15
- end)
16
- assert_equal(TestZipFile::TEST_ZIP2.comment, cdir.comment)
17
- end
18
- end
19
-
20
- def test_read_from_invalid_stream
21
- File.open('test/data/file2.txt', 'rb') do |zipFile|
22
- cdir = ::Zip::CentralDirectory.new
23
- cdir.read_from_stream(zipFile)
24
- end
25
- fail 'ZipError expected!'
26
- rescue ::Zip::Error
27
- end
28
-
29
- def test_read_from_truncated_zip_file
30
- fragment = ''
31
- File.open('test/data/testDirectory.bin', 'rb') { |f| fragment = f.read }
32
- fragment.slice!(12) # removed part of first cdir entry. eocd structure still complete
33
- fragment.extend(IOizeString)
34
- entry = ::Zip::CentralDirectory.new
35
- entry.read_from_stream(fragment)
36
- fail 'ZipError expected'
37
- rescue ::Zip::Error
38
- end
39
-
40
- def test_write_to_stream
41
- entries = [::Zip::Entry.new('file.zip', 'flimse', 'myComment', 'somethingExtra'),
42
- ::Zip::Entry.new('file.zip', 'secondEntryName'),
43
- ::Zip::Entry.new('file.zip', 'lastEntry.txt', 'Has a comment too')]
44
- cdir = ::Zip::CentralDirectory.new(entries, 'my zip comment')
45
- File.open('test/data/generated/cdirtest.bin', 'wb') { |f| cdir.write_to_stream(f) }
46
- cdirReadback = ::Zip::CentralDirectory.new
47
- File.open('test/data/generated/cdirtest.bin', 'rb') { |f| cdirReadback.read_from_stream(f) }
48
-
49
- assert_equal(cdir.entries.sort, cdirReadback.entries.sort)
50
- end
51
-
52
- def test_write64_to_stream
53
- ::Zip.write_zip64_support = true
54
- entries = [::Zip::Entry.new('file.zip', 'file1-little', 'comment1', '', 200, 101, ::Zip::Entry::STORED, 200),
55
- ::Zip::Entry.new('file.zip', 'file2-big', 'comment2', '', 18_000_000_000, 102, ::Zip::Entry::DEFLATED, 20_000_000_000),
56
- ::Zip::Entry.new('file.zip', 'file3-alsobig', 'comment3', '', 15_000_000_000, 103, ::Zip::Entry::DEFLATED, 21_000_000_000),
57
- ::Zip::Entry.new('file.zip', 'file4-little', 'comment4', '', 100, 104, ::Zip::Entry::DEFLATED, 121)]
58
- [0, 250, 18_000_000_300, 33_000_000_350].each_with_index do |offset, index|
59
- entries[index].local_header_offset = offset
60
- end
61
- cdir = ::Zip::CentralDirectory.new(entries, 'zip comment')
62
- File.open('test/data/generated/cdir64test.bin', 'wb') { |f| cdir.write_to_stream(f) }
63
- cdirReadback = ::Zip::CentralDirectory.new
64
- File.open('test/data/generated/cdir64test.bin', 'rb') { |f| cdirReadback.read_from_stream(f) }
65
-
66
- assert_equal(cdir.entries.sort, cdirReadback.entries.sort)
67
- assert_equal(::Zip::VERSION_NEEDED_TO_EXTRACT_ZIP64, cdirReadback.instance_variable_get(:@version_needed_for_extract))
68
- end
69
-
70
- def test_equality
71
- cdir1 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
72
- 'somethingExtra'),
73
- ::Zip::Entry.new('file.zip', 'secondEntryName'),
74
- ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
75
- 'my zip comment')
76
- cdir2 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
77
- 'somethingExtra'),
78
- ::Zip::Entry.new('file.zip', 'secondEntryName'),
79
- ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
80
- 'my zip comment')
81
- cdir3 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
82
- 'somethingExtra'),
83
- ::Zip::Entry.new('file.zip', 'secondEntryName'),
84
- ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
85
- 'comment?')
86
- cdir4 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
87
- 'somethingExtra'),
88
- ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
89
- 'comment?')
90
- assert_equal(cdir1, cdir1)
91
- assert_equal(cdir1, cdir2)
92
-
93
- assert(cdir1 != cdir3)
94
- assert(cdir2 != cdir3)
95
- assert(cdir2 != cdir3)
96
- assert(cdir3 != cdir4)
97
-
98
- assert(cdir3 != 'hello')
99
- end
100
- end