Allow a full group path on the NuGet group packages API

What does this MR do and why?

The group-level NuGet API documents :id as a group ID or full group path, but lib/api/nuget_group_packages.rb validated :id with POSITIVE_INTEGER_REGEX. A request such as /api/v4/groups/example-group/-/packages/nuget/index.json failed with {"error":"id is invalid"} before group lookup could run.

This MR drops that integer-only regexp and declares :id the same way as other group package APIs (Maven, PyPI, npm, Debian):

params do
  requires :id, types: [Integer, String], desc: 'The ID or URL-encoded path of the group.'
end

resource :groups, requirements: ::API::NAMESPACE_OR_PROJECT_REQUIREMENTS do

find_group / find_authorized_group! already accept an ID or path, and the resource already used API::NAMESPACE_OR_PROJECT_REQUIREMENTS, so :id remains a single path segment. Nested groups must be URL-encoded (parent%2Fchild), as with the rest of the Groups API.

Why this is not a docs-only correction

I looked at whether the integer restriction was intentional:

  • NuGet v2/v3 routes (/nuget/v2, /nuget/index, metadata, query, symbol files) sit under groups/:id/-/packages/nuget/. They do not compete with :id.
  • ServiceIndexPresenter always builds resource URLs with project_or_group.id, so once the index is fetched by path, follow-up client requests keep using numeric IDs that already work.
  • POSITIVE_INTEGER_REGEX is also used to validate the take query parameter on the search endpoint. Reusing it on :id looks like overly strict parameter validation, not a route-conflict workaround.
  • Maven, PyPI, npm, and Debian group endpoints already accept an ID or URL-encoded path.

The project-level NuGet API still uses the integer regexp. This MR leaves that alone; the reported issue is the group endpoint.

Request specs cover a numeric ID, a top-level full path, and a URL-encoded nested path, and assert that the service index resource URLs still contain the numeric group ID. Shared examples that expected 400 for non-integer group IDs now treat those values as lookup/auth failures when allow_full_path is enabled. The project examples are unchanged.

The OpenAPI parameter description uses "ID or URL-encoded path of the group." The package docs keep "The group ID or full group path" and add that / in a nested path must be encoded as %2F. Shared examples still cover numeric IDs.

Anonymous access by path

The public service-index routes use project_or_group_without_auth, so a guessable full path can return 200 for an existing private group and 404 for a missing one, and the 200 includes the numeric group ID. A numeric ID already returned 200 for private groups before this MR, and the project-level API plus the Maven, PyPI, npm, and Debian group endpoints behave the same way. Private routes (metadata, query) still call authenticate! first, so anonymous requests get 401 for any ID. This is recorded here as accepted behaviour, not a new regression.

References

Closes #641185 (closed)

Screenshots or screen recordings

Not applicable (API validation change).

How to set up and validate locally

  1. In a group with Package Registry enabled (a subgroup works too), compare:

    curl --url "http://gdk.test:3000/api/v4/groups/<numeric-id>/-/packages/nuget/index.json"
    curl --url "http://gdk.test:3000/api/v4/groups/<group-path>/-/packages/nuget/index.json"
    curl --url "http://gdk.test:3000/api/v4/groups/<parent>%2F<child>/-/packages/nuget/index.json"
  2. All three should return a service index. Resource @id URLs should use the numeric group ID, for example /groups/<numeric-id>/-/packages/nuget/query.

MR acceptance checklist

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

Edited by Priyanshu Jha

Merge request reports

Loading
Loading