archive-zip 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/LICENSE +22 -57
- data/{NEWS → NEWS.md} +29 -16
- data/README.md +250 -0
- data/Rakefile +119 -76
- data/lib/archive/support/binary_stringio.rb +9 -2
- data/lib/archive/support/time.rb +2 -2
- data/lib/archive/zip.rb +1 -1
- data/lib/archive/zip/entry.rb +2 -2
- data/lib/archive/zip/version.rb +1 -1
- data/spec/archive/zip/archive_spec.rb +54 -0
- data/spec/archive/zip/codec/deflate/compress/checksum_spec.rb +8 -6
- data/spec/archive/zip/codec/deflate/compress/close_spec.rb +13 -12
- data/spec/archive/zip/codec/deflate/compress/crc32_spec.rb +6 -4
- data/spec/archive/zip/codec/deflate/compress/data_descriptor_spec.rb +17 -10
- data/spec/archive/zip/codec/deflate/compress/new_spec.rb +7 -5
- data/spec/archive/zip/codec/deflate/compress/open_spec.rb +9 -7
- data/spec/archive/zip/codec/deflate/compress/write_spec.rb +15 -15
- data/spec/archive/zip/codec/deflate/decompress/checksum_spec.rb +6 -4
- data/spec/archive/zip/codec/deflate/decompress/close_spec.rb +10 -9
- data/spec/archive/zip/codec/deflate/decompress/crc32_spec.rb +6 -4
- data/spec/archive/zip/codec/deflate/decompress/data_descriptor_spec.rb +17 -10
- data/spec/archive/zip/codec/deflate/decompress/new_spec.rb +5 -3
- data/spec/archive/zip/codec/deflate/decompress/open_spec.rb +7 -5
- data/spec/archive/zip/codec/null_encryption/decrypt/close_spec.rb +10 -9
- data/spec/archive/zip/codec/null_encryption/decrypt/new_spec.rb +6 -4
- data/spec/archive/zip/codec/null_encryption/decrypt/open_spec.rb +8 -6
- data/spec/archive/zip/codec/null_encryption/decrypt/read_spec.rb +8 -6
- data/spec/archive/zip/codec/null_encryption/decrypt/rewind_spec.rb +9 -7
- data/spec/archive/zip/codec/null_encryption/decrypt/seek_spec.rb +15 -13
- data/spec/archive/zip/codec/null_encryption/decrypt/tell_spec.rb +8 -6
- data/spec/archive/zip/codec/null_encryption/encrypt/close_spec.rb +10 -9
- data/spec/archive/zip/codec/null_encryption/encrypt/new_spec.rb +5 -3
- data/spec/archive/zip/codec/null_encryption/encrypt/open_spec.rb +9 -5
- data/spec/archive/zip/codec/null_encryption/encrypt/rewind_spec.rb +9 -7
- data/spec/archive/zip/codec/null_encryption/encrypt/seek_spec.rb +15 -13
- data/spec/archive/zip/codec/null_encryption/encrypt/tell_spec.rb +11 -9
- data/spec/archive/zip/codec/null_encryption/encrypt/write_spec.rb +12 -10
- data/spec/archive/zip/codec/store/compress/close_spec.rb +10 -9
- data/spec/archive/zip/codec/store/compress/data_descriptor_spec.rb +19 -10
- data/spec/archive/zip/codec/store/compress/new_spec.rb +5 -3
- data/spec/archive/zip/codec/store/compress/open_spec.rb +7 -5
- data/spec/archive/zip/codec/store/compress/rewind_spec.rb +9 -7
- data/spec/archive/zip/codec/store/compress/seek_spec.rb +15 -13
- data/spec/archive/zip/codec/store/compress/tell_spec.rb +11 -9
- data/spec/archive/zip/codec/store/compress/write_spec.rb +10 -10
- data/spec/archive/zip/codec/store/decompress/close_spec.rb +10 -9
- data/spec/archive/zip/codec/store/decompress/data_descriptor_spec.rb +17 -10
- data/spec/archive/zip/codec/store/decompress/new_spec.rb +5 -3
- data/spec/archive/zip/codec/store/decompress/open_spec.rb +7 -5
- data/spec/archive/zip/codec/store/decompress/read_spec.rb +8 -6
- data/spec/archive/zip/codec/store/decompress/rewind_spec.rb +9 -7
- data/spec/archive/zip/codec/store/decompress/seek_spec.rb +15 -13
- data/spec/archive/zip/codec/store/decompress/tell_spec.rb +8 -6
- data/spec/archive/zip/codec/traditional_encryption/decrypt/close_spec.rb +13 -24
- data/spec/archive/zip/codec/traditional_encryption/decrypt/new_spec.rb +6 -4
- data/spec/archive/zip/codec/traditional_encryption/decrypt/open_spec.rb +10 -6
- data/spec/archive/zip/codec/traditional_encryption/decrypt/read_spec.rb +12 -13
- data/spec/archive/zip/codec/traditional_encryption/decrypt/rewind_spec.rb +10 -12
- data/spec/archive/zip/codec/traditional_encryption/decrypt/seek_spec.rb +16 -18
- data/spec/archive/zip/codec/traditional_encryption/decrypt/tell_spec.rb +8 -6
- data/spec/archive/zip/codec/traditional_encryption/encrypt/close_spec.rb +13 -24
- data/spec/archive/zip/codec/traditional_encryption/encrypt/new_spec.rb +5 -3
- data/spec/archive/zip/codec/traditional_encryption/encrypt/open_spec.rb +7 -5
- data/spec/archive/zip/codec/traditional_encryption/encrypt/rewind_spec.rb +10 -12
- data/spec/archive/zip/codec/traditional_encryption/encrypt/seek_spec.rb +16 -18
- data/spec/archive/zip/codec/traditional_encryption/encrypt/tell_spec.rb +12 -14
- data/spec/archive/zip/codec/traditional_encryption/encrypt/write_spec.rb +8 -23
- data/spec/binary_stringio/new_spec.rb +18 -12
- data/spec/binary_stringio/set_encoding_spec.rb +10 -7
- data/spec/ioextensions/read_exactly_spec.rb +14 -12
- data/spec/zlib/zreader/checksum_spec.rb +10 -8
- data/spec/zlib/zreader/close_spec.rb +5 -3
- data/spec/zlib/zreader/compressed_size_spec.rb +6 -4
- data/spec/zlib/zreader/new_spec.rb +7 -5
- data/spec/zlib/zreader/open_spec.rb +9 -7
- data/spec/zlib/zreader/read_spec.rb +10 -8
- data/spec/zlib/zreader/rewind_spec.rb +7 -5
- data/spec/zlib/zreader/seek_spec.rb +13 -11
- data/spec/zlib/zreader/tell_spec.rb +8 -6
- data/spec/zlib/zreader/uncompressed_size_spec.rb +6 -4
- data/spec/zlib/zwriter/checksum_spec.rb +10 -8
- data/spec/zlib/zwriter/close_spec.rb +5 -3
- data/spec/zlib/zwriter/compressed_size_spec.rb +6 -4
- data/spec/zlib/zwriter/new_spec.rb +10 -8
- data/spec/zlib/zwriter/open_spec.rb +12 -10
- data/spec/zlib/zwriter/rewind_spec.rb +9 -7
- data/spec/zlib/zwriter/seek_spec.rb +15 -17
- data/spec/zlib/zwriter/tell_spec.rb +11 -9
- data/spec/zlib/zwriter/uncompressed_size_spec.rb +6 -4
- data/spec/zlib/zwriter/write_spec.rb +9 -9
- metadata +268 -217
- data/CONTRIBUTORS +0 -13
- data/GPL +0 -676
- data/HACKING +0 -105
- data/LEGAL +0 -8
- data/README +0 -151
- data/TODO +0 -5
- data/default.mspec +0 -8
- data/spec_helper.rb +0 -49
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/zip/codec/traditional_encryption'
|
6
8
|
|
7
9
|
describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt#rewind" do
|
@@ -13,26 +15,22 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt#rewind" do
|
|
13
15
|
TraditionalEncryptionSpecs.mtime
|
14
16
|
) do |d|
|
15
17
|
d.read(4)
|
16
|
-
|
17
|
-
d.read.
|
18
|
+
d.rewind
|
19
|
+
d.read.must_equal(TraditionalEncryptionSpecs.test_data)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
24
|
it "raises Errno::EINVAL when attempting to rewind the stream when the delegate does not respond to rewind" do
|
23
|
-
delegate =
|
24
|
-
|
25
|
-
|
26
|
-
#delegate.should_receive(:read).with(an_instance_of(Fixnum)).at_least(:once).and_return { |n| "\000" * n }
|
27
|
-
# Use the following instead for now.
|
28
|
-
delegate.should_receive(:read).once.and_return("\000" * 12)
|
29
|
-
delegate.should_receive(:close).and_return(nil)
|
25
|
+
delegate = MiniTest::Mock.new
|
26
|
+
delegate.expect(:read, "\000" * 12, [Integer])
|
27
|
+
delegate.expect(:close, nil)
|
30
28
|
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
31
29
|
delegate,
|
32
30
|
TraditionalEncryptionSpecs.password,
|
33
31
|
TraditionalEncryptionSpecs.mtime
|
34
32
|
) do |d|
|
35
|
-
lambda { d.rewind }.
|
33
|
+
lambda { d.rewind }.must_raise(Errno::EINVAL)
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/zip/codec/traditional_encryption'
|
6
8
|
|
7
9
|
describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt#seek" do
|
@@ -13,25 +15,21 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt#seek" do
|
|
13
15
|
TraditionalEncryptionSpecs.mtime
|
14
16
|
) do |d|
|
15
17
|
d.read(4)
|
16
|
-
|
18
|
+
d.seek(0).must_equal(0)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
23
|
it "raises Errno::EINVAL when attempting to seek to the beginning of the stream when the delegate does not respond to rewind" do
|
22
|
-
delegate =
|
23
|
-
|
24
|
-
|
25
|
-
#delegate.should_receive(:read).with(an_instance_of(Fixnum)).at_least(:once).and_return { |n| "\000" * n }
|
26
|
-
# Use the following instead for now.
|
27
|
-
delegate.should_receive(:read).once.and_return("\000" * 12)
|
28
|
-
delegate.should_receive(:close).and_return(nil)
|
24
|
+
delegate = MiniTest::Mock.new
|
25
|
+
delegate.expect(:read, "\000" * 12, [Integer])
|
26
|
+
delegate.expect(:close, nil)
|
29
27
|
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
30
28
|
delegate,
|
31
29
|
TraditionalEncryptionSpecs.password,
|
32
30
|
TraditionalEncryptionSpecs.mtime
|
33
31
|
) do |d|
|
34
|
-
lambda { d.seek(0) }.
|
32
|
+
lambda { d.seek(0) }.must_raise(Errno::EINVAL)
|
35
33
|
end
|
36
34
|
end
|
37
35
|
|
@@ -47,8 +45,8 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt#seek" do
|
|
47
45
|
d.fill_size = 0
|
48
46
|
|
49
47
|
d.read(4)
|
50
|
-
lambda { d.seek(1, IO::SEEK_CUR) }.
|
51
|
-
lambda { d.seek(-1, IO::SEEK_CUR) }.
|
48
|
+
lambda { d.seek(1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
|
49
|
+
lambda { d.seek(-1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
|
52
50
|
end
|
53
51
|
end
|
54
52
|
end
|
@@ -60,8 +58,8 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt#seek" do
|
|
60
58
|
TraditionalEncryptionSpecs.password,
|
61
59
|
TraditionalEncryptionSpecs.mtime
|
62
60
|
) do |d|
|
63
|
-
lambda { d.seek(-1, IO::SEEK_SET) }.
|
64
|
-
lambda { d.seek(1, IO::SEEK_SET) }.
|
61
|
+
lambda { d.seek(-1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
|
62
|
+
lambda { d.seek(1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
|
65
63
|
end
|
66
64
|
end
|
67
65
|
end
|
@@ -73,9 +71,9 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt#seek" do
|
|
73
71
|
TraditionalEncryptionSpecs.password,
|
74
72
|
TraditionalEncryptionSpecs.mtime
|
75
73
|
) do |d|
|
76
|
-
lambda { d.seek(0, IO::SEEK_END) }.
|
77
|
-
lambda { d.seek(-1, IO::SEEK_END) }.
|
78
|
-
lambda { d.seek(1, IO::SEEK_END) }.
|
74
|
+
lambda { d.seek(0, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
75
|
+
lambda { d.seek(-1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
76
|
+
lambda { d.seek(1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
79
77
|
end
|
80
78
|
end
|
81
79
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/zip/codec/traditional_encryption'
|
6
8
|
|
7
9
|
describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt#tell" do
|
@@ -12,13 +14,13 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt#tell" do
|
|
12
14
|
TraditionalEncryptionSpecs.password,
|
13
15
|
TraditionalEncryptionSpecs.mtime
|
14
16
|
) do |d|
|
15
|
-
d.tell.
|
17
|
+
d.tell.must_equal(0)
|
16
18
|
d.read(4)
|
17
|
-
d.tell.
|
19
|
+
d.tell.must_equal(4)
|
18
20
|
d.read
|
19
|
-
d.tell.
|
21
|
+
d.tell.must_equal(235)
|
20
22
|
d.rewind
|
21
|
-
d.tell.
|
23
|
+
d.tell.must_equal(0)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/zip/codec/traditional_encryption'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -13,17 +15,13 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#close" do
|
|
13
15
|
TraditionalEncryptionSpecs.mtime
|
14
16
|
)
|
15
17
|
e.close
|
16
|
-
e.closed?.
|
18
|
+
e.closed?.must_equal(true)
|
17
19
|
end
|
18
20
|
|
19
21
|
it "closes the delegate stream by default" do
|
20
|
-
delegate =
|
21
|
-
|
22
|
-
|
23
|
-
#delegate.should_receive(:write).with(an_instance_of(String)).at_least(:once).and_return { |s| s.length }
|
24
|
-
# Use the following instead for now.
|
25
|
-
delegate.should_receive(:write).at_least(:once).and_return(1)
|
26
|
-
delegate.should_receive(:close).and_return(nil)
|
22
|
+
delegate = MiniTest::Mock.new
|
23
|
+
delegate.expect(:write, 12, [String])
|
24
|
+
delegate.expect(:close, nil)
|
27
25
|
e = Archive::Zip::Codec::TraditionalEncryption::Encrypt.new(
|
28
26
|
delegate,
|
29
27
|
TraditionalEncryptionSpecs.password,
|
@@ -33,13 +31,9 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#close" do
|
|
33
31
|
end
|
34
32
|
|
35
33
|
it "optionally leaves the delegate stream open" do
|
36
|
-
delegate =
|
37
|
-
|
38
|
-
|
39
|
-
#delegate.should_receive(:write).with(an_instance_of(String)).at_least(:once).and_return { |s| s.length }
|
40
|
-
# Use the following instead for now.
|
41
|
-
delegate.should_receive(:write).at_least(:once).and_return(1)
|
42
|
-
delegate.should_receive(:close).and_return(nil)
|
34
|
+
delegate = MiniTest::Mock.new
|
35
|
+
delegate.expect(:write, 12, [String])
|
36
|
+
delegate.expect(:close, nil)
|
43
37
|
e = Archive::Zip::Codec::TraditionalEncryption::Encrypt.new(
|
44
38
|
delegate,
|
45
39
|
TraditionalEncryptionSpecs.password,
|
@@ -47,13 +41,8 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#close" do
|
|
47
41
|
)
|
48
42
|
e.close(true)
|
49
43
|
|
50
|
-
delegate =
|
51
|
-
|
52
|
-
# of version 1.5.10.
|
53
|
-
#delegate.should_receive(:write).with(an_instance_of(String)).at_least(:once).and_return { |s| s.length }
|
54
|
-
# Use the following instead for now.
|
55
|
-
delegate.should_receive(:write).at_least(:once).and_return(1)
|
56
|
-
delegate.should_not_receive(:close)
|
44
|
+
delegate = MiniTest::Mock.new
|
45
|
+
delegate.expect(:write, 12, [String])
|
57
46
|
e = Archive::Zip::Codec::TraditionalEncryption::Encrypt.new(
|
58
47
|
delegate,
|
59
48
|
TraditionalEncryptionSpecs.password,
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/zip/codec/traditional_encryption'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -12,7 +14,7 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt.new" do
|
|
12
14
|
TraditionalEncryptionSpecs.password,
|
13
15
|
TraditionalEncryptionSpecs.mtime
|
14
16
|
)
|
15
|
-
e.
|
17
|
+
e.must_be_instance_of(Archive::Zip::Codec::TraditionalEncryption::Encrypt)
|
16
18
|
e.close
|
17
19
|
end
|
18
20
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/zip/codec/traditional_encryption'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -12,7 +14,7 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt.open" do
|
|
12
14
|
TraditionalEncryptionSpecs.password,
|
13
15
|
TraditionalEncryptionSpecs.mtime
|
14
16
|
)
|
15
|
-
e.
|
17
|
+
e.must_be_instance_of(Archive::Zip::Codec::TraditionalEncryption::Encrypt)
|
16
18
|
e.close
|
17
19
|
end
|
18
20
|
|
@@ -22,7 +24,7 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt.open" do
|
|
22
24
|
TraditionalEncryptionSpecs.password,
|
23
25
|
TraditionalEncryptionSpecs.mtime
|
24
26
|
) do |encryptor|
|
25
|
-
encryptor.
|
27
|
+
encryptor.must_be_instance_of(Archive::Zip::Codec::TraditionalEncryption::Encrypt)
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
@@ -34,6 +36,6 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt.open" do
|
|
34
36
|
) do |encryptor|
|
35
37
|
encryptor
|
36
38
|
end
|
37
|
-
e.closed?.
|
39
|
+
e.closed?.must_equal(true)
|
38
40
|
end
|
39
41
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/zip/codec/traditional_encryption'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -16,26 +18,22 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#rewind" do
|
|
16
18
|
e.write('test')
|
17
19
|
# Ensure repeatable test data is used for encryption header.
|
18
20
|
srand(0)
|
19
|
-
|
21
|
+
e.rewind
|
20
22
|
e.write(TraditionalEncryptionSpecs.test_data)
|
21
23
|
end
|
22
|
-
encrypted_data.string.
|
24
|
+
encrypted_data.string.must_equal(TraditionalEncryptionSpecs.encrypted_data)
|
23
25
|
end
|
24
26
|
|
25
27
|
it "raises Errno::EINVAL when attempting to rewind the stream when the delegate does not respond to rewind" do
|
26
|
-
delegate =
|
27
|
-
|
28
|
-
|
29
|
-
#delegate.should_receive(:write).with(an_instance_of(String)).at_least(:once).and_return { |s| s.length }
|
30
|
-
# Use the following instead for now.
|
31
|
-
delegate.should_receive(:write).at_least(:once).and_return(1)
|
32
|
-
delegate.should_receive(:close).once.and_return(nil)
|
28
|
+
delegate = MiniTest::Mock.new
|
29
|
+
delegate.expect(:write, 12, [String])
|
30
|
+
delegate.expect(:close, nil)
|
33
31
|
Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
34
32
|
delegate,
|
35
33
|
TraditionalEncryptionSpecs.password,
|
36
34
|
TraditionalEncryptionSpecs.mtime
|
37
35
|
) do |e|
|
38
|
-
lambda { e.rewind }.
|
36
|
+
lambda { e.rewind }.must_raise(Errno::EINVAL)
|
39
37
|
end
|
40
38
|
end
|
41
39
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/zip/codec/traditional_encryption'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -14,24 +16,20 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#seek" do
|
|
14
16
|
TraditionalEncryptionSpecs.mtime
|
15
17
|
) do |e|
|
16
18
|
e.write('test')
|
17
|
-
|
19
|
+
e.seek(0).must_equal(0)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
23
|
it "raises Errno::EINVAL when attempting to seek to the beginning of the stream when the delegate does not respond to rewind" do
|
22
|
-
delegate =
|
23
|
-
|
24
|
-
|
25
|
-
#delegate.should_receive(:write).with(an_instance_of(String)).at_least(:once).and_return { |s| s.length }
|
26
|
-
# Use the following instead for now.
|
27
|
-
delegate.should_receive(:write).at_least(:once).and_return(1)
|
28
|
-
delegate.should_receive(:close).and_return(nil)
|
24
|
+
delegate = MiniTest::Mock.new
|
25
|
+
delegate.expect(:write, 12, [String])
|
26
|
+
delegate.expect(:close, nil)
|
29
27
|
Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
30
28
|
delegate,
|
31
29
|
TraditionalEncryptionSpecs.password,
|
32
30
|
TraditionalEncryptionSpecs.mtime
|
33
31
|
) do |e|
|
34
|
-
lambda { e.seek(0) }.
|
32
|
+
lambda { e.seek(0) }.must_raise(Errno::EINVAL)
|
35
33
|
end
|
36
34
|
end
|
37
35
|
|
@@ -43,8 +41,8 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#seek" do
|
|
43
41
|
TraditionalEncryptionSpecs.mtime
|
44
42
|
) do |e|
|
45
43
|
e.write('test')
|
46
|
-
lambda { e.seek(1, IO::SEEK_CUR) }.
|
47
|
-
lambda { e.seek(-1, IO::SEEK_CUR) }.
|
44
|
+
lambda { e.seek(1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
|
45
|
+
lambda { e.seek(-1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
|
48
46
|
end
|
49
47
|
end
|
50
48
|
|
@@ -55,8 +53,8 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#seek" do
|
|
55
53
|
TraditionalEncryptionSpecs.password,
|
56
54
|
TraditionalEncryptionSpecs.mtime
|
57
55
|
) do |e|
|
58
|
-
lambda { e.seek(-1, IO::SEEK_SET) }.
|
59
|
-
lambda { e.seek(1, IO::SEEK_SET) }.
|
56
|
+
lambda { e.seek(-1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
|
57
|
+
lambda { e.seek(1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
@@ -67,9 +65,9 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#seek" do
|
|
67
65
|
TraditionalEncryptionSpecs.password,
|
68
66
|
TraditionalEncryptionSpecs.mtime
|
69
67
|
) do |e|
|
70
|
-
lambda { e.seek(0, IO::SEEK_END) }.
|
71
|
-
lambda { e.seek(-1, IO::SEEK_END) }.
|
72
|
-
lambda { e.seek(1, IO::SEEK_END) }.
|
68
|
+
lambda { e.seek(0, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
69
|
+
lambda { e.seek(-1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
70
|
+
lambda { e.seek(1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
73
71
|
end
|
74
72
|
end
|
75
73
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/zip/codec/traditional_encryption'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -13,30 +15,26 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#tell" do
|
|
13
15
|
TraditionalEncryptionSpecs.password,
|
14
16
|
TraditionalEncryptionSpecs.mtime
|
15
17
|
) do |e|
|
16
|
-
e.tell.
|
18
|
+
e.tell.must_equal(0)
|
17
19
|
e.write('test1')
|
18
|
-
e.tell.
|
20
|
+
e.tell.must_equal(5)
|
19
21
|
e.write('test2')
|
20
|
-
e.tell.
|
22
|
+
e.tell.must_equal(10)
|
21
23
|
e.rewind
|
22
|
-
e.tell.
|
24
|
+
e.tell.must_equal(0)
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
28
|
it "raises IOError on closed stream" do
|
27
|
-
delegate =
|
28
|
-
|
29
|
-
|
30
|
-
#delegate.should_receive(:write).with(an_instance_of(String)).at_least(:once).and_return { |s| s.length }
|
31
|
-
# Use the following instead for now.
|
32
|
-
delegate.should_receive(:write).at_least(:once).and_return(1)
|
33
|
-
delegate.should_receive(:close).once.and_return(nil)
|
29
|
+
delegate = MiniTest::Mock.new
|
30
|
+
delegate.expect(:write, 12, [String])
|
31
|
+
delegate.expect(:close, nil)
|
34
32
|
lambda do
|
35
33
|
Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
36
34
|
delegate,
|
37
35
|
TraditionalEncryptionSpecs.password,
|
38
36
|
TraditionalEncryptionSpecs.mtime
|
39
37
|
) { |e| e }.tell
|
40
|
-
end.
|
38
|
+
end.must_raise(IOError)
|
41
39
|
end
|
42
40
|
end
|
@@ -1,28 +1,13 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
5
7
|
require 'archive/zip/codec/traditional_encryption'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
8
10
|
describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#write" do
|
9
|
-
it "calls the write method of the delegate" do
|
10
|
-
delegate = mock('delegate')
|
11
|
-
# RSpec's mocking facility supposedly supports this, but MSpec's does not as
|
12
|
-
# of version 1.5.10.
|
13
|
-
#delegate.should_receive(:write).with(an_instance_of(String)).at_least(:once).and_return { |s| s.length }
|
14
|
-
# Use the following instead for now.
|
15
|
-
delegate.should_receive(:write).at_least(:once).and_return(1)
|
16
|
-
delegate.should_receive(:close).once.and_return(nil)
|
17
|
-
Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
18
|
-
delegate,
|
19
|
-
TraditionalEncryptionSpecs.password,
|
20
|
-
TraditionalEncryptionSpecs.mtime
|
21
|
-
) do |e|
|
22
|
-
e.write(TraditionalEncryptionSpecs.test_data)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
11
|
it "writes encrypted data to the delegate" do
|
27
12
|
# Ensure repeatable test data is used for encryption header.
|
28
13
|
srand(0)
|
@@ -34,7 +19,7 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#write" do
|
|
34
19
|
) do |e|
|
35
20
|
e.write(TraditionalEncryptionSpecs.test_data)
|
36
21
|
end
|
37
|
-
encrypted_data.string.
|
22
|
+
encrypted_data.string.must_equal(TraditionalEncryptionSpecs.encrypted_data)
|
38
23
|
end
|
39
24
|
|
40
25
|
it "writes encrypted data to a delegate that only performs partial writes" do
|
@@ -56,7 +41,7 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#write" do
|
|
56
41
|
) do |e|
|
57
42
|
e.write(TraditionalEncryptionSpecs.test_data)
|
58
43
|
end
|
59
|
-
encrypted_data.string.
|
44
|
+
encrypted_data.string.must_equal(TraditionalEncryptionSpecs.encrypted_data)
|
60
45
|
end
|
61
46
|
|
62
47
|
it "writes encrypted data to a delegate that raises Errno::EAGAIN" do
|
@@ -89,7 +74,7 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#write" do
|
|
89
74
|
retry
|
90
75
|
end
|
91
76
|
end
|
92
|
-
encrypted_data.string.
|
77
|
+
encrypted_data.string.must_equal(TraditionalEncryptionSpecs.encrypted_data)
|
93
78
|
end
|
94
79
|
|
95
80
|
it "writes encrypted data to a delegate that raises Errno::EINTR" do
|
@@ -122,6 +107,6 @@ describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#write" do
|
|
122
107
|
retry
|
123
108
|
end
|
124
109
|
end
|
125
|
-
encrypted_data.string.
|
110
|
+
encrypted_data.string.must_equal(TraditionalEncryptionSpecs.encrypted_data)
|
126
111
|
end
|
127
112
|
end
|