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