forked from jdleesmiller/rubyzip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test cases for encryption support
- Loading branch information
Showing
3 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
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
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,55 @@ | ||
require 'test_helper' | ||
|
||
class NullEncrypterTest < MiniTest::Test | ||
def setup | ||
@encrypter = ::Zip::NullEncrypter.new | ||
end | ||
|
||
def test_header_bytesize | ||
assert_equal 0, @encrypter.header_bytesize | ||
end | ||
|
||
def test_gp_flags | ||
assert_equal 0, @encrypter.gp_flags | ||
end | ||
|
||
def test_header | ||
[nil, '', 'a' * 10, 0xffffffff].each do |arg| | ||
assert_empty @encrypter.header(arg) | ||
end | ||
end | ||
|
||
def test_encrypt | ||
[nil, '', 'a' * 10, 0xffffffff].each do |data| | ||
assert_equal data, @encrypter.encrypt(data) | ||
end | ||
end | ||
|
||
def test_reset! | ||
assert_respond_to @encrypter, :reset! | ||
end | ||
end | ||
|
||
class NullDecrypterTest < MiniTest::Test | ||
def setup | ||
@decrypter = ::Zip::NullDecrypter.new | ||
end | ||
|
||
def test_header_bytesize | ||
assert_equal 0, @decrypter.header_bytesize | ||
end | ||
|
||
def test_gp_flags | ||
assert_equal 0, @decrypter.gp_flags | ||
end | ||
|
||
def test_decrypt | ||
[nil, '', 'a' * 10, 0xffffffff].each do |data| | ||
assert_equal data, @decrypter.decrypt(data) | ||
end | ||
end | ||
|
||
def test_reset! | ||
assert_respond_to @decrypter, :reset! | ||
end | ||
end |
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,79 @@ | ||
require 'test_helper' | ||
|
||
class TraditionalEncrypterTest < MiniTest::Test | ||
def setup | ||
@encrypter = ::Zip::TraditionalEncrypter.new('password') | ||
end | ||
|
||
def test_header_bytesize | ||
assert_equal 12, @encrypter.header_bytesize | ||
end | ||
|
||
def test_gp_flags | ||
assert_equal 1, @encrypter.gp_flags | ||
end | ||
|
||
def test_header | ||
@encrypter.reset! | ||
exepected = [239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 116, 154].pack("C*") | ||
Random.stub(:rand, 1) do | ||
assert_equal exepected, @encrypter.header(0xffffffff) | ||
end | ||
end | ||
|
||
def test_encrypt | ||
@encrypter.reset! | ||
Random.stub(:rand, 1) { @encrypter.header(0xffffffff) } | ||
assert_raises(NoMethodError) { @encrypter.encrypt(nil) } | ||
assert_raises(NoMethodError) { @encrypter.encrypt(1) } | ||
assert_equal '', @encrypter.encrypt('') | ||
assert_equal [2, 25, 13, 222, 17, 190, 250, 133, 133, 166].pack("C*"), @encrypter.encrypt('a' * 10) | ||
end | ||
|
||
def test_reset! | ||
@encrypter.reset! | ||
Random.stub(:rand, 1) { @encrypter.header(0xffffffff) } | ||
[2, 25, 13, 222, 17, 190, 250, 133, 133, 166].map(&:chr).each do |c| | ||
assert_equal c, @encrypter.encrypt('a') | ||
end | ||
assert_equal 134.chr, @encrypter.encrypt('a') | ||
@encrypter.reset! | ||
Random.stub(:rand, 1) { @encrypter.header(0xffffffff) } | ||
[2, 25, 13, 222, 17, 190, 250, 133, 133, 166].map(&:chr).each do |c| | ||
assert_equal c, @encrypter.encrypt('a') | ||
end | ||
end | ||
end | ||
|
||
class TraditionalDecrypterTest < MiniTest::Test | ||
def setup | ||
@decrypter = ::Zip::TraditionalDecrypter.new('password') | ||
end | ||
|
||
def test_header_bytesize | ||
assert_equal 12, @decrypter.header_bytesize | ||
end | ||
|
||
def test_gp_flags | ||
assert_equal 1, @decrypter.gp_flags | ||
end | ||
|
||
def test_decrypt | ||
@decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 116, 154].pack("C*")) | ||
[2, 25, 13, 222, 17, 190, 250, 133, 133, 166].map(&:chr).each do |c| | ||
assert_equal 'a', @decrypter.decrypt(c) | ||
end | ||
end | ||
|
||
def test_reset! | ||
@decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 116, 154].pack("C*")) | ||
[2, 25, 13, 222, 17, 190, 250, 133, 133, 166].map(&:chr).each do |c| | ||
assert_equal 'a', @decrypter.decrypt(c) | ||
end | ||
assert_equal 229.chr, @decrypter.decrypt(2.chr) | ||
@decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 116, 154].pack("C*")) | ||
[2, 25, 13, 222, 17, 190, 250, 133, 133, 166].map(&:chr).each do |c| | ||
assert_equal 'a', @decrypter.decrypt(c) | ||
end | ||
end | ||
end |