Commit 12642e1d authored by syasonik's avatar syasonik

Target stubs for embed domains

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