summaryrefslogtreecommitdiff
path: root/spec/requests/projects/blob_spec.rb
blob: 7d62619e76aadcf9aec8ba11d204a42def210bed (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Blobs', feature_category: :source_code_management do
  let_it_be(:project) { create(:project, :public, :repository, lfs: true) }

  describe 'GET /:namespace_id/:project_id/-/blob/:id' do
    subject(:request) do
      get namespace_project_blob_path(namespace_id: project.namespace, project_id: project, id: id)
    end

    context 'with LFS file' do
      let(:id) { 'master/files/lfs/lfs_object.iso' }
      let(:object_store_host) { 'http://127.0.0.1:9000' }
      let(:connect_src) do
        csp = response.headers['Content-Security-Policy']
        csp.split('; ').find { |src| src.starts_with?('connect-src') }
      end

      let(:gitlab_config) do
        Gitlab.config.gitlab.deep_merge(
          'content_security_policy' => {
            'enabled' => content_security_policy_enabled
          }
        )
      end

      let(:lfs_config) do
        Gitlab.config.lfs.deep_merge(
          'enabled' => lfs_enabled,
          'object_store' => {
            'remote_directory' => 'lfs-objects',
            'enabled' => true,
            'proxy_download' => proxy_download,
            'connection' => {
              'endpoint' => object_store_host,
              'path_style' => true
            }
          }
        )
      end

      before do
        stub_config_setting(gitlab_config)
        stub_lfs_setting(lfs_config)
        stub_lfs_object_storage(proxy_download: proxy_download)

        request
      end

      describe 'directly downloading lfs file' do
        let(:lfs_enabled) { true }
        let(:proxy_download) { false }
        let(:content_security_policy_enabled) { true }

        it { expect(response).to have_gitlab_http_status(:success) }

        it { expect(connect_src).to include(object_store_host) }

        context 'when lfs is disabled' do
          let(:lfs_enabled) { false }

          it { expect(response).to have_gitlab_http_status(:success) }

          it { expect(connect_src).not_to include(object_store_host) }
        end

        context 'when content_security_policy is disabled' do
          let(:content_security_policy_enabled) { false }

          it { expect(response).to have_gitlab_http_status(:success) }

          it { expect(connect_src).not_to include(object_store_host) }
        end

        context 'when proxy download is enabled' do
          let(:proxy_download) { true }

          it { expect(response).to have_gitlab_http_status(:success) }

          it { expect(connect_src).not_to include(object_store_host) }
        end
      end
    end
  end
end