summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2019-01-10 10:26:44 +0000
committerGitLab Release Tools Bot <robert+release-tools@gitlab.com>2019-01-16 18:13:13 +0000
commit6da1bb47a40fc37eb6d28e739afbb47383f0726d (patch)
tree6d19bf8fcf700a37cde5140e2049f31901805201
parent0c12584ec6ee77ab8e593ea9cdef2e3d406b9753 (diff)
downloadgitlab-ce-6da1bb47a40fc37eb6d28e739afbb47383f0726d.tar.gz
Merge branch 'sh-fix-request-profiles-html' into 'master'
Fix requests profiler in admin page not rendering HTML properly Closes #56152 See merge request gitlab-org/gitlab-ce!24291 (cherry picked from commit 59c0c173b471d50007442c95464df0cac0030fc6) 4ac4ba26 Fix requests profiler in admin page not rendering HTML properly
-rw-r--r--app/controllers/admin/requests_profiles_controller.rb2
-rw-r--r--changelogs/unreleased/sh-fix-request-profiles-html.yml5
-rw-r--r--spec/controllers/admin/requests_profiles_controller_spec.rb47
3 files changed, 53 insertions, 1 deletions
diff --git a/app/controllers/admin/requests_profiles_controller.rb b/app/controllers/admin/requests_profiles_controller.rb
index 57f7d3e3951..89d4c4f18d9 100644
--- a/app/controllers/admin/requests_profiles_controller.rb
+++ b/app/controllers/admin/requests_profiles_controller.rb
@@ -11,7 +11,7 @@ class Admin::RequestsProfilesController < Admin::ApplicationController
profile = Gitlab::RequestProfiler::Profile.find(clean_name)
if profile
- render html: profile.content
+ render html: profile.content.html_safe
else
redirect_to admin_requests_profiles_path, alert: 'Profile not found'
end
diff --git a/changelogs/unreleased/sh-fix-request-profiles-html.yml b/changelogs/unreleased/sh-fix-request-profiles-html.yml
new file mode 100644
index 00000000000..74e4115db8e
--- /dev/null
+++ b/changelogs/unreleased/sh-fix-request-profiles-html.yml
@@ -0,0 +1,5 @@
+---
+title: Fix requests profiler in admin page not rendering HTML properly
+merge_request: 24291
+author:
+type: fixed
diff --git a/spec/controllers/admin/requests_profiles_controller_spec.rb b/spec/controllers/admin/requests_profiles_controller_spec.rb
new file mode 100644
index 00000000000..10850cb4603
--- /dev/null
+++ b/spec/controllers/admin/requests_profiles_controller_spec.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Admin::RequestsProfilesController do
+ set(:admin) { create(:admin) }
+
+ before do
+ sign_in(admin)
+ end
+
+ describe '#show' do
+ let(:basename) { "profile_#{Time.now.to_i}.html" }
+ let(:tmpdir) { Dir.mktmpdir('profiler-test') }
+ let(:test_file) { File.join(tmpdir, basename) }
+ let(:profile) { Gitlab::RequestProfiler::Profile.new(basename) }
+ let(:sample_data) do
+ <<~HTML
+ <!DOCTYPE html>
+ <html>
+ <body>
+ <h1>My First Heading</h1>
+ <p>My first paragraph.</p>
+ </body>
+ </html>
+ HTML
+ end
+
+ before do
+ stub_const('Gitlab::RequestProfiler::PROFILES_DIR', tmpdir)
+ output = File.open(test_file, 'w')
+ output.write(sample_data)
+ output.close
+ end
+
+ after do
+ File.unlink(test_file)
+ end
+
+ it 'loads an HTML profile' do
+ get :show, params: { name: basename }
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response.body).to eq(sample_data)
+ end
+ end
+end