Class: EncryptionTest

Inherits:
MiniTest::Test
  • Object
show all
Defined in:
lib/hotplate/gems/rubyzip-1.1.7/test/encryption_test.rb

Constant Summary collapse

ENCRYPT_ZIP_TEST_FILE =
'test/data/zipWithEncryption.zip'
INPUT_FILE1 =
'test/data/file1.txt'

Instance Method Summary collapse

Instance Method Details

#setupObject



7
8
9
10
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/encryption_test.rb', line 7

def setup
  @default_compression = Zip.default_compression
  Zip.default_compression = ::Zlib::DEFAULT_COMPRESSION
end

#teardownObject



12
13
14
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/encryption_test.rb', line 12

def teardown
  Zip.default_compression = @default_compression
end

#test_decryptObject



34
35
36
37
38
39
40
41
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/encryption_test.rb', line 34

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

#test_encryptObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hotplate/gems/rubyzip-1.1.7/test/encryption_test.rb', line 16

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