From bd0aae21a5709a3d2557b5ac85a2a56ec0e4e681 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Mon, 27 May 2019 10:36:06 +1200 Subject: Be explicit about setting :masked Only some values can be masked. Currently API defaults :masked to false and browser defaults :masked to true - resolve this ambiguity by requiring QA to be explicit about which value it requires for :masked. --- qa/qa/resource/ci_variable.rb | 5 +++-- .../features/browser_ui/4_verify/ci_variable/add_ci_variable_spec.rb | 1 + .../browser_ui/6_release/deploy_key/clone_using_deploy_key_spec.rb | 1 + .../7_configure/auto_devops/create_project_with_auto_devops_spec.rb | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/qa/qa/resource/ci_variable.rb b/qa/qa/resource/ci_variable.rb index 341d3c1ed7e..dc9af14d83e 100644 --- a/qa/qa/resource/ci_variable.rb +++ b/qa/qa/resource/ci_variable.rb @@ -3,7 +3,7 @@ module QA module Resource class CiVariable < Base - attr_accessor :key, :value + attr_accessor :key, :value, :masked attribute :project do Project.fabricate! do |resource| @@ -49,7 +49,8 @@ module QA def api_post_body { key: key, - value: value + value: value, + masked: masked } end end diff --git a/qa/qa/specs/features/browser_ui/4_verify/ci_variable/add_ci_variable_spec.rb b/qa/qa/specs/features/browser_ui/4_verify/ci_variable/add_ci_variable_spec.rb index 561a8895329..b060f15168c 100644 --- a/qa/qa/specs/features/browser_ui/4_verify/ci_variable/add_ci_variable_spec.rb +++ b/qa/qa/specs/features/browser_ui/4_verify/ci_variable/add_ci_variable_spec.rb @@ -16,6 +16,7 @@ module QA resource.project = project resource.key = 'VARIABLE_KEY' resource.value = 'some_CI_variable' + resource.masked = false end project.visit! diff --git a/qa/qa/specs/features/browser_ui/6_release/deploy_key/clone_using_deploy_key_spec.rb b/qa/qa/specs/features/browser_ui/6_release/deploy_key/clone_using_deploy_key_spec.rb index 609155da855..2fe4e4d9d1f 100644 --- a/qa/qa/specs/features/browser_ui/6_release/deploy_key/clone_using_deploy_key_spec.rb +++ b/qa/qa/specs/features/browser_ui/6_release/deploy_key/clone_using_deploy_key_spec.rb @@ -60,6 +60,7 @@ module QA resource.project = @project resource.key = deploy_key_name resource.value = key.private_key + resource.masked = false end gitlab_ci = <<~YAML diff --git a/qa/qa/specs/features/browser_ui/7_configure/auto_devops/create_project_with_auto_devops_spec.rb b/qa/qa/specs/features/browser_ui/7_configure/auto_devops/create_project_with_auto_devops_spec.rb index 0971e551db1..9201a05337f 100644 --- a/qa/qa/specs/features/browser_ui/7_configure/auto_devops/create_project_with_auto_devops_spec.rb +++ b/qa/qa/specs/features/browser_ui/7_configure/auto_devops/create_project_with_auto_devops_spec.rb @@ -34,6 +34,7 @@ module QA resource.project = @project resource.key = 'CODE_QUALITY_DISABLED' resource.value = '1' + resource.masked = false end # Set an application secret CI variable (prefixed with K8S_SECRET_) @@ -41,6 +42,7 @@ module QA resource.project = @project resource.key = 'K8S_SECRET_OPTIONAL_MESSAGE' resource.value = 'you_can_see_this_variable' + resource.masked = false end # Connect K8s cluster -- cgit v1.2.1 From 33132427b3d4a14975b948fb15e22bc8a376dda2 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Mon, 27 May 2019 11:54:16 +1200 Subject: Add support for toggling masked on UI In addition to API, add support for toggling mased on UI too. (Though fabricate_via_browser_ui is private) --- app/views/ci/variables/_variable_row.html.haml | 2 +- qa/qa/page/project/settings/ci_variables.rb | 24 +++++++++++++++++++++++- qa/qa/resource/ci_variable.rb | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/views/ci/variables/_variable_row.html.haml b/app/views/ci/variables/_variable_row.html.haml index 89bd7b31352..ca2521e9bc6 100644 --- a/app/views/ci/variables/_variable_row.html.haml +++ b/app/views/ci/variables/_variable_row.html.haml @@ -59,7 +59,7 @@ .append-right-default = s_("CiVariable|Masked") %button{ type: 'button', - class: "js-project-feature-toggle project-feature-toggle #{'is-checked' if is_masked}", + class: "js-project-feature-toggle project-feature-toggle qa-variable-masked #{'is-checked' if is_masked}", "aria-label": s_("CiVariable|Toggle masked") } %input{ type: "hidden", class: 'js-ci-variable-input-masked js-project-feature-toggle-input', diff --git a/qa/qa/page/project/settings/ci_variables.rb b/qa/qa/page/project/settings/ci_variables.rb index 567fe6f83c8..3621e618bf2 100644 --- a/qa/qa/page/project/settings/ci_variables.rb +++ b/qa/qa/page/project/settings/ci_variables.rb @@ -11,6 +11,7 @@ module QA element :variable_row, '.ci-variable-row-body' # rubocop:disable QA/ElementWithPattern element :variable_key, '.qa-ci-variable-input-key' # rubocop:disable QA/ElementWithPattern element :variable_value, '.qa-ci-variable-input-value' # rubocop:disable QA/ElementWithPattern + element :variable_masked end view 'app/views/ci/variables/_index.html.haml' do @@ -18,7 +19,7 @@ module QA element :reveal_values, '.js-secret-value-reveal-button' # rubocop:disable QA/ElementWithPattern end - def fill_variable(key, value) + def fill_variable(key, value, masked) keys = all_elements(:ci_variable_input_key) index = keys.size - 1 @@ -32,6 +33,9 @@ module QA # The code was inspired from: # https://github.com/teamcapybara/capybara/blob/679548cea10773d45e32808f4d964377cfe5e892/lib/capybara/selenium/node.rb#L217 execute_script("arguments[0].value = #{value.to_json}", node) + + masked_node = all_elements(:variable_masked)[index] + toggle_masked(masked_node, masked) end def save_variables @@ -47,6 +51,24 @@ module QA find('.qa-ci-variable-input-value').value end end + + private + + def toggle_masked(masked_node, masked) + wait(reload: false) do + masked_node.click + + masked ? masked_enabled?(masked_node) : masked_disabled?(masked_node) + end + end + + def masked_enabled?(masked_node) + masked_node[:class].include?('is-checked') + end + + def masked_disabled?(masked_node) + !masked_enabled?(masked_node) + end end end end diff --git a/qa/qa/resource/ci_variable.rb b/qa/qa/resource/ci_variable.rb index dc9af14d83e..b178a64b72d 100644 --- a/qa/qa/resource/ci_variable.rb +++ b/qa/qa/resource/ci_variable.rb @@ -19,7 +19,7 @@ module QA Page::Project::Settings::CICD.perform do |setting| setting.expand_ci_variables do |page| - page.fill_variable(key, value) + page.fill_variable(key, value, masked) page.save_variables end -- cgit v1.2.1