Commit 1b310703 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix redirect loop when navigating folders with @

Fixes Constraints::JiraEncodedUrlConstrainer to only look
for the @ character in the project path
parent ecb6b73b
......@@ -3,7 +3,7 @@
module Constraints
class JiraEncodedUrlConstrainer
def matches?(request)
request.path.starts_with?('/-/jira') || request.path.include?(Gitlab::Jira::Dvcs::ENCODED_SLASH)
request.path.starts_with?('/-/jira') || request.params[:project_id].include?(Gitlab::Jira::Dvcs::ENCODED_SLASH)
end
end
end
......@@ -3,26 +3,34 @@
require 'spec_helper'
describe Constraints::JiraEncodedUrlConstrainer do
let(:namespace_id) { 'group' }
let(:project_id) { 'project' }
let(:path) { "/#{namespace_id}/#{project_id}" }
let(:request) { double(:request, path: path, params: { namespace_id: namespace_id, project_id: project_id }) }
describe '#matches?' do
using RSpec::Parameterized::TableSyntax
subject { described_class.new.matches?(request) }
where(:path, :match_result) do
"/-/jira/group/project" | true
"/-/jira/group/sub_group#{Gitlab::Jira::Dvcs::ENCODED_SLASH}sub_project" | true
"/group/sub_group#{Gitlab::Jira::Dvcs::ENCODED_SLASH}sub_project" | true
"/group/project" | false
context 'when there is no /-/jira prefix and no encoded slash' do
it { is_expected.to eq(false) }
end
with_them do
it 'matches path with /-/jira prefix or encoded slash' do
request = build_request(path)
context 'when tree path contains encoded slash' do
let(:path) { "/#{namespace_id}/#{project_id}/tree/folder-with-#{Gitlab::Jira::Dvcs::ENCODED_SLASH}" }
expect(subject.matches?(request)).to eq(match_result)
end
it { is_expected.to eq(false) }
end
context 'when path has /-/jira prefix' do
let(:path) { "/-/jira/#{namespace_id}/#{project_id}" }
it { is_expected.to eq(true) }
end
def build_request(path)
double(:request, path: path)
context 'when project_id has encoded slash' do
let(:project_id) { "sub_group#{Gitlab::Jira::Dvcs::ENCODED_SLASH}sub_project" }
it { is_expected.to eq(true) }
end
end
end
......@@ -59,4 +59,14 @@ describe 'Jira referenced paths', type: :request do
end
end
end
context 'when tree path has an @' do
let(:path) { '/group/project/tree/folder-with-@' }
it 'does not do a redirect' do
get path
expect(response).not_to have_gitlab_http_status(:moved_permanently)
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