debian-mirror-gitlab/spec/helpers/groups/observability_helper_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
3.9 KiB
Ruby
Raw Normal View History

2023-01-13 00:05:48 +05:30
# frozen_string_literal: true
require "spec_helper"
RSpec.describe Groups::ObservabilityHelper do
let(:group) { build_stubbed(:group) }
let(:observability_url) { Gitlab::Observability.observability_url }
describe '#observability_iframe_src' do
context 'if observability_path is missing from params' do
it 'returns the iframe src for action: dashboards' do
allow(helper).to receive(:params).and_return({ action: 'dashboards' })
2023-03-04 22:38:38 +05:30
expect(helper.observability_iframe_src(group)).to eq("#{observability_url}/-/#{group.id}/")
2023-01-13 00:05:48 +05:30
end
it 'returns the iframe src for action: manage' do
allow(helper).to receive(:params).and_return({ action: 'manage' })
2023-03-04 22:38:38 +05:30
expect(helper.observability_iframe_src(group)).to eq("#{observability_url}/-/#{group.id}/dashboards")
2023-01-13 00:05:48 +05:30
end
it 'returns the iframe src for action: explore' do
allow(helper).to receive(:params).and_return({ action: 'explore' })
2023-03-04 22:38:38 +05:30
expect(helper.observability_iframe_src(group)).to eq("#{observability_url}/-/#{group.id}/explore")
2023-01-13 00:05:48 +05:30
end
end
context 'if observability_path exists in params' do
context 'if observability_path is valid' do
it 'returns the iframe src by injecting the observability path' do
allow(helper).to receive(:params).and_return({ action: '/explore', observability_path: '/foo?bar=foobar' })
2023-03-04 22:38:38 +05:30
expect(helper.observability_iframe_src(group)).to eq("#{observability_url}/-/#{group.id}/foo?bar=foobar")
2023-01-13 00:05:48 +05:30
end
end
context 'if observability_path is not valid' do
it 'returns the iframe src by injecting the sanitised observability path' do
allow(helper).to receive(:params).and_return({
action: '/explore',
observability_path:
"/test?groupId=<script>alert('attack!')</script>"
})
expect(helper.observability_iframe_src(group)).to eq(
2023-03-04 22:38:38 +05:30
"#{observability_url}/-/#{group.id}/test?groupId=alert('attack!')"
2023-01-13 00:05:48 +05:30
)
end
end
end
context 'when observability ui is standalone' do
before do
stub_env('STANDALONE_OBSERVABILITY_UI', 'true')
end
it 'returns the iframe src without group.id for action: dashboards' do
allow(helper).to receive(:params).and_return({ action: 'dashboards' })
expect(helper.observability_iframe_src(group)).to eq("#{observability_url}/")
end
it 'returns the iframe src without group.id for action: manage' do
allow(helper).to receive(:params).and_return({ action: 'manage' })
expect(helper.observability_iframe_src(group)).to eq("#{observability_url}/dashboards")
end
it 'returns the iframe src without group.id for action: explore' do
allow(helper).to receive(:params).and_return({ action: 'explore' })
expect(helper.observability_iframe_src(group)).to eq("#{observability_url}/explore")
end
end
end
describe '#observability_page_title' do
it 'returns the title for action: dashboards' do
allow(helper).to receive(:params).and_return({ action: 'dashboards' })
expect(helper.observability_page_title).to eq("Dashboards")
end
it 'returns the title for action: manage' do
allow(helper).to receive(:params).and_return({ action: 'manage' })
expect(helper.observability_page_title).to eq("Manage Dashboards")
end
it 'returns the title for action: explore' do
allow(helper).to receive(:params).and_return({ action: 'explore' })
expect(helper.observability_page_title).to eq("Explore")
end
it 'returns the default title for unknown action' do
allow(helper).to receive(:params).and_return({ action: 'unknown' })
expect(helper.observability_page_title).to eq("Dashboards")
end
end
end