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

Add a spec for a fast forward merge

parent c5159a49
...@@ -440,65 +440,73 @@ describe Gitlab::Checks::ChangeAccess do ...@@ -440,65 +440,73 @@ describe Gitlab::Checks::ChangeAccess do
end end
end end
end end
end
context 'Check commit author rules' do context 'file lock rules' do
before do let!(:path_lock) { create(:path_lock, path: 'README', project: project) }
stub_licensed_features(commit_committer_check: true)
end
let(:push_rule) { create(:push_rule, commit_committer_check: true) }
context 'with a commit from the authenticated user' do before do
before do allow(project.repository).to receive(:new_commits).and_return(
allow_any_instance_of(Commit).to receive(:committer_email).and_return(user.email) project.repository.commits_between('be93687618e4b132087f430a4d8fc3a609c9b77c', '54fcc214b94e78d7a41a9a8fe6d87a5e59500e51')
end )
end
it 'does not return an error' do it 'returns an error if the changes update a path locked by another user' do
expect { subject }.not_to raise_error expect { subject }.to raise_error(Gitlab::GitAccess::UnauthorizedError, "The path 'README' is locked by #{path_lock.user.name}")
end end
end
it 'allows the commit when they were done with another email that belongs to the current user' do context 'Check commit author rules' do
allow_any_instance_of(Commit).to receive(:committer_email).and_return('secondary_email@user.com') before do
user.emails.create(email: 'secondary_email@user.com', confirmed_at: Time.now) stub_licensed_features(commit_committer_check: true)
end
expect { subject }.not_to raise_error let(:push_rule) { create(:push_rule, commit_committer_check: true) }
end let(:project) { create(:project, :public, :repository, push_rule: push_rule) }
it 'raises an error when the commit was done with an unverified email' do context 'with a commit from the authenticated user' do
allow_any_instance_of(Commit).to receive(:committer_email).and_return('secondary_email@user.com') before do
user.emails.create(email: 'secondary_email@user.com') allow(project.repository).to receive(:new_commits).and_return(
project.repository.commits_between('be93687618e4b132087f430a4d8fc3a609c9b77c', '54fcc214b94e78d7a41a9a8fe6d87a5e59500e51')
)
allow_any_instance_of(Commit).to receive(:committer_email).and_return(user.email)
end
expect { subject } it 'does not return an error' do
.to raise_error(Gitlab::GitAccess::UnauthorizedError, expect { subject }.not_to raise_error
"Committer email 'secondary_email@user.com' not verified. Verify the email on your profile page.")
end
end end
context 'with a commit using an unknown e-mail' do it 'allows the commit when they were done with another email that belongs to the current user' do
before do user.emails.create(email: 'secondary_email@user.com', confirmed_at: Time.now)
allow_any_instance_of(Commit).to receive(:committer_email).and_return('some@mail.com') allow_any_instance_of(Commit).to receive(:committer_email).and_return('secondary_email@user.com')
end
it 'returns an error' do expect { subject }.not_to raise_error
expect { subject }
.to raise_error(Gitlab::GitAccess::UnauthorizedError,
"Committer 'some@mail.com' unknown, do you need to add that email to your profile?")
end
end end
end
end
context 'file lock rules' do it 'raises an error when the commit was done with an unverified email' do
let!(:path_lock) { create(:path_lock, path: 'README', project: project) } user.emails.create(email: 'secondary_email@user.com')
allow_any_instance_of(Commit).to receive(:committer_email).and_return('secondary_email@user.com')
before do expect { subject }
allow(project.repository).to receive(:new_commits).and_return( .to raise_error(Gitlab::GitAccess::UnauthorizedError,
project.repository.commits_between('be93687618e4b132087f430a4d8fc3a609c9b77c', '54fcc214b94e78d7a41a9a8fe6d87a5e59500e51') "Committer email 'secondary_email@user.com' not verified. Verify the email on your profile page.")
) end
it 'raises an error when using an unknown email' do
allow_any_instance_of(Commit).to receive(:committer_email).and_return('some@mail.com')
expect { subject }
.to raise_error(Gitlab::GitAccess::UnauthorizedError,
"Committer 'some@mail.com' unknown, do you need to add that email to your profile?")
end
end end
it 'returns an error if the changes update a path locked by another user' do context 'for an ff merge request' do
expect { subject }.to raise_error(Gitlab::GitAccess::UnauthorizedError, "The path 'README' is locked by #{path_lock.user.name}") # the signed-commits branch fast-forwards onto master
let(:newrev) { '2d1096e3' }
it 'does not raise errors for a fast forward' do
expect { subject }.not_to raise_error
end
end end
end 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