Skip to content

Add host and username/password support to cargo registry handler#140

Merged
brettfo merged 3 commits into
mainfrom
brettfo/cargo-host-username-password
Jun 11, 2026
Merged

Add host and username/password support to cargo registry handler#140
brettfo merged 3 commits into
mainfrom
brettfo/cargo-host-username-password

Conversation

@brettfo

@brettfo brettfo commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

The cargo handler previously only accepted url and token credential values. This adds support for:

  • host as an alternative to url for matching requests (using helpers.CheckHost)
  • username/password as an alternative to token for authentication (sets Basic auth)

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

  • Host-only matching with token auth
  • URL matching with username/password (basic auth)
  • Host matching with username/password (basic auth)
  • Token precedence over password
  • Rejection of credentials with no url or host

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>
@brettfo brettfo requested a review from a team as a code owner June 10, 2026 18:18
Copilot AI review requested due to automatic review settings June 10, 2026 18:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and password, 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 url and host.
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
}
Comment thread internal/handlers/cargo_registry.go
Comment thread internal/handlers/cargo_registry.go
Comment thread internal/handlers/cargo_registry_test.go
- 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>
Comment thread internal/handlers/cargo_registry.go
Comment thread internal/handlers/cargo_registry.go Outdated
Comment thread internal/handlers/cargo_registry_test.go
@brettfo brettfo force-pushed the brettfo/cargo-host-username-password branch 2 times, most recently from 71c0518 to 89d637b Compare June 10, 2026 22:30
- 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>
@brettfo brettfo force-pushed the brettfo/cargo-host-username-password branch from 89d637b to 56dc1e0 Compare June 11, 2026 13:23
@brettfo brettfo merged commit 827e737 into main Jun 11, 2026
207 of 208 checks passed
@brettfo brettfo deleted the brettfo/cargo-host-username-password branch June 11, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants