blob: 62aaec851620a693ee3fdc305d20a777a7ec6a2e (
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
|
# frozen_string_literal: true
RSpec.shared_examples 'raw snippet blob' do
context 'with valid params' do
before do
subject
end
it 'delivers file with correct Workhorse headers' do
expect(response.header['Content-Type']).to eq('text/plain; charset=utf-8')
expect(response.header[Gitlab::Workhorse::DETECT_HEADER]).to eq 'true'
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with('git-blob:')
end
it 'responds with status 200' do
expect(response).to have_gitlab_http_status(:ok)
end
end
context 'Content Disposition' do
context 'when the disposition is inline' do
let(:inline) { true }
it 'returns inline in the content disposition header' do
subject
expect(response.header['Content-Disposition']).to eq('inline')
end
end
context 'when the disposition is attachment' do
let(:inline) { false }
it 'returns attachment plus the filename in the content disposition header' do
subject
expect(response.header['Content-Disposition']).to match "attachment; filename=\"#{filepath}\""
end
context 'when the feature flag attachment_with_filename is disabled' do
it 'returns just attachment in the disposition header' do
stub_feature_flags(attachment_with_filename: false)
subject
expect(response.header['Content-Disposition']).to eq 'attachment'
end
end
end
end
context 'with invalid file path' do
let(:filepath) { 'doesnotexist' }
it_behaves_like 'returning response status', :not_found
end
context 'with invalid ref' do
let(:ref) { 'doesnotexist' }
it_behaves_like 'returning response status', :not_found
end
it_behaves_like 'content disposition headers'
end
RSpec.shared_examples 'raw snippet without repository' do |unauthorized_status|
context 'when authorized' do
it 'returns a 422' do
subject
expect(response).to have_gitlab_http_status(:unprocessable_entity)
end
end
context 'when unauthorized' do
let(:visibility) { :private }
it_behaves_like 'returning response status', unauthorized_status
end
end
|