Commit fefab474569f231676a4fd1579a70723d729f206

Authored by Dmitry Medvinsky
1 parent c0090a3f

Fix `/:username.keys` response content type

Currently this method responds with `text/html`. It is kind of unusable
if you open it in a browser. The browser thinks it is HTML and renders
it as HTML, meaning new lines are dropped. So it's very hard to
distinguish where the key starts and where it ends.

This commit changes the content type header to `text/plain`.
@@ -29,6 +29,7 @@ v 6.7.0 @@ -29,6 +29,7 @@ v 6.7.0
29 - Better API responses for access_levels (sponsored by O'Reilly Media) 29 - Better API responses for access_levels (sponsored by O'Reilly Media)
30 - Requires at least 2 unicorn workers 30 - Requires at least 2 unicorn workers
31 - Requires gitlab-shell v1.9+ 31 - Requires gitlab-shell v1.9+
  32 + - Fix `/:username.keys` response content type (Dmitry Medvinsky)
32 33
33 v 6.6.5 34 v 6.6.5
34 - Added option to remove issue assignee on project issue page and issue edit page (Jason Blanchard) 35 - Added option to remove issue assignee on project issue page and issue edit page (Jason Blanchard)
app/controllers/profiles/keys_controller.rb
@@ -41,7 +41,7 @@ class Profiles::KeysController < ApplicationController @@ -41,7 +41,7 @@ class Profiles::KeysController < ApplicationController
41 begin 41 begin
42 user = User.find_by_username(params[:username]) 42 user = User.find_by_username(params[:username])
43 if user.present? 43 if user.present?
44 - render text: user.all_ssh_keys.join("\n") 44 + render text: user.all_ssh_keys.join("\n"), content_type: "text/plain"
45 else 45 else
46 render_404 and return 46 render_404 and return
47 end 47 end
spec/controllers/profile_keys_controller_spec.rb
@@ -24,6 +24,11 @@ describe Profiles::KeysController do @@ -24,6 +24,11 @@ describe Profiles::KeysController do
24 24
25 expect(response.body).to eq("") 25 expect(response.body).to eq("")
26 end 26 end
  27 +
  28 + it "should respond with text/plain content type" do
  29 + get :get_keys, username: user.username
  30 + expect(response.content_type).to eq("text/plain")
  31 + end
27 end 32 end
28 33
29 describe "user with keys" do 34 describe "user with keys" do
@@ -44,6 +49,11 @@ describe Profiles::KeysController do @@ -44,6 +49,11 @@ describe Profiles::KeysController do
44 expect(response.body).not_to eq("") 49 expect(response.body).not_to eq("")
45 expect(response.body).to eq(user.all_ssh_keys.join("\n")) 50 expect(response.body).to eq(user.all_ssh_keys.join("\n"))
46 end 51 end
  52 +
  53 + it "should respond with text/plain content type" do
  54 + get :get_keys, username: user.username
  55 + expect(response.content_type).to eq("text/plain")
  56 + end
47 end 57 end
48 end 58 end
49 end 59 end