From d29220645ea7f40c31002ae33f926ca1f418b198 Mon Sep 17 00:00:00 2001
From: Will Meek <wmeek@gitlab.com>
Date: Wed, 19 Jan 2022 22:56:54 +0000
Subject: [PATCH] Add a check for Configuration History

Configuration History should not exist when
CI config is not present. Auto Devops button
should be present. As per bugfix MR
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/70025
---
 .../security_configuration/components/app.vue |  9 ++-
 .../components/auto_dev_ops_alert.vue         |  1 +
 .../.gitlab-ci.yml                            | 23 ------
 .../page/project/secure/configuration_form.rb | 46 +++++++++++
 ...enable_scanning_from_configuration_spec.rb | 81 ++++++++++---------
 qa/qa/support/matchers/have_matcher.rb        |  3 +
 6 files changed, 97 insertions(+), 66 deletions(-)
 delete mode 100644 qa/qa/ee/fixtures/secure_scanning_enable_from_ui_files/.gitlab-ci.yml

diff --git a/app/assets/javascripts/security_configuration/components/app.vue b/app/assets/javascripts/security_configuration/components/app.vue
index 304aa80e388fd..d228f77f27d43 100644
--- a/app/assets/javascripts/security_configuration/components/app.vue
+++ b/app/assets/javascripts/security_configuration/components/app.vue
@@ -192,9 +192,12 @@ export default {
               {{ $options.i18n.description }}
             </p>
             <p v-if="canViewCiHistory">
-              <gl-link data-testid="security-view-history-link" :href="gitlabCiHistoryPath">{{
-                $options.i18n.configurationHistory
-              }}</gl-link>
+              <gl-link
+                data-testid="security-view-history-link"
+                data-qa-selector="security_configuration_history_link"
+                :href="gitlabCiHistoryPath"
+                >{{ $options.i18n.configurationHistory }}</gl-link
+              >
             </p>
           </template>
 
diff --git a/app/assets/javascripts/security_configuration/components/auto_dev_ops_alert.vue b/app/assets/javascripts/security_configuration/components/auto_dev_ops_alert.vue
index ce6a1b4888b0b..315f676e6597a 100644
--- a/app/assets/javascripts/security_configuration/components/auto_dev_ops_alert.vue
+++ b/app/assets/javascripts/security_configuration/components/auto_dev_ops_alert.vue
@@ -28,6 +28,7 @@ export default {
     variant="info"
     :primary-button-link="autoDevopsPath"
     :primary-button-text="$options.i18n.primaryButtonText"
+    data-qa-selector="autodevops_container"
     @dismiss="dismissMethod"
   >
     <gl-sprintf :message="$options.i18n.body">
diff --git a/qa/qa/ee/fixtures/secure_scanning_enable_from_ui_files/.gitlab-ci.yml b/qa/qa/ee/fixtures/secure_scanning_enable_from_ui_files/.gitlab-ci.yml
deleted file mode 100644
index 5e9cbdd23a1be..0000000000000
--- a/qa/qa/ee/fixtures/secure_scanning_enable_from_ui_files/.gitlab-ci.yml
+++ /dev/null
@@ -1,23 +0,0 @@
-include:
-  template: License-Scanning.gitlab-ci.yml
-
-.sast-analyzer:
-  script:
-    - echo "Skipped"
-  artifacts:
-    reports:
-      sast: gl-sast-report.json
-
-.ds-analyzer:
-  script:
-    - echo "Skipped"
-  artifacts:
-    reports:
-      dependency_scanning: gl-dependency-scanning-report.json
-
-license_scanning:
-  script:
-    - echo "Skipped"
-  artifacts:
-    reports:
-      license_scanning: gl-license-scanning-report.json
diff --git a/qa/qa/page/project/secure/configuration_form.rb b/qa/qa/page/project/secure/configuration_form.rb
index 3e89a57e87081..fa1fad4427310 100644
--- a/qa/qa/page/project/secure/configuration_form.rb
+++ b/qa/qa/page/project/secure/configuration_form.rb
@@ -8,6 +8,10 @@ class ConfigurationForm < QA::Page::Base
           include QA::Page::Component::Select2
           include QA::Page::Settings::Common
 
+          view 'app/assets/javascripts/security_configuration/components/app.vue' do
+            element :security_configuration_history_link
+          end
+
           view 'app/assets/javascripts/security_configuration/components/feature_card.vue' do
             element :dependency_scanning_status, "`${feature.type}_status`" # rubocop:disable QA/ElementWithPattern
             element :sast_status, "`${feature.type}_status`" # rubocop:disable QA/ElementWithPattern
@@ -15,6 +19,22 @@ class ConfigurationForm < QA::Page::Base
             element :dependency_scanning_mr_button, "`${feature.type}_mr_button`" # rubocop:disable QA/ElementWithPattern
           end
 
+          view 'app/assets/javascripts/security_configuration/components/auto_dev_ops_alert.vue' do
+            element :autodevops_container
+          end
+
+          def has_security_configuration_history_link?
+            has_element?(:security_configuration_history_link)
+          end
+
+          def has_no_security_configuration_history_link?
+            has_no_element?(:security_configuration_history_link)
+          end
+
+          def click_security_configuration_history_link
+            click_element(:security_configuration_history_link)
+          end
+
           def click_sast_enable_button
             click_element(:sast_enable_button)
           end
@@ -29,11 +49,37 @@ def has_sast_status?(status_text)
             end
           end
 
+          def has_no_sast_status?(status_text)
+            within_element(:sast_status) do
+              has_no_text?(status_text)
+            end
+          end
+
           def has_dependency_scanning_status?(status_text)
             within_element(:dependency_scanning_status) do
               has_text?(status_text)
             end
           end
+
+          def has_no_dependency_scanning_status?(status_text)
+            within_element(:dependency_scanning_status) do
+              has_no_text?(status_text)
+            end
+          end
+
+          def has_auto_devops_container?
+            has_element?(:autodevops_container)
+          end
+
+          def has_no_auto_devops_container?
+            has_no_element?(:autodevops_container)
+          end
+
+          def has_auto_devops_container_description?
+            within_element(:autodevops_container) do
+              has_text?('Quickly enable all continuous testing and compliance tools by enabling Auto DevOps')
+            end
+          end
         end
       end
     end
diff --git a/qa/qa/specs/features/ee/browser_ui/13_secure/enable_scanning_from_configuration_spec.rb b/qa/qa/specs/features/ee/browser_ui/13_secure/enable_scanning_from_configuration_spec.rb
index d1c3957de84d5..29f1a86ae12e3 100644
--- a/qa/qa/specs/features/ee/browser_ui/13_secure/enable_scanning_from_configuration_spec.rb
+++ b/qa/qa/specs/features/ee/browser_ui/13_secure/enable_scanning_from_configuration_spec.rb
@@ -1,7 +1,7 @@
 # frozen_string_literal: true
 
 module QA
-  RSpec.describe 'Secure' do
+  RSpec.describe 'Secure', :aggregate_failures do
     context 'Enable Scanning from UI' do
       let(:test_data_sast_string_fields_array) do
         [
@@ -53,20 +53,13 @@ module QA
 
       describe 'enable dependency scanning from configuration' do
         it 'runs dependency scanning job when enabled from configuration', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347621' do
-          Flow::Pipeline.visit_latest_pipeline
-
-          # Baseline that we do not initially have a Dependency Scanning job
-          Page::Project::Pipeline::Show.perform do |pipeline|
-            aggregate_failures "test Dependency Scanning jobs are not present in pipeline" do
-              expect(pipeline).to have_no_job('gemnasium-dependency_scanning')
-              expect(pipeline).to have_no_job('bundler-audit-dependency_scanning')
-            end
-          end
-
           Page::Project::Menu.perform(&:click_on_security_configuration_link)
 
           Page::Project::Secure::ConfigurationForm.perform do |config_form|
             expect(config_form).to have_dependency_scanning_status('Not enabled')
+            expect(config_form).to have_auto_devops_container
+            expect(config_form).to have_auto_devops_container_description
+            expect(config_form).to have_no_security_configuration_history_link
 
             config_form.click_dependency_scanning_mr_button
           end
@@ -83,36 +76,48 @@ module QA
           Flow::Pipeline.visit_latest_pipeline
 
           Page::Project::Pipeline::Show.perform do |pipeline|
-            aggregate_failures "test Dependency Scanning jobs are present in pipeline" do
-              expect(pipeline).to have_job('gemnasium-dependency_scanning')
-              expect(pipeline).to have_job('bundler-audit-dependency_scanning')
-            end
+            expect(pipeline).to have_job('gemnasium-dependency_scanning')
+            expect(pipeline).to have_job('bundler-audit-dependency_scanning')
           end
 
           Page::Project::Menu.perform(&:click_on_security_configuration_link)
 
           Page::Project::Secure::ConfigurationForm.perform do |config_form|
-            aggregate_failures "test Dependency Scanning status is Enabled" do
-              expect(config_form).to have_dependency_scanning_status('Enabled')
-              expect(config_form).not_to have_dependency_scanning_status('Not enabled')
-            end
+            expect(config_form).to have_dependency_scanning_status('Enabled')
+            expect(config_form).to have_no_dependency_scanning_status('Not enabled')
+            expect(config_form).to have_security_configuration_history_link
+            expect(config_form).to have_no_auto_devops_container
+
+            config_form.click_security_configuration_history_link
+          end
+
+          Page::File::Show.perform do |file_page|
+            expect(file_page).to have_content('template: Security/Dependency-Scanning.gitlab-ci.yml')
           end
         end
       end
 
       describe 'enable sast from configuration' do
-        it 'runs sast job when enabled from configuration', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347685' do
-          Flow::Pipeline.visit_latest_pipeline
-
-          # Baseline that we do not initially have a sast job
-          Page::Project::Pipeline::Show.perform do |pipeline|
-            expect(pipeline).to have_no_job('brakeman-sast')
+        def sast_config_expects(current_page, sast_string_fields, sast_int_fields)
+          expect(current_page).to have_file('.gitlab-ci.yml')
+          sast_string_fields.each do |field_type, field_value|
+            expect(current_page).to have_content("#{field_type}: #{field_value}")
           end
+          sast_int_fields.each do |field_type, field_value|
+            expect(current_page).to have_content("#{field_type}: '#{field_value}'")
+          end
+          expect(current_page).to have_content("stage: #{test_stage_name}")
+          expect(current_page).to have_content("SAST_EXCLUDED_ANALYZERS: #{test_data_checkbox_exclude_array.join(', ')}")
+        end
 
+        it 'runs sast job when enabled from configuration', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347685' do
           Page::Project::Menu.perform(&:click_on_security_configuration_link)
 
           Page::Project::Secure::ConfigurationForm.perform do |config_form|
             expect(config_form).to have_sast_status('Not enabled')
+            expect(config_form).to have_auto_devops_container
+            expect(config_form).to have_auto_devops_container_description
+            expect(config_form).to have_no_security_configuration_history_link
 
             config_form.click_sast_enable_button
             config_form.click_expand_button
@@ -136,17 +141,7 @@ module QA
 
             new_merge_request.click_diffs_tab
 
-            aggregate_failures "test Merge Request contents" do
-              expect(new_merge_request).to have_file('.gitlab-ci.yml')
-              test_data_sast_string_fields_array.each do |test_data_string_array|
-                expect(new_merge_request).to have_content("#{test_data_string_array.first}: #{test_data_string_array[1]}")
-              end
-              test_data_int_fields_array.each do |test_data_int_array|
-                expect(new_merge_request).to have_content("#{test_data_int_array.first}: '#{test_data_int_array[1]}'")
-              end
-              expect(new_merge_request).to have_content("stage: #{test_stage_name}")
-              expect(new_merge_request).to have_content("SAST_EXCLUDED_ANALYZERS: #{test_data_checkbox_exclude_array.join(', ')}")
-            end
+            sast_config_expects(new_merge_request, test_data_sast_string_fields_array, test_data_int_fields_array)
 
             new_merge_request.create_merge_request
           end
@@ -164,10 +159,16 @@ module QA
           Page::Project::Menu.perform(&:click_on_security_configuration_link)
 
           Page::Project::Secure::ConfigurationForm.perform do |config_form|
-            aggregate_failures "test SAST status is Enabled" do
-              expect(config_form).to have_sast_status('Enabled')
-              expect(config_form).not_to have_sast_status('Not enabled')
-            end
+            expect(config_form).to have_sast_status('Enabled')
+            expect(config_form).to have_no_sast_status('Not enabled')
+            expect(config_form).to have_security_configuration_history_link
+            expect(config_form).to have_no_auto_devops_container
+
+            config_form.click_security_configuration_history_link
+          end
+
+          Page::File::Show.perform do |file_page|
+            sast_config_expects(file_page, test_data_sast_string_fields_array, test_data_int_fields_array)
           end
         end
       end
diff --git a/qa/qa/support/matchers/have_matcher.rb b/qa/qa/support/matchers/have_matcher.rb
index 47d2d246460a9..a90d2df96aeef 100644
--- a/qa/qa/support/matchers/have_matcher.rb
+++ b/qa/qa/support/matchers/have_matcher.rb
@@ -5,6 +5,7 @@ module Support
     module Matchers
       module HaveMatcher
         PREDICATE_TARGETS = %w[
+          auto_devops_container
           element
           file_content
           assignee
@@ -17,6 +18,8 @@ module HaveMatcher
           package
           pipeline
           related_issue_item
+          sast_status
+          security_configuration_history_link
           snippet_description
           tag
           label
-- 
GitLab