Commit 392091d1 authored by Ramya Authappan's avatar Ramya Authappan

Merge branch 'license_policy_spec' into 'master'

Add a licence_compliance_spec end to end test

See merge request gitlab-org/gitlab!38598
parents 305cada9 893082c0
......@@ -154,7 +154,9 @@ export default {
<gl-tab data-testid="policiesTab">
<template #title>
<span data-testid="policiesTabTitle">{{ s__('Licenses|Policies') }}</span>
<span data-qa-selector="policies_tab" data-testid="policiesTabTitle">{{
s__('Licenses|Policies')
}}</span>
<gl-badge pill>{{ policyCount }}</gl-badge>
</template>
......
......@@ -86,7 +86,7 @@ export default {
v-if="canBlacklist"
class="btn btn-remove btn-inverted js-modal-secondary-action"
data-dismiss="modal"
data-qa-selector="blacklist_license_button"
data-qa-selector="deny_license_button"
@click="denyLicense(currentLicenseInModal)"
>
{{ s__('LicenseCompliance|Deny') }}
......
......@@ -105,6 +105,7 @@ module QA
autoload :Repository, 'qa/ee/page/project/sub_menus/repository'
autoload :Settings, 'qa/ee/page/project/sub_menus/settings'
autoload :Project, 'qa/ee/page/project/sub_menus/project'
autoload :LicenseCompliance, 'qa/ee/page/project/sub_menus/license_compliance'
end
module Issue
......@@ -148,6 +149,7 @@ module QA
autoload :DependencyList, 'qa/ee/page/project/secure/dependency_list'
autoload :SecurityDashboard, 'qa/ee/page/project/secure/security_dashboard'
autoload :VulnerabilityDetails, 'qa/ee/page/project/secure/vulnerability_details'
autoload :LicenseCompliance, 'qa/ee/page/project/secure/license_compliance'
end
module PathLocks
......
......@@ -22,7 +22,7 @@ module QA
view 'ee/app/assets/javascripts/vue_shared/license_compliance/components/set_approval_status_modal.vue' do
element :license_management_modal
element :approve_license_button
element :blacklist_license_button
element :deny_license_button
end
view 'ee/app/assets/javascripts/vue_shared/license_compliance/mr_widget_license_report.vue' do
......@@ -37,7 +37,7 @@ module QA
end
end
def has_blacklisted_license?(name)
def has_denied_license?(name)
within_element(:report_item_row, text: name) do
has_element?(:status_failed_icon, wait: 1)
end
......@@ -52,12 +52,18 @@ module QA
def approve_license(name)
click_license(name)
wait_until(reload: false) do
has_element?(:approve_license_button, wait: 1)
end
click_element(:approve_license_button)
end
def blacklist_license(name)
def deny_license(name)
click_license(name)
click_element(:blacklist_license_button)
wait_until(reload: false) do
has_element?(:deny_license_button, wait: 1)
end
click_element(:deny_license_button)
end
end
end
......
......@@ -119,9 +119,9 @@ module QA
approve_license(name)
end
def blacklist_license_with_mr(name)
def deny_license_with_mr(name)
expand_license_report unless license_report_expanded?
blacklist_license(name)
deny_license(name)
end
def expand_vulnerability_report
......
......@@ -12,6 +12,7 @@ module QA
base.class_eval do
prepend QA::Page::Project::SubMenus::Common
prepend SubMenus::LicenseCompliance
prepend SubMenus::SecurityCompliance
prepend SubMenus::Project
prepend SubMenus::Repository
......
# frozen_string_literal: true
module QA
module EE
module Page
module Project
module Secure
class LicenseCompliance < QA::Page::Base
include QA::Page::Component::Select2
view 'ee/app/assets/javascripts/license_compliance/components/app.vue' do
element :policies_tab
end
view 'ee/app/assets/javascripts/vue_shared/license_compliance/license_management.vue' do
element :license_add_button
end
view 'ee/app/assets/javascripts/vue_shared/license_compliance/components/add_license_form.vue' do
element :license_radio, 'data-qa-selector="`${option.value}_license_radio`"' # rubocop:disable QA/ElementWithPattern
element :add_license_submit_button
end
view 'ee/app/assets/javascripts/vue_shared/license_compliance/components/admin_license_management_row.vue' do
element :admin_license_compliance_row
element :license_name_content
end
def approve_license(license)
click_element :license_add_button
expand_select_list
search_and_select license
click_element :approved_license_radio
click_element :add_license_submit_button
has_approved_license? license
end
def has_approved_license?(name)
within_element(:admin_license_compliance_row, text: name) do
has_element?(:status_success_icon)
end
end
def deny_license(license)
click_element :license_add_button
expand_select_list
search_and_select license
click_element :blacklisted_license_radio
click_element :add_license_submit_button
has_denied_license? license
end
def has_denied_license?(name)
within_element(:admin_license_compliance_row, text: name) do
has_element?(:status_failed_icon)
end
end
def open_tab
click_element :policies_tab
end
end
end
end
end
end
end
# frozen_string_literal: true
module QA
module EE
module Page
module Project
module SubMenus
module LicenseCompliance
extend QA::Page::PageConcern
def self.prepended(base)
base.class_eval do
view 'ee/app/views/layouts/nav/sidebar/_project_security_link.html.haml' do
element :licenses_list_link
element :security_dashboard_link
end
end
end
def click_on_license_compliance
hover_security_compliance do
within_submenu do
click_element(:licenses_list_link)
end
end
end
def hover_security_compliance
within_sidebar do
find_element(:security_dashboard_link).hover
yield
end
end
end
end
end
end
end
end
# frozen_string_literal: true
require 'pathname'
module QA
RSpec.describe 'Secure', :docker, :runner do
let(:approved_license_name) { "MIT License" }
let(:denied_license_name) { "WTFPL" }
describe 'License Compliance page' do
after(:all) do
@runner.remove_via_api!
end
before(:all) do
@executor = "qa-runner-#{Time.now.to_i}"
Flow::Login.sign_in
@project = Resource::Project.fabricate_via_api! do |project|
project.name = Runtime::Env.auto_devops_project_name || 'project-with-secure'
project.description = 'Project with Secure'
end
@runner = Resource::Runner.fabricate! do |runner|
runner.project = @project
runner.name = @executor
runner.tags = %w[qa test]
end
# Push fixture to generate Secure reports
Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = @project
project_push.directory = Pathname
.new(__dir__)
.join('../../../../../ee/fixtures/secure_license_files')
project_push.commit_message = 'Create Secure compatible application to serve premade reports'
end.project.visit!
Page::Project::Menu.perform(&:click_ci_cd_pipelines)
Page::Project::Pipeline::Index.perform(&:wait_for_latest_pipeline_success)
end
before do
Flow::Login.sign_in_unless_signed_in
end
it 'can approve a license in the license compliance page' do
@project.visit!
Page::Project::Menu.perform(&:click_on_license_compliance)
EE::Page::Project::Secure::LicenseCompliance.perform do |license_compliance|
license_compliance.open_tab
license_compliance.approve_license approved_license_name
expect(license_compliance).to have_approved_license approved_license_name
end
end
it 'can deny a license in the settings page' do
@project.visit!
Page::Project::Menu.perform(&:click_on_license_compliance)
EE::Page::Project::Secure::LicenseCompliance.perform do |license_compliance|
license_compliance.open_tab
license_compliance.deny_license denied_license_name
expect(license_compliance).to have_denied_license denied_license_name
end
end
end
describe 'License Compliance pipeline reports' do
let(:number_of_licenses_in_fixture) { 2 }
let(:executor) {"qa-runner-#{Time.now.to_i}"}
after do
@runner.remove_via_api!
end
before do
@executor = "qa-runner-#{Time.now.to_i}"
Flow::Login.sign_in
@project = Resource::Project.fabricate_via_api! do |project|
project.name = Runtime::Env.auto_devops_project_name || 'project-with-secure'
project.description = 'Project with Secure'
end
@runner = Resource::Runner.fabricate! do |runner|
runner.project = @project
runner.name = executor
runner.tags = %w[qa test]
end
# Push fixture to generate Secure reports
Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = @project
project_push.directory = Pathname
.new(__dir__)
.join('../../../../../ee/fixtures/secure_premade_reports')
project_push.commit_message = 'Create Secure compatible application to serve premade reports'
end.project.visit!
Page::Project::Menu.perform(&:click_ci_cd_pipelines)
Page::Project::Pipeline::Index.perform(&:wait_for_latest_pipeline_success)
end
it 'can approve and deny licenses in the pipeline' do
Page::Project::Menu.perform(&:click_ci_cd_pipelines)
Page::Project::Pipeline::Index.perform(&:click_on_latest_pipeline)
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_on_licenses
expect(pipeline).to have_license_count_of number_of_licenses_in_fixture
pipeline.approve_license(approved_license_name)
pipeline.deny_license(denied_license_name)
end
Page::Project::Menu.perform(&:click_on_license_compliance)
EE::Page::Project::Secure::LicenseCompliance.perform do |license_compliance|
license_compliance.open_tab
expect(license_compliance).to have_approved_license approved_license_name
expect(license_compliance).to have_denied_license denied_license_name
end
end
end
end
end
......@@ -6,7 +6,7 @@ module QA
RSpec.describe 'Secure', :docker, :runner do
describe 'License merge request widget' do
let(:approved_license_name) { "MIT" }
let(:blacklisted_license_name) { "Zlib" }
let(:denied_license_name) { "Zlib" }
let(:executor) {"qa-runner-#{Time.now.to_i}"}
after do
......@@ -121,12 +121,12 @@ module QA
Page::MergeRequest::Show.perform do |show|
show.approve_license_with_mr(approved_license_name)
show.blacklist_license_with_mr(blacklisted_license_name)
show.deny_license_with_mr(denied_license_name)
show.wait_for_license_compliance_report
expect(show).to have_approved_license approved_license_name
expect(show).to have_blacklisted_license blacklisted_license_name
expect(show).to have_denied_license denied_license_name
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment