mail-gpg 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,4 +15,5 @@ rdoc
15
15
  spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
+ test/gpghome/random_seed
18
19
  tmp
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.0.6 2013-08-28
2
+
3
+ * bugfix: onlyu encrypt to specified keys if :keys option is present
4
+
1
5
  == 0.0.5 2013-08-28
2
6
 
3
7
  * add some docs to the Hkp client
@@ -63,15 +63,14 @@ module Mail
63
63
  # normalizes the list of recipients' emails, key ids and key data to a
64
64
  # list of Key objects
65
65
  def keys_for_data(emails_or_shas_or_keys, key_data = nil)
66
- keys = if key_data
67
- emails_or_shas_or_keys.map do |r|
66
+ if key_data
67
+ [emails_or_shas_or_keys].flatten.map do |r|
68
68
  # import any given keys
69
69
  k = key_data[r]
70
70
  if k and k =~ /-----BEGIN PGP/
71
- GPGME::Key.import k
72
- k = nil
71
+ k = GPGME::Key.import(k).imports.map(&:fpr)
73
72
  end
74
- GPGME::Key.find(:public, k || r)
73
+ GPGME::Key.find(:public, k || r, :encrypt)
75
74
  end.flatten
76
75
  else
77
76
  # key lookup in keychain for all receivers
@@ -1,5 +1,5 @@
1
1
  module Mail
2
2
  module Gpg
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -0,0 +1,83 @@
1
+ require 'test_helper'
2
+ require 'mail/gpg/encrypted_part'
3
+ require 'pry-nav'
4
+
5
+ class EncryptedPartTest < Test::Unit::TestCase
6
+ context 'EncryptedPart' do
7
+ setup do
8
+ mail = Mail.new do
9
+ to 'jane@foo.bar'
10
+ from 'joe@foo.bar'
11
+ subject 'test'
12
+ body 'i am unencrypted'
13
+ end
14
+ @part = Mail::Gpg::EncryptedPart.new(mail)
15
+ end
16
+
17
+ def check_key_list(keys)
18
+ assert_equal 1, keys.size
19
+ assert_equal GPGME::Key, keys.first.class
20
+ assert_equal 'jane@foo.bar', keys.first.email
21
+ end
22
+
23
+ context 'with email address' do
24
+ setup do
25
+ @email = 'jane@foo.bar'
26
+ end
27
+
28
+ should 'resolve email to gpg keys' do
29
+ assert keys = @part.send(:keys_for_data, @email)
30
+ check_key_list keys
31
+ end
32
+
33
+ should 'resolve emails to gpg keys' do
34
+ assert keys = @part.send(:keys_for_data, [@email])
35
+ check_key_list keys
36
+ end
37
+
38
+ end
39
+
40
+ context 'with key id' do
41
+ setup do
42
+ @key_id = GPGME::Key.find(:public, 'jane@foo.bar').first.sha
43
+ end
44
+
45
+ should 'resolve single id gpg keys' do
46
+ assert keys = @part.send(:keys_for_data, @key_id)
47
+ check_key_list keys
48
+ end
49
+ should 'resolve id list to gpg keys' do
50
+ assert keys = @part.send(:keys_for_data, [@key_id])
51
+ check_key_list keys
52
+ end
53
+ end
54
+
55
+ context 'with key fingerprint' do
56
+ setup do
57
+ @key_fpr = GPGME::Key.find(:public, 'jane@foo.bar').first.fingerprint
58
+ end
59
+
60
+ should 'resolve single id gpg keys' do
61
+ assert keys = @part.send(:keys_for_data, @key_fpr)
62
+ check_key_list keys
63
+ end
64
+ should 'resolve id list to gpg keys' do
65
+ assert keys = @part.send(:keys_for_data, [@key_fpr])
66
+ check_key_list keys
67
+ end
68
+ end
69
+
70
+ context 'with emails and key data' do
71
+ setup do
72
+ @key = GPGME::Key.find(:public, 'jane@foo.bar').first.export(armor: true).to_s
73
+ @emails = ['jane@foo.bar']
74
+ @key_data = { 'jane@foo.bar' => @key }
75
+ end
76
+
77
+ should 'resolve to gpg keys' do
78
+ assert keys = @part.send(:keys_for_data, @emails, @key_data)
79
+ check_key_list keys
80
+ end
81
+ end
82
+ end
83
+ end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail-gpg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-26 00:00:00.000000000 Z
12
+ date: 2013-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mail
@@ -154,6 +154,7 @@ files:
154
154
  - lib/mail/gpg/version_part.rb
155
155
  - mail-gpg.gemspec
156
156
  - test/action_mailer_test.rb
157
+ - test/encrypted_part_test.rb
157
158
  - test/gpg_test.rb
158
159
  - test/gpghome/pubring.gpg
159
160
  - test/gpghome/pubring.gpg~
@@ -189,6 +190,7 @@ specification_version: 3
189
190
  summary: GPG/MIME encryption plugin for the Ruby Mail Library
190
191
  test_files:
191
192
  - test/action_mailer_test.rb
193
+ - test/encrypted_part_test.rb
192
194
  - test/gpg_test.rb
193
195
  - test/gpghome/pubring.gpg
194
196
  - test/gpghome/pubring.gpg~