Commit cd6ba78a authored by Krasimir Angelov's avatar Krasimir Angelov

Fix Namespace.find_by_pages_host - return results only for subdomains

of the configured Pages domain.

Related to https://gitlab.com/gitlab-org/gitlab/issues/28781.
parent f00a62b5
......@@ -123,8 +123,10 @@ class Namespace < ApplicationRecord
def find_by_pages_host(host)
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)
end
end
......
......@@ -199,6 +199,13 @@ describe Namespace do
expect(described_class.find_by_pages_host(host)).to eq(namespace)
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
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