2019-04-15 10:17:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-03-10 13:50:42 +00:00
|
|
|
require 'spec_helper'
|
2020-06-03 18:08:28 +00:00
|
|
|
RSpec.shared_examples 'content 5 min private cached with revalidation' do
|
2017-02-22 18:30:53 +00:00
|
|
|
it 'ensures content will not be cached without revalidation' do
|
2019-10-14 15:06:07 +00:00
|
|
|
expect(subject['Cache-Control']).to eq('max-age=300, private, must-revalidate')
|
2017-02-22 18:30:53 +00:00
|
|
|
end
|
|
|
|
end
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-06-03 18:08:28 +00:00
|
|
|
RSpec.shared_examples 'content not cached' do
|
2018-10-18 11:28:12 +00:00
|
|
|
it 'ensures content will not be cached without revalidation' do
|
2019-11-01 15:06:21 +00:00
|
|
|
expect(subject['Cache-Control']).to eq('max-age=0, private, must-revalidate')
|
2018-10-18 11:28:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-03 18:08:28 +00:00
|
|
|
RSpec.shared_examples 'content publicly cached' do
|
2019-01-21 21:25:54 +00:00
|
|
|
it 'ensures content is publicly cached' do
|
|
|
|
expect(subject['Cache-Control']).to eq('max-age=300, public')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-03 18:08:28 +00:00
|
|
|
RSpec.describe UploadsController do
|
2019-07-09 18:51:42 +00:00
|
|
|
include WorkhorseHelpers
|
|
|
|
|
2018-06-05 21:18:06 +00:00
|
|
|
let!(:user) { create(:user, avatar: fixture_file_upload("spec/fixtures/dk.png", "image/png")) }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2019-07-09 18:51:42 +00:00
|
|
|
describe 'POST #authorize' do
|
|
|
|
it_behaves_like 'handle uploads authorize' do
|
|
|
|
let(:uploader_class) { PersonalFileUploader }
|
|
|
|
let(:model) { create(:personal_snippet, :public) }
|
|
|
|
let(:params) do
|
|
|
|
{ model: 'personal_snippet', id: model.id }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-01 13:14:35 +00:00
|
|
|
describe 'POST create' do
|
2018-06-05 21:18:06 +00:00
|
|
|
let(:jpg) { fixture_file_upload('spec/fixtures/rails_sample.jpg', 'image/jpg') }
|
|
|
|
let(:txt) { fixture_file_upload('spec/fixtures/doc_sample.txt', 'text/plain') }
|
2017-05-01 13:14:35 +00:00
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
context 'snippet uploads' do
|
|
|
|
let(:model) { 'personal_snippet' }
|
|
|
|
let(:snippet) { create(:personal_snippet, :public) }
|
2017-05-01 13:14:35 +00:00
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
context 'when a user does not have permissions to upload a file' do
|
|
|
|
it "returns 401 when the user is not logged in" do
|
|
|
|
post :create, params: { model: model, id: snippet.id }, format: :json
|
2017-05-01 13:14:35 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2019-06-04 23:50:57 +00:00
|
|
|
end
|
2017-05-01 13:14:35 +00:00
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
it "returns 404 when user can't comment on a snippet" do
|
|
|
|
private_snippet = create(:personal_snippet, :private)
|
2017-05-01 13:14:35 +00:00
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
sign_in(user)
|
|
|
|
post :create, params: { model: model, id: private_snippet.id }, format: :json
|
2017-05-01 13:14:35 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2019-06-04 23:50:57 +00:00
|
|
|
end
|
2017-05-01 13:14:35 +00:00
|
|
|
end
|
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
context 'when a user is logged in' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
2017-05-01 13:14:35 +00:00
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
it "returns an error without file" do
|
|
|
|
post :create, params: { model: model, id: snippet.id }, format: :json
|
2017-05-01 13:14:35 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:unprocessable_entity)
|
2019-06-04 23:50:57 +00:00
|
|
|
end
|
2017-05-01 13:14:35 +00:00
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
it "returns an error with invalid model" do
|
|
|
|
expect { post :create, params: { model: 'invalid', id: snippet.id }, format: :json }
|
|
|
|
.to raise_error(ActionController::UrlGenerationError)
|
|
|
|
end
|
2017-05-01 13:14:35 +00:00
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
it "returns 404 status when object not found" do
|
2020-04-01 15:07:45 +00:00
|
|
|
post :create, params: { model: model, id: non_existing_record_id }, format: :json
|
2017-05-01 13:14:35 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2017-05-01 13:14:35 +00:00
|
|
|
end
|
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
context 'with valid image' do
|
|
|
|
before do
|
|
|
|
post :create, params: { model: 'personal_snippet', id: snippet.id, file: jpg }, format: :json
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a content with original filename, new link, and correct type.' do
|
|
|
|
expect(response.body).to match '\"alt\":\"rails_sample\"'
|
|
|
|
expect(response.body).to match "\"url\":\"/uploads"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a corresponding Upload record' do
|
|
|
|
upload = Upload.last
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(upload).to exist
|
|
|
|
expect(upload.model).to eq snippet
|
|
|
|
end
|
|
|
|
end
|
2017-05-01 13:14:35 +00:00
|
|
|
end
|
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
context 'with valid non-image file' do
|
|
|
|
before do
|
|
|
|
post :create, params: { model: 'personal_snippet', id: snippet.id, file: txt }, format: :json
|
|
|
|
end
|
2017-05-01 13:14:35 +00:00
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
it 'returns a content with original filename, new link, and correct type.' do
|
|
|
|
expect(response.body).to match '\"alt\":\"doc_sample.txt\"'
|
|
|
|
expect(response.body).to match "\"url\":\"/uploads"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a corresponding Upload record' do
|
|
|
|
upload = Upload.last
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(upload).to exist
|
|
|
|
expect(upload.model).to eq snippet
|
|
|
|
end
|
2017-05-01 13:14:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-06-04 23:50:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'user uploads' do
|
|
|
|
let(:model) { 'user' }
|
|
|
|
|
|
|
|
it 'returns 401 when the user has no access' do
|
|
|
|
post :create, params: { model: 'user', id: user.id }, format: :json
|
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2019-06-04 23:50:57 +00:00
|
|
|
end
|
2017-05-01 13:14:35 +00:00
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
context 'when user is logged in' do
|
2017-05-01 13:14:35 +00:00
|
|
|
before do
|
2019-06-04 23:50:57 +00:00
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
|
|
|
post :create, params: { model: model, id: user.id, file: jpg }, format: :json
|
2017-05-01 13:14:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a content with original filename, new link, and correct type.' do
|
2019-06-04 23:50:57 +00:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response.body).to match '\"alt\":\"rails_sample\"'
|
|
|
|
expect(response.body).to match "\"url\":\"/uploads/-/system/user/#{user.id}/"
|
2017-05-01 13:14:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a corresponding Upload record' do
|
2019-06-04 23:50:57 +00:00
|
|
|
expect { subject }.to change { Upload.count }
|
|
|
|
|
2017-05-01 13:14:35 +00:00
|
|
|
upload = Upload.last
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(upload).to exist
|
2019-06-04 23:50:57 +00:00
|
|
|
expect(upload.model).to eq user
|
2017-05-01 13:14:35 +00:00
|
|
|
end
|
|
|
|
end
|
2017-05-29 07:54:35 +00:00
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
context 'with valid non-image file' do
|
|
|
|
subject do
|
|
|
|
post :create, params: { model: model, id: user.id, file: txt }, format: :json
|
|
|
|
end
|
2017-05-29 07:54:35 +00:00
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
it 'returns a content with original filename, new link, and correct type.' do
|
|
|
|
subject
|
2017-05-29 07:54:35 +00:00
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
expect(response.body).to match '\"alt\":\"doc_sample.txt\"'
|
|
|
|
expect(response.body).to match "\"url\":\"/uploads/-/system/user/#{user.id}/"
|
|
|
|
end
|
2017-05-29 07:54:35 +00:00
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
it 'creates a corresponding Upload record' do
|
|
|
|
expect { subject }.to change { Upload.count }
|
2017-05-29 07:54:35 +00:00
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
upload = Upload.last
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(upload).to exist
|
|
|
|
expect(upload.model).to eq user
|
|
|
|
end
|
|
|
|
end
|
2017-05-29 07:54:35 +00:00
|
|
|
end
|
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
it 'returns 404 when given user is not the logged in one' do
|
|
|
|
another_user = create(:user)
|
2017-05-29 07:54:35 +00:00
|
|
|
|
2019-06-04 23:50:57 +00:00
|
|
|
post :create, params: { model: model, id: another_user.id, file: txt }, format: :json
|
2017-05-29 07:54:35 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2017-05-29 07:54:35 +00:00
|
|
|
end
|
|
|
|
end
|
2017-05-01 13:14:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-10 13:50:42 +00:00
|
|
|
describe "GET show" do
|
2017-02-13 22:42:46 +00:00
|
|
|
context 'Content-Disposition security measures' do
|
2019-12-16 18:08:22 +00:00
|
|
|
let(:expected_disposition) { 'inline;' }
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project, :public) }
|
2017-02-13 22:42:46 +00:00
|
|
|
|
2019-12-16 18:08:22 +00:00
|
|
|
shared_examples_for 'uploaded file with disposition' do
|
|
|
|
it 'returns correct Content-Disposition' do
|
|
|
|
get :show, params: { model: 'note', mounted_as: 'attachment', id: note.id, filename: filename }
|
2017-02-13 22:42:46 +00:00
|
|
|
|
2019-12-16 18:08:22 +00:00
|
|
|
expect(response['Content-Disposition']).to start_with(expected_disposition)
|
2017-02-13 22:42:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-16 18:08:22 +00:00
|
|
|
context 'for PNG files' do
|
|
|
|
let(:filename) { 'dk.png' }
|
|
|
|
let(:expected_disposition) { 'inline;' }
|
|
|
|
let(:note) { create(:note, :with_attachment, project: project) }
|
|
|
|
|
|
|
|
it_behaves_like 'uploaded file with disposition'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for PDF files' do
|
|
|
|
let(:filename) { 'git-cheat-sheet.pdf' }
|
|
|
|
let(:expected_disposition) { 'inline;' }
|
|
|
|
let(:note) { create(:note, :with_pdf_attachment, project: project) }
|
|
|
|
|
|
|
|
it_behaves_like 'uploaded file with disposition'
|
|
|
|
end
|
|
|
|
|
2017-02-13 22:42:46 +00:00
|
|
|
context 'for SVG files' do
|
2019-12-16 18:08:22 +00:00
|
|
|
let(:filename) { 'unsanitized.svg' }
|
|
|
|
let(:expected_disposition) { 'attachment;' }
|
|
|
|
let(:note) { create(:note, :with_svg_attachment, project: project) }
|
2017-02-13 22:42:46 +00:00
|
|
|
|
2019-12-16 18:08:22 +00:00
|
|
|
it_behaves_like 'uploaded file with disposition'
|
2017-02-13 22:42:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-10 13:50:42 +00:00
|
|
|
context "when viewing a user avatar" do
|
|
|
|
context "when signed in" do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user is blocked" do
|
|
|
|
before do
|
|
|
|
user.block
|
|
|
|
end
|
|
|
|
|
2019-12-03 18:06:49 +00:00
|
|
|
it "responds with status 401" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "user", mounted_as: "avatar", id: user.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user isn't blocked" do
|
|
|
|
it "responds with status 200" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "user", mounted_as: "avatar", id: user.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
2017-02-22 18:30:53 +00:00
|
|
|
|
2019-01-21 22:58:54 +00:00
|
|
|
it_behaves_like 'content publicly cached' do
|
2017-02-22 18:30:53 +00:00
|
|
|
subject do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'user', mounted_as: 'avatar', id: user.id, filename: 'dk.png' }
|
2018-01-29 17:57:34 +00:00
|
|
|
|
2017-02-22 18:30:53 +00:00
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
2016-03-19 00:04:53 +00:00
|
|
|
|
2015-03-10 13:50:42 +00:00
|
|
|
context "when not signed in" do
|
|
|
|
it "responds with status 200" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "user", mounted_as: "avatar", id: user.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
2017-02-22 18:30:53 +00:00
|
|
|
|
2019-01-21 22:58:54 +00:00
|
|
|
it_behaves_like 'content publicly cached' do
|
2017-02-22 18:30:53 +00:00
|
|
|
subject do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'user', mounted_as: 'avatar', id: user.id, filename: 'dk.png' }
|
2018-01-29 17:57:34 +00:00
|
|
|
|
2017-02-22 18:30:53 +00:00
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when viewing a project avatar" do
|
2018-06-05 21:18:06 +00:00
|
|
|
let!(:project) { create(:project, avatar: fixture_file_upload("spec/fixtures/dk.png", "image/png")) }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
|
|
|
context "when the project is public" do
|
|
|
|
before do
|
|
|
|
project.update_attribute(:visibility_level, Project::PUBLIC)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when not signed in" do
|
|
|
|
it "responds with status 200" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "project", mounted_as: "avatar", id: project.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
2017-02-22 18:30:53 +00:00
|
|
|
|
2019-10-14 15:06:07 +00:00
|
|
|
it_behaves_like 'content 5 min private cached with revalidation' do
|
2017-02-22 18:30:53 +00:00
|
|
|
subject do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'project', mounted_as: 'avatar', id: project.id, filename: 'dk.png' }
|
2018-01-29 17:57:34 +00:00
|
|
|
|
2017-02-22 18:30:53 +00:00
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when signed in" do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "responds with status 200" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "project", mounted_as: "avatar", id: project.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
2017-02-22 18:30:53 +00:00
|
|
|
|
2019-10-14 15:06:07 +00:00
|
|
|
it_behaves_like 'content 5 min private cached with revalidation' do
|
2017-02-22 18:30:53 +00:00
|
|
|
subject do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'project', mounted_as: 'avatar', id: project.id, filename: 'dk.png' }
|
2018-01-29 17:57:34 +00:00
|
|
|
|
2017-02-22 18:30:53 +00:00
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the project is private" do
|
|
|
|
before do
|
|
|
|
project.update_attribute(:visibility_level, Project::PRIVATE)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when not signed in" do
|
2019-12-03 18:06:49 +00:00
|
|
|
it "responds with status 401" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "project", mounted_as: "avatar", id: project.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when signed in" do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user has access to the project" do
|
|
|
|
before do
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user is blocked" do
|
|
|
|
before do
|
|
|
|
user.block
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
|
2019-12-03 18:06:49 +00:00
|
|
|
it "responds with status 401" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "project", mounted_as: "avatar", id: project.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user isn't blocked" do
|
|
|
|
it "responds with status 200" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "project", mounted_as: "avatar", id: project.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
2017-02-22 18:30:53 +00:00
|
|
|
|
2019-10-14 15:06:07 +00:00
|
|
|
it_behaves_like 'content 5 min private cached with revalidation' do
|
2017-02-22 18:30:53 +00:00
|
|
|
subject do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'project', mounted_as: 'avatar', id: project.id, filename: 'dk.png' }
|
2018-01-29 17:57:34 +00:00
|
|
|
|
2017-02-22 18:30:53 +00:00
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user doesn't have access to the project" do
|
|
|
|
it "responds with status 404" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "project", mounted_as: "avatar", id: project.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when viewing a group avatar" do
|
2019-01-16 12:09:29 +00:00
|
|
|
let!(:group) { create(:group, avatar: fixture_file_upload("spec/fixtures/dk.png", "image/png")) }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
context "when the group is public" do
|
2015-03-10 13:50:42 +00:00
|
|
|
context "when not signed in" do
|
|
|
|
it "responds with status 200" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "group", mounted_as: "avatar", id: group.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
2017-02-22 18:30:53 +00:00
|
|
|
|
2019-10-14 15:06:07 +00:00
|
|
|
it_behaves_like 'content 5 min private cached with revalidation' do
|
2017-02-22 18:30:53 +00:00
|
|
|
subject do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'group', mounted_as: 'avatar', id: group.id, filename: 'dk.png' }
|
2018-01-29 17:57:34 +00:00
|
|
|
|
2017-02-22 18:30:53 +00:00
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when signed in" do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "responds with status 200" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "group", mounted_as: "avatar", id: group.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
2017-02-22 18:30:53 +00:00
|
|
|
|
2019-10-14 15:06:07 +00:00
|
|
|
it_behaves_like 'content 5 min private cached with revalidation' do
|
2017-02-22 18:30:53 +00:00
|
|
|
subject do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'group', mounted_as: 'avatar', id: group.id, filename: 'dk.png' }
|
2018-01-29 17:57:34 +00:00
|
|
|
|
2017-02-22 18:30:53 +00:00
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
context "when the group is private" do
|
2016-03-20 22:09:33 +00:00
|
|
|
before do
|
|
|
|
group.update_attribute(:visibility_level, Gitlab::VisibilityLevel::PRIVATE)
|
|
|
|
end
|
|
|
|
|
2015-03-10 13:50:42 +00:00
|
|
|
context "when signed in" do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user has access to the project" do
|
|
|
|
before do
|
2016-03-20 22:09:33 +00:00
|
|
|
group.add_developer(user)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user is blocked" do
|
|
|
|
before do
|
|
|
|
user.block
|
|
|
|
end
|
|
|
|
|
2019-12-03 18:06:49 +00:00
|
|
|
it "responds with status 401" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "group", mounted_as: "avatar", id: group.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user isn't blocked" do
|
|
|
|
it "responds with status 200" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "group", mounted_as: "avatar", id: group.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
2017-02-22 18:30:53 +00:00
|
|
|
|
2019-10-14 15:06:07 +00:00
|
|
|
it_behaves_like 'content 5 min private cached with revalidation' do
|
2017-02-22 18:30:53 +00:00
|
|
|
subject do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'group', mounted_as: 'avatar', id: group.id, filename: 'dk.png' }
|
2018-01-29 17:57:34 +00:00
|
|
|
|
2017-02-22 18:30:53 +00:00
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user doesn't have access to the project" do
|
|
|
|
it "responds with status 404" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "group", mounted_as: "avatar", id: group.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when viewing a note attachment" do
|
|
|
|
let!(:note) { create(:note, :with_attachment) }
|
|
|
|
let(:project) { note.project }
|
|
|
|
|
|
|
|
context "when the project is public" do
|
|
|
|
before do
|
|
|
|
project.update_attribute(:visibility_level, Project::PUBLIC)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when not signed in" do
|
|
|
|
it "responds with status 200" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "note", mounted_as: "attachment", id: note.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
2017-02-22 18:30:53 +00:00
|
|
|
|
2019-11-01 15:06:21 +00:00
|
|
|
it_behaves_like 'content not cached' do
|
2017-02-22 18:30:53 +00:00
|
|
|
subject do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'note', mounted_as: 'attachment', id: note.id, filename: 'dk.png' }
|
2018-01-29 17:57:34 +00:00
|
|
|
|
2017-02-22 18:30:53 +00:00
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when signed in" do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "responds with status 200" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "note", mounted_as: "attachment", id: note.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
2017-02-22 18:30:53 +00:00
|
|
|
|
2019-11-01 15:06:21 +00:00
|
|
|
it_behaves_like 'content not cached' do
|
2017-02-22 18:30:53 +00:00
|
|
|
subject do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'note', mounted_as: 'attachment', id: note.id, filename: 'dk.png' }
|
2018-01-29 17:57:34 +00:00
|
|
|
|
2017-02-22 18:30:53 +00:00
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the project is private" do
|
|
|
|
before do
|
|
|
|
project.update_attribute(:visibility_level, Project::PRIVATE)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when not signed in" do
|
2019-12-03 18:06:49 +00:00
|
|
|
it "responds with status 401" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "note", mounted_as: "attachment", id: note.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when signed in" do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user has access to the project" do
|
|
|
|
before do
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user is blocked" do
|
|
|
|
before do
|
|
|
|
user.block
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
|
2019-12-03 18:06:49 +00:00
|
|
|
it "responds with status 401" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "note", mounted_as: "attachment", id: note.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user isn't blocked" do
|
|
|
|
it "responds with status 200" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "note", mounted_as: "attachment", id: note.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
2017-02-22 18:30:53 +00:00
|
|
|
|
2019-11-01 15:06:21 +00:00
|
|
|
it_behaves_like 'content not cached' do
|
2017-02-22 18:30:53 +00:00
|
|
|
subject do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'note', mounted_as: 'attachment', id: note.id, filename: 'dk.png' }
|
2018-01-29 17:57:34 +00:00
|
|
|
|
2017-02-22 18:30:53 +00:00
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user doesn't have access to the project" do
|
|
|
|
it "responds with status 404" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: "note", mounted_as: "attachment", id: note.id, filename: "dk.png" }
|
2015-03-10 13:50:42 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-05-19 09:20:51 +00:00
|
|
|
|
2021-10-13 09:11:55 +00:00
|
|
|
context "when viewing a topic avatar" do
|
|
|
|
let!(:topic) { create(:topic, avatar: fixture_file_upload("spec/fixtures/dk.png", "image/png")) }
|
|
|
|
|
|
|
|
context "when signed in" do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "responds with status 200" do
|
|
|
|
get :show, params: { model: "projects/topic", mounted_as: "avatar", id: topic.id, filename: "dk.png" }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'content publicly cached' do
|
|
|
|
subject do
|
|
|
|
get :show, params: { model: "projects/topic", mounted_as: "avatar", id: topic.id, filename: "dk.png" }
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when not signed in" do
|
|
|
|
it "responds with status 200" do
|
|
|
|
get :show, params: { model: "projects/topic", mounted_as: "avatar", id: topic.id, filename: "dk.png" }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'content publicly cached' do
|
|
|
|
subject do
|
|
|
|
get :show, params: { model: "projects/topic", mounted_as: "avatar", id: topic.id, filename: "dk.png" }
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-19 09:20:51 +00:00
|
|
|
context 'Appearance' do
|
|
|
|
context 'when viewing a custom header logo' do
|
2018-06-05 21:18:06 +00:00
|
|
|
let!(:appearance) { create :appearance, header_logo: fixture_file_upload('spec/fixtures/dk.png', 'image/png') }
|
2017-05-19 09:20:51 +00:00
|
|
|
|
|
|
|
context 'when not signed in' do
|
|
|
|
it 'responds with status 200' do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'appearance', mounted_as: 'header_logo', id: appearance.id, filename: 'dk.png' }
|
2017-05-19 09:20:51 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-05-19 09:20:51 +00:00
|
|
|
end
|
|
|
|
|
2019-01-21 22:58:54 +00:00
|
|
|
it_behaves_like 'content publicly cached' do
|
2017-05-19 09:20:51 +00:00
|
|
|
subject do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'appearance', mounted_as: 'header_logo', id: appearance.id, filename: 'dk.png' }
|
2018-01-29 17:57:34 +00:00
|
|
|
|
2017-05-19 09:20:51 +00:00
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when viewing a custom logo' do
|
2018-06-05 21:18:06 +00:00
|
|
|
let!(:appearance) { create :appearance, logo: fixture_file_upload('spec/fixtures/dk.png', 'image/png') }
|
2017-05-19 09:20:51 +00:00
|
|
|
|
|
|
|
context 'when not signed in' do
|
|
|
|
it 'responds with status 200' do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'appearance', mounted_as: 'logo', id: appearance.id, filename: 'dk.png' }
|
2017-05-19 09:20:51 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-05-19 09:20:51 +00:00
|
|
|
end
|
|
|
|
|
2019-01-21 22:58:54 +00:00
|
|
|
it_behaves_like 'content publicly cached' do
|
2017-05-19 09:20:51 +00:00
|
|
|
subject do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'appearance', mounted_as: 'logo', id: appearance.id, filename: 'dk.png' }
|
2018-01-29 17:57:34 +00:00
|
|
|
|
2017-05-19 09:20:51 +00:00
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-04-12 12:11:21 +00:00
|
|
|
|
2018-04-12 12:13:06 +00:00
|
|
|
context 'original filename or a version filename must match' do
|
2018-06-11 11:54:25 +00:00
|
|
|
let!(:appearance) { create :appearance, favicon: fixture_file_upload('spec/fixtures/dk.png', 'image/png') }
|
2018-04-12 12:11:21 +00:00
|
|
|
|
2018-04-12 12:13:06 +00:00
|
|
|
context 'has a valid filename on the original file' do
|
|
|
|
it 'successfully returns the file' do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'appearance', mounted_as: 'favicon', id: appearance.id, filename: 'dk.png' }
|
2018-04-12 12:13:06 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-01-29 18:08:47 +00:00
|
|
|
expect(response.header['Content-Disposition']).to include('filename="dk.png"')
|
2018-04-12 12:13:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'has an invalid filename on the original file' do
|
|
|
|
it 'returns a 404' do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { model: 'appearance', mounted_as: 'favicon', id: appearance.id, filename: 'bogus.png' }
|
2018-04-12 12:13:06 +00:00
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2018-04-12 12:13:06 +00:00
|
|
|
end
|
|
|
|
end
|
2018-04-12 12:11:21 +00:00
|
|
|
end
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|
2019-07-09 18:51:42 +00:00
|
|
|
|
|
|
|
def post_authorize(verified: true)
|
|
|
|
request.headers.merge!(workhorse_internal_api_request_header) if verified
|
|
|
|
|
2021-09-30 18:11:31 +00:00
|
|
|
post :authorize, params: params, format: :json
|
2019-07-09 18:51:42 +00:00
|
|
|
end
|
2015-03-10 13:50:42 +00:00
|
|
|
end
|