Commit da85ceb0 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '321772-version-dupe-check' into 'master'

Check duplicate package regex against version as well as name

See merge request gitlab-org/gitlab!60760
parents a48b0f16 4fac51d7
......@@ -22,7 +22,7 @@ class Namespace::PackageSetting < ApplicationRecord
duplicates_allowed = package.package_settings["#{package.package_type}_duplicates_allowed"]
regex = ::Gitlab::UntrustedRegexp.new("\\A#{package.package_settings["#{package.package_type}_duplicate_exception_regex"]}\\z")
duplicates_allowed || regex.match?(package.name)
duplicates_allowed || regex.match?(package.name) || regex.match?(package.version)
end
end
end
---
title: Check duplicate package regex against version as well as name
merge_request: 60760
author:
type: fixed
......@@ -625,7 +625,7 @@ In the UI:
1. For your group, go to **Settings > Packages & Registries**.
1. Expand the **Package Registry** section.
1. Turn on the **Reject duplicates** toggle.
1. Optional. To allow some duplicate packages, in the **Exceptions** box, enter a regex pattern that matches the names of packages you want to allow.
1. Optional. To allow some duplicate packages, in the **Exceptions** box, enter a regex pattern that matches the names and/or versions of packages you want to allow.
Your changes are automatically saved.
......
......@@ -42,7 +42,7 @@ RSpec.describe Namespace::PackageSetting do
context 'package types with package_settings' do
# As more package types gain settings they will be added to this list
[:maven_package].each do |format|
let_it_be(:package) { create(format) } # rubocop:disable Rails/SaveBang
let_it_be(:package) { create(format, name: 'foo', version: 'beta') } # rubocop:disable Rails/SaveBang
let_it_be(:package_type) { package.package_type }
let_it_be(:package_setting) { package.project.namespace.package_settings }
......@@ -50,6 +50,8 @@ RSpec.describe Namespace::PackageSetting do
true | '' | true
false | '' | false
false | '.*' | true
false | 'fo.*' | true
false | 'be.*' | true
end
with_them do
......
......@@ -130,7 +130,15 @@ RSpec.describe Packages::Maven::FindOrCreatePackageService do
context 'when the package name matches the exception regex' do
before do
package_settings.update!(maven_duplicate_exception_regex: '.*')
package_settings.update!(maven_duplicate_exception_regex: existing_package.name)
end
it_behaves_like 'reuse existing package'
end
context 'when the package version matches the exception regex' do
before do
package_settings.update!(maven_duplicate_exception_regex: existing_package.version)
end
it_behaves_like 'reuse existing package'
......
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