-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test case for traditional encryption
zip file generated by archive-zip as reference
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'test_helper' | ||
|
||
class EncryptionTest < MiniTest::Test | ||
ENCRYPT_ZIP_TEST_FILE = 'test/data/zipWithEncryption.zip' | ||
INPUT_FILE1 = 'test/data/file1.txt' | ||
|
||
def test_encrypt | ||
test_file = open(ENCRYPT_ZIP_TEST_FILE, 'rb').read | ||
|
||
@rand = [250, 143, 107, 13, 143, 22, 155, 75, 228, 150, 12] | ||
@output = ::Zip::DOSTime.stub(:now, ::Zip::DOSTime.new(2014, 12, 17, 15, 56, 24)) do | ||
Random.stub(:rand, lambda { |range| @rand.shift }) do | ||
Zip::OutputStream.write_buffer(::StringIO.new(''), Zip::TraditionalEncrypter.new('password')) do |zos| | ||
zos.put_next_entry('file1.txt') | ||
zos.write open(INPUT_FILE1).read | ||
end.string | ||
end | ||
end | ||
|
||
@output.unpack("C*").each_with_index do |c, i| | ||
assert_equal test_file[i].ord, c | ||
end | ||
end | ||
|
||
def test_decrypt | ||
Zip::InputStream.open(ENCRYPT_ZIP_TEST_FILE, 0, Zip::TraditionalDecrypter.new('password')) do |zis| | ||
entry = zis.get_next_entry | ||
assert_equal 'file1.txt', entry.name | ||
assert_equal 1327, entry.size | ||
assert_equal open(INPUT_FILE1, 'r').read, zis.read | ||
end | ||
end | ||
end |