Sha256: 299e6564cf49aac8855f1d4472f540f5c93e911975f015c8032dc5e86d09e99a

Contents?: true

Size: 1.34 KB

Versions: 20

Compression:

Stored size: 1.34 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 ".file" do
      it "reads encrypted file" do
        IOStreams::Pgp::Writer.file(temp_file.path, recipient: "receiver@example.org") do |io|
          io.write(decrypted)
        end

        result = IOStreams::Pgp::Reader.file(temp_file.path, passphrase: "receiver_passphrase", &:read)
        assert_equal decrypted, result
      end

      it "fails with bad passphrase" do
        assert_raises IOStreams::Pgp::Failure do
          IOStreams::Pgp::Reader.file(temp_file.path, passphrase: "BAD", &:read)
        end
      end

      it "streams input" do
        io_string = StringIO.new("".b)
        IOStreams::Pgp::Writer.stream(io_string, recipient: "receiver@example.org", signer: "sender@example.org", signer_passphrase: "sender_passphrase") do |io|
          io.write(decrypted)
        end

        io     = StringIO.new(io_string.string)
        result = IOStreams::Pgp::Reader.stream(io, passphrase: "receiver_passphrase", &:read)
        assert_equal decrypted, result
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
iostreams-1.10.3 test/pgp_reader_test.rb
iostreams-1.10.2 test/pgp_reader_test.rb
iostreams-1.10.1 test/pgp_reader_test.rb
iostreams-1.10.0 test/pgp_reader_test.rb
iostreams-1.9.0 test/pgp_reader_test.rb
iostreams-1.8.0 test/pgp_reader_test.rb
iostreams-1.7.0 test/pgp_reader_test.rb
iostreams-1.6.2 test/pgp_reader_test.rb
iostreams-1.6.1 test/pgp_reader_test.rb
iostreams-1.6.0 test/pgp_reader_test.rb
iostreams-1.5.1 test/pgp_reader_test.rb
iostreams-1.5.0 test/pgp_reader_test.rb
iostreams-1.4.0 test/pgp_reader_test.rb
iostreams-1.3.3 test/pgp_reader_test.rb
iostreams-1.3.2 test/pgp_reader_test.rb
iostreams-1.3.1 test/pgp_reader_test.rb
iostreams-1.3.0 test/pgp_reader_test.rb
iostreams-1.2.1 test/pgp_reader_test.rb
iostreams-1.2.0 test/pgp_reader_test.rb
iostreams-1.1.1 test/pgp_reader_test.rb