2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'variable list' do
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'shows list of variables' do
|
|
|
|
page.within('.js-ci-variable-list-section') do
|
|
|
|
expect(first('.js-ci-variable-input-key').value).to eq(variable.key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it 'adds new CI variable' do
|
2018-03-17 18:26:18 +05:30
|
|
|
page.within('.js-ci-variable-list-section .js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('key')
|
2019-07-07 11:18:12 +05:30
|
|
|
find('.js-ci-variable-input-value').set('key_value')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
visit page_path
|
|
|
|
|
|
|
|
# We check the first row because it re-sorts to alphabetical order on refresh
|
2019-07-31 22:56:46 +05:30
|
|
|
page.within('.js-ci-variable-list-section .js-row:nth-child(2)') do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(find('.js-ci-variable-input-key').value).to eq('key')
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(find('.js-ci-variable-input-value', visible: false).value).to eq('key_value')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it 'adds a new protected variable' do
|
2018-03-17 18:26:18 +05:30
|
|
|
page.within('.js-ci-variable-list-section .js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('key')
|
2019-07-07 11:18:12 +05:30
|
|
|
find('.js-ci-variable-input-value').set('key_value')
|
|
|
|
find('.ci-variable-protected-item .js-project-feature-toggle').click
|
|
|
|
|
|
|
|
expect(find('.js-ci-variable-input-protected', visible: false).value).to eq('true')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
visit page_path
|
|
|
|
|
|
|
|
# We check the first row because it re-sorts to alphabetical order on refresh
|
2019-07-31 22:56:46 +05:30
|
|
|
page.within('.js-ci-variable-list-section .js-row:nth-child(2)') do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(find('.js-ci-variable-input-key').value).to eq('key')
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(find('.js-ci-variable-input-value', visible: false).value).to eq('key_value')
|
|
|
|
expect(find('.js-ci-variable-input-protected', visible: false).value).to eq('true')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it 'defaults to unmasked' do
|
2018-03-17 18:26:18 +05:30
|
|
|
page.within('.js-ci-variable-list-section .js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('key')
|
2019-07-07 11:18:12 +05:30
|
|
|
find('.js-ci-variable-input-value').set('key_value')
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(find('.js-ci-variable-input-masked', visible: false).value).to eq('false')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
visit page_path
|
|
|
|
|
|
|
|
# We check the first row because it re-sorts to alphabetical order on refresh
|
2019-07-31 22:56:46 +05:30
|
|
|
page.within('.js-ci-variable-list-section .js-row:nth-child(2)') do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(find('.js-ci-variable-input-key').value).to eq('key')
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(find('.js-ci-variable-input-value', visible: false).value).to eq('key_value')
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(find('.js-ci-variable-input-masked', visible: false).value).to eq('false')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
context 'defaults to the application setting' do
|
|
|
|
context 'application setting is true' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(protected_ci_variables: true)
|
|
|
|
|
|
|
|
visit page_path
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults to protected' do
|
|
|
|
page.within('.js-ci-variable-list-section .js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('key')
|
|
|
|
end
|
|
|
|
|
|
|
|
values = all('.js-ci-variable-input-protected', visible: false).map(&:value)
|
|
|
|
|
|
|
|
expect(values).to eq %w(false true true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows a message regarding the changed default' do
|
|
|
|
expect(page).to have_content 'Environment variables are configured by your administrator to be protected by default'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'application setting is false' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(protected_ci_variables: false)
|
|
|
|
|
|
|
|
visit page_path
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults to unprotected' do
|
|
|
|
page.within('.js-ci-variable-list-section .js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('key')
|
|
|
|
end
|
|
|
|
|
|
|
|
values = all('.js-ci-variable-input-protected', visible: false).map(&:value)
|
|
|
|
|
|
|
|
expect(values).to eq %w(false false false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not show a message regarding the default' do
|
|
|
|
expect(page).not_to have_content 'Environment variables are configured by your administrator to be protected by default'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'reveals and hides variables' do
|
|
|
|
page.within('.js-ci-variable-list-section') do
|
|
|
|
expect(first('.js-ci-variable-input-key').value).to eq(variable.key)
|
|
|
|
expect(first('.js-ci-variable-input-value', visible: false).value).to eq(variable.value)
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(page).to have_content('*' * 17)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
click_button('Reveal value')
|
|
|
|
|
|
|
|
expect(first('.js-ci-variable-input-key').value).to eq(variable.key)
|
|
|
|
expect(first('.js-ci-variable-input-value').value).to eq(variable.value)
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(page).not_to have_content('*' * 17)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
click_button('Hide value')
|
|
|
|
|
|
|
|
expect(first('.js-ci-variable-input-key').value).to eq(variable.key)
|
|
|
|
expect(first('.js-ci-variable-input-value', visible: false).value).to eq(variable.value)
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(page).to have_content('*' * 17)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'deletes variable' do
|
|
|
|
page.within('.js-ci-variable-list-section') do
|
|
|
|
expect(page).to have_selector('.js-row', count: 2)
|
|
|
|
|
|
|
|
first('.js-row-remove-button').click
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
expect(page).to have_selector('.js-row', count: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'edits variable' do
|
|
|
|
page.within('.js-ci-variable-list-section') do
|
|
|
|
click_button('Reveal value')
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
page.within('.js-row:nth-child(2)') do
|
2018-03-17 18:26:18 +05:30
|
|
|
find('.js-ci-variable-input-key').set('new_key')
|
|
|
|
find('.js-ci-variable-input-value').set('new_value')
|
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
visit page_path
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
page.within('.js-row:nth-child(2)') do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(find('.js-ci-variable-input-key').value).to eq('new_key')
|
|
|
|
expect(find('.js-ci-variable-input-value', visible: false).value).to eq('new_value')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'edits variable to be protected' do
|
|
|
|
# Create the unprotected variable
|
|
|
|
page.within('.js-ci-variable-list-section .js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('unprotected_key')
|
|
|
|
find('.js-ci-variable-input-value').set('unprotected_value')
|
|
|
|
|
|
|
|
expect(find('.js-ci-variable-input-protected', visible: false).value).to eq('false')
|
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
visit page_path
|
|
|
|
|
|
|
|
# We check the first row because it re-sorts to alphabetical order on refresh
|
2019-07-31 22:56:46 +05:30
|
|
|
page.within('.js-ci-variable-list-section .js-row:nth-child(3)') do
|
2018-03-17 18:26:18 +05:30
|
|
|
find('.ci-variable-protected-item .js-project-feature-toggle').click
|
|
|
|
|
|
|
|
expect(find('.js-ci-variable-input-protected', visible: false).value).to eq('true')
|
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
visit page_path
|
|
|
|
|
|
|
|
# We check the first row because it re-sorts to alphabetical order on refresh
|
2019-07-31 22:56:46 +05:30
|
|
|
page.within('.js-ci-variable-list-section .js-row:nth-child(3)') do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(find('.js-ci-variable-input-key').value).to eq('unprotected_key')
|
|
|
|
expect(find('.js-ci-variable-input-value', visible: false).value).to eq('unprotected_value')
|
|
|
|
expect(find('.js-ci-variable-input-protected', visible: false).value).to eq('true')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'edits variable to be unprotected' do
|
|
|
|
# Create the protected variable
|
|
|
|
page.within('.js-ci-variable-list-section .js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('protected_key')
|
|
|
|
find('.js-ci-variable-input-value').set('protected_value')
|
|
|
|
find('.ci-variable-protected-item .js-project-feature-toggle').click
|
|
|
|
|
|
|
|
expect(find('.js-ci-variable-input-protected', visible: false).value).to eq('true')
|
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
visit page_path
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
page.within('.js-ci-variable-list-section .js-row:nth-child(2)') do
|
2018-03-17 18:26:18 +05:30
|
|
|
find('.ci-variable-protected-item .js-project-feature-toggle').click
|
|
|
|
|
|
|
|
expect(find('.js-ci-variable-input-protected', visible: false).value).to eq('false')
|
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
visit page_path
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
page.within('.js-ci-variable-list-section .js-row:nth-child(2)') do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(find('.js-ci-variable-input-key').value).to eq('protected_key')
|
|
|
|
expect(find('.js-ci-variable-input-value', visible: false).value).to eq('protected_value')
|
|
|
|
expect(find('.js-ci-variable-input-protected', visible: false).value).to eq('false')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it 'edits variable to be unmasked' do
|
2019-09-04 21:01:54 +05:30
|
|
|
page.within('.js-ci-variable-list-section .js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('unmasked_key')
|
|
|
|
find('.js-ci-variable-input-value').set('unmasked_value')
|
|
|
|
expect(find('.js-ci-variable-input-masked', visible: false).value).to eq('false')
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
find('.ci-variable-masked-item .js-project-feature-toggle').click
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(find('.js-ci-variable-input-masked', visible: false).value).to eq('true')
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
visit page_path
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
page.within('.js-ci-variable-list-section .js-row:nth-child(2)') do
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(find('.js-ci-variable-input-masked', visible: false).value).to eq('true')
|
|
|
|
|
|
|
|
find('.ci-variable-masked-item .js-project-feature-toggle').click
|
|
|
|
|
|
|
|
expect(find('.js-ci-variable-input-masked', visible: false).value).to eq('false')
|
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
visit page_path
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
page.within('.js-ci-variable-list-section .js-row:nth-child(2)') do
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(find('.js-ci-variable-input-masked', visible: false).value).to eq('false')
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'edits variable to be masked' do
|
|
|
|
page.within('.js-ci-variable-list-section .js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('masked_key')
|
|
|
|
find('.js-ci-variable-input-value').set('masked_value')
|
|
|
|
expect(find('.js-ci-variable-input-masked', visible: false).value).to eq('false')
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
find('.ci-variable-masked-item .js-project-feature-toggle').click
|
|
|
|
|
|
|
|
expect(find('.js-ci-variable-input-masked', visible: false).value).to eq('true')
|
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
visit page_path
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
page.within('.js-ci-variable-list-section .js-row:nth-child(2)') do
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(find('.js-ci-variable-input-masked', visible: false).value).to eq('true')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'handles multiple edits and deletion in the middle' do
|
|
|
|
page.within('.js-ci-variable-list-section') do
|
|
|
|
# Create 2 variables
|
|
|
|
page.within('.js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('akey')
|
|
|
|
find('.js-ci-variable-input-value').set('akeyvalue')
|
|
|
|
end
|
|
|
|
page.within('.js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('zkey')
|
|
|
|
find('.js-ci-variable-input-value').set('zkeyvalue')
|
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
expect(page).to have_selector('.js-row', count: 4)
|
|
|
|
|
|
|
|
# Remove the `akey` variable
|
2019-07-31 22:56:46 +05:30
|
|
|
page.within('.js-row:nth-child(3)') do
|
2018-03-17 18:26:18 +05:30
|
|
|
first('.js-row-remove-button').click
|
|
|
|
end
|
|
|
|
|
|
|
|
# Add another variable
|
|
|
|
page.within('.js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('ckey')
|
|
|
|
find('.js-ci-variable-input-value').set('ckeyvalue')
|
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
visit page_path
|
|
|
|
|
|
|
|
# Expect to find 3 variables(4 rows) in alphbetical order
|
|
|
|
expect(page).to have_selector('.js-row', count: 4)
|
|
|
|
row_keys = all('.js-ci-variable-input-key')
|
|
|
|
expect(row_keys[0].value).to eq('ckey')
|
|
|
|
expect(row_keys[1].value).to eq('test_key')
|
|
|
|
expect(row_keys[2].value).to eq('zkey')
|
|
|
|
expect(row_keys[3].value).to eq('')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows validation error box about duplicate keys' do
|
|
|
|
page.within('.js-ci-variable-list-section .js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('samekey')
|
2019-07-07 11:18:12 +05:30
|
|
|
find('.js-ci-variable-input-value').set('value123')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
page.within('.js-ci-variable-list-section .js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('samekey')
|
2019-07-07 11:18:12 +05:30
|
|
|
find('.js-ci-variable-input-value').set('value456')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(all('.js-ci-variable-list-section .js-ci-variable-error-box ul li').count).to eq(1)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
# We check the first row because it re-sorts to alphabetical order on refresh
|
|
|
|
page.within('.js-ci-variable-list-section') do
|
|
|
|
expect(find('.js-ci-variable-error-box')).to have_content(/Validation failed Variables have duplicate values \(.+\)/)
|
|
|
|
end
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it 'shows validation error box about masking empty values' do
|
2019-07-07 11:18:12 +05:30
|
|
|
page.within('.js-ci-variable-list-section .js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('empty_value')
|
|
|
|
find('.js-ci-variable-input-value').set('')
|
2019-09-04 21:01:54 +05:30
|
|
|
find('.ci-variable-masked-item .js-project-feature-toggle').click
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
page.within('.js-ci-variable-list-section') do
|
|
|
|
expect(all('.js-ci-variable-error-box ul li').count).to eq(1)
|
|
|
|
expect(find('.js-ci-variable-error-box')).to have_content(/Validation failed Variables value is invalid/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows validation error box about unmaskable values' do
|
|
|
|
page.within('.js-ci-variable-list-section .js-row:last-child') do
|
|
|
|
find('.js-ci-variable-input-key').set('unmaskable_value')
|
|
|
|
find('.js-ci-variable-input-value').set('???')
|
2019-09-04 21:01:54 +05:30
|
|
|
find('.ci-variable-masked-item .js-project-feature-toggle').click
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
click_button('Save variables')
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
page.within('.js-ci-variable-list-section') do
|
|
|
|
expect(all('.js-ci-variable-error-box ul li').count).to eq(1)
|
|
|
|
expect(find('.js-ci-variable-error-box')).to have_content(/Validation failed Variables value is invalid/)
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|