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
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'shows a list of variables' do
|
|
|
|
page.within('.ci-variable-table') do
|
|
|
|
expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Key"]').text).to eq(variable.key)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'adds a new CI variable' do
|
|
|
|
click_button('Add Variable')
|
|
|
|
|
|
|
|
fill_variable('key', 'key_value') do
|
|
|
|
click_button('Add variable')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within('.ci-variable-table') do
|
|
|
|
expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Key"]').text).to eq('key')
|
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
|
2021-01-29 00:20:46 +05:30
|
|
|
click_button('Add Variable')
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
fill_variable('key', 'key_value') do
|
|
|
|
click_button('Add variable')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within('.ci-variable-table') do
|
|
|
|
expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Key"]').text).to eq('key')
|
|
|
|
expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Protected"] svg[data-testid="mobile-issue-close-icon"]')).to be_present
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it 'defaults to unmasked' do
|
2021-01-29 00:20:46 +05:30
|
|
|
click_button('Add Variable')
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
fill_variable('key', 'key_value') do
|
|
|
|
click_button('Add variable')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within('.ci-variable-table') do
|
|
|
|
expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Key"]').text).to eq('key')
|
|
|
|
expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Masked"] svg[data-testid="close-icon"]')).to be_present
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'reveals and hides variables' do
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within('.ci-variable-table') do
|
|
|
|
expect(first('.js-ci-variable-row td[data-label="Key"]').text).to eq(variable.key)
|
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')
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(first('.js-ci-variable-row td[data-label="Key"]').text).to eq(variable.key)
|
|
|
|
expect(first('.js-ci-variable-row td[data-label="Value"]').text).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')
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(first('.js-ci-variable-row td[data-label="Key"]').text).to eq(variable.key)
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(page).to have_content('*' * 17)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'deletes a variable' do
|
|
|
|
expect(page).to have_selector('.js-ci-variable-row', count: 1)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within('.ci-variable-table') do
|
|
|
|
click_button('Edit')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within('#add-ci-variable') do
|
|
|
|
click_button('Delete variable')
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
wait_for_requests
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(first('.js-ci-variable-row').text).to eq('There are no variables yet.')
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'edits a variable' do
|
|
|
|
page.within('.ci-variable-table') do
|
|
|
|
click_button('Edit')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within('#add-ci-variable') do
|
|
|
|
find('[data-qa-selector="ci_variable_key_field"] input').set('new_key')
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
click_button('Update variable')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(first('.js-ci-variable-row td[data-label="Key"]').text).to eq('new_key')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'edits a variable to be unmasked' do
|
|
|
|
page.within('.ci-variable-table') do
|
|
|
|
click_button('Edit')
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within('#add-ci-variable') do
|
|
|
|
find('[data-testid="ci-variable-protected-checkbox"]').click
|
|
|
|
find('[data-testid="ci-variable-masked-checkbox"]').click
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
click_button('Update variable')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within('.ci-variable-table') do
|
|
|
|
expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Masked"] svg[data-testid="close-icon"]')).to be_present
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'edits a variable to be masked' do
|
|
|
|
page.within('.ci-variable-table') do
|
|
|
|
click_button('Edit')
|
|
|
|
end
|
|
|
|
|
|
|
|
page.within('#add-ci-variable') do
|
|
|
|
find('[data-testid="ci-variable-masked-checkbox"]').click
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
click_button('Update variable')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within('.ci-variable-table') do
|
|
|
|
click_button('Edit')
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within('#add-ci-variable') do
|
|
|
|
find('[data-testid="ci-variable-masked-checkbox"]').click
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
click_button('Update variable')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within('.ci-variable-table') do
|
|
|
|
expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Masked"] svg[data-testid="mobile-issue-close-icon"]')).to be_present
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'shows a validation error box about duplicate keys' do
|
|
|
|
click_button('Add Variable')
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
fill_variable('key', 'key_value') do
|
|
|
|
click_button('Add variable')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
wait_for_requests
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
click_button('Add Variable')
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
fill_variable('key', 'key_value') do
|
|
|
|
click_button('Add variable')
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(find('.flash-container')).to be_present
|
|
|
|
expect(find('.flash-text').text).to have_content('Variables key (key) has already been taken')
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'prevents a variable to be added if no values are provided when a variable is set to masked' do
|
|
|
|
click_button('Add Variable')
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within('#add-ci-variable') do
|
|
|
|
find('[data-qa-selector="ci_variable_key_field"] input').set('empty_mask_key')
|
|
|
|
find('[data-testid="ci-variable-protected-checkbox"]').click
|
|
|
|
find('[data-testid="ci-variable-masked-checkbox"]').click
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(find_button('Add variable', disabled: true)).to be_present
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'shows validation error box about unmaskable values' do
|
|
|
|
click_button('Add Variable')
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
fill_variable('empty_mask_key', '???', protected: true, masked: true) do
|
|
|
|
expect(page).to have_content('This variable can not be masked')
|
|
|
|
expect(find_button('Add variable', disabled: true)).to be_present
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'handles multiple edits and a deletion' do
|
|
|
|
# Create two variables
|
|
|
|
click_button('Add Variable')
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
fill_variable('akey', 'akeyvalue') do
|
|
|
|
click_button('Add variable')
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
click_button('Add Variable')
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
fill_variable('zkey', 'zkeyvalue') do
|
|
|
|
click_button('Add variable')
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
wait_for_requests
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(page).to have_selector('.js-ci-variable-row', count: 3)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
# Remove the `akey` variable
|
|
|
|
page.within('.ci-variable-table') do
|
|
|
|
page.within('.js-ci-variable-row:first-child') do
|
|
|
|
click_button('Edit')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within('#add-ci-variable') do
|
|
|
|
click_button('Delete variable')
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
wait_for_requests
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
# Add another variable
|
|
|
|
click_button('Add Variable')
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
fill_variable('ckey', 'ckeyvalue') do
|
|
|
|
click_button('Add variable')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
# expect to find 3 rows of variables in alphabetical order
|
|
|
|
expect(page).to have_selector('.js-ci-variable-row', count: 3)
|
|
|
|
rows = all('.js-ci-variable-row')
|
|
|
|
expect(rows[0].find('td[data-label="Key"]').text).to eq('ckey')
|
|
|
|
expect(rows[1].find('td[data-label="Key"]').text).to eq('test_key')
|
|
|
|
expect(rows[2].find('td[data-label="Key"]').text).to eq('zkey')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
context 'defaults to the application setting' do
|
|
|
|
context 'application setting is true' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(protected_ci_variables: true)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
visit page_path
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'defaults to protected' do
|
|
|
|
click_button('Add Variable')
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within('#add-ci-variable') do
|
|
|
|
expect(find('[data-testid="ci-variable-protected-checkbox"]')).to be_checked
|
|
|
|
end
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
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
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
context 'application setting is false' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(protected_ci_variables: false)
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
visit page_path
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'defaults to unprotected' do
|
|
|
|
click_button('Add Variable')
|
|
|
|
|
|
|
|
page.within('#add-ci-variable') do
|
|
|
|
expect(find('[data-testid="ci-variable-protected-checkbox"]')).not_to be_checked
|
|
|
|
end
|
|
|
|
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
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
def fill_variable(key, value, protected: false, masked: false)
|
|
|
|
page.within('#add-ci-variable') do
|
|
|
|
find('[data-qa-selector="ci_variable_key_field"] input').set(key)
|
|
|
|
find('[data-qa-selector="ci_variable_value_field"]').set(value) if value.present?
|
|
|
|
find('[data-testid="ci-variable-protected-checkbox"]').click if protected
|
|
|
|
find('[data-testid="ci-variable-masked-checkbox"]').click if masked
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
yield
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|