Skip to content

Refactor Namespace::PackageSetting duplicate checking

Radamanthus Batnag requested to merge 482901-refactor-duplicate-checks into master

Context

Our logic for allowing/preventing duplicates in the Maven Package registry does three checks:

  • 1️⃣ Does the group settings allow duplicates for Maven packages?
  • 2️⃣ Is the package a duplicate of an existing package?
  • 3️⃣ Does the package name or version match the exception regex?

These checks are done in two places in the code:

  • The checks for 1️⃣ and 3️⃣ are in ::Namespace::PackageSetting.duplicates_allowed?(package) link to code
  • The check for 2️⃣ is in app/services/packages/maven/find_or_create_package_service.rb link to code

This currently works and enforces this behavior:

If Allow duplicates is off, duplicates are not allowed except if the package name or version matches the Exceptions regexp.

But if we want to add the behavior If Allow duplicates is on, duplicates are allowed except if the package name or version matches the Exceptions regexp. then the code can be come complicated.

It will be easier to implement the new behavior if we have three check methods, one for each of 1️⃣, 2️⃣ and 3️⃣ above.

What does this MR do and why?

This MR creates two new class methods in ::Namespace::PackageSetting:

  • .duplicates_allowed_for_package?(package)
  • .matches_duplicate_exception?(package)

The two new methods replace ::Namespace::PackageSetting.duplicates_allowed?(package). We do not yet remove this method, though, because this is still used by other package formats.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

No UI or behavior changes 🌈

How to set up and validate locally

Handling of maven duplicate package uploads should remain the same.

https://docs.gitlab.com/ee/user/packages/maven_repository/?tab=mvn#publish-a-package https://docs.gitlab.com/ee/user/packages/maven_repository/#do-not-allow-duplicate-maven-packages

  1. With Allow duplicates enabled:
  • Repeat uploads of the package should be successful
  1. With Allow duplicates disabled, exception regexp set to blank:
  • Upload a package named bananas the first time -> should be successful
  • Upload a package named bananas again -> should fail with the duplicate package error
  1. With Allow duplicates disabled, exception regexp set to banana:
  • Upload a package named bananas multiple times -> should be successful, because the exception regexp matches the package name
  1. With Allow duplicates disabled, exception regexp set to 1.0:
  • Upload a package named bananas, version 1.0.1 multiple times -> should be successful, because the exception regexp matches the package version

Related to #482901

Edited by Radamanthus Batnag

Merge request reports

Loading