rubyzip 1.1.7 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubyzip might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +75 -40
- data/Rakefile +3 -4
- data/lib/zip.rb +3 -5
- data/lib/zip/central_directory.rb +7 -7
- data/lib/zip/compressor.rb +0 -0
- data/lib/zip/constants.rb +2 -2
- data/lib/zip/crypto/null_encryption.rb +3 -3
- data/lib/zip/crypto/traditional_encryption.rb +5 -5
- data/lib/zip/decompressor.rb +2 -2
- data/lib/zip/deflater.rb +8 -6
- data/lib/zip/dos_time.rb +4 -5
- data/lib/zip/entry.rb +75 -81
- data/lib/zip/entry_set.rb +11 -11
- data/lib/zip/errors.rb +1 -0
- data/lib/zip/extra_field.rb +6 -6
- data/lib/zip/extra_field/generic.rb +7 -7
- data/lib/zip/extra_field/ntfs.rb +14 -16
- data/lib/zip/extra_field/old_unix.rb +9 -10
- data/lib/zip/extra_field/universal_time.rb +14 -14
- data/lib/zip/extra_field/unix.rb +8 -9
- data/lib/zip/extra_field/zip64.rb +12 -11
- data/lib/zip/extra_field/zip64_placeholder.rb +1 -1
- data/lib/zip/file.rb +47 -60
- data/lib/zip/filesystem.rb +132 -135
- data/lib/zip/inflater.rb +3 -3
- data/lib/zip/input_stream.rb +13 -7
- data/lib/zip/ioextras.rb +1 -3
- data/lib/zip/ioextras/abstract_input_stream.rb +5 -9
- data/lib/zip/ioextras/abstract_output_stream.rb +2 -4
- data/lib/zip/null_compressor.rb +2 -2
- data/lib/zip/null_decompressor.rb +3 -3
- data/lib/zip/null_input_stream.rb +0 -0
- data/lib/zip/output_stream.rb +8 -9
- data/lib/zip/pass_thru_compressor.rb +4 -4
- data/lib/zip/pass_thru_decompressor.rb +2 -3
- data/lib/zip/streamable_directory.rb +2 -2
- data/lib/zip/streamable_stream.rb +2 -2
- data/lib/zip/version.rb +1 -1
- data/samples/example.rb +29 -39
- data/samples/example_filesystem.rb +16 -18
- data/samples/example_recursive.rb +32 -25
- data/samples/{gtkRubyzip.rb → gtk_ruby_zip.rb} +23 -25
- data/samples/qtzip.rb +17 -26
- data/samples/write_simple.rb +12 -13
- data/samples/zipfind.rb +24 -32
- data/test/basic_zip_file_test.rb +11 -15
- data/test/case_sensitivity_test.rb +69 -0
- data/test/central_directory_entry_test.rb +32 -36
- data/test/central_directory_test.rb +46 -50
- data/test/crypto/null_encryption_test.rb +8 -4
- data/test/crypto/traditional_encryption_test.rb +5 -5
- data/test/data/notzippedruby.rb +1 -1
- data/test/data/oddExtraField.zip +0 -0
- data/test/data/test.xls +0 -0
- data/test/deflater_test.rb +10 -12
- data/test/encryption_test.rb +2 -2
- data/test/entry_set_test.rb +50 -25
- data/test/entry_test.rb +76 -87
- data/test/errors_test.rb +0 -2
- data/test/extra_field_test.rb +19 -21
- data/test/file_extract_directory_test.rb +12 -14
- data/test/file_extract_test.rb +33 -40
- data/test/file_permissions_test.rb +69 -0
- data/test/file_split_test.rb +24 -27
- data/test/file_test.rb +196 -172
- data/test/filesystem/dir_iterator_test.rb +13 -17
- data/test/filesystem/directory_test.rb +80 -90
- data/test/filesystem/file_mutating_test.rb +51 -63
- data/test/filesystem/file_nonmutating_test.rb +222 -228
- data/test/filesystem/file_stat_test.rb +17 -19
- data/test/gentestfiles.rb +47 -55
- data/test/inflater_test.rb +1 -1
- data/test/input_stream_test.rb +46 -34
- data/test/ioextras/abstract_input_stream_test.rb +22 -23
- data/test/ioextras/abstract_output_stream_test.rb +32 -32
- data/test/ioextras/fake_io_test.rb +1 -1
- data/test/local_entry_test.rb +36 -38
- data/test/output_stream_test.rb +20 -21
- data/test/pass_thru_compressor_test.rb +5 -6
- data/test/pass_thru_decompressor_test.rb +0 -1
- data/test/samples/example_recursive_test.rb +37 -0
- data/test/settings_test.rb +18 -15
- data/test/test_helper.rb +50 -44
- data/test/unicode_file_names_and_comments_test.rb +5 -7
- data/test/zip64_full_test.rb +9 -11
- data/test/zip64_support_test.rb +0 -1
- metadata +14 -32
@@ -0,0 +1,69 @@
|
|
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,73 +1,69 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class ZipCentralDirectoryEntryTest < MiniTest::Test
|
4
|
-
|
5
4
|
def test_read_from_stream
|
6
|
-
File.open(
|
7
|
-
|file|
|
5
|
+
File.open('test/data/testDirectory.bin', 'rb') do |file|
|
8
6
|
entry = ::Zip::Entry.read_c_dir_entry(file)
|
9
7
|
|
10
|
-
assert_equal(
|
8
|
+
assert_equal('longAscii.txt', entry.name)
|
11
9
|
assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
|
12
|
-
assert_equal(
|
10
|
+
assert_equal(106_490, entry.size)
|
13
11
|
assert_equal(3784, entry.compressed_size)
|
14
12
|
assert_equal(0xfcd1799c, entry.crc)
|
15
|
-
assert_equal(
|
13
|
+
assert_equal('', entry.comment)
|
16
14
|
|
17
15
|
entry = ::Zip::Entry.read_c_dir_entry(file)
|
18
|
-
assert_equal(
|
16
|
+
assert_equal('empty.txt', entry.name)
|
19
17
|
assert_equal(::Zip::Entry::STORED, entry.compression_method)
|
20
18
|
assert_equal(0, entry.size)
|
21
19
|
assert_equal(0, entry.compressed_size)
|
22
20
|
assert_equal(0x0, entry.crc)
|
23
|
-
assert_equal(
|
21
|
+
assert_equal('', entry.comment)
|
24
22
|
|
25
23
|
entry = ::Zip::Entry.read_c_dir_entry(file)
|
26
|
-
assert_equal(
|
24
|
+
assert_equal('short.txt', entry.name)
|
27
25
|
assert_equal(::Zip::Entry::STORED, entry.compression_method)
|
28
26
|
assert_equal(6, entry.size)
|
29
27
|
assert_equal(6, entry.compressed_size)
|
30
28
|
assert_equal(0xbb76fe69, entry.crc)
|
31
|
-
assert_equal(
|
29
|
+
assert_equal('', entry.comment)
|
32
30
|
|
33
31
|
entry = ::Zip::Entry.read_c_dir_entry(file)
|
34
|
-
assert_equal(
|
32
|
+
assert_equal('longBinary.bin', entry.name)
|
35
33
|
assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
|
36
|
-
assert_equal(
|
37
|
-
assert_equal(
|
34
|
+
assert_equal(1_000_024, entry.size)
|
35
|
+
assert_equal(70_847, entry.compressed_size)
|
38
36
|
assert_equal(0x10da7d59, entry.crc)
|
39
37
|
assert_equal('', entry.comment)
|
40
38
|
|
41
39
|
entry = ::Zip::Entry.read_c_dir_entry(file)
|
42
|
-
|
43
|
-
# Fields that are not check by this test:
|
44
|
-
# version made by 2 bytes
|
45
|
-
# version needed to extract 2 bytes
|
46
|
-
# general purpose bit flag 2 bytes
|
47
|
-
# last mod file time 2 bytes
|
48
|
-
# last mod file date 2 bytes
|
49
|
-
# compressed size 4 bytes
|
50
|
-
# uncompressed size 4 bytes
|
51
|
-
# disk number start 2 bytes
|
52
|
-
# internal file attributes 2 bytes
|
53
|
-
# external file attributes 4 bytes
|
54
|
-
# relative offset of local header 4 bytes
|
55
|
-
|
56
|
-
# file name (variable size)
|
57
|
-
# extra field (variable size)
|
58
|
-
# file comment (variable size)
|
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
|
59
53
|
|
60
|
-
|
54
|
+
# file name (variable size)
|
55
|
+
# extra field (variable size)
|
56
|
+
# file comment (variable size)
|
57
|
+
end
|
61
58
|
end
|
62
59
|
|
63
|
-
def
|
64
|
-
fragment=
|
65
|
-
File.open(
|
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
|
66
63
|
fragment.extend(IOizeString)
|
67
64
|
entry = ::Zip::Entry.new
|
68
65
|
entry.read_c_dir_entry(fragment)
|
69
|
-
fail
|
66
|
+
fail 'ZipError expected'
|
70
67
|
rescue ::Zip::Error
|
71
68
|
end
|
72
|
-
|
73
69
|
end
|
@@ -1,96 +1,92 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class ZipCentralDirectoryTest < MiniTest::Test
|
4
|
-
|
5
4
|
def teardown
|
6
5
|
::Zip.reset!
|
7
6
|
end
|
8
7
|
|
9
8
|
def test_read_from_stream
|
10
|
-
::File.open(TestZipFile::TEST_ZIP2.zip_name,
|
11
|
-
|zipFile|
|
9
|
+
::File.open(TestZipFile::TEST_ZIP2.zip_name, 'rb') do |zipFile|
|
12
10
|
cdir = ::Zip::CentralDirectory.read_from_stream(zipFile)
|
13
11
|
|
14
12
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names.size, cdir.size)
|
15
|
-
assert(cdir.entries.sort.compare_enumerables(TestZipFile::TEST_ZIP2.entry_names.sort)
|
16
|
-
|cdirEntry, testEntryName|
|
13
|
+
assert(cdir.entries.sort.compare_enumerables(TestZipFile::TEST_ZIP2.entry_names.sort) do |cdirEntry, testEntryName|
|
17
14
|
cdirEntry.name == testEntryName
|
18
|
-
|
15
|
+
end)
|
19
16
|
assert_equal(TestZipFile::TEST_ZIP2.comment, cdir.comment)
|
20
|
-
|
17
|
+
end
|
21
18
|
end
|
22
19
|
|
23
|
-
def
|
24
|
-
File.open(
|
25
|
-
|zipFile|
|
20
|
+
def test_read_from_invalid_stream
|
21
|
+
File.open('test/data/file2.txt', 'rb') do |zipFile|
|
26
22
|
cdir = ::Zip::CentralDirectory.new
|
27
23
|
cdir.read_from_stream(zipFile)
|
28
|
-
|
29
|
-
fail
|
24
|
+
end
|
25
|
+
fail 'ZipError expected!'
|
30
26
|
rescue ::Zip::Error
|
31
27
|
end
|
32
28
|
|
33
|
-
def
|
34
|
-
fragment=
|
35
|
-
File.open(
|
29
|
+
def test_read_from_truncated_zip_file
|
30
|
+
fragment = ''
|
31
|
+
File.open('test/data/testDirectory.bin', 'rb') { |f| fragment = f.read }
|
36
32
|
fragment.slice!(12) # removed part of first cdir entry. eocd structure still complete
|
37
33
|
fragment.extend(IOizeString)
|
38
34
|
entry = ::Zip::CentralDirectory.new
|
39
35
|
entry.read_from_stream(fragment)
|
40
|
-
fail
|
36
|
+
fail 'ZipError expected'
|
41
37
|
rescue ::Zip::Error
|
42
38
|
end
|
43
39
|
|
44
40
|
def test_write_to_stream
|
45
|
-
entries = [::Zip::Entry.new(
|
46
|
-
::Zip::Entry.new(
|
47
|
-
::Zip::Entry.new(
|
48
|
-
cdir = ::Zip::CentralDirectory.new(entries,
|
49
|
-
File.open(
|
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) }
|
50
46
|
cdirReadback = ::Zip::CentralDirectory.new
|
51
|
-
File.open(
|
47
|
+
File.open('test/data/generated/cdirtest.bin', 'rb') { |f| cdirReadback.read_from_stream(f) }
|
52
48
|
|
53
49
|
assert_equal(cdir.entries.sort, cdirReadback.entries.sort)
|
54
50
|
end
|
55
51
|
|
56
52
|
def test_write64_to_stream
|
57
53
|
::Zip.write_zip64_support = true
|
58
|
-
entries = [::Zip::Entry.new(
|
59
|
-
::Zip::Entry.new(
|
60
|
-
::Zip::Entry.new(
|
61
|
-
::Zip::Entry.new(
|
62
|
-
[0, 250,
|
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|
|
63
59
|
entries[index].local_header_offset = offset
|
64
60
|
end
|
65
|
-
cdir = ::Zip::CentralDirectory.new(entries,
|
66
|
-
File.open(
|
61
|
+
cdir = ::Zip::CentralDirectory.new(entries, 'zip comment')
|
62
|
+
File.open('test/data/generated/cdir64test.bin', 'wb') { |f| cdir.write_to_stream(f) }
|
67
63
|
cdirReadback = ::Zip::CentralDirectory.new
|
68
|
-
File.open(
|
64
|
+
File.open('test/data/generated/cdir64test.bin', 'rb') { |f| cdirReadback.read_from_stream(f) }
|
69
65
|
|
70
66
|
assert_equal(cdir.entries.sort, cdirReadback.entries.sort)
|
71
67
|
assert_equal(::Zip::VERSION_NEEDED_TO_EXTRACT_ZIP64, cdirReadback.instance_variable_get(:@version_needed_for_extract))
|
72
68
|
end
|
73
69
|
|
74
70
|
def test_equality
|
75
|
-
cdir1 = ::Zip::CentralDirectory.new([::Zip::Entry.new(
|
76
|
-
|
77
|
-
::Zip::Entry.new(
|
78
|
-
::Zip::Entry.new(
|
79
|
-
|
80
|
-
cdir2 = ::Zip::CentralDirectory.new([::Zip::Entry.new(
|
81
|
-
|
82
|
-
::Zip::Entry.new(
|
83
|
-
::Zip::Entry.new(
|
84
|
-
|
85
|
-
cdir3 = ::Zip::CentralDirectory.new([::Zip::Entry.new(
|
86
|
-
|
87
|
-
::Zip::Entry.new(
|
88
|
-
::Zip::Entry.new(
|
89
|
-
|
90
|
-
cdir4 = ::Zip::CentralDirectory.new([::Zip::Entry.new(
|
91
|
-
|
92
|
-
::Zip::Entry.new(
|
93
|
-
|
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?')
|
94
90
|
assert_equal(cdir1, cdir1)
|
95
91
|
assert_equal(cdir1, cdir2)
|
96
92
|
|
@@ -99,6 +95,6 @@ class ZipCentralDirectoryTest < MiniTest::Test
|
|
99
95
|
assert(cdir2 != cdir3)
|
100
96
|
assert(cdir3 != cdir4)
|
101
97
|
|
102
|
-
assert(cdir3 !=
|
98
|
+
assert(cdir3 != 'hello')
|
103
99
|
end
|
104
100
|
end
|
@@ -4,7 +4,7 @@ class NullEncrypterTest < MiniTest::Test
|
|
4
4
|
def setup
|
5
5
|
@encrypter = ::Zip::NullEncrypter.new
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def test_header_bytesize
|
9
9
|
assert_equal 0, @encrypter.header_bytesize
|
10
10
|
end
|
@@ -18,7 +18,9 @@ class NullEncrypterTest < MiniTest::Test
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_encrypt
|
21
|
-
|
21
|
+
assert_nil @encrypter.encrypt(nil)
|
22
|
+
|
23
|
+
['', 'a' * 10, 0xffffffff].each do |data|
|
22
24
|
assert_equal data, @encrypter.encrypt(data)
|
23
25
|
end
|
24
26
|
end
|
@@ -32,7 +34,7 @@ class NullDecrypterTest < MiniTest::Test
|
|
32
34
|
def setup
|
33
35
|
@decrypter = ::Zip::NullDecrypter.new
|
34
36
|
end
|
35
|
-
|
37
|
+
|
36
38
|
def test_header_bytesize
|
37
39
|
assert_equal 0, @decrypter.header_bytesize
|
38
40
|
end
|
@@ -42,7 +44,9 @@ class NullDecrypterTest < MiniTest::Test
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def test_decrypt
|
45
|
-
|
47
|
+
assert_nil @decrypter.decrypt(nil)
|
48
|
+
|
49
|
+
['', 'a' * 10, 0xffffffff].each do |data|
|
46
50
|
assert_equal data, @decrypter.decrypt(data)
|
47
51
|
end
|
48
52
|
end
|
@@ -16,7 +16,7 @@ class TraditionalEncrypterTest < MiniTest::Test
|
|
16
16
|
|
17
17
|
def test_header
|
18
18
|
@encrypter.reset!
|
19
|
-
exepected = [239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack(
|
19
|
+
exepected = [239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*')
|
20
20
|
Random.stub(:rand, 1) do
|
21
21
|
assert_equal exepected, @encrypter.header(@mtime)
|
22
22
|
end
|
@@ -28,7 +28,7 @@ class TraditionalEncrypterTest < MiniTest::Test
|
|
28
28
|
assert_raises(NoMethodError) { @encrypter.encrypt(nil) }
|
29
29
|
assert_raises(NoMethodError) { @encrypter.encrypt(1) }
|
30
30
|
assert_equal '', @encrypter.encrypt('')
|
31
|
-
assert_equal [100, 218, 7, 114, 226, 82, 62, 93, 224, 62].pack(
|
31
|
+
assert_equal [100, 218, 7, 114, 226, 82, 62, 93, 224, 62].pack('C*'), @encrypter.encrypt('a' * 10)
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_reset!
|
@@ -60,19 +60,19 @@ class TraditionalDecrypterTest < MiniTest::Test
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_decrypt
|
63
|
-
@decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack(
|
63
|
+
@decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*'))
|
64
64
|
[100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c|
|
65
65
|
assert_equal 'a', @decrypter.decrypt(c)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_reset!
|
70
|
-
@decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack(
|
70
|
+
@decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*'))
|
71
71
|
[100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c|
|
72
72
|
assert_equal 'a', @decrypter.decrypt(c)
|
73
73
|
end
|
74
74
|
assert_equal 91.chr, @decrypter.decrypt(2.chr)
|
75
|
-
@decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack(
|
75
|
+
@decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*'))
|
76
76
|
[100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c|
|
77
77
|
assert_equal 'a', @decrypter.decrypt(c)
|
78
78
|
end
|
data/test/data/notzippedruby.rb
CHANGED
Binary file
|
data/test/data/test.xls
ADDED
Binary file
|
data/test/deflater_test.rb
CHANGED
@@ -8,15 +8,15 @@ class DeflaterTest < MiniTest::Test
|
|
8
8
|
DEFAULT_COMP_FILE = 'test/data/generated/compressiontest_default_compression.bin'
|
9
9
|
NO_COMP_FILE = 'test/data/generated/compressiontest_no_compression.bin'
|
10
10
|
|
11
|
-
def
|
12
|
-
txt = load_file(
|
11
|
+
def test_output_operator
|
12
|
+
txt = load_file('test/data/file2.txt')
|
13
13
|
deflate(txt, DEFLATER_TEST_FILE)
|
14
14
|
inflatedTxt = inflate(DEFLATER_TEST_FILE)
|
15
15
|
assert_equal(txt, inflatedTxt)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_default_compression
|
19
|
-
txt = load_file(
|
19
|
+
txt = load_file('test/data/file2.txt')
|
20
20
|
|
21
21
|
Zip.default_compression = ::Zlib::BEST_COMPRESSION
|
22
22
|
deflate(txt, BEST_COMP_FILE)
|
@@ -34,31 +34,29 @@ class DeflaterTest < MiniTest::Test
|
|
34
34
|
assert(default < no)
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
37
|
private
|
38
|
+
|
39
39
|
def load_file(fileName)
|
40
40
|
txt = nil
|
41
|
-
File.open(fileName,
|
41
|
+
File.open(fileName, 'rb') { |f| txt = f.read }
|
42
42
|
end
|
43
43
|
|
44
44
|
def deflate(data, fileName)
|
45
|
-
File.open(fileName,
|
46
|
-
|file|
|
45
|
+
File.open(fileName, 'wb') do |file|
|
47
46
|
deflater = ::Zip::Deflater.new(file)
|
48
47
|
deflater << data
|
49
48
|
deflater.finish
|
50
49
|
assert_equal(deflater.size, data.size)
|
51
|
-
file <<
|
52
|
-
|
50
|
+
file << 'trailing data for zlib with -MAX_WBITS'
|
51
|
+
end
|
53
52
|
end
|
54
53
|
|
55
54
|
def inflate(fileName)
|
56
55
|
txt = nil
|
57
|
-
File.open(fileName,
|
58
|
-
|file|
|
56
|
+
File.open(fileName, 'rb') do |file|
|
59
57
|
inflater = ::Zip::Inflater.new(file)
|
60
58
|
txt = inflater.sysread
|
61
|
-
|
59
|
+
end
|
62
60
|
end
|
63
61
|
|
64
62
|
def test_crc
|