Commit f10153818b51da7ee4e691cea308dd8964d908c9
1 parent
39aeac71
Exists in
spb-stable
and in
3 other branches
Split the user ssh keys by newline, not the characters "\n"
before: GET /user.keys ssh-rsa ...\nssh-rsa ...\nssh-rsa ... after: GET /user.keys ssh-rsa ... ssh-rsa ... sha-rsa ...
Showing
3 changed files
with
56 additions
and
1 deletions
Show diff stats
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") |
45 | else | 45 | else |
46 | render_404 and return | 46 | render_404 and return |
47 | end | 47 | end |
@@ -0,0 +1,49 @@ | @@ -0,0 +1,49 @@ | ||
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe Profiles::KeysController do | ||
4 | + let(:user) { create(:user) } | ||
5 | + | ||
6 | + describe "#get_keys" do | ||
7 | + describe "non existant user" do | ||
8 | + it "should generally not work" do | ||
9 | + get :get_keys, username: 'not-existent' | ||
10 | + | ||
11 | + expect(response).not_to be_success | ||
12 | + end | ||
13 | + end | ||
14 | + | ||
15 | + describe "user with no keys" do | ||
16 | + it "should generally work" do | ||
17 | + get :get_keys, username: user.username | ||
18 | + | ||
19 | + expect(response).to be_success | ||
20 | + end | ||
21 | + | ||
22 | + it "should render all keys separated with a new line" do | ||
23 | + get :get_keys, username: user.username | ||
24 | + | ||
25 | + expect(response.body).to eq("") | ||
26 | + end | ||
27 | + end | ||
28 | + | ||
29 | + describe "user with keys" do | ||
30 | + before do | ||
31 | + user.keys << create(:key) | ||
32 | + user.keys << create(:another_key) | ||
33 | + end | ||
34 | + | ||
35 | + it "should generally work" do | ||
36 | + get :get_keys, username: user.username | ||
37 | + | ||
38 | + expect(response).to be_success | ||
39 | + end | ||
40 | + | ||
41 | + it "should render all keys separated with a new line" do | ||
42 | + get :get_keys, username: user.username | ||
43 | + | ||
44 | + expect(response.body).not_to eq("") | ||
45 | + expect(response.body).to eq(user.all_ssh_keys.join("\n")) | ||
46 | + end | ||
47 | + end | ||
48 | + end | ||
49 | +end |
spec/factories.rb
@@ -207,6 +207,12 @@ FactoryGirl.define do | @@ -207,6 +207,12 @@ FactoryGirl.define do | ||
207 | end | 207 | end |
208 | end | 208 | end |
209 | 209 | ||
210 | + factory :another_key do | ||
211 | + key do | ||
212 | + "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDmTillFzNTrrGgwaCKaSj+QCz81E6jBc/s9av0+3b1Hwfxgkqjl4nAK/OD2NjgyrONDTDfR8cRN4eAAy6nY8GLkOyYBDyuc5nTMqs5z3yVuTwf3koGm/YQQCmo91psZ2BgDFTor8SVEE5Mm1D1k3JDMhDFxzzrOtRYFPci9lskTJaBjpqWZ4E9rDTD2q/QZntCqbC3wE9uSemRQB5f8kik7vD/AD8VQXuzKladrZKkzkONCPWsXDspUitjM8HkQdOf0PsYn1CMUC1xKYbCxkg5TkEosIwGv6CoEArUrdu/4+10LVslq494mAvEItywzrluCLCnwELfW+h/m8UHoVhZ" | ||
213 | + end | ||
214 | + end | ||
215 | + | ||
210 | factory :invalid_key do | 216 | factory :invalid_key do |
211 | key do | 217 | key do |
212 | "ssh-rsa this_is_invalid_key==" | 218 | "ssh-rsa this_is_invalid_key==" |