Commit 00aaf503 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'sh-fix-error-500-no-avatars' into 'master'

Fix Error 500 when repository has no avatar

Closes #42249

See merge request gitlab-org/gitlab-ce!16601
parents d460d0af b9c53748
...@@ -132,6 +132,8 @@ module Gitlab ...@@ -132,6 +132,8 @@ module Gitlab
end end
def find_by_gitaly(repository, sha, path, limit: MAX_DATA_DISPLAY_SIZE) def find_by_gitaly(repository, sha, path, limit: MAX_DATA_DISPLAY_SIZE)
return unless path
path = path.sub(/\A\/*/, '') path = path.sub(/\A\/*/, '')
path = '/' if path.empty? path = '/' if path.empty?
name = File.basename(path) name = File.basename(path)
...@@ -173,6 +175,8 @@ module Gitlab ...@@ -173,6 +175,8 @@ module Gitlab
end end
def find_by_rugged(repository, sha, path, limit:) def find_by_rugged(repository, sha, path, limit:)
return unless path
rugged_commit = repository.lookup(sha) rugged_commit = repository.lookup(sha)
root_tree = rugged_commit.tree root_tree = rugged_commit.tree
......
require 'spec_helper' require 'spec_helper'
describe Projects::AvatarsController do describe Projects::AvatarsController do
let(:project) { create(:project, avatar: fixture_file_upload(Rails.root + "spec/fixtures/dk.png", "image/png")) } let(:project) { create(:project, :repository, avatar: fixture_file_upload(Rails.root + "spec/fixtures/dk.png", "image/png")) }
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
...@@ -10,6 +10,12 @@ describe Projects::AvatarsController do ...@@ -10,6 +10,12 @@ describe Projects::AvatarsController do
controller.instance_variable_set(:@project, project) controller.instance_variable_set(:@project, project)
end end
it 'GET #show' do
get :show, namespace_id: project.namespace.id, project_id: project.id
expect(response).to have_gitlab_http_status(404)
end
it 'removes avatar from DB by calling destroy' do it 'removes avatar from DB by calling destroy' do
delete :destroy, namespace_id: project.namespace.id, project_id: project.id delete :destroy, namespace_id: project.namespace.id, project_id: project.id
expect(project.avatar.present?).to be_falsey expect(project.avatar.present?).to be_falsey
......
...@@ -16,6 +16,18 @@ describe Gitlab::Git::Blob, seed_helper: true do ...@@ -16,6 +16,18 @@ describe Gitlab::Git::Blob, seed_helper: true do
end end
shared_examples 'finding blobs' do shared_examples 'finding blobs' do
context 'nil path' do
let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, nil) }
it { expect(blob).to eq(nil) }
end
context 'blank path' do
let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, '') }
it { expect(blob).to eq(nil) }
end
context 'file in subdir' do context 'file in subdir' do
let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, "files/ruby/popen.rb") } let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, "files/ruby/popen.rb") }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment