Skip to content
Snippets Groups Projects
Commit 46f7447f authored by Alexis Reigel's avatar Alexis Reigel :coffee:
Browse files

perform signature update in sidekiq worker

parent bf30f501
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !9546. Comments created here will be created in the context of that merge request.
......@@ -28,7 +28,7 @@ class GpgKey < ActiveRecord::Base
unless: -> { errors.has_key?(:key) }
before_validation :extract_fingerprint, :extract_primary_keyid
after_create :update_invalid_gpg_signatures
after_create :update_invalid_gpg_signatures_after_create
after_create :notify_user
def key=(value)
......@@ -54,7 +54,7 @@ def verified?
end
def update_invalid_gpg_signatures
Gitlab::Gpg::InvalidGpgSignatureUpdater.new(self).run
InvalidGpgSignatureUpdateWorker.perform_async(self.id)
end
private
......@@ -74,4 +74,8 @@ def extract_primary_keyid
def notify_user
run_after_commit { NotificationService.new.new_gpg_key(self) }
end
def update_invalid_gpg_signatures_after_create
run_after_commit { update_invalid_gpg_signatures }
end
end
......@@ -11,6 +11,7 @@ class User < ActiveRecord::Base
include CaseSensitivity
include TokenAuthenticatable
include IgnorableColumn
include AfterCommitQueue
DEFAULT_NOTIFICATION_LEVEL = :participating
......@@ -504,7 +505,7 @@ def update_emails_with_primary_email
end
def update_invalid_gpg_signatures
gpg_keys.each(&:update_invalid_gpg_signatures)
run_after_commit { gpg_keys.each(&:update_invalid_gpg_signatures) }
end
# Returns the groups a user has access to
......
class InvalidGpgSignatureUpdateWorker
include Sidekiq::Worker
include DedicatedSidekiqQueue
def perform(gpg_key_id)
if gpg_key = GpgKey.find_by(id: gpg_key_id)
Gitlab::Gpg::InvalidGpgSignatureUpdater.new(gpg_key).run
else
Rails.logger.error("InvalidGpgSignatureUpdateWorker: couldn't find gpg_key with ID=#{gpg_key_id}, skipping job")
end
end
end
......@@ -55,3 +55,4 @@
- [update_user_activity, 1]
- [propagate_service_template, 1]
- [background_migration, 1]
- [invalid_gpg_signature_update, 2]
......@@ -223,7 +223,9 @@
user = create :user, email: 'unrelated.user@example.org'
project.team << [user, :master]
create :gpg_key, key: GpgHelpers::User1.public_key, user: user
Sidekiq::Testing.inline! do
create :gpg_key, key: GpgHelpers::User1.public_key, user: user
end
login_with(user)
......@@ -235,8 +237,10 @@
end
# user changes his email which makes the gpg key verified
user.skip_reconfirmation!
user.update_attributes!(email: GpgHelpers::User1.emails.first)
Sidekiq::Testing.inline! do
user.skip_reconfirmation!
user.update_attributes!(email: GpgHelpers::User1.emails.first)
end
visit namespace_project_commits_path(project.namespace, project, :master)
......@@ -260,7 +264,9 @@
end
# user adds the gpg key which makes the signature valid
create :gpg_key, key: GpgHelpers::User1.public_key, user: user
Sidekiq::Testing.inline! do
create :gpg_key, key: GpgHelpers::User1.public_key, user: user
end
visit namespace_project_commits_path(project.namespace, project, :master)
......
require 'spec_helper'
describe InvalidGpgSignatureUpdateWorker do
context 'when GpgKey is found' do
let(:gpg_key) { create(:gpg_key) }
it 'calls NotificationService.new.run' do
invalid_signature_updater = double(:invalid_signature_updater)
expect(Gitlab::Gpg::InvalidGpgSignatureUpdater).to receive(:new).with(gpg_key).and_return(invalid_signature_updater)
expect(invalid_signature_updater).to receive(:run)
described_class.new.perform(gpg_key.id)
end
end
context 'when GpgKey is not found' do
let(:nonexisting_gpg_key_id) { -1 }
it 'logs InvalidGpgSignatureUpdateWorker process skipping' do
expect(Rails.logger).to receive(:error).
with("InvalidGpgSignatureUpdateWorker: couldn't find gpg_key with ID=-1, skipping job")
described_class.new.perform(nonexisting_gpg_key_id)
end
it 'does not raise errors' do
expect { described_class.new.perform(nonexisting_gpg_key_id) }.not_to raise_error
end
it 'does not call NotificationService.new.run' do
expect(Gitlab::Gpg::InvalidGpgSignatureUpdater).not_to receive(:new)
described_class.new.perform(nonexisting_gpg_key_id)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment