Commit 8eb9f47a authored by Avielle Wolfe's avatar Avielle Wolfe Committed by Furkan Ayhan

Fix GRPC 500 from BlobsResolver

Passing an invalid ref into the BlobsResolver was resulting in a 500
because of a GRPC::InvalidArgument error raised from Gitaly. This commit
instead checks that the ref is valid and raises a GraphQL ArgumentError
if it is not, which will be properly returned to the client by GraphQL.

Changelog: fixed
parent f55115d0
......@@ -30,8 +30,17 @@ module Resolvers
return [] if repository.empty?
ref ||= repository.root_ref
validate_ref(ref)
repository.blobs_at(paths.map { |path| [ref, path] })
end
private
def validate_ref(ref)
unless Gitlab::GitRefValidator.validate(ref)
raise Gitlab::Graphql::Errors::ArgumentError, 'Ref is not valid'
end
end
end
end
......@@ -68,6 +68,28 @@ RSpec.describe Resolvers::BlobsResolver do
)
end
end
context 'when specifying an invalid ref' do
let(:ref) { 'ma:in' }
it 'raises an ArgumentError' do
expect { resolve_blobs }.to raise_error(
Gitlab::Graphql::Errors::ArgumentError,
'Ref is not valid'
)
end
end
context 'when passing an empty ref' do
let(:ref) { '' }
it 'raises an ArgumentError' do
expect { resolve_blobs }.to raise_error(
Gitlab::Graphql::Errors::ArgumentError,
'Ref is not valid'
)
end
end
end
end
end
......
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