registry/internal
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Ville Vesilehto 76365a61e3
fix: use io.LimitReader in key fetcher (#558)
## Motivation and Context

Replace server-only `http.MaxBytesReader(nil, ...)` with
`io.LimitReader` to cap the fetched body to 4KB in key fetcher. This
avoids passing a `nil` ResponseWriter and aligns with Go idioms. If more
than 4KB is received, return a clear error. Previously `MaxBytesReader`
returned a misleading `http: request body too large` error, which is
server-oriented. With this change the error becomes `HTTP auth key
response too large`.

## How Has This Been Tested?
<!-- Have you tested this in a real application? Which scenarios were
tested? -->

Add tests covering success, oversized bodies, connection failure,
non-200 status, and read failures. This covers almost all lines of
`FetchKey` method of `DefaultHTTPKeyFetcher`. For tests, I also added a
new initialiser `NewDefaultHTTPKeyFetcherWithClient` so that the HTTP
client could be modified for test use.

Tests use `httptest.NewTLSServer` plus a helper to construct a client
pinned to the test server.

`auth` package test coverage increased from 56.8% to 59.3%.

## Breaking Changes
<!-- Will users need to update their code or configurations? -->

None.

## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update

## Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have read the [MCP
Documentation](https://modelcontextprotocol.io)
- [x] My code follows the repository's style guidelines
- [x] New and existing tests pass locally
- [x] I have added appropriate error handling
- [ ] I have added or updated documentation as needed

## Additional context
<!-- Add any other context, implementation notes, or design decisions
-->

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-09-26 11:24:07 +01:00
..
api fix: use io.LimitReader in key fetcher (#558) 2025-09-26 11:24:07 +01:00
auth Deduplicate server JSON structs between publisher and registry (#318) 2025-08-28 14:58:15 +01:00
config Remove leftover psql references (#541) 2025-09-23 23:22:11 +01:00
database Fix atomic latest version update to prevent missing isLatest flags (#530) 2025-09-24 18:27:36 +01:00
importer Fix atomic latest version update to prevent missing isLatest flags (#530) 2025-09-24 18:27:36 +01:00
service Fix atomic latest version update to prevent missing isLatest flags (#530) 2025-09-24 18:27:36 +01:00
telemetry Add OpenTelemetry metrics instrumentation (#290) 2025-08-21 14:23:37 +01:00
validators Extra validation for registries (#484) 2025-09-23 23:05:10 +01:00