1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
# frozen_string_literal: true
module QA
RSpec.describe 'Package', :orchestrated, :packages, :reliable, :object_storage, quarantine: {
only: { job: 'object_storage' },
issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/341209#note_681513082',
type: :investigating
} do
describe 'Maven Repository' do
include Runtime::Fixtures
let(:group_id) { 'com.gitlab.qa' }
let(:artifact_id) { "maven-#{SecureRandom.hex(8)}" }
let(:another_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?)
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
Resource::Package.init do |package|
package.name = package_name
package.project = project
end
end
let!(:runner) do
Resource::Runner.fabricate! do |runner|
runner.name = "qa-runner-#{Time.now.to_i}"
runner.tags = ["runner-for-#{project.group.name}"]
runner.executor = :docker
runner.token = project.group.runners_token
end
end
let!(:gitlab_address_with_port) do
uri = URI.parse(Runtime::Scenario.gitlab_address)
"#{uri.scheme}://#{uri.host}:#{uri.port}"
end
let(:pom_xml) do
{
file_path: 'pom.xml',
content: <<~XML
<project>
<groupId>#{group_id}</groupId>
<artifactId>#{artifact_id}</artifactId>
<version>1.0</version>
<modelVersion>4.0.0</modelVersion>
<repositories>
<repository>
<id>#{project.name}</id>
<url>#{gitlab_address_with_port}/api/v4/groups/#{project.group.id}/-/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>#{project.name}</id>
<url>#{gitlab_address_with_port}/api/v4/projects/#{project.id}/packages/maven</url>
</repository>
<snapshotRepository>
<id>#{project.name}</id>
<url>#{gitlab_address_with_port}/api/v4/projects/#{project.id}/packages/maven</url>
</snapshotRepository>
</distributionManagement>
</project>
XML
}
end
let(:pom_xml_another_project) do
{
file_path: 'pom.xml',
content: <<~XML
<project>
<groupId>#{group_id}</groupId>
<artifactId>#{another_artifact_id}</artifactId>
<version>1.0</version>
<modelVersion>4.0.0</modelVersion>
<repositories>
<repository>
<id>#{another_project.name}</id>
<url>#{gitlab_address_with_port}/api/v4/groups/#{another_project.group.id}/-/packages/maven</url>
</repository>
</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>
<dependency>
<groupId>#{group_id}</groupId>
<artifactId>#{artifact_id}</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
XML
}
end
let(:settings_xml) do
{
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>#{project.name}</id>
<configuration>
<httpHeaders>
<property>
<name>Private-Token</name>
<value>#{auth_token}</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
XML
}
end
let(:gitlab_ci_deploy_yml) 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
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
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
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([
gitlab_ci_deploy_yml,
settings_xml,
pom_xml
])
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
Page::Project::Packages::Show.perform do |show|
expect(show).to have_package_info(package_name, "1.0")
show.click_delete
end
Page::Project::Packages::Index.perform do |index|
expect(index).to have_content("Package deleted successfully")
expect(index).not_to have_package(package_name)
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/-/quality/test_cases/1830' 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_deploy_yml,
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(&:set_allow_duplicates_enabled)
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
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_deploy_yml,
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
|