Add host and username/password support to cargo registry handler#140
Merged
Conversation
The cargo handler now accepts 'host' as an alternative to 'url' for matching requests, and 'username'/'password' as an alternative to 'token' for authentication (using basic auth). Token takes precedence when both are present. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR extends the Cargo registry request handler to support additional credential shapes, enabling request matching by host (as an alternative to url) and authentication via username/password (Basic auth) as an alternative to a raw token, aligning behavior with other registry/feed handlers in this proxy.
Changes:
- Extend cargo registry credential parsing to accept
host,username, andpassword, while keeping token-first precedence. - Update request matching to allow host-based matching in addition to URL-based matching.
- Add unit tests covering host-only matching, Basic auth behavior, token precedence, and ignoring credentials missing both
urlandhost.
Show a summary per file
| File | Description |
|---|---|
| internal/handlers/cargo_registry.go | Adds host-based matching and username/password authentication support for cargo registry requests. |
| internal/handlers/cargo_registry_test.go | Adds tests for host matching, Basic auth, token precedence, and rejecting incomplete credentials. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 2
Comment on lines
118
to
121
| for _, cred := range h.credentials { | ||
| if !helpers.UrlMatchesRequest(req, cred.url, true) { | ||
| if !helpers.UrlMatchesRequest(req, cred.url, true) && !helpers.CheckHost(req, cred.host) { | ||
| continue | ||
| } |
kbukum1
reviewed
Jun 10, 2026
kbukum1
reviewed
Jun 10, 2026
- Only use host-based matching when url is not set, preventing credential leakage to unrelated paths on the same host - Update warning message to mention both token and password - Add regression test for url+host scoping behavior Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
kbukum1
reviewed
Jun 10, 2026
kbukum1
reviewed
Jun 10, 2026
kbukum1
reviewed
Jun 10, 2026
71c0518 to
89d637b
Compare
- Only assign host to credential struct when url is empty (clearer intent) - Update warning to say 'missing token or username/password' - Use more realistic org-scoped paths in regression test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
89d637b to
56dc1e0
Compare
kbukum1
approved these changes
Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The cargo handler previously only accepted url and token credential values. This adds support for:
When both token and username/password are provided, token takes precedence. Credentials with neither url nor host are rejected with a warning.
Modeled after the NuGet feed handler's approach to dynamically handling these credential variants.
Tests added