2020-12-03 18:10:10 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Auth::DependencyProxyAuthenticationService do
|
|
|
|
let_it_be(:user) { create(:user) }
|
2021-06-29 03:07:32 +00:00
|
|
|
|
2020-12-03 18:10:10 +00:00
|
|
|
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 15:09:35 +00:00
|
|
|
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-08-04 09:08:21 +00:00
|
|
|
shared_examples 'returning a token' do
|
|
|
|
it 'returns a token' do
|
|
|
|
expect(subject[:token]).not_to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-03 18:10:10 +00:00
|
|
|
context 'dependency proxy is not enabled' do
|
|
|
|
before do
|
|
|
|
stub_config(dependency_proxy: { enabled: false })
|
|
|
|
end
|
|
|
|
|
2021-04-28 15:09:35 +00:00
|
|
|
it_behaves_like 'returning', status: 404, message: 'dependency proxy not enabled'
|
2020-12-03 18:10:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'without a user' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
2021-04-28 15:09:35 +00:00
|
|
|
it_behaves_like 'returning', status: 403, message: 'access forbidden'
|
|
|
|
end
|
|
|
|
|
2021-08-04 09:08:21 +00:00
|
|
|
context 'with a deploy token as user' do
|
|
|
|
let_it_be(:user) { create(:deploy_token, :group, :dependency_proxy_scopes) }
|
|
|
|
|
|
|
|
it_behaves_like 'returning a token'
|
|
|
|
end
|
|
|
|
|
2020-12-03 18:10:10 +00:00
|
|
|
context 'with a user' do
|
2021-08-04 09:08:21 +00:00
|
|
|
it_behaves_like 'returning a token'
|
2020-12-03 18:10:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|