File: package_files_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (47 lines) | stat: -rw-r--r-- 1,262 bytes parent folder | download
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'PackageFiles', feature_category: :groups_and_projects do
  let(:user) { create(:user) }
  let(:project) { create(:project) }
  let!(:package) { create(:maven_package, project: project) }
  let!(:package_file) { package.package_files.first }

  before do
    sign_in(user)
  end

  context 'user with master role' do
    before do
      project.add_maintainer(user)
    end

    it 'allows direct download by url' do
      visit download_project_package_file_path(project, package_file)

      expect(status_code).to eq(200)
    end

    it 'does not allow download of package belonging to different project' do
      another_package = create(:maven_package)
      another_file = another_package.package_files.first

      visit download_project_package_file_path(project, another_file)

      expect(status_code).to eq(404)
    end
  end

  it 'does not allow direct download when no access to the project' do
    visit download_project_package_file_path(project, package_file)

    expect(status_code).to eq(404)
  end

  it 'gives 404 when no package file exist' do
    visit download_project_package_file_path(project, non_existing_record_id)

    expect(status_code).to eq(404)
  end
end