diff options
-rw-r--r-- | lib/gitlab/git/blob.rb | 4 | ||||
-rw-r--r-- | spec/controllers/projects/avatars_controller_spec.rb | 8 | ||||
-rw-r--r-- | spec/lib/gitlab/git/blob_spec.rb | 12 |
3 files changed, 23 insertions, 1 deletions
diff --git a/lib/gitlab/git/blob.rb b/lib/gitlab/git/blob.rb index 031fccba92b..f421bf69e8f 100644 --- a/lib/gitlab/git/blob.rb +++ b/lib/gitlab/git/blob.rb @@ -132,6 +132,8 @@ module Gitlab end def find_by_gitaly(repository, sha, path, limit: MAX_DATA_DISPLAY_SIZE) + return unless path + path = path.sub(/\A\/*/, '') path = '/' if path.empty? name = File.basename(path) @@ -173,6 +175,8 @@ module Gitlab end def find_by_rugged(repository, sha, path, limit:) + return unless path + rugged_commit = repository.lookup(sha) root_tree = rugged_commit.tree diff --git a/spec/controllers/projects/avatars_controller_spec.rb b/spec/controllers/projects/avatars_controller_spec.rb index 3bbe168f6d5..6a41c4d23ea 100644 --- a/spec/controllers/projects/avatars_controller_spec.rb +++ b/spec/controllers/projects/avatars_controller_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' 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) } before do @@ -10,6 +10,12 @@ describe Projects::AvatarsController do controller.instance_variable_set(:@project, project) 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 delete :destroy, namespace_id: project.namespace.id, project_id: project.id expect(project.avatar.present?).to be_falsey diff --git a/spec/lib/gitlab/git/blob_spec.rb b/spec/lib/gitlab/git/blob_spec.rb index 07eb5b82d5f..8706c89c147 100644 --- a/spec/lib/gitlab/git/blob_spec.rb +++ b/spec/lib/gitlab/git/blob_spec.rb @@ -16,6 +16,18 @@ describe Gitlab::Git::Blob, seed_helper: true do end 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 let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, "files/ruby/popen.rb") } |