Commit cbf7ac4b authored by Jarka Košanová's avatar Jarka Košanová

Merge branch 'verify_reference_for_atom_format' into 'master'

Validate that reference exists for atom format

See merge request gitlab-org/gitlab!79635
parents 27f5e271 b5b4bdf2
......@@ -16,6 +16,8 @@ module ExtractsPath
id_without_atom = id.sub(/\.atom$/, '')
valid_refs = ref_names.select { |v| "#{id_without_atom}/".start_with?("#{v}/") }
raise InvalidPathError if valid_refs.blank?
valid_refs.max_by(&:length)
end
......
......@@ -151,6 +151,20 @@ RSpec.describe Projects::CommitsController do
expect(response.media_type).to eq('text/html')
end
end
context 'when the ref does not exist' do
before do
get(:show, params: {
namespace_id: project.namespace,
project_id: project,
id: 'unknown.atom'
})
end
it 'returns 404 page' do
expect(response).to be_not_found
end
end
end
end
......
......@@ -209,8 +209,8 @@ RSpec.describe ExtractsPath do
expect(extract_ref_without_atom('release/app/v1.0.0.atom')).to eq('release/app/v1.0.0')
end
it 'returns nil if there are no matching refs' do
expect(extract_ref_without_atom('foo.atom')).to eq(nil)
it 'raises an error if there are no matching refs' do
expect { extract_ref_without_atom('foo.atom') }.to raise_error(ExtractsRef::InvalidPathError)
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