summaryrefslogtreecommitdiff
path: root/spec/controllers/concerns/project_unauthorized_spec.rb
blob: 57ac00cf4ddb1c056725e7a4e23c6b2aebee1635 (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
# frozen_string_literal: true

require 'spec_helper'

describe ProjectUnauthorized do
  include ExternalAuthorizationServiceHelpers
  let(:user) { create(:user) }

  before do
    sign_in user
  end

  render_views

  describe '#project_unauthorized_proc' do
    controller(::Projects::ApplicationController) do
      def show
        head :ok
      end
    end

    let(:project) { create(:project) }

    before do
      project.add_developer(user)
    end

    it 'renders a 200 when the service allows access to the project' do
      external_service_allow_access(user, project)

      get :show, params: { namespace_id: project.namespace.to_param, id: project.to_param }

      expect(response).to have_gitlab_http_status(200)
    end

    it 'renders a 403 when the service denies access to the project' do
      external_service_deny_access(user, project)

      get :show, params: { namespace_id: project.namespace.to_param, id: project.to_param }

      expect(response).to have_gitlab_http_status(403)
      expect(response.body).to match("External authorization denied access to this project")
    end

    it 'renders a 404 when the user cannot see the project at all' do
      other_project = create(:project, :private)

      get :show, params: { namespace_id: other_project.namespace.to_param, id: other_project.to_param }

      expect(response).to have_gitlab_http_status(404)
    end
  end
end