Commit e1ab44be authored by Bob Van Landuyt's avatar Bob Van Landuyt

Validate the commit using all known email addresses for the user

parent 5e42f026
......@@ -33,11 +33,11 @@ class PushRule < ActiveRecord::Base
commit.has_signature?
end
def author_allowed?(committer_email, current_user_email)
def committer_allowed?(committer, current_user)
return true unless available?(:commit_author_check)
return true unless commit_author_check
committer_email.casecmp(current_user_email) == 0
current_user == committer
end
def commit_message_allowed?(message)
......
......@@ -213,7 +213,7 @@ module Gitlab
return "Author's email '#{commit.author_email}' does not follow the pattern '#{push_rule.author_email_regex}'"
end
unless push_rule.author_allowed?(commit.committer_email, user_access.user.email)
unless push_rule.committer_allowed?(commit.committer, user_access.user)
return "You can only push your own commits to this repository"
end
......
......@@ -456,6 +456,13 @@ describe Gitlab::Checks::ChangeAccess do
it 'does not return an error' do
expect { subject }.not_to raise_error
end
it 'allows the commit when they were done with another email that belongs to the current user' do
allow_any_instance_of(Commit).to receive(:committer_email).and_return('secondary_email@user.com')
user.emails.create(email: 'secondary_email@user.com')
expect { subject }.not_to raise_error
end
end
context 'with a commit from a different user' do
......
......@@ -352,4 +352,6 @@ describe MergeRequests::MergeService do
end
end
end
context ''
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