File: decrypted_part_test.rb

package info (click to toggle)
ruby-mail-gpg 0.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 328 kB
  • sloc: ruby: 2,289; makefile: 6
file content (45 lines) | stat: -rw-r--r-- 1,411 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'test_helper'
require 'mail/gpg/decrypted_part'
require 'mail/gpg/encrypted_part'

class DecryptedPartTest < MailGpgTestCase
  context 'DecryptedPart' do
    setup do
      @mail = Mail.new do
        to 'jane@foo.bar'
        from 'joe@foo.bar'
        subject 'test'
        body 'i am unencrypted'
      end
      @part = Mail::Gpg::EncryptedPart.new(@mail, { recipients: ['jane@foo.bar'],
                                                    :sign => true,
                                                    :password => 'abc' })
    end

    should 'decrypt' do
      assert mail = Mail::Gpg::DecryptedPart.new(@part, { :password => 'abc' })
      assert mail == @mail
      assert mail.message_id == @mail.message_id
      assert mail.message_id != @part.message_id
    end

    should 'decrypt and verify' do
      assert mail = Mail::Gpg::DecryptedPart.new(@part, { :verify => true, :password => 'abc' })
      assert mail == @mail
      assert mail.message_id == @mail.message_id
      assert mail.message_id != @part.message_id
      assert vr = mail.verify_result
      assert sig = vr.signatures.first
      assert sig.to_s=~ /Joe/
      assert sig.valid?
    end

    should 'raise encoding error for non gpg mime type' do
      part = Mail::Part.new(@part)
      part.content_type = 'text/plain'
      assert_raise(EncodingError) { Mail::Gpg::DecryptedPart.new(part) }
    end


  end
end