debian-mirror-gitlab/spec/services/auth/dependency_proxy_authentication_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.4 KiB
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Auth::DependencyProxyAuthenticationService, feature_category: :dependency_proxy do
2021-02-22 17:27:13 +05:30
let_it_be(:user) { create(:user) }
2021-09-30 23:02:18 +05:30
2021-02-22 17:27:13 +05:30
let(:service) { Auth::DependencyProxyAuthenticationService.new(nil, user) }
before do
stub_config(dependency_proxy: { enabled: true })
end
describe '#execute' do
subject { service.execute(authentication_abilities: nil) }
2021-04-28 17:22:55 +05:30
shared_examples 'returning' do |status:, message:|
it "returns #{message}", :aggregate_failures do
expect(subject[:http_status]).to eq(status)
expect(subject[:message]).to eq(message)
end
end
2021-10-27 15:23:28 +05:30
shared_examples 'returning a token' do
it 'returns a token' do
expect(subject[:token]).not_to be_nil
end
end
2021-02-22 17:27:13 +05:30
context 'dependency proxy is not enabled' do
before do
stub_config(dependency_proxy: { enabled: false })
end
2021-04-28 17:22:55 +05:30
it_behaves_like 'returning', status: 404, message: 'dependency proxy not enabled'
2021-02-22 17:27:13 +05:30
end
context 'without a user' do
let(:user) { nil }
2021-04-28 17:22:55 +05:30
it_behaves_like 'returning', status: 403, message: 'access forbidden'
end
context 'with a deploy token as user' do
2021-10-27 15:23:28 +05:30
let_it_be(:user) { create(:deploy_token, :group, :dependency_proxy_scopes) }
2021-02-22 17:27:13 +05:30
2021-10-27 15:23:28 +05:30
it_behaves_like 'returning a token'
2021-02-22 17:27:13 +05:30
end
context 'with a user' do
2021-10-27 15:23:28 +05:30
it_behaves_like 'returning a token'
2021-02-22 17:27:13 +05:30
end
end
end