Commit 6f17ddae authored by Sofia Vistas's avatar Sofia Vistas Committed by Dan Davison

Add test for maven duplicate settings

Prior to this change, there was no
test coverage on the newly feature that
prevent users from publishing duplicate
 Maven packages via the UI

This change adds the simplest test case
for a new group setting for the package
registry that allows you to choose
 whether or not you'd like to allow or
disallow duplicate Maven or Gradle uploads
parent 09f7b555
...@@ -111,7 +111,10 @@ export default { ...@@ -111,7 +111,10 @@ export default {
{{ alertMessage }} {{ alertMessage }}
</gl-alert> </gl-alert>
<settings-block :default-expanded="defaultExpanded"> <settings-block
:default-expanded="defaultExpanded"
data-qa-selector="package_registry_settings_content"
>
<template #title> {{ $options.i18n.PACKAGE_SETTINGS_HEADER }}</template> <template #title> {{ $options.i18n.PACKAGE_SETTINGS_HEADER }}</template>
<template #description> <template #description>
<span data-testid="description"> <span data-testid="description">
......
...@@ -79,6 +79,7 @@ export default { ...@@ -79,6 +79,7 @@ export default {
<form> <form>
<div class="gl-display-flex"> <div class="gl-display-flex">
<gl-toggle <gl-toggle
data-qa-selector="allow_duplicates_checkbox"
:value="mavenDuplicatesAllowed" :value="mavenDuplicatesAllowed"
@change="update($options.modelNames.MAVEN_DUPLICATES_ALLOWED, $event)" @change="update($options.modelNames.MAVEN_DUPLICATES_ALLOWED, $event)"
/> />
......
- if group_packages_list_nav? - if group_packages_list_nav?
= nav_link(controller: :packages_and_registries) do = nav_link(controller: :packages_and_registries) do
= link_to group_settings_packages_and_registries_path(@group), title: _('Packages & Registries') do = link_to group_settings_packages_and_registries_path(@group), title: _('Packages & Registries'), data: { qa_selector: 'group_package_settings_link' } do
%span %span
= _('Packages & Registries') = _('Packages & Registries')
...@@ -232,6 +232,7 @@ module QA ...@@ -232,6 +232,7 @@ module QA
module Settings module Settings
autoload :General, 'qa/page/group/settings/general' autoload :General, 'qa/page/group/settings/general'
autoload :PackageRegistries, 'qa/page/group/settings/package_registries'
end end
end end
......
...@@ -14,6 +14,10 @@ module QA ...@@ -14,6 +14,10 @@ module QA
element :group_settings_item element :group_settings_item
end end
view 'app/views/groups/sidebar/_packages_settings.html.haml' do
element :group_package_settings_link
end
view 'app/views/layouts/nav/sidebar/_analytics_links.html.haml' do view 'app/views/layouts/nav/sidebar/_analytics_links.html.haml' do
element :analytics_link element :analytics_link
element :analytics_sidebar_submenu element :analytics_sidebar_submenu
...@@ -55,6 +59,15 @@ module QA ...@@ -55,6 +59,15 @@ module QA
end end
end end
def go_to_package_settings
scroll_to_element(:group_settings_item)
hover_element(:group_settings_item) do
within_submenu(:group_sidebar_submenu) do
click_element(:group_package_settings_link)
end
end
end
private private
def hover_issues def hover_issues
......
# frozen_string_literal: true
module QA
module Page
module Group
module Settings
class PackageRegistries < QA::Page::Base
include ::QA::Page::Settings::Common
view 'app/assets/javascripts/packages_and_registries/settings/group/components/group_settings_app.vue' do
element :package_registry_settings_content
end
view 'app/assets/javascripts/packages_and_registries/settings/group/components/maven_settings.vue' do
element :allow_duplicates_checkbox
end
def set_allow_duplicates_disabled
expand_content :package_registry_settings_content do
uncheck_element :allow_duplicates_checkbox
end
end
def has_allow_duplicates_enabled?
expand_content :package_registry_settings_content
!find_element(:allow_duplicates_checkbox).checked?
end
end
end
end
end
end
# frozen_string_literal: true # frozen_string_literal: true
require 'securerandom'
module QA module QA
RSpec.describe 'Package', :orchestrated, :packages do RSpec.describe 'Package', :orchestrated, :packages do
describe 'Maven Repository' do describe 'Maven Repository' do
include Runtime::Fixtures include Runtime::Fixtures
let(:group_id) { 'com.gitlab.qa' } let(:group_id) { 'com.gitlab.qa' }
let(:artifact_id) { 'maven' } let(:artifact_id) { "maven-#{SecureRandom.hex(8)}" }
let(:package_name) { "#{group_id}/#{artifact_id}".tr('.', '/') } let(:package_name) { "#{group_id}/#{artifact_id}".tr('.', '/') }
let(:auth_token) do let(:auth_token) do
unless Page::Main::Menu.perform(&:signed_in?) unless Page::Main::Menu.perform(&:signed_in?)
...@@ -22,12 +24,19 @@ module QA ...@@ -22,12 +24,19 @@ module QA
end end
end end
let(:another_project) do
Resource::Project.fabricate_via_api! do |another_project|
another_project.name = 'another-maven-package-project'
another_project.group = project.group
end
end
let!(:runner) do let!(:runner) do
Resource::Runner.fabricate! do |runner| Resource::Runner.fabricate! do |runner|
runner.name = "qa-runner-#{Time.now.to_i}" runner.name = "qa-runner-#{Time.now.to_i}"
runner.tags = ["runner-for-#{project.name}"] runner.tags = ["runner-for-#{project.group.name}"]
runner.executor = :docker runner.executor = :docker
runner.project = project runner.token = project.group.sandbox.runners_token
end end
end end
...@@ -90,6 +99,28 @@ module QA ...@@ -90,6 +99,28 @@ module QA
} }
end end
let(:gitlab_ci_yaml) do
{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
deploy:
image: maven:3.6-jdk-11
script:
- 'mvn deploy -s settings.xml'
- "mvn dependency:get -Dartifact=#{group_id}:#{artifact_id}:1.0"
only:
- "#{project.default_branch}"
tags:
- "runner-for-#{project.group.name}"
YAML
}
end
after do
runner.remove_via_api!
end
it 'publishes a maven package and deletes it', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/943' do it 'publishes a maven package and deletes it', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/943' do
# Use a maven docker container to deploy the package # Use a maven docker container to deploy the package
with_fixtures([pom_xml, settings_xml]) do |dir| with_fixtures([pom_xml, settings_xml]) do |dir|
...@@ -122,23 +153,9 @@ module QA ...@@ -122,23 +153,9 @@ module QA
commit.project = project commit.project = project
commit.commit_message = 'Add .gitlab-ci.yml' commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([ commit.add_files([
{ gitlab_ci_yaml,
file_path: '.gitlab-ci.yml', settings_xml,
content: pom_xml
<<~YAML
deploy:
image: maven:3.6-jdk-11
script:
- 'mvn deploy -s settings.xml'
- "mvn dependency:get -Dartifact=#{group_id}:#{artifact_id}:1.0"
only:
- "#{project.default_branch}"
tags:
- "runner-for-#{project.name}"
YAML
},
settings_xml,
pom_xml
]) ])
end end
...@@ -153,6 +170,98 @@ module QA ...@@ -153,6 +170,98 @@ module QA
expect(job).to be_successful(timeout: 800) expect(job).to be_successful(timeout: 800)
end end
end end
context 'when "allow duplicate" setting is disabled' do
before do
Flow::Login.sign_in
project.group.visit!
Page::Group::Menu.perform(&:go_to_package_settings)
Page::Group::Settings::PackageRegistries.perform(&:set_allow_duplicates_disabled)
end
it 'prevents users from publishing duplicate Maven packages at the group level', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1717' do
with_fixtures([pom_xml, settings_xml]) do |dir|
Service::DockerRun::Maven.new(dir).publish!
end
project.visit!
Page::Project::Menu.perform(&:click_packages_link)
Page::Project::Packages::Index.perform do |index|
expect(index).to have_package(package_name)
end
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = another_project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([
gitlab_ci_yaml,
settings_xml,
pom_xml
])
end
another_project.visit!
Flow::Pipeline.visit_latest_pipeline
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('deploy')
end
Page::Project::Job::Show.perform do |job|
expect(job).not_to be_successful(timeout: 800)
end
end
end
context 'when "allow duplicate" setting is enabled' do
before do
Flow::Login.sign_in
project.group.visit!
Page::Group::Menu.perform(&:go_to_package_settings)
Page::Group::Settings::PackageRegistries.perform do |settings|
expect(settings).to have_allow_duplicates_enabled
end
end
it 'allows users to publish duplicate Maven packages at the group level', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1722' do
with_fixtures([pom_xml, settings_xml]) do |dir|
Service::DockerRun::Maven.new(dir).publish!
end
project.visit!
Page::Project::Menu.perform(&:click_packages_link)
Page::Project::Packages::Index.perform do |index|
expect(index).to have_package(package_name)
end
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = another_project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([
gitlab_ci_yaml,
settings_xml,
pom_xml
])
end
another_project.visit!
Flow::Pipeline.visit_latest_pipeline
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('deploy')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 800)
end
end
end
end end
end 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