2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Profiles::KeysController do
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
describe 'POST #create' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a new key' do
|
|
|
|
expires_at = 3.days.from_now
|
|
|
|
|
|
|
|
expect do
|
|
|
|
post :create, params: { key: build(:key, expires_at: expires_at).attributes }
|
|
|
|
end.to change { Key.count }.by(1)
|
|
|
|
|
|
|
|
expect(Key.last.expires_at).to be_like_time(expires_at)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
describe "#get_keys" do
|
2018-12-13 13:39:08 +05:30
|
|
|
describe "non existent user" do
|
2016-09-13 17:45:13 +05:30
|
|
|
it "does not generally work" do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :get_keys, params: { username: 'not-existent' }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(response).not_to be_successful
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "user with no keys" do
|
2016-09-13 17:45:13 +05:30
|
|
|
it "does generally work" do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :get_keys, params: { username: user.username }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(response).to be_successful
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "renders all keys separated with a new line" do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :get_keys, params: { username: user.username }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
expect(response.body).to eq("")
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "responds with text/plain content type" do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :get_keys, params: { username: user.username }
|
2014-09-02 18:07:02 +05:30
|
|
|
expect(response.content_type).to eq("text/plain")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "user with keys" do
|
2017-08-17 22:00:37 +05:30
|
|
|
let!(:key) { create(:key, user: user) }
|
|
|
|
let!(:another_key) { create(:another_key, user: user) }
|
|
|
|
let!(:deploy_key) { create(:deploy_key, user: user) }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "does generally work" do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :get_keys, params: { username: user.username }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(response).to be_successful
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it "renders all non deploy keys separated with a new line" do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :get_keys, params: { username: user.username }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(response.body).not_to eq('')
|
2014-09-02 18:07:02 +05:30
|
|
|
expect(response.body).to eq(user.all_ssh_keys.join("\n"))
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(response.body).to include(key.key.sub(' dummy@gitlab.com', ''))
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(response.body).to include(another_key.key.sub(' dummy@gitlab.com', ''))
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(response.body).not_to include(deploy_key.key)
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "does not render the comment of the key" do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :get_keys, params: { username: user.username }
|
2015-09-11 14:41:01 +05:30
|
|
|
|
|
|
|
expect(response.body).not_to match(/dummy@gitlab.com/)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "responds with text/plain content type" do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :get_keys, params: { username: user.username }
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
expect(response.content_type).to eq("text/plain")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|