diff --git a/Gemfile b/Gemfile index 9fa34ae0b..1ce95bfce 100644 --- a/Gemfile +++ b/Gemfile @@ -157,7 +157,7 @@ gem 'zip-zip', require: 'zip' # gnupg for email encryption # -gem 'mail-gpg' +gem 'mail-gpg', '~> 0.3.3' ## # Environment specific diff --git a/Gemfile.lock b/Gemfile.lock index fadacb322..d162771ff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -299,4 +299,4 @@ DEPENDENCIES zip-zip BUNDLED WITH - 1.16.0 + 1.16.1 diff --git a/app/models/mailer/page_histories.rb b/app/models/mailer/page_histories.rb index 7df058507..ae0280751 100644 --- a/app/models/mailer/page_histories.rb +++ b/app/models/mailer/page_histories.rb @@ -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 diff --git a/app/models/pgp_key.rb b/app/models/pgp_key.rb index 5f7c8c433..f7f1dc33a 100644 --- a/app/models/pgp_key.rb +++ b/app/models/pgp_key.rb @@ -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 @@ -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) diff --git a/test/helpers/pgp_test_helper.rb b/test/helpers/pgp_test_helper.rb deleted file mode 100644 index 7c4757ced..000000000 --- a/test/helpers/pgp_test_helper.rb +++ /dev/null @@ -1,8 +0,0 @@ -module PgpTestHelper - 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 -end diff --git a/test/test_helper.rb b/test/test_helper.rb index 9ac729f6c..bde1b4f83 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -27,7 +27,6 @@ class ActiveSupport::TestCase include FunctionalTestHelper include DebugTestHelper include CrabgrassTestHelper - include PgpTestHelper # for fixture_file_upload include ActionDispatch::TestProcess diff --git a/test/unit/mailer/page_histories_test.rb b/test/unit/mailer/page_histories_test.rb index 7eeeca015..271009a99 100644 --- a/test/unit/mailer/page_histories_test.rb +++ b/test/unit/mailer/page_histories_test.rb @@ -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 @@ -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) diff --git a/test/unit/mailer/pgp_key_upload_test.rb b/test/unit/mailer/pgp_key_upload_test.rb index 0cf86c49d..b5df3077c 100644 --- a/test/unit/mailer/pgp_key_upload_test.rb +++ b/test/unit/mailer/pgp_key_upload_test.rb @@ -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