2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2016-09-02 11:55:16 -04:00
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe 'Profile > SSH Keys' do
|
2016-09-02 11:55:16 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2016-09-02 11:55:16 -04:00
|
|
|
end
|
|
|
|
|
2016-10-02 11:00:41 -04:00
|
|
|
describe 'User adds a key' do
|
|
|
|
before do
|
|
|
|
visit profile_keys_path
|
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'auto-populates the title', :js do
|
2016-09-02 11:55:16 -04:00
|
|
|
fill_in('Key', with: attributes_for(:key).fetch(:key))
|
|
|
|
|
2017-02-23 12:48:44 -05:00
|
|
|
expect(page).to have_field("Title", with: "dummy@gitlab.com")
|
2016-09-02 11:55:16 -04:00
|
|
|
end
|
2016-10-02 11:00:41 -04:00
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'saves the new key' do
|
2016-10-02 11:00:41 -04:00
|
|
|
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-01-01 08:55:52 -05:00
|
|
|
expect(find('.breadcrumbs-sub-title')).to have_link(attrs[:title])
|
2016-10-02 11:00:41 -04:00
|
|
|
end
|
2017-08-21 06:30:03 -04:00
|
|
|
|
2018-07-06 10:36:02 -04:00
|
|
|
it 'shows a confirmable warning if the key does not start with ssh-' do
|
|
|
|
attrs = attributes_for(:key)
|
|
|
|
|
|
|
|
fill_in('Key', with: 'invalid-key')
|
|
|
|
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
|
|
|
|
|
2017-08-21 06:30:03 -04:00
|
|
|
context 'when only DSA and ECDSA keys are allowed' do
|
|
|
|
before do
|
2017-08-25 09:08:48 -04:00
|
|
|
forbidden = ApplicationSetting::FORBIDDEN_KEY_VALUE
|
|
|
|
stub_application_setting(rsa_key_restriction: forbidden, ed25519_key_restriction: forbidden)
|
2017-08-21 06:30:03 -04:00
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'shows a validation error' do
|
2017-08-21 06:30:03 -04:00
|
|
|
attrs = attributes_for(:key)
|
|
|
|
|
|
|
|
fill_in('Key', with: attrs[:key])
|
|
|
|
fill_in('Title', with: attrs[:title])
|
|
|
|
click_button('Add key')
|
|
|
|
|
2017-08-25 09:08:48 -04:00
|
|
|
expect(page).to have_content('Key type is forbidden. Must be DSA or ECDSA')
|
2017-08-21 06:30:03 -04:00
|
|
|
end
|
|
|
|
end
|
2016-10-02 11:00:41 -04:00
|
|
|
end
|
|
|
|
|
2020-12-09 13:09:48 -05:00
|
|
|
it 'user sees their keys' do
|
2016-10-02 11:00:41 -04:00
|
|
|
key = create(:key, user: user)
|
|
|
|
visit profile_keys_path
|
|
|
|
|
|
|
|
expect(page).to have_content(key.title)
|
|
|
|
end
|
|
|
|
|
2020-09-30 11:09:46 -04:00
|
|
|
describe 'User removes a key', :js do
|
|
|
|
shared_examples 'removes key' do
|
|
|
|
it 'removes key' do
|
|
|
|
visit path
|
|
|
|
click_button('Delete')
|
2016-10-02 11:00:41 -04:00
|
|
|
|
2020-09-30 11:09:46 -04:00
|
|
|
page.within('.modal') do
|
|
|
|
page.click_button('Delete')
|
|
|
|
end
|
2016-10-02 11:00:41 -04:00
|
|
|
|
2020-09-30 11:09:46 -04:00
|
|
|
expect(page).to have_content('Your SSH keys (0)')
|
|
|
|
end
|
|
|
|
end
|
2016-10-02 11:00:41 -04:00
|
|
|
|
2020-09-30 11:09:46 -04:00
|
|
|
context 'via the key index' do
|
|
|
|
before do
|
|
|
|
create(:key, user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:path) { profile_keys_path }
|
2016-10-02 11:00:41 -04:00
|
|
|
|
2020-09-30 11:09:46 -04:00
|
|
|
it_behaves_like 'removes key'
|
|
|
|
end
|
2016-10-02 11:00:41 -04:00
|
|
|
|
2020-09-30 11:09:46 -04:00
|
|
|
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-02 11:55:16 -04:00
|
|
|
end
|
|
|
|
end
|