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

secure_files_spec.rb « settings « projects « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ee38acf19532c08823f3b46da7e518300ee7fa20 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Secure Files', :js do
  let(:project) { create(:project) }
  let(:user) { create(:user) }

  before do
    stub_feature_flags(ci_secure_files_read_only: false)
    project.add_maintainer(user)
    sign_in(user)
  end

  context 'when the :ci_secure_files feature flag is enabled' do
    before do
      stub_feature_flags(ci_secure_files: true)

      visit project_settings_ci_cd_path(project)
    end

    context 'authenticated user with admin permissions' do
      it 'shows the secure files settings' do
        expect(page).to have_content('Secure Files')
      end
    end
  end

  context 'when the :ci_secure_files feature flag is disabled' do
    before do
      stub_feature_flags(ci_secure_files: false)

      visit project_settings_ci_cd_path(project)
    end

    context 'authenticated user with admin permissions' do
      it 'does not shows the secure files settings' do
        expect(page).not_to have_content('Secure Files')
      end
    end
  end

  it 'user sees the Secure Files list component' do
    visit project_settings_ci_cd_path(project)

    within '#js-secure-files' do
      expect(page).to have_content('There are no secure files yet.')
    end
  end

  it 'prompts the user to confirm before deleting a file' do
    file = create(:ci_secure_file, project: project)

    visit project_settings_ci_cd_path(project)

    within '#js-secure-files' do
      expect(page).to have_content(file.name)

      find('button.btn-danger-secondary').click
    end

    expect(page).to have_content("Delete #{file.name}?")

    click_on('Delete secure file')

    visit project_settings_ci_cd_path(project)

    within '#js-secure-files' do
      expect(page).not_to have_content(file.name)
    end
  end

  it 'displays an uploaded file in the file list' do
    visit project_settings_ci_cd_path(project)

    within '#js-secure-files' do
      expect(page).to have_content('There are no secure files yet.')

      page.attach_file('spec/fixtures/ci_secure_files/upload-keystore.jks') do
        click_button 'Upload File'
      end

      expect(page).to have_content('upload-keystore.jks')
    end
  end

  it 'displays an error when a duplicate file upload is attempted' do
    create(:ci_secure_file, project: project, name: 'upload-keystore.jks')
    visit project_settings_ci_cd_path(project)

    within '#js-secure-files' do
      expect(page).to have_content('upload-keystore.jks')

      page.attach_file('spec/fixtures/ci_secure_files/upload-keystore.jks') do
        click_button 'Upload File'
      end

      expect(page).to have_content('A file with this name already exists.')
    end
  end
end