summaryrefslogtreecommitdiff
path: root/spec/controllers/admin
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-01-09 22:50:51 -0800
committerStan Hu <stanhu@gmail.com>2019-01-09 23:09:43 -0800
commit4ac4ba2654c9ffa6065e6d4789c279d676c5971b (patch)
treea12e4e42f65bd2e62486b066373e37e93377fd93 /spec/controllers/admin
parent4a6c7661edae664a7f6366201d017e24d8f42026 (diff)
downloadgitlab-ce-4ac4ba2654c9ffa6065e6d4789c279d676c5971b.tar.gz
Fix requests profiler in admin page not rendering HTML properly
By default in Rails 5, content passed to `render` will be escaped. This doesn't work for the HTML profile output, which should be considered safe HTML already. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/56152
Diffstat (limited to 'spec/controllers/admin')
-rw-r--r--spec/controllers/admin/requests_profiles_controller_spec.rb47
1 files changed, 47 insertions, 0 deletions
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