diff options
Diffstat (limited to 'spec/lib/gitlab/checks/push_check_spec.rb')
-rw-r--r-- | spec/lib/gitlab/checks/push_check_spec.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/lib/gitlab/checks/push_check_spec.rb b/spec/lib/gitlab/checks/push_check_spec.rb index 45ab13cf0cf..262438256b4 100644 --- a/spec/lib/gitlab/checks/push_check_spec.rb +++ b/spec/lib/gitlab/checks/push_check_spec.rb @@ -18,5 +18,26 @@ RSpec.describe Gitlab::Checks::PushCheck do expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You are not allowed to push code to this project.') end end + + context 'when using a DeployKeyAccess instance' do + let(:deploy_key) { create(:deploy_key) } + let(:user_access) { Gitlab::DeployKeyAccess.new(deploy_key, container: project) } + + context 'when the deploy key cannot push to the targetted branch' do + it 'raises an error' do + allow(user_access).to receive(:can_push_to_branch?).and_return(false) + + expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You are not allowed to push code to this project.') + end + end + + context 'when the deploy key can push to the targetted branch' do + it 'is valid' do + allow(user_access).to receive(:can_push_to_branch?).and_return(true) + + expect { subject.validate! }.not_to raise_error + end + end + end end end |