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

delete_spec.rb « rule « protection « container_registry « mutations « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dd661c302ffd1cb3a1535b13146d403ad51f168d (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Deleting a container registry protection rule', :aggregate_failures, feature_category: :container_registry do
  include GraphqlHelpers

  let_it_be(:project) { create(:project, :repository) }
  let_it_be_with_refind(:container_protection_rule) do
    create(:container_registry_protection_rule, project: project)
  end

  let_it_be(:current_user) { create(:user, maintainer_projects: [project]) }

  let(:mutation) { graphql_mutation(:delete_container_registry_protection_rule, input) }
  let(:mutation_response) { graphql_mutation_response(:delete_container_registry_protection_rule) }
  let(:input) { { id: container_protection_rule.to_global_id } }

  subject(:post_graphql_mutation_delete_container_registry_protection_rule) do
    post_graphql_mutation(mutation, current_user: current_user)
  end

  shared_examples 'an erroneous response' do
    it { post_graphql_mutation_delete_container_registry_protection_rule.tap { expect(mutation_response).to be_blank } }

    it do
      expect { post_graphql_mutation_delete_container_registry_protection_rule }
        .not_to change { ::ContainerRegistry::Protection::Rule.count }
    end
  end

  it_behaves_like 'a working GraphQL mutation'

  it 'responds with deleted container registry protection rule' do
    expect { post_graphql_mutation_delete_container_registry_protection_rule }
      .to change { ::ContainerRegistry::Protection::Rule.count }.from(1).to(0)

    expect_graphql_errors_to_be_empty

    expect(mutation_response).to include(
      'errors' => be_blank,
      'containerRegistryProtectionRule' => {
        'id' => container_protection_rule.to_global_id.to_s,
        'repositoryPathPattern' => container_protection_rule.repository_path_pattern,
        'deleteProtectedUpToAccessLevel' => container_protection_rule.delete_protected_up_to_access_level.upcase,
        'pushProtectedUpToAccessLevel' => container_protection_rule.push_protected_up_to_access_level.upcase
      }
    )
  end

  context 'with existing container registry protection rule belonging to other project' do
    let_it_be(:container_protection_rule) do
      create(:container_registry_protection_rule, repository_path_pattern: 'protection_rule_other_project')
    end

    it_behaves_like 'an erroneous response'

    it { is_expected.tap { expect_graphql_errors_to_include(/you don't have permission to perform this action/) } }
  end

  context 'with deleted container registry protection rule' do
    let!(:container_protection_rule) do
      create(:container_registry_protection_rule, project: project,
        repository_path_pattern: 'protection_rule_deleted').destroy!
    end

    it_behaves_like 'an erroneous response'

    it { is_expected.tap { expect_graphql_errors_to_include(/you don't have permission to perform this action/) } }
  end

  context 'when current_user does not have permission' do
    let_it_be(:developer) { create(:user).tap { |u| project.add_developer(u) } }
    let_it_be(:reporter) { create(:user).tap { |u| project.add_reporter(u) } }
    let_it_be(:guest) { create(:user).tap { |u| project.add_guest(u) } }
    let_it_be(:anonymous) { create(:user) }

    where(:current_user) do
      [ref(:developer), ref(:reporter), ref(:guest), ref(:anonymous)]
    end

    with_them do
      it_behaves_like 'an erroneous response'

      it { is_expected.tap { expect_graphql_errors_to_include(/you don't have permission to perform this action/) } }
    end
  end

  context "when feature flag ':container_registry_protected_containers' disabled" do
    before do
      stub_feature_flags(container_registry_protected_containers: false)
    end

    it_behaves_like 'an erroneous response'

    it do
      post_graphql_mutation_delete_container_registry_protection_rule

      expect_graphql_errors_to_include(/'container_registry_protected_containers' feature flag is disabled/)
    end
  end
end