Fix trailing slash in Maven dependency proxy upstream URL
🔥 Problem
The maven dependency proxy will not work if the upstream url ends with a slash. Example: https://repo.maven.apache.org/maven2/
.
With this url, the dependency proxy will end up in errors ranging from 404 Not found
to 401 Unauthenticated
.
🚒 Solution
- Add
DependencyProxy::Packages::Setting#form_maven_upstream
method that forms the upstream URL and makes sure the extra/
are removed. - Modify API::DependencyProxy::Packages::Maven#remote_package_file_url to use
DependencyProxy::Packages::Setting#form_maven_upstream
. - Add the needed specs.
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
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
The same steps mentioned here can be followed to test Maven dependency proxy. The only difference will be in the value of maven_external_registry_url
when creating a dependency_proxy_packages_setting
record; we need to append a trailing slash at its end:
Project.find(<local_project_id>).create_dependency_proxy_packages_setting!(maven_external_registry_url: 'https://gitlab.com/api/v4/projects/22780791/packages/maven/', maven_external_registry_username: '<username for gitlab.com>', maven_external_registry_password: '<pat for gitlab.com>', enabled: true)
On this branch, the dependency proxy should work as expected, even with the extra /
in maven_external_registry_url
. On master, it wouldn't work.
Related to #452046 (closed)