2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
require 'spec_helper'
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe 'Profile > SSH Keys' do
|
2016-09-29 09:46:39 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
describe 'User adds a key' do
|
|
|
|
before do
|
|
|
|
visit profile_keys_path
|
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'auto-populates the title', :js do
|
2016-09-29 09:46:39 +05:30
|
|
|
fill_in('Key', with: attributes_for(:key).fetch(:key))
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(page).to have_field("Title", with: "dummy@gitlab.com")
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'saves the new key' do
|
2016-11-03 12:29:30 +05:30
|
|
|
attrs = attributes_for(:key)
|
|
|
|
|
|
|
|
fill_in('Key', with: attrs[:key])
|
|
|
|
fill_in('Title', with: attrs[:title])
|
|
|
|
click_button('Add key')
|
|
|
|
|
|
|
|
expect(page).to have_content("Title: #{attrs[:title]}")
|
|
|
|
expect(page).to have_content(attrs[:key])
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(find('.breadcrumbs-sub-title')).to have_link(attrs[:title])
|
|
|
|
end
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it 'shows a confirmable warning if the key begins with an algorithm name that is unsupported' do
|
2018-11-08 19:23:39 +05:30
|
|
|
attrs = attributes_for(:key)
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
fill_in('Key', with: 'unsupported-ssh-rsa key')
|
2018-11-08 19:23:39 +05:30
|
|
|
fill_in('Title', with: attrs[:title])
|
|
|
|
click_button('Add key')
|
|
|
|
|
|
|
|
expect(page).to have_selector('.js-add-ssh-key-validation-warning')
|
|
|
|
|
|
|
|
find('.js-add-ssh-key-validation-confirm-submit').click
|
|
|
|
|
|
|
|
expect(page).to have_content('Key is invalid')
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when only DSA and ECDSA keys are allowed' do
|
|
|
|
before do
|
|
|
|
forbidden = ApplicationSetting::FORBIDDEN_KEY_VALUE
|
2022-04-04 11:22:00 +05:30
|
|
|
stub_application_setting(
|
|
|
|
rsa_key_restriction: forbidden,
|
|
|
|
ed25519_key_restriction: forbidden,
|
|
|
|
ecdsa_sk_key_restriction: forbidden,
|
|
|
|
ed25519_sk_key_restriction: forbidden
|
|
|
|
)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'shows a validation error' do
|
2018-03-17 18:26:18 +05:30
|
|
|
attrs = attributes_for(:key)
|
|
|
|
|
|
|
|
fill_in('Key', with: attrs[:key])
|
|
|
|
fill_in('Title', with: attrs[:title])
|
|
|
|
click_button('Add key')
|
|
|
|
|
|
|
|
expect(page).to have_content('Key type is forbidden. Must be DSA or ECDSA')
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'user sees their keys' do
|
2016-11-03 12:29:30 +05:30
|
|
|
key = create(:key, user: user)
|
|
|
|
visit profile_keys_path
|
|
|
|
|
|
|
|
expect(page).to have_content(key.title)
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
describe 'User removes a key', :js do
|
|
|
|
shared_examples 'removes key' do
|
|
|
|
it 'removes key' do
|
|
|
|
visit path
|
|
|
|
click_button('Delete')
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
page.within('.modal') do
|
|
|
|
page.click_button('Delete')
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(page).to have_content('Your SSH keys (0)')
|
|
|
|
end
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
context 'via the key index' do
|
|
|
|
before do
|
|
|
|
create(:key, user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:path) { profile_keys_path }
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it_behaves_like 'removes key'
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
context 'via its details page' do
|
|
|
|
let(:key) { create(:key, user: user) }
|
|
|
|
let(:path) { profile_keys_path(key) }
|
|
|
|
|
|
|
|
it_behaves_like 'removes key'
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|