diff options
author | Mayra Cabrera <mcabrera@gitlab.com> | 2018-04-01 01:45:02 +0300 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2018-04-07 05:20:16 +0300 |
commit | aaa6d80870d5215390a7cd919d91309e5a8795b7 (patch) | |
tree | ddc2f5c4f52e0b280c85096784b70d8131f8da10 /spec/lib | |
parent | 345ac03b7afb1dc9b941c53bc45cc3dfcf22e61c (diff) |
Implement read_registry for DeployTokens
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/auth_spec.rb | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/spec/lib/gitlab/auth_spec.rb b/spec/lib/gitlab/auth_spec.rb index 685a0bb54be..758fb17cd81 100644 --- a/spec/lib/gitlab/auth_spec.rb +++ b/spec/lib/gitlab/auth_spec.rb @@ -270,14 +270,6 @@ describe Gitlab::Auth do .to eq(auth_success) end - it 'fails if deploy token does not have read_repo as scope' do - deploy_token = create(:deploy_token, :read_registry, project: project) - - expect(gl_auth).to receive(:rate_limit!).with('ip', success: false, login: '') - expect(gl_auth.find_for_git_client('', deploy_token.token, project: project, ip: 'ip')) - .to eq(auth_failure) - end - it 'fails if token is nil' do expect(gl_auth).to receive(:rate_limit!).with('ip', success: false, login: '') expect(gl_auth.find_for_git_client('', nil, project: project, ip: 'ip')) @@ -305,6 +297,35 @@ describe Gitlab::Auth do expect(gl_auth.find_for_git_client('deploy-token', deploy_token.token, project: project, ip: 'ip')) .to eq(auth_failure) end + + context 'when registry enabled' do + before do + stub_container_registry_config(enabled: true) + end + + it 'succeeds if deploy token does have read_registry as scope' do + deploy_token = create(:deploy_token, :read_registry, project: project) + auth_success = Gitlab::Auth::Result.new(deploy_token, project, :deploy_token, [:read_container_image]) + + expect(gl_auth).to receive(:rate_limit!).with('ip', success: true, login: '') + expect(gl_auth.find_for_git_client('', deploy_token.token, project: project, ip: 'ip')) + .to eq(auth_success) + end + end + + context 'when registry disabled' do + before do + stub_container_registry_config(enabled: false) + end + + it 'fails if deploy token have read_registry as scope' do + deploy_token = create(:deploy_token, :read_registry, project: project) + + expect(gl_auth).to receive(:rate_limit!).with('ip', success: false, login: '') + expect(gl_auth.find_for_git_client('', deploy_token.token, project: project, ip: 'ip')) + .to eq(auth_failure) + end + end end end |