registry/internal/api/handlers/v0
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
..
auth fix: use io.LimitReader in key fetcher (#558) 2025-09-26 11:24:07 +01:00
edit.go Introduce serverId, rename id to versionId (#465) 2025-09-21 15:00:09 +03:00
edit_test.go Remove the in-memory database (#537) 2025-09-23 16:40:20 +01:00
health.go Add OpenTelemetry metrics instrumentation (#290) 2025-08-21 14:23:37 +01:00
health_test.go Add OpenTelemetry metrics instrumentation (#290) 2025-08-21 14:23:37 +01:00
ping.go api: Use Huma to generate swagger docs and parse JSON automatically (#262) 2025-08-13 16:57:55 +01:00
ping_test.go auth: New auth flow (#273) 2025-08-15 13:03:35 +01:00
publish.go Improve publish permission error message to show available permissions (#417) 2025-09-10 12:28:22 -07:00
publish_integration_test.go Remove the in-memory database (#537) 2025-09-23 16:40:20 +01:00
publish_registry_validation_test.go Remove the in-memory database (#537) 2025-09-23 16:40:20 +01:00
publish_test.go Remove the in-memory database (#537) 2025-09-23 16:40:20 +01:00
response.go auth: New auth flow (#273) 2025-08-15 13:03:35 +01:00
servers.go Introduce serverId, rename id to versionId (#465) 2025-09-21 15:00:09 +03:00
servers_test.go Remove the in-memory database (#537) 2025-09-23 16:40:20 +01:00
telemetry_test.go Remove the in-memory database (#537) 2025-09-23 16:40:20 +01:00