2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-05-09 15:06:32 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe Auth::ContainerRegistryAuthenticationService do
|
2020-11-11 07:09:06 -05:00
|
|
|
include AdminModeHelper
|
|
|
|
|
2020-12-16 22:10:36 -05:00
|
|
|
it_behaves_like 'a container registry auth service'
|
2021-07-14 14:08:31 -04:00
|
|
|
|
|
|
|
context 'when in migration mode' do
|
|
|
|
include_context 'container registry auth service context'
|
|
|
|
|
|
|
|
let_it_be(:current_user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'a modified token with migration eligibility' do |eligible|
|
|
|
|
it_behaves_like 'a valid token'
|
|
|
|
it { expect(payload['access']).to include(include('migration_eligible' => eligible)) }
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'a modified token' do
|
|
|
|
context 'with a non eligible root ancestor and project' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(container_registry_migration_phase1_deny: project.root_ancestor)
|
|
|
|
stub_feature_flags(container_registry_migration_phase1_allow: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a modified token with migration eligibility', false
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a non eligible root ancestor and eligible project' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(container_registry_migration_phase1_deny: false)
|
|
|
|
stub_feature_flags(container_registry_migration_phase1_deny: project.root_ancestor)
|
|
|
|
stub_feature_flags(container_registry_migration_phase1_allow: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a modified token with migration eligibility', false
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an eligible root ancestor and non eligible project' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(container_registry_migration_phase1_deny: false)
|
|
|
|
stub_feature_flags(container_registry_migration_phase1_allow: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a modified token with migration eligibility', false
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an eligible root ancestor and project' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(container_registry_migration_phase1_deny: false)
|
|
|
|
stub_feature_flags(container_registry_migration_phase1_allow: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a modified token with migration eligibility', true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with pull action' do
|
|
|
|
let(:current_params) do
|
|
|
|
{ scopes: ["repository:#{project.full_path}:pull"] }
|
|
|
|
end
|
|
|
|
|
2021-08-13 11:11:15 -04:00
|
|
|
it_behaves_like 'a modified token'
|
2021-07-14 14:08:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with push action' do
|
|
|
|
let(:current_params) do
|
|
|
|
{ scopes: ["repository:#{project.full_path}:push"] }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a modified token'
|
|
|
|
end
|
|
|
|
|
2021-08-13 11:11:15 -04:00
|
|
|
context 'with multiple actions' do
|
2021-07-14 14:08:31 -04:00
|
|
|
let(:current_params) do
|
|
|
|
{ scopes: ["repository:#{project.full_path}:pull,push,delete"] }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a modified token'
|
|
|
|
end
|
2021-08-19 05:10:34 -04:00
|
|
|
|
|
|
|
describe '#access_token' do
|
|
|
|
let(:token) { described_class.access_token(%w[push], [project.full_path]) }
|
|
|
|
|
|
|
|
subject { { token: token } }
|
|
|
|
|
|
|
|
it_behaves_like 'a modified token'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not in migration mode' do
|
|
|
|
include_context 'container registry auth service context'
|
|
|
|
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_feature_flags(container_registry_migration_phase1: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'an unmodified token' do
|
|
|
|
it_behaves_like 'a valid token'
|
|
|
|
it { expect(payload['access']).not_to include(have_key('migration_eligible')) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#access_token' do
|
|
|
|
let(:token) { described_class.access_token(%w[push], [project.full_path]) }
|
|
|
|
|
|
|
|
subject { { token: token } }
|
|
|
|
|
|
|
|
it_behaves_like 'an unmodified token'
|
|
|
|
end
|
2021-07-14 14:08:31 -04:00
|
|
|
end
|
2016-05-09 15:06:32 -04:00
|
|
|
end
|