Commit e63b693f authored by Alexis Reigel's avatar Alexis Reigel

generate gpg signature on push

parent 4c5d4a69
...@@ -56,6 +56,8 @@ class GitPushService < BaseService ...@@ -56,6 +56,8 @@ class GitPushService < BaseService
perform_housekeeping perform_housekeeping
update_caches update_caches
update_signatures
end end
def update_gitattributes def update_gitattributes
...@@ -80,6 +82,12 @@ class GitPushService < BaseService ...@@ -80,6 +82,12 @@ class GitPushService < BaseService
ProjectCacheWorker.perform_async(@project.id, types, [:commit_count, :repository_size]) ProjectCacheWorker.perform_async(@project.id, types, [:commit_count, :repository_size])
end end
def update_signatures
@push_commits.each do |commit|
CreateGpgSignatureWorker.perform_async(commit.sha, @project.id)
end
end
# Schedules processing of commit messages. # Schedules processing of commit messages.
def process_commit_messages def process_commit_messages
default = is_default_branch? default = is_default_branch?
......
class CreateGpgSignatureWorker
include Sidekiq::Worker
include DedicatedSidekiqQueue
def perform(commit_sha, project_id)
project = Project.find_by(id: project_id)
unless project
return Rails.logger.error("CreateGpgSignatureWorker: couldn't find project with ID=#{project_id}, skipping job")
end
commit = project.commit(commit_sha)
unless commit
return Rails.logger.error("CreateGpgSignatureWorker: couldn't find commit with commit_sha=#{commit_sha}, skipping job")
end
commit.signature
end
end
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
- [emails_on_push, 2] - [emails_on_push, 2]
- [mailers, 2] - [mailers, 2]
- [invalid_gpg_signature_update, 2] - [invalid_gpg_signature_update, 2]
- [create_gpg_signature, 2]
- [upload_checksum, 1] - [upload_checksum, 1]
- [use_key, 1] - [use_key, 1]
- [repository_fork, 1] - [repository_fork, 1]
......
...@@ -681,6 +681,24 @@ describe GitPushService, services: true do ...@@ -681,6 +681,24 @@ describe GitPushService, services: true do
end end
end end
describe '#update_signatures' do
let(:service) do
described_class.new(
project,
user,
oldrev: sample_commit.parent_id,
newrev: sample_commit.id,
ref: 'refs/heads/master'
)
end
it 'calls CreateGpgSignatureWorker.perform_async for each commit' do
expect(CreateGpgSignatureWorker).to receive(:perform_async).with(sample_commit.id, project.id)
execute_service(project, user, @oldrev, @newrev, @ref)
end
end
def execute_service(project, user, oldrev, newrev, ref) def execute_service(project, user, oldrev, newrev, ref)
service = described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref ) service = described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref )
service.execute service.execute
......
require 'spec_helper'
describe CreateGpgSignatureWorker do
context 'when GpgKey is found' do
it 'calls Commit#signature' do
commit_sha = '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'
project = create :project
commit = instance_double(Commit)
allow(Project).to receive(:find_by).with(id: project.id).and_return(project)
allow(project).to receive(:commit).with(commit_sha).and_return(commit)
expect(commit).to receive(:signature)
described_class.new.perform(commit_sha, project.id)
end
end
context 'when Commit is not found' do
let(:nonexisting_commit_sha) { 'bogus' }
let(:project) { create :project }
it 'logs CreateGpgSignatureWorker process skipping' do
expect(Rails.logger).to receive(:error)
.with("CreateGpgSignatureWorker: couldn't find commit with commit_sha=bogus, skipping job")
described_class.new.perform(nonexisting_commit_sha, project.id)
end
it 'does not raise errors' do
expect { described_class.new.perform(nonexisting_commit_sha, project.id) }.not_to raise_error
end
it 'does not call Commit#signature' do
expect_any_instance_of(Commit).not_to receive(:signature)
described_class.new.perform(nonexisting_commit_sha, project.id)
end
end
context 'when Project is not found' do
let(:nonexisting_project_id) { -1 }
it 'logs CreateGpgSignatureWorker process skipping' do
expect(Rails.logger).to receive(:error)
.with("CreateGpgSignatureWorker: couldn't find project with ID=-1, skipping job")
described_class.new.perform(anything, nonexisting_project_id)
end
it 'does not raise errors' do
expect { described_class.new.perform(anything, nonexisting_project_id) }.not_to raise_error
end
it 'does not call Commit#signature' do
expect_any_instance_of(Commit).not_to receive(:signature)
described_class.new.perform(anything, nonexisting_project_id)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment