2014-02-11 13:15:13 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Profiles::KeysController do
|
2016-04-14 06:20:16 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
describe '#new' do
|
|
|
|
before { sign_in(user) }
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'redirects to #index' do
|
2016-04-14 06:20:16 -04:00
|
|
|
get :new
|
|
|
|
|
|
|
|
expect(response).to redirect_to(profile_keys_path)
|
|
|
|
end
|
|
|
|
end
|
2014-02-11 13:15:13 -05:00
|
|
|
|
|
|
|
describe "#get_keys" do
|
|
|
|
describe "non existant user" do
|
2016-07-25 14:16:19 -04:00
|
|
|
it "does not generally work" do
|
2014-02-11 13:15:13 -05:00
|
|
|
get :get_keys, username: 'not-existent'
|
|
|
|
|
|
|
|
expect(response).not_to be_success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "user with no keys" do
|
2016-07-25 14:16:19 -04:00
|
|
|
it "does generally work" do
|
2014-02-11 13:15:13 -05:00
|
|
|
get :get_keys, username: user.username
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it "renders all keys separated with a new line" do
|
2014-02-11 13:15:13 -05:00
|
|
|
get :get_keys, username: user.username
|
|
|
|
|
|
|
|
expect(response.body).to eq("")
|
|
|
|
end
|
2014-03-19 09:32:38 -04:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it "responds with text/plain content type" do
|
2014-03-19 09:32:38 -04:00
|
|
|
get :get_keys, username: user.username
|
|
|
|
expect(response.content_type).to eq("text/plain")
|
|
|
|
end
|
2014-02-11 13:15:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "user with keys" do
|
|
|
|
before do
|
|
|
|
user.keys << create(:key)
|
|
|
|
user.keys << create(:another_key)
|
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it "does generally work" do
|
2014-02-11 13:15:13 -05:00
|
|
|
get :get_keys, username: user.username
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it "renders all keys separated with a new line" do
|
2014-02-11 13:15:13 -05:00
|
|
|
get :get_keys, username: user.username
|
|
|
|
|
|
|
|
expect(response.body).not_to eq("")
|
|
|
|
expect(response.body).to eq(user.all_ssh_keys.join("\n"))
|
2015-06-19 13:17:34 -04:00
|
|
|
|
|
|
|
# Unique part of key 1
|
|
|
|
expect(response.body).to match(/PWx6WM4lhHNedGfBpPJNPpZ/)
|
|
|
|
# Key 2
|
|
|
|
expect(response.body).to match(/AQDmTillFzNTrrGgwaCKaSj/)
|
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it "does not render the comment of the key" do
|
2015-06-19 13:17:34 -04:00
|
|
|
get :get_keys, username: user.username
|
|
|
|
|
|
|
|
expect(response.body).not_to match(/dummy@gitlab.com/)
|
2014-02-11 13:15:13 -05:00
|
|
|
end
|
2014-03-19 09:32:38 -04:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it "responds with text/plain content type" do
|
2014-03-19 09:32:38 -04:00
|
|
|
get :get_keys, username: user.username
|
|
|
|
expect(response.content_type).to eq("text/plain")
|
|
|
|
end
|
2014-02-11 13:15:13 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|