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

dashboard_controller_spec.rb « agents « clusters « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c3c16d9b38549aac6edc965b8de63fd424ddedbc (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Clusters::Agents::DashboardController, feature_category: :deployment_management do
  describe 'GET show' do
    let_it_be(:organization) { create(:group) }
    let_it_be(:agent_management_project) { create(:project, group: organization) }
    let_it_be(:agent) { create(:cluster_agent, project: agent_management_project) }
    let_it_be(:deployment_project) { create(:project, group: organization) }
    let(:user) { create(:user) }
    let(:stub_ff) { true }

    before do
      allow(::Gitlab::Kas).to receive(:enabled?).and_return(true)
    end

    context 'with authorized user' do
      let!(:authorization) do
        create(
          :agent_user_access_project_authorization,
          agent: agent,
          project: deployment_project
        )
      end

      before do
        stub_feature_flags(k8s_dashboard: stub_ff)
        deployment_project.add_member(user, :developer)
        sign_in(user)
        get kubernetes_dashboard_path(agent.id)
      end

      it 'sets the kas cookie' do
        expect(
          request.env['action_dispatch.cookies'][Gitlab::Kas::COOKIE_KEY]
        ).to be_present
      end

      it 'returns not found' do
        expect(response).to have_gitlab_http_status(:ok)
      end

      context 'with k8s_dashboard feature flag disabled' do
        let(:stub_ff) { false }

        it 'does not set the kas cookie' do
          expect(
            request.env['action_dispatch.cookies'][Gitlab::Kas::COOKIE_KEY]
          ).not_to be_present
        end

        it 'returns not found' do
          expect(response).to have_gitlab_http_status(:not_found)
        end
      end
    end

    context 'with unauthorized user' do
      before do
        sign_in(user)
        get kubernetes_dashboard_path(agent.id)
      end

      it 'does not set the kas cookie' do
        expect(
          request.env['action_dispatch.cookies'][Gitlab::Kas::COOKIE_KEY]
        ).not_to be_present
      end

      it 'returns not found' do
        expect(response).to have_gitlab_http_status(:not_found)
      end
    end
  end
end