Commit 5160fb12 authored by David Fernandez's avatar David Fernandez Committed by Dan Davison

Update maven repository QA spec

parent 790eea67
...@@ -43,7 +43,7 @@ module QA ...@@ -43,7 +43,7 @@ module QA
def with_allow_duplicates_button def with_allow_duplicates_button
within_element :allow_duplicates_toggle do within_element :allow_duplicates_toggle do
toggle = find('button.gl-toggle') toggle = find('button.gl-toggle:not(.is-disabled)')
yield(toggle) yield(toggle)
end end
end end
......
...@@ -3,77 +3,56 @@ ...@@ -3,77 +3,56 @@
module QA module QA
RSpec.describe 'Package', :orchestrated, :packages, :object_storage do RSpec.describe 'Package', :orchestrated, :packages, :object_storage do
describe 'Maven Repository' do describe 'Maven Repository' do
using RSpec::Parameterized::TableSyntax
include Runtime::Fixtures include Runtime::Fixtures
include_context 'packages registry qa scenario'
let(:group_id) { 'com.gitlab.qa' } let(:group_id) { 'com.gitlab.qa' }
let(:artifact_id) { "maven-#{SecureRandom.hex(8)}" } let(:artifact_id) { "maven-#{SecureRandom.hex(8)}" }
let(:another_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(:package_version) { '1.3.7' }
unless Page::Main::Menu.perform(&:signed_in?) let(:package_type) { 'maven' }
Flow::Login.sign_in
end
Resource::PersonalAccessToken.fabricate!.token
end
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'maven-package-project'
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(:package) do let(:package_gitlab_ci_file) do
Resource::Package.init do |package| {
package.name = package_name file_path: '.gitlab-ci.yml',
package.project = project content:
end <<~YAML
end deploy:
image: maven:3.6-jdk-11
let!(:runner) do script:
Resource::Runner.fabricate! do |runner| - 'mvn deploy -s settings.xml'
runner.name = "qa-runner-#{Time.now.to_i}" only:
runner.tags = ["runner-for-#{project.group.name}"] - "#{package_project.default_branch}"
runner.executor = :docker tags:
runner.token = project.group.runners_token - "runner-for-#{package_project.group.name}"
end YAML
end }
let!(:gitlab_address_with_port) do
uri = URI.parse(Runtime::Scenario.gitlab_address)
"#{uri.scheme}://#{uri.host}:#{uri.port}"
end end
let(:pom_xml) do let(:package_pom_file) do
{ {
file_path: 'pom.xml', file_path: 'pom.xml',
content: <<~XML content: <<~XML
<project> <project>
<groupId>#{group_id}</groupId> <groupId>#{group_id}</groupId>
<artifactId>#{artifact_id}</artifactId> <artifactId>#{artifact_id}</artifactId>
<version>1.0</version> <version>#{package_version}</version>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<repositories> <repositories>
<repository> <repository>
<id>#{project.name}</id> <id>#{package_project.name}</id>
<url>#{gitlab_address_with_port}/api/v4/groups/#{project.group.id}/-/packages/maven</url> <url>#{gitlab_address_with_port}/api/v4/groups/#{package_project.group.id}/-/packages/maven</url>
</repository> </repository>
</repositories> </repositories>
<distributionManagement> <distributionManagement>
<repository> <repository>
<id>#{project.name}</id> <id>#{package_project.name}</id>
<url>#{gitlab_address_with_port}/api/v4/projects/#{project.id}/packages/maven</url> <url>#{gitlab_address_with_port}/api/v4/projects/#{package_project.id}/packages/maven</url>
</repository> </repository>
<snapshotRepository> <snapshotRepository>
<id>#{project.name}</id> <id>#{package_project.name}</id>
<url>#{gitlab_address_with_port}/api/v4/projects/#{project.id}/packages/maven</url> <url>#{gitlab_address_with_port}/api/v4/projects/#{package_project.id}/packages/maven</url>
</snapshotRepository> </snapshotRepository>
</distributionManagement> </distributionManagement>
</project> </project>
...@@ -81,36 +60,43 @@ module QA ...@@ -81,36 +60,43 @@ module QA
} }
end end
let(:pom_xml_another_project) do let(:client_gitlab_ci_file) do
{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
install:
image: maven:3.6-jdk-11
script:
- "mvn install -s settings.xml"
only:
- "#{client_project.default_branch}"
tags:
- "runner-for-#{client_project.group.name}"
YAML
}
end
let(:client_pom_file) do
{ {
file_path: 'pom.xml', file_path: 'pom.xml',
content: <<~XML content: <<~XML
<project> <project>
<groupId>#{group_id}</groupId> <groupId>#{group_id}</groupId>
<artifactId>#{another_artifact_id}</artifactId> <artifactId>maven_client</artifactId>
<version>1.0</version> <version>1.0</version>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<repositories> <repositories>
<repository> <repository>
<id>#{another_project.name}</id> <id>#{package_project.name}</id>
<url>#{gitlab_address_with_port}/api/v4/groups/#{another_project.group.id}/-/packages/maven</url> <url>#{gitlab_address_with_port}/api/v4/groups/#{package_project.group.id}/-/packages/maven</url>
</repository> </repository>
</repositories> </repositories>
<distributionManagement>
<repository>
<id>#{another_project.name}</id>
<url>#{gitlab_address_with_port}/api/v4/projects/#{another_project.id}/packages/maven</url>
</repository>
<snapshotRepository>
<id>#{another_project.name}</id>
<url>#{gitlab_address_with_port}/api/v4/projects/#{another_project.id}/packages/maven</url>
</snapshotRepository>
</distributionManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>#{group_id}</groupId> <groupId>#{group_id}</groupId>
<artifactId>#{artifact_id}</artifactId> <artifactId>#{artifact_id}</artifactId>
<version>1.0</version> <version>#{package_version}</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -118,7 +104,7 @@ module QA ...@@ -118,7 +104,7 @@ module QA
} }
end end
let(:settings_xml) do let(:settings_xml_with_pat) do
{ {
file_path: 'settings.xml', file_path: 'settings.xml',
content: <<~XML content: <<~XML
...@@ -126,12 +112,12 @@ module QA ...@@ -126,12 +112,12 @@ module QA
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd"> xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers> <servers>
<server> <server>
<id>#{project.name}</id> <id>#{package_project.name}</id>
<configuration> <configuration>
<httpHeaders> <httpHeaders>
<property> <property>
<name>Private-Token</name> <name>Private-Token</name>
<value>#{auth_token}</value> <value>#{personal_access_token}</value>
</property> </property>
</httpHeaders> </httpHeaders>
</configuration> </configuration>
...@@ -142,196 +128,187 @@ module QA ...@@ -142,196 +128,187 @@ module QA
} }
end end
let(:gitlab_ci_deploy_yml) do where(:authentication_token_type, :maven_header_name) do
{ :personal_access_token | 'Private-Token'
file_path: '.gitlab-ci.yml', :ci_job_token | 'Job-Token'
content: :project_deploy_token | 'Deploy-Token'
<<~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
let(:gitlab_ci_install_yml) do
{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
install:
image: maven:3.6-jdk-11
script:
- "mvn install"
only:
- "#{project.default_branch}"
tags:
- "runner-for-#{another_project.group.name}"
YAML
}
end
after do
runner.remove_via_api!
project.remove_via_api!
another_project.remove_via_api!
end end
it 'pushes and pulls a Maven package via CI and deletes it', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1627' do with_them do
Resource::Repository::Commit.fabricate_via_api! do |commit| let(:token) do
commit.project = project case authentication_token_type
commit.commit_message = 'Add .gitlab-ci.yml' when :personal_access_token
commit.add_files([ personal_access_token
gitlab_ci_deploy_yml, when :ci_job_token
settings_xml, '${env.CI_JOB_TOKEN}'
pom_xml when :project_deploy_token
]) project_deploy_token.password
end end
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
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = another_project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([
gitlab_ci_install_yml,
pom_xml_another_project
])
end
another_project.visit!
Flow::Pipeline.visit_latest_pipeline
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('install')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 800)
end
project.visit!
Page::Project::Menu.perform(&:click_packages_link)
Page::Project::Packages::Index.perform do |index|
expect(index).to have_package(package_name)
index.click_package(package_name)
end end
Page::Project::Packages::Show.perform do |show| let(:settings_xml) do
expect(show).to have_package_info(package_name, "1.0") {
show.click_delete file_path: 'settings.xml',
content: <<~XML
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id>#{package_project.name}</id>
<configuration>
<httpHeaders>
<property>
<name>#{maven_header_name}</name>
<value>#{token}</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
XML
}
end end
Page::Project::Packages::Index.perform do |index| it "pushes and pulls a maven package via maven using #{params[:authentication_token_type]}" do
expect(index).to have_content("Package deleted successfully") # pushing
expect(index).not_to have_package(package_name) Resource::Repository::Commit.fabricate_via_api! do |commit|
end commit.project = package_project
end commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([
package_gitlab_ci_file,
package_pom_file,
settings_xml
])
end
context 'when "allow duplicate" setting is disabled' do package_project.visit!
before do
Flow::Login.sign_in
project.group.visit! Flow::Pipeline.visit_latest_pipeline
Page::Group::Menu.perform(&:go_to_package_settings) Page::Project::Pipeline::Show.perform do |pipeline|
Page::Group::Settings::PackageRegistries.perform(&:set_allow_duplicates_disabled) pipeline.click_job('deploy')
end end
it 'prevents users from publishing duplicate Maven packages at the group level', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1830' do Page::Project::Job::Show.perform do |job|
with_fixtures([pom_xml, settings_xml]) do |dir| expect(job).to be_successful(timeout: 800)
Service::DockerRun::Maven.new(dir).publish!
end end
project.visit!
Page::Project::Menu.perform(&:click_packages_link) Page::Project::Menu.perform(&:click_packages_link)
Page::Project::Packages::Index.perform do |index| Page::Project::Packages::Index.perform do |index|
expect(index).to have_package(package_name) expect(index).to have_package(package_name)
index.click_package(package_name)
end end
Page::Project::Packages::Show.perform do |show|
expect(show).to have_package_info(package_name, package_version)
end
# pulling
Resource::Repository::Commit.fabricate_via_api! do |commit| Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = another_project commit.project = client_project
commit.commit_message = 'Add .gitlab-ci.yml' commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([ commit.add_files([
gitlab_ci_deploy_yml, client_gitlab_ci_file,
settings_xml, client_pom_file,
pom_xml settings_xml
]) ])
end end
another_project.visit! client_project.visit!
Flow::Pipeline.visit_latest_pipeline Flow::Pipeline.visit_latest_pipeline
Page::Project::Pipeline::Show.perform do |pipeline| Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('deploy') pipeline.click_job('install')
end end
Page::Project::Job::Show.perform do |job| Page::Project::Job::Show.perform do |job|
expect(job).not_to be_successful(timeout: 800) expect(job).to be_successful(timeout: 800)
end end
end end
end
context 'when "allow duplicate" setting is enabled' do context 'duplication setting' do
before do before do
Flow::Login.sign_in package_project.group.visit!
project.group.visit! Page::Group::Menu.perform(&:go_to_package_settings)
end
Page::Group::Menu.perform(&:go_to_package_settings) context 'when disabled' do
Page::Group::Settings::PackageRegistries.perform(&:set_allow_duplicates_enabled) before do
end Page::Group::Settings::PackageRegistries.perform(&:set_allow_duplicates_disabled)
end
it 'allows users to publish duplicate Maven packages at the group level', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1829' do it "prevents users from publishing group level Maven packages duplicates using #{params[:authentication_token_type]}" do
with_fixtures([pom_xml, settings_xml]) do |dir| create_duplicated_package
Service::DockerRun::Maven.new(dir).publish!
end
project.visit! push_duplicated_package
Page::Project::Menu.perform(&:click_packages_link)
Page::Project::Packages::Index.perform do |index| client_project.visit!
expect(index).to have_package(package_name)
show_latest_deploy_job
Page::Project::Job::Show.perform do |job|
expect(job).not_to be_successful(timeout: 800)
end
end
end end
Resource::Repository::Commit.fabricate_via_api! do |commit| context 'when enabled' do
commit.project = another_project before do
commit.commit_message = 'Add .gitlab-ci.yml' Page::Group::Settings::PackageRegistries.perform(&:set_allow_duplicates_enabled)
commit.add_files([ end
gitlab_ci_deploy_yml,
settings_xml, it "allows users to publish group level Maven packages duplicates using #{params[:authentication_token_type]}" do
pom_xml create_duplicated_package
])
push_duplicated_package
show_latest_deploy_job
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 800)
end
end
end end
another_project.visit! def create_duplicated_package
Flow::Pipeline.visit_latest_pipeline with_fixtures([package_pom_file, settings_xml_with_pat]) do |dir|
Service::DockerRun::Maven.new(dir).publish!
end
Page::Project::Pipeline::Show.perform do |pipeline| package_project.visit!
pipeline.click_job('deploy')
Page::Project::Menu.perform(&:click_packages_link)
Page::Project::Packages::Index.perform do |index|
expect(index).to have_package(package_name)
end
end end
Page::Project::Job::Show.perform do |job| def push_duplicated_package
expect(job).to be_successful(timeout: 800) Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = client_project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([
package_gitlab_ci_file,
package_pom_file,
settings_xml
])
end
end
def show_latest_deploy_job
client_project.visit!
Flow::Pipeline.visit_latest_pipeline
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('deploy')
end
end end
end end
end end
......
...@@ -43,7 +43,7 @@ module QA ...@@ -43,7 +43,7 @@ module QA
let(:project_deploy_token) do let(:project_deploy_token) do
Resource::DeployToken.fabricate_via_browser_ui! do |deploy_token| Resource::DeployToken.fabricate_via_browser_ui! do |deploy_token|
deploy_token.name = 'helm-package-deploy-token' deploy_token.name = 'package-deploy-token'
deploy_token.project = package_project deploy_token.project = package_project
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