Commit 889bb0f2 authored by Dan Davison's avatar Dan Davison

Merge branch 'settings-duplicate-packages-mvn' into 'master'

Add test for maven duplicate settings

See merge request gitlab-org/gitlab!54942
parents 79dce87e 6f17ddae
......@@ -111,7 +111,10 @@ export default {
{{ alertMessage }}
</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 #description>
<span data-testid="description">
......
......@@ -79,6 +79,7 @@ export default {
<form>
<div class="gl-display-flex">
<gl-toggle
data-qa-selector="allow_duplicates_checkbox"
:value="mavenDuplicatesAllowed"
@change="update($options.modelNames.MAVEN_DUPLICATES_ALLOWED, $event)"
/>
......
- if group_packages_list_nav?
= 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
= _('Packages & Registries')
......@@ -232,6 +232,7 @@ module QA
module Settings
autoload :General, 'qa/page/group/settings/general'
autoload :PackageRegistries, 'qa/page/group/settings/package_registries'
end
end
......
......@@ -14,6 +14,10 @@ module QA
element :group_settings_item
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
element :analytics_link
element :analytics_sidebar_submenu
......@@ -55,6 +59,15 @@ module QA
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
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
require 'securerandom'
module QA
RSpec.describe 'Package', :orchestrated, :packages do
describe 'Maven Repository' do
include Runtime::Fixtures
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(:auth_token) do
unless Page::Main::Menu.perform(&:signed_in?)
......@@ -22,12 +24,19 @@ module QA
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
Resource::Runner.fabricate! do |runner|
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.project = project
runner.token = project.group.sandbox.runners_token
end
end
......@@ -90,6 +99,28 @@ module QA
}
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
# Use a maven docker container to deploy the package
with_fixtures([pom_xml, settings_xml]) do |dir|
......@@ -122,23 +153,9 @@ module QA
commit.project = project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([
{
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.name}"
YAML
},
settings_xml,
pom_xml
gitlab_ci_yaml,
settings_xml,
pom_xml
])
end
......@@ -153,6 +170,98 @@ module QA
expect(job).to be_successful(timeout: 800)
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
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