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

Add a spec for a fast forward merge

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