Sha256: 13cd8e2f9846a5d5ae97b187c40bf01eac4075212d582d9383a50473364c7303

Contents?: true

Size: 1.26 KB

Versions: 59

Compression:

Stored size: 1.26 KB

Contents

require 'test_helper'

class EncryptionTest < MiniTest::Test
  ENCRYPT_ZIP_TEST_FILE = 'test/data/zipWithEncryption.zip'
  INPUT_FILE1 = 'test/data/file1.txt'

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

  def teardown
    Zip.default_compression = @default_compression
  end

  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, ->(_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

Version data entries

59 entries across 47 versions & 5 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/rubyzip-1.3.0/test/encryption_test.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.3/test/encryption_test.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/test/encryption_test.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.4/test/encryption_test.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.4/test/encryption_test.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.4/test/encryption_test.rb
rubyzip-1.3.0 test/encryption_test.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.2/test/encryption_test.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.2/test/encryption_test.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.4/test/encryption_test.rb
rubyzip-1.2.4 test/encryption_test.rb
rubyzip-1.2.3 test/encryption_test.rb
tdiary-5.0.13 vendor/bundle/gems/rubyzip-1.2.2/test/encryption_test.rb
tdiary-5.0.12.1 vendor/bundle/gems/rubyzip-1.2.2/test/encryption_test.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.2/test/encryption_test.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.2/test/encryption_test.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.2/test/encryption_test.rb
tdiary-5.0.11 vendor/bundle/gems/rubyzip-1.2.2/test/encryption_test.rb
tdiary-5.0.11 vendor/bundle/gems/rubyzip-1.2.1/test/encryption_test.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.2/test/encryption_test.rb