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/null_encryption'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -9,24 +11,23 @@ describe "Archive::Zip::Codec::NullEncryption::Decrypt#close" do
|
|
9
11
|
it "closes the stream" do
|
10
12
|
d = Archive::Zip::Codec::NullEncryption::Decrypt.new(BinaryStringIO.new)
|
11
13
|
d.close
|
12
|
-
d.closed?.
|
14
|
+
d.closed?.must_equal(true)
|
13
15
|
end
|
14
16
|
|
15
17
|
it "closes the delegate stream by default" do
|
16
|
-
delegate =
|
17
|
-
delegate.
|
18
|
+
delegate = MiniTest::Mock.new
|
19
|
+
delegate.expect(:close, nil)
|
18
20
|
d = Archive::Zip::Codec::NullEncryption::Decrypt.new(delegate)
|
19
21
|
d.close
|
20
22
|
end
|
21
23
|
|
22
24
|
it "optionally leaves the delegate stream open" do
|
23
|
-
delegate =
|
24
|
-
delegate.
|
25
|
+
delegate = MiniTest::Mock.new
|
26
|
+
delegate.expect(:close, nil)
|
25
27
|
d = Archive::Zip::Codec::NullEncryption::Decrypt.new(delegate)
|
26
28
|
d.close(true)
|
27
29
|
|
28
|
-
delegate =
|
29
|
-
delegate.should_not_receive(:close)
|
30
|
+
delegate = MiniTest::Mock.new
|
30
31
|
d = Archive::Zip::Codec::NullEncryption::Decrypt.new(delegate)
|
31
32
|
d.close(false)
|
32
33
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
require '
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
7
|
+
require 'archive/zip/codec/null_encryption'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
8
10
|
describe "Archive::Zip::Codec::NullEncryption::Decrypt.new" do
|
9
11
|
it "returns a new instance" do
|
10
12
|
d = Archive::Zip::Codec::NullEncryption::Decrypt.new(BinaryStringIO.new)
|
11
|
-
d.
|
13
|
+
d.must_be_instance_of(Archive::Zip::Codec::NullEncryption::Decrypt)
|
12
14
|
d.close
|
13
15
|
end
|
14
16
|
end
|
@@ -1,20 +1,22 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
require '
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
+
|
7
|
+
require 'archive/zip/codec/null_encryption'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
8
10
|
describe "Archive::Zip::Codec::NullEncryption::Decrypt.open" do
|
9
11
|
it "returns a new instance when run without a block" do
|
10
12
|
d = Archive::Zip::Codec::NullEncryption::Decrypt.open(BinaryStringIO.new)
|
11
|
-
d.
|
13
|
+
d.must_be_instance_of(Archive::Zip::Codec::NullEncryption::Decrypt)
|
12
14
|
d.close
|
13
15
|
end
|
14
16
|
|
15
17
|
it "executes a block with a new instance as an argument" do
|
16
18
|
Archive::Zip::Codec::NullEncryption::Decrypt.open(BinaryStringIO.new) do |decryptor|
|
17
|
-
decryptor.
|
19
|
+
decryptor.must_be_instance_of(Archive::Zip::Codec::NullEncryption::Decrypt)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
@@ -22,6 +24,6 @@ describe "Archive::Zip::Codec::NullEncryption::Decrypt.open" do
|
|
22
24
|
d = Archive::Zip::Codec::NullEncryption::Decrypt.open(BinaryStringIO.new) do |decryptor|
|
23
25
|
decryptor
|
24
26
|
end
|
25
|
-
d.closed?.
|
27
|
+
d.closed?.must_equal(true)
|
26
28
|
end
|
27
29
|
end
|
@@ -1,14 +1,16 @@
|
|
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/null_encryption'
|
6
8
|
|
7
9
|
describe "Archive::Zip::Codec::NullEncryption::Decrypt#read" do
|
8
10
|
it "calls the read method of the delegate" do
|
9
|
-
delegate =
|
10
|
-
delegate.
|
11
|
-
delegate.
|
11
|
+
delegate = MiniTest::Mock.new
|
12
|
+
delegate.expect(:read, nil, [Integer])
|
13
|
+
delegate.expect(:close, nil)
|
12
14
|
Archive::Zip::Codec::NullEncryption::Decrypt.open(delegate) do |d|
|
13
15
|
d.read
|
14
16
|
end
|
@@ -17,7 +19,7 @@ describe "Archive::Zip::Codec::NullEncryption::Decrypt#read" do
|
|
17
19
|
it "passes data through unmodified" do
|
18
20
|
NullEncryptionSpecs.encrypted_data do |ed|
|
19
21
|
Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
|
20
|
-
d.read.
|
22
|
+
d.read.must_equal(NullEncryptionSpecs.test_data)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
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/null_encryption'
|
6
8
|
|
7
9
|
describe "Archive::Zip::Codec::NullEncryption::Decrypt#rewind" do
|
@@ -9,17 +11,17 @@ describe "Archive::Zip::Codec::NullEncryption::Decrypt#rewind" do
|
|
9
11
|
NullEncryptionSpecs.encrypted_data do |ed|
|
10
12
|
Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
|
11
13
|
d.read(4)
|
12
|
-
|
13
|
-
d.read.
|
14
|
+
d.rewind
|
15
|
+
d.read.must_equal(NullEncryptionSpecs.test_data)
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
20
|
it "raises Errno::EINVAL when attempting to rewind the stream when the delegate does not respond to rewind" do
|
19
|
-
delegate =
|
20
|
-
delegate.
|
21
|
+
delegate = MiniTest::Mock.new
|
22
|
+
delegate.expect(:close, nil)
|
21
23
|
Archive::Zip::Codec::NullEncryption::Decrypt.open(delegate) do |d|
|
22
|
-
lambda { d.rewind }.
|
24
|
+
lambda { d.rewind }.must_raise(Errno::EINVAL)
|
23
25
|
end
|
24
26
|
end
|
25
27
|
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/null_encryption'
|
6
8
|
|
7
9
|
describe "Archive::Zip::Codec::NullEncryption::Decrypt#seek" do
|
@@ -9,16 +11,16 @@ describe "Archive::Zip::Codec::NullEncryption::Decrypt#seek" do
|
|
9
11
|
NullEncryptionSpecs.encrypted_data do |ed|
|
10
12
|
Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
|
11
13
|
d.read(4)
|
12
|
-
|
14
|
+
d.seek(0).must_equal(0)
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
19
|
it "raises Errno::EINVAL when attempting to seek to the beginning of the stream when the delegate does not respond to rewind" do
|
18
|
-
delegate =
|
19
|
-
delegate.
|
20
|
+
delegate = MiniTest::Mock.new
|
21
|
+
delegate.expect(:close, nil)
|
20
22
|
Archive::Zip::Codec::NullEncryption::Decrypt.open(delegate) do |d|
|
21
|
-
lambda { d.seek(0) }.
|
23
|
+
lambda { d.seek(0) }.must_raise(Errno::EINVAL)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -30,8 +32,8 @@ describe "Archive::Zip::Codec::NullEncryption::Decrypt#seek" do
|
|
30
32
|
d.fill_size = 0
|
31
33
|
|
32
34
|
d.read(4)
|
33
|
-
lambda { d.seek(1, IO::SEEK_CUR) }.
|
34
|
-
lambda { d.seek(-1, IO::SEEK_CUR) }.
|
35
|
+
lambda { d.seek(1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
|
36
|
+
lambda { d.seek(-1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
@@ -39,8 +41,8 @@ describe "Archive::Zip::Codec::NullEncryption::Decrypt#seek" do
|
|
39
41
|
it "raises Errno::EINVAL when seeking a non-zero offset relative to the beginning of the stream" do
|
40
42
|
NullEncryptionSpecs.encrypted_data do |ed|
|
41
43
|
Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
|
42
|
-
lambda { d.seek(-1, IO::SEEK_SET) }.
|
43
|
-
lambda { d.seek(1, IO::SEEK_SET) }.
|
44
|
+
lambda { d.seek(-1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
|
45
|
+
lambda { d.seek(1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
@@ -48,9 +50,9 @@ describe "Archive::Zip::Codec::NullEncryption::Decrypt#seek" do
|
|
48
50
|
it "raises Errno::EINVAL when seeking relative to the end of the stream" do
|
49
51
|
NullEncryptionSpecs.encrypted_data do |ed|
|
50
52
|
Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
|
51
|
-
lambda { d.seek(0, IO::SEEK_END) }.
|
52
|
-
lambda { d.seek(-1, IO::SEEK_END) }.
|
53
|
-
lambda { d.seek(1, IO::SEEK_END) }.
|
53
|
+
lambda { d.seek(0, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
54
|
+
lambda { d.seek(-1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
55
|
+
lambda { d.seek(1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|
@@ -1,20 +1,22 @@
|
|
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/null_encryption'
|
6
8
|
|
7
9
|
describe "Archive::Zip::Codec::NullEncryption::Decrypt#tell" do
|
8
10
|
it "returns the current position of the stream" do
|
9
11
|
NullEncryptionSpecs.encrypted_data do |ed|
|
10
12
|
Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
|
11
|
-
d.tell.
|
13
|
+
d.tell.must_equal(0)
|
12
14
|
d.read(4)
|
13
|
-
d.tell.
|
15
|
+
d.tell.must_equal(4)
|
14
16
|
d.read
|
15
|
-
d.tell.
|
17
|
+
d.tell.must_equal(235)
|
16
18
|
d.rewind
|
17
|
-
d.tell.
|
19
|
+
d.tell.must_equal(0)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
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/null_encryption'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -9,24 +11,23 @@ describe "Archive::Zip::Codec::NullEncryption::Encrypt#close" do
|
|
9
11
|
it "closes the stream" do
|
10
12
|
e = Archive::Zip::Codec::NullEncryption::Encrypt.new(BinaryStringIO.new)
|
11
13
|
e.close
|
12
|
-
e.closed?.
|
14
|
+
e.closed?.must_equal(true)
|
13
15
|
end
|
14
16
|
|
15
17
|
it "closes the delegate stream by default" do
|
16
|
-
delegate =
|
17
|
-
delegate.
|
18
|
+
delegate = MiniTest::Mock.new
|
19
|
+
delegate.expect(:close, nil)
|
18
20
|
e = Archive::Zip::Codec::NullEncryption::Encrypt.new(delegate)
|
19
21
|
e.close
|
20
22
|
end
|
21
23
|
|
22
24
|
it "optionally leaves the delegate stream open" do
|
23
|
-
delegate =
|
24
|
-
delegate.
|
25
|
+
delegate = MiniTest::Mock.new
|
26
|
+
delegate.expect(:close, nil)
|
25
27
|
e = Archive::Zip::Codec::NullEncryption::Encrypt.new(delegate)
|
26
28
|
e.close(true)
|
27
29
|
|
28
|
-
delegate =
|
29
|
-
delegate.should_not_receive(:close)
|
30
|
+
delegate = MiniTest::Mock.new
|
30
31
|
e = Archive::Zip::Codec::NullEncryption::Encrypt.new(delegate)
|
31
32
|
e.close(false)
|
32
33
|
end
|
@@ -1,14 +1,16 @@
|
|
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/null_encryption'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
8
10
|
describe "Archive::Zip::Codec::NullEncryption::Encrypt.new" do
|
9
11
|
it "returns a new instance" do
|
10
12
|
e = Archive::Zip::Codec::NullEncryption::Encrypt.new(BinaryStringIO.new)
|
11
|
-
e.
|
13
|
+
e.must_be_instance_of(Archive::Zip::Codec::NullEncryption::Encrypt)
|
12
14
|
e.close
|
13
15
|
end
|
14
16
|
end
|
@@ -1,20 +1,24 @@
|
|
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/null_encryption'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
8
10
|
describe "Archive::Zip::Codec::NullEncryption::Encrypt.open" do
|
9
11
|
it "returns a new instance when run without a block" do
|
10
12
|
e = Archive::Zip::Codec::NullEncryption::Encrypt.open(BinaryStringIO.new)
|
11
|
-
e.
|
13
|
+
e.must_be_instance_of(Archive::Zip::Codec::NullEncryption::Encrypt)
|
12
14
|
e.close
|
13
15
|
end
|
14
16
|
|
15
17
|
it "executes a block with a new instance as an argument" do
|
16
18
|
Archive::Zip::Codec::NullEncryption::Encrypt.open(BinaryStringIO.new) do |encryptor|
|
17
|
-
encryptor.
|
19
|
+
encryptor.must_be_instance_of(
|
20
|
+
Archive::Zip::Codec::NullEncryption::Encrypt
|
21
|
+
)
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
@@ -22,6 +26,6 @@ describe "Archive::Zip::Codec::NullEncryption::Encrypt.open" do
|
|
22
26
|
e = Archive::Zip::Codec::NullEncryption::Encrypt.open(BinaryStringIO.new) do |encryptor|
|
23
27
|
encryptor
|
24
28
|
end
|
25
|
-
e.closed?.
|
29
|
+
e.closed?.must_equal(true)
|
26
30
|
end
|
27
31
|
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/null_encryption'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -10,17 +12,17 @@ describe "Archive::Zip::Codec::NullEncryption::Encrypt#rewind" do
|
|
10
12
|
encrypted_data = BinaryStringIO.new
|
11
13
|
Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
|
12
14
|
e.write('test')
|
13
|
-
|
15
|
+
e.rewind
|
14
16
|
e.write(NullEncryptionSpecs.test_data)
|
15
17
|
end
|
16
|
-
encrypted_data.string.
|
18
|
+
encrypted_data.string.must_equal(NullEncryptionSpecs.encrypted_data)
|
17
19
|
end
|
18
20
|
|
19
21
|
it "raises Errno::EINVAL when attempting to rewind the stream when the delegate does not respond to rewind" do
|
20
|
-
delegate =
|
21
|
-
delegate.
|
22
|
+
delegate = MiniTest::Mock.new
|
23
|
+
delegate.expect(:close, nil)
|
22
24
|
Archive::Zip::Codec::NullEncryption::Encrypt.open(delegate) do |e|
|
23
|
-
lambda { e.rewind }.
|
25
|
+
lambda { e.rewind }.must_raise(Errno::EINVAL)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
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/null_encryption'
|
6
8
|
require 'archive/support/binary_stringio'
|
7
9
|
|
@@ -10,15 +12,15 @@ describe "Archive::Zip::Codec::NullEncryption::Encrypt#seek" do
|
|
10
12
|
encrypted_data = BinaryStringIO.new
|
11
13
|
Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
|
12
14
|
e.write('test')
|
13
|
-
|
15
|
+
e.seek(0).must_equal(0)
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
19
|
it "raises Errno::EINVAL when attempting to seek to the beginning of the stream when the delegate does not respond to rewind" do
|
18
|
-
delegate =
|
19
|
-
delegate.
|
20
|
+
delegate = MiniTest::Mock.new
|
21
|
+
delegate.expect(:close, nil)
|
20
22
|
Archive::Zip::Codec::NullEncryption::Encrypt.open(delegate) do |e|
|
21
|
-
lambda { e.seek(0) }.
|
23
|
+
lambda { e.seek(0) }.must_raise(Errno::EINVAL)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -26,25 +28,25 @@ describe "Archive::Zip::Codec::NullEncryption::Encrypt#seek" do
|
|
26
28
|
encrypted_data = BinaryStringIO.new
|
27
29
|
Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
|
28
30
|
e.write('test')
|
29
|
-
lambda { e.seek(1, IO::SEEK_CUR) }.
|
30
|
-
lambda { e.seek(-1, IO::SEEK_CUR) }.
|
31
|
+
lambda { e.seek(1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
|
32
|
+
lambda { e.seek(-1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
36
|
it "raises Errno::EINVAL when seeking a non-zero offset relative to the beginning of the stream" do
|
35
37
|
encrypted_data = BinaryStringIO.new
|
36
38
|
Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
|
37
|
-
lambda { e.seek(-1, IO::SEEK_SET) }.
|
38
|
-
lambda { e.seek(1, IO::SEEK_SET) }.
|
39
|
+
lambda { e.seek(-1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
|
40
|
+
lambda { e.seek(1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
44
|
it "raises Errno::EINVAL when seeking relative to the end of the stream" do
|
43
45
|
encrypted_data = BinaryStringIO.new
|
44
46
|
Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
|
45
|
-
lambda { e.seek(0, IO::SEEK_END) }.
|
46
|
-
lambda { e.seek(-1, IO::SEEK_END) }.
|
47
|
-
lambda { e.seek(1, IO::SEEK_END) }.
|
47
|
+
lambda { e.seek(0, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
48
|
+
lambda { e.seek(-1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
49
|
+
lambda { e.seek(1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|