Commit ce8e273a authored by Rubén Dávila's avatar Rubén Dávila Committed by Bob Van Landuyt

Check commit author for regular commits

parent c9caccd9
......@@ -44,6 +44,7 @@ class PushRule < ActiveRecord::Base
branch_name_regex.present? ||
author_email_regex.present? ||
reject_unsigned_commits ||
commit_author_check ||
member_check ||
file_name_regex.present? ||
max_file_size > 0 ||
......
......@@ -230,6 +230,12 @@ module Gitlab
end
end
if push_rule.commit_author_check
unless commit.committer_email.casecmp(user_access.user.email) == 0
return "You can only push your own commits to this repository"
end
end
nil
end
......
......@@ -440,6 +440,30 @@ describe Gitlab::Checks::ChangeAccess do
end
end
end
context 'Check commit author rules' do
let(:push_rule) { create(:push_rule, commit_author_check: true) }
context 'with a commit from the authenticated user' do
before do
allow_any_instance_of(Commit).to receive(:committer_email).and_return(user.email)
end
it 'does not return an error' do
expect { subject }.not_to raise_error
end
end
context 'with a commit from a different user' do
before do
allow_any_instance_of(Commit).to receive(:committer_email).and_return('some@mail.com')
end
it 'returns an error' do
expect { subject }.to raise_error(Gitlab::GitAccess::UnauthorizedError, "You can only push your own commits to this repository")
end
end
end
end
context 'file lock rules' do
......
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