Merge pull request #6297 from jojosch/user-public-ssh-keys-newline

Split the user ssh keys by newline, not the characters "\n"
This commit is contained in:
Dmitriy Zaporozhets 2014-02-11 21:07:52 +02:00
commit 1bcf0aa2e6
3 changed files with 56 additions and 1 deletions

View file

@ -41,7 +41,7 @@ class Profiles::KeysController < ApplicationController
begin
user = User.find_by_username(params[:username])
if user.present?
render text: user.all_ssh_keys.join('\n')
render text: user.all_ssh_keys.join("\n")
else
render_404 and return
end

View file

@ -0,0 +1,49 @@
require 'spec_helper'
describe Profiles::KeysController do
let(:user) { create(:user) }
describe "#get_keys" do
describe "non existant user" do
it "should generally not work" do
get :get_keys, username: 'not-existent'
expect(response).not_to be_success
end
end
describe "user with no keys" do
it "should generally work" do
get :get_keys, username: user.username
expect(response).to be_success
end
it "should render all keys separated with a new line" do
get :get_keys, username: user.username
expect(response.body).to eq("")
end
end
describe "user with keys" do
before do
user.keys << create(:key)
user.keys << create(:another_key)
end
it "should generally work" do
get :get_keys, username: user.username
expect(response).to be_success
end
it "should render all keys separated with a new line" do
get :get_keys, username: user.username
expect(response.body).not_to eq("")
expect(response.body).to eq(user.all_ssh_keys.join("\n"))
end
end
end
end

View file

@ -207,6 +207,12 @@ FactoryGirl.define do
end
end
factory :another_key do
key do
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDmTillFzNTrrGgwaCKaSj+QCz81E6jBc/s9av0+3b1Hwfxgkqjl4nAK/OD2NjgyrONDTDfR8cRN4eAAy6nY8GLkOyYBDyuc5nTMqs5z3yVuTwf3koGm/YQQCmo91psZ2BgDFTor8SVEE5Mm1D1k3JDMhDFxzzrOtRYFPci9lskTJaBjpqWZ4E9rDTD2q/QZntCqbC3wE9uSemRQB5f8kik7vD/AD8VQXuzKladrZKkzkONCPWsXDspUitjM8HkQdOf0PsYn1CMUC1xKYbCxkg5TkEosIwGv6CoEArUrdu/4+10LVslq494mAvEItywzrluCLCnwELfW+h/m8UHoVhZ"
end
end
factory :invalid_key do
key do
"ssh-rsa this_is_invalid_key=="