Commit 88837103 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'fix-namespace-find-by-pages-host' into 'master'

Fix Namespace.find_by_pages_host

See merge request gitlab-org/gitlab!21529
parents 5ddd2e67 cd6ba78a
...@@ -123,8 +123,10 @@ class Namespace < ApplicationRecord ...@@ -123,8 +123,10 @@ class Namespace < ApplicationRecord
def find_by_pages_host(host) def find_by_pages_host(host)
gitlab_host = "." + Settings.pages.host.downcase gitlab_host = "." + Settings.pages.host.downcase
name = host.downcase.delete_suffix(gitlab_host) host = host.downcase
return unless host.ends_with?(gitlab_host)
name = host.delete_suffix(gitlab_host)
Namespace.find_by_full_path(name) Namespace.find_by_full_path(name)
end end
end end
......
...@@ -199,6 +199,13 @@ describe Namespace do ...@@ -199,6 +199,13 @@ describe Namespace do
expect(described_class.find_by_pages_host(host)).to eq(namespace) expect(described_class.find_by_pages_host(host)).to eq(namespace)
end end
it "returns no result if the provided host is not subdomain of the Pages host" do
create(:namespace, name: 'namespace.io')
host = "namespace.io"
expect(described_class.find_by_pages_host(host)).to eq(nil)
end
end end
describe '#ancestors_upto' do describe '#ancestors_upto' do
......
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