Skip to content
Snippets Groups Projects
Commit f2644adf authored by Sean McGivern's avatar Sean McGivern
Browse files

Merge branch 'dz-fix-constrainer-for-relative-url' into 'master'

Fix constrainers for relative url

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/23675

See merge request !7071
parents 4028022f ccd81a87
No related branches found
No related tags found
No related merge requests found
Loading
@@ -15,6 +15,7 @@ Please view this file on the master branch, on stable branches it's out of date.
Loading
@@ -15,6 +15,7 @@ Please view this file on the master branch, on stable branches it's out of date.
- Fix error in generating labels - Fix error in generating labels
- Fix reply-by-email not working due to queue name mismatch - Fix reply-by-email not working due to queue name mismatch
- Expire and build repository cache after project import - Expire and build repository cache after project import
- Fix 404 for group pages when GitLab setup uses relative url
   
## 8.13.0 (2016-10-22) ## 8.13.0 (2016-10-22)
- Removes extra line for empty issue description. (!7045) - Removes extra line for empty issue description. (!7045)
Loading
Loading
class NamespaceUrlConstrainer class NamespaceUrlConstrainer
def matches?(request) def matches?(request)
id = request.path.sub(/\A\/+/, '').split('/').first.sub(/.atom\z/, '') id = request.path
id = id.sub(/\A#{relative_url_root}/, '') if relative_url_root
id = id.sub(/\A\/+/, '').split('/').first
id = id.sub(/.atom\z/, '') if id
   
if id =~ Gitlab::Regex.namespace_regex if id =~ Gitlab::Regex.namespace_regex
find_resource(id) find_resource(id)
Loading
@@ -10,4 +13,12 @@ class NamespaceUrlConstrainer
Loading
@@ -10,4 +13,12 @@ class NamespaceUrlConstrainer
def find_resource(id) def find_resource(id)
Namespace.find_by_path(id) Namespace.find_by_path(id)
end end
private
def relative_url_root
if defined?(Gitlab::Application.config.relative_url_root)
Gitlab::Application.config.relative_url_root
end
end
end end
Loading
@@ -17,6 +17,16 @@ describe NamespaceUrlConstrainer, lib: true do
Loading
@@ -17,6 +17,16 @@ describe NamespaceUrlConstrainer, lib: true do
it { expect(subject.matches?(request '/g/gitlab')).to be_falsey } it { expect(subject.matches?(request '/g/gitlab')).to be_falsey }
it { expect(subject.matches?(request '/.gitlab')).to be_falsey } it { expect(subject.matches?(request '/.gitlab')).to be_falsey }
end end
context 'relative url' do
before do
allow(Gitlab::Application.config).to receive(:relative_url_root) { '/gitlab' }
end
it { expect(subject.matches?(request '/gitlab/gitlab')).to be_truthy }
it { expect(subject.matches?(request '/gitlab/gitlab-ce')).to be_falsey }
it { expect(subject.matches?(request '/gitlab/')).to be_falsey }
end
end end
   
def request(path) def request(path)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment