Skip to content

Commit

Permalink
Update mail-gpg after fix of key handling for invalid or empty keys
Browse files Browse the repository at this point in the history
jkraemer/mail-gpg#55
now mail-gpg raises an exception when dealing with invalid keys
  • Loading branch information
dgt committed Apr 16, 2018
1 parent 8e186e8 commit cab8ca6
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ gem 'zip-zip', require: 'zip'

# gnupg for email encryption
#
gem 'mail-gpg'
gem 'mail-gpg', '~> 0.3.3'

##
# Environment specific
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ GEM
ffi (1.9.17)
globalid (0.4.1)
activesupport (>= 4.2.0)
gpgme (2.0.13)
mini_portile2 (~> 2.1)
gpgme (2.0.16)
mini_portile2 (~> 2.3)
haml (4.0.7)
tilt
haml-rails (0.9.0)
Expand All @@ -133,7 +133,7 @@ GEM
nokogiri (>= 1.5.9)
mail (2.7.0)
mini_mime (>= 0.1.1)
mail-gpg (0.3.1)
mail-gpg (0.3.3)
gpgme (~> 2.0, >= 2.0.2)
mail (~> 2.5, >= 2.5.3)
middleware (0.1.0)
Expand Down Expand Up @@ -271,7 +271,7 @@ DEPENDENCIES
http_accept_language (~> 2.0)
i18n (~> 0.7)
json (~> 1.8)
mail-gpg
mail-gpg (~> 0.3.3)
mime-types
minitest
mysql2 (~> 0.3.18)
Expand Down Expand Up @@ -299,4 +299,4 @@ DEPENDENCIES
zip-zip

BUNDLED WITH
1.16.0
1.16.1
11 changes: 3 additions & 8 deletions app/models/mailer/page_histories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,13 @@ def mail(options = {})
return if @histories.blank? || @recipient.email.blank?
@histories = @histories.group_by(&:page).to_a
options = add_encrypt_options(options)
create_fresh_gpg_directory if options[:gpg]
# FIXME: We want a new keyring for each encryption (or user).
# The following solution does not work for parallel requests.
#PgpKey.create_fresh_gpg_directory if options[:gpg]
options = add_sign_options(options)
super options.reverse_merge from: sender, to: @recipient.email
end

def create_fresh_gpg_directory
gpg_dir = Rails.root.join('assets','keyrings', "tmp").to_s
FileUtils.rm_rf(gpg_dir) if File.exist?(gpg_dir)
FileUtils.makedirs(gpg_dir)
ENV['GNUPGHOME']=gpg_dir
end

def self.digest_recipients
User.where(receive_notifications: 'Digest')
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/pgp_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def expired?

def update_key
if self.key_changed?
create_fresh_gpg_directory
PgpKey.create_fresh_gpg_directory
import_key
end
end
Expand Down Expand Up @@ -53,7 +53,7 @@ def notify_user
end
end

def create_fresh_gpg_directory
def self.create_fresh_gpg_directory
gpg_dir = Rails.root.join('assets','keyrings', "tmp").to_s
FileUtils.rm_rf(gpg_dir) if File.exist?(gpg_dir)
FileUtils.makedirs(gpg_dir)
Expand Down
8 changes: 0 additions & 8 deletions test/helpers/pgp_test_helper.rb

This file was deleted.

1 change: 0 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class ActiveSupport::TestCase
include FunctionalTestHelper
include DebugTestHelper
include CrabgrassTestHelper
include PgpTestHelper
# for fixture_file_upload
include ActionDispatch::TestProcess

Expand Down
7 changes: 1 addition & 6 deletions test/unit/mailer/page_histories_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ def setup
# only :blue (and :dolphin) have a valid key. :red's is broken, :yellow's is expired and green
# does not have a key
@user = users(:blue)
# FIXME: If we use a broken/expired key, mail-gpg does not raise an exception.
# Instead it encrypts the email using all keys available in the keyring
# As a workaround to make tests pass we create a new keyring for each test.
# see: https://github.com/jkraemer/mail-gpg/issues/55
# create_fresh_gpg_directory
watch_page
mailer_class.deliveries = nil
end
Expand Down Expand Up @@ -65,7 +60,7 @@ def test_send_plain_digest_encrypted
assert mailer_class.deliveries.first.encrypted?
end

def test_send_encrypted_paranoid_digest_encrypted
def test_send_paranoid_digest_encrypted
with_paranoid_emails
receive_notifications 'Digest'
updated_page_as users(:red)
Expand Down
1 change: 0 additions & 1 deletion test/unit/mailer/pgp_key_upload_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class Mailer::PgpKeyUploadTest < ActionMailer::TestCase
# key is invalid or expired

def setup
create_fresh_gpg_directory
mailer_class.deliveries = nil
end

Expand Down

0 comments on commit cab8ca6

Please sign in to comment.