Sha256: 141502353c04d28f416d2d9a59b3d7a8e1d6f4103d4d96b417999e234313da2e

Contents?: true

Size: 1.22 KB

Versions: 7

Compression:

Stored size: 1.22 KB

Contents

require_relative 'test_helper'

module Streams
  class PgpReaderTest < Minitest::Test
    describe IOStreams::Pgp::Reader do
      before do
        file_name  = File.join(File.dirname(__FILE__), 'files', 'text.txt')
        @data      = File.read(file_name)
        @temp_file = Tempfile.new('iostreams')
        @file_name = @temp_file.to_path
      end

      after do
        @temp_file.delete if @temp_file
      end

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

          result = IOStreams::Pgp::Reader.open(@file_name, passphrase: 'receiver_passphrase') { |file| file.read }
          assert_equal @data, result
        end

        it 'fails with bad passphrase' do
          assert_raises IOStreams::Pgp::Failure do
            IOStreams::Pgp::Reader.open(@file_name, 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
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
iostreams-0.14.0 test/pgp_reader_test.rb
iostreams-0.13.0 test/pgp_reader_test.rb
iostreams-0.12.1 test/pgp_reader_test.rb
iostreams-0.12.0 test/pgp_reader_test.rb
iostreams-0.11.0 test/pgp_reader_test.rb
iostreams-0.10.1 test/pgp_reader_test.rb
iostreams-0.10.0 test/pgp_reader_test.rb