diff --git a/app/controllers/profiles/keys_controller.rb b/app/controllers/profiles/keys_controller.rb index 2b991957b70..3bb1b0c2f2a 100644 --- a/app/controllers/profiles/keys_controller.rb +++ b/app/controllers/profiles/keys_controller.rb @@ -40,7 +40,7 @@ class Profiles::KeysController < ApplicationController if params[:username].present? begin user = User.find_by_username(params[:username]) - user.present? ? (render :text => user.all_ssh_keys) : + user.present? ? (render :text => user.all_ssh_keys.join('\n')) : (render_404 and return) rescue => e render text: e.message diff --git a/app/models/user.rb b/app/models/user.rb index 225c97d35ff..4c58effaf38 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -393,6 +393,6 @@ class User < ActiveRecord::Base end def all_ssh_keys - keys.collect{|x| x.key}.join("\n") + keys.collect{|x| x.key} end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index f6c9f82c4ee..f7e242af00a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -276,4 +276,16 @@ describe User do User.by_username_or_id('bar').should be_nil end end + + describe 'all_ssh_keys' do + it { should have_many(:keys).dependent(:destroy) } + + it "should have all ssh keys" do + user = create :user + key = create :key, key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD33bWLBxu48Sev9Fert1yzEO4WGcWglWF7K/AwblIUFselOt/QdOL9DSjpQGxLagO1s9wl53STIO8qGS4Ms0EJZyIXOEFMjFJ5xmjSy+S37By4sG7SsltQEHMxtbtFOaW5LV2wCrX+rUsRNqLMamZjgjcPO0/EgGCXIGMAYW4O7cwGZdXWYIhQ1Vwy+CsVMDdPkPgBXqK7nR/ey8KMs8ho5fMNgB5hBw/AL9fNGhRw3QTD6Q12Nkhl4VZES2EsZqlpNnJttnPdp847DUsT6yuLRlfiQfz5Cn9ysHFdXObMN5VYIiPFwHeYCZp1X2S4fDZooRE8uOLTfxWHPXwrhqSH", user_id: user.id + + user.all_ssh_keys.should include(key.key) + end + + end end diff --git a/spec/routing/routing_spec.rb b/spec/routing/routing_spec.rb index 946ef7c28cb..f5ffb211530 100644 --- a/spec/routing/routing_spec.rb +++ b/spec/routing/routing_spec.rb @@ -183,6 +183,11 @@ describe Profiles::KeysController, "routing" do it "to #destroy" do delete("/profile/keys/1").should route_to('profiles/keys#destroy', id: '1') end + + # get all the ssh-keys of a user + it "to #get_keys" do + get("/foo.keys").should route_to('profiles/keys#get_keys', username: 'foo') + end end # dashboard GET /dashboard(.:format) dashboard#show