Welcome to mirror list, hosted at ThFree Co, Russian Federation.

container_registry_authentication_service_spec.rb « auth « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b456f7a2745a03b948634b9d40da58eff6a25fb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Auth::ContainerRegistryAuthenticationService do
  include AdminModeHelper

  it_behaves_like 'a container registry auth service'

  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

      it_behaves_like 'a modified token'
    end

    context 'with push action' do
      let(:current_params) do
        { scopes: ["repository:#{project.full_path}:push"] }
      end

      it_behaves_like 'a modified token'
    end

    context 'with multiple actions' do
      let(:current_params) do
        { scopes: ["repository:#{project.full_path}:pull,push,delete"] }
      end

      it_behaves_like 'a modified token'
    end
  end
end