2019-04-15 10:17:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-02-11 18:15:13 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Profiles::KeysController do
|
2016-04-14 10:20:16 +00:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2014-02-11 18:15:13 +00:00
|
|
|
describe "#get_keys" do
|
2018-10-30 10:53:01 +00:00
|
|
|
describe "non existent user" do
|
2016-07-25 18:16:19 +00:00
|
|
|
it "does not generally work" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :get_keys, params: { username: 'not-existent' }
|
2014-02-11 18:15:13 +00:00
|
|
|
|
|
|
|
expect(response).not_to be_success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "user with no keys" do
|
2016-07-25 18:16:19 +00:00
|
|
|
it "does generally work" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :get_keys, params: { username: user.username }
|
2014-02-11 18:15:13 +00:00
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it "renders all keys separated with a new line" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :get_keys, params: { username: user.username }
|
2014-02-11 18:15:13 +00:00
|
|
|
|
|
|
|
expect(response.body).to eq("")
|
|
|
|
end
|
2014-03-19 13:32:38 +00:00
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it "responds with text/plain content type" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :get_keys, params: { username: user.username }
|
2014-03-19 13:32:38 +00:00
|
|
|
expect(response.content_type).to eq("text/plain")
|
|
|
|
end
|
2014-02-11 18:15:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "user with keys" do
|
2017-02-07 12:56:50 +00:00
|
|
|
let!(:key) { create(:key, user: user) }
|
|
|
|
let!(:another_key) { create(:another_key, user: user) }
|
|
|
|
let!(:deploy_key) { create(:deploy_key, user: user) }
|
2014-02-11 18:15:13 +00:00
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it "does generally work" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :get_keys, params: { username: user.username }
|
2014-02-11 18:15:13 +00:00
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
|
2017-02-07 12:56:50 +00:00
|
|
|
it "renders all non deploy keys separated with a new line" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :get_keys, params: { username: user.username }
|
2014-02-11 18:15:13 +00:00
|
|
|
|
2017-02-07 12:56:50 +00:00
|
|
|
expect(response.body).not_to eq('')
|
2014-02-11 18:15:13 +00:00
|
|
|
expect(response.body).to eq(user.all_ssh_keys.join("\n"))
|
2015-06-19 17:17:34 +00:00
|
|
|
|
2017-02-07 12:56:50 +00:00
|
|
|
expect(response.body).to include(key.key.sub(' dummy@gitlab.com', ''))
|
2017-05-31 13:43:19 +00:00
|
|
|
expect(response.body).to include(another_key.key.sub(' dummy@gitlab.com', ''))
|
2017-02-07 12:56:50 +00:00
|
|
|
|
|
|
|
expect(response.body).not_to include(deploy_key.key)
|
2015-06-19 17:17:34 +00:00
|
|
|
end
|
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it "does not render the comment of the key" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :get_keys, params: { username: user.username }
|
2015-06-19 17:17:34 +00:00
|
|
|
|
|
|
|
expect(response.body).not_to match(/dummy@gitlab.com/)
|
2014-02-11 18:15:13 +00:00
|
|
|
end
|
2014-03-19 13:32:38 +00:00
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it "responds with text/plain content type" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :get_keys, params: { username: user.username }
|
2018-11-23 16:44:09 +00:00
|
|
|
|
2014-03-19 13:32:38 +00:00
|
|
|
expect(response.content_type).to eq("text/plain")
|
|
|
|
end
|
2014-02-11 18:15:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|