Commit 67d90cc1 authored by Stan Hu's avatar Stan Hu

Merge branch 'sy-fix-leaky-domain' into 'master'

Target stubs for embed domains

Closes #233077

See merge request gitlab-org/gitlab!38416
parents 3c4b5ff9 12642e1d
......@@ -12,7 +12,7 @@ module Banzai
def xpath_search
"descendant-or-self::a[contains(@href,'metrics_dashboard') and \
contains(@href,'prometheus/alerts') and \
starts-with(@href, '#{::Gitlab.config.gitlab.url}')]"
starts-with(@href, '#{gitlab_domain}')]"
end
# Regular expression matching alert dashboard urls
......
......@@ -14,10 +14,7 @@ RSpec.describe 'Metrics rendering', :js, :kubeclient, :use_clean_rails_memory_st
before do
clear_host_from_memoized_variables
allow(::Gitlab.config.gitlab)
.to receive(:url)
.and_return(urls.root_url.chomp('/'))
stub_gitlab_domain
stub_licensed_features(prometheus_alerts: true)
......
......@@ -15,7 +15,7 @@ module Banzai
def xpath_search
"descendant-or-self::a[contains(@href,'clusters') and \
starts-with(@href, '#{::Gitlab.config.gitlab.url}')]"
starts-with(@href, '#{gitlab_domain}')]"
end
def link_pattern
......
......@@ -82,6 +82,10 @@ module Banzai
def metrics_dashboard_url
raise NotImplementedError
end
def gitlab_domain
::Gitlab.config.gitlab.url
end
end
end
end
......@@ -11,7 +11,7 @@ module Banzai
def xpath_search
"descendant-or-self::a[contains(@href,'metrics') and \
contains(@href,'environments') and \
starts-with(@href, '#{Gitlab.config.gitlab.url}')]"
starts-with(@href, '#{gitlab_domain}')]"
end
# Regular expression matching metrics urls
......
......@@ -92,12 +92,16 @@ module Gitlab
end
def gitlab_host_pattern
Regexp.escape(Gitlab.config.gitlab.url)
Regexp.escape(gitlab_domain)
end
def project_path_pattern
"\/#{Project.reference_pattern}"
end
def gitlab_domain
Gitlab.config.gitlab.url
end
end
end
end
......
......@@ -18,10 +18,7 @@ RSpec.describe 'Metrics rendering', :js, :kubeclient, :use_clean_rails_memory_st
before do
clear_host_from_memoized_variables
allow(::Gitlab.config.gitlab)
.to receive(:url)
.and_return(urls.root_url.chomp('/'))
stub_gitlab_domain
project.add_developer(user)
sign_in(user)
......
......@@ -13,4 +13,14 @@ module MetricsDashboardUrlHelpers
Gitlab::Metrics::Dashboard::Url.clear_memoization(method_name)
end
end
def stub_gitlab_domain
allow_any_instance_of(Banzai::Filter::InlineEmbedsFilter)
.to receive(:gitlab_domain)
.and_return(urls.root_url.chomp('/'))
allow(Gitlab::Metrics::Dashboard::Url)
.to receive(:gitlab_domain)
.and_return(urls.root_url.chomp('/'))
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