Sha256: 1c98cf32b61aeec5e79ebb61dbe09ccffa80c650084bcaae506c7ec718cee0bb

Contents?: true

Size: 1.12 KB

Versions: 10

Compression:

Stored size: 1.12 KB

Contents

require_relative 'test_helper'

class PgpReaderTest < Minitest::Test
  describe IOStreams::Pgp::Reader do
    let :temp_file do
      Tempfile.new('iostreams')
    end

    let :decrypted do
      file_name = File.join(File.dirname(__FILE__), 'files', 'text.txt')
      File.read(file_name)
    end

    after do
      temp_file.delete
    end

    describe '.open' do
      it 'reads encrypted file' do
        IOStreams::Pgp::Writer.open(temp_file.path, recipient: 'receiver@example.org') do |io|
          io.write(decrypted)
        end

        result = IOStreams::Pgp::Reader.open(temp_file.path, passphrase: 'receiver_passphrase') { |file| file.read }
        assert_equal decrypted, result
      end

      it 'fails with bad passphrase' do
        assert_raises IOStreams::Pgp::Failure do
          IOStreams::Pgp::Reader.open(temp_file.path, passphrase: 'BAD') { |file| file.read }
        end
      end

      it 'fails with stream input' do
        io = StringIO.new
        assert_raises NotImplementedError do
          IOStreams::Pgp::Reader.open(io, passphrase: 'BAD') { |file| file.read }
        end
      end

    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
iostreams-0.19.0 test/pgp_reader_test.rb
iostreams-0.18.0 test/pgp_reader_test.rb
iostreams-0.17.3 test/pgp_reader_test.rb
iostreams-0.17.2 test/pgp_reader_test.rb
iostreams-0.17.1 test/pgp_reader_test.rb
iostreams-0.17.0 test/pgp_reader_test.rb
iostreams-0.16.2 test/pgp_reader_test.rb
iostreams-0.16.1 test/pgp_reader_test.rb
iostreams-0.16.0 test/pgp_reader_test.rb
iostreams-0.15.0 test/pgp_reader_test.rb