fix(protocol): report Chronos's own info error as that error, not a disposed stream

The identity check reads Chronos's error body to tell it from another
service; GetInfoAsync then read it again and threw ObjectDisposedException.
The identity now carries the parsed error and GetInfoAsync throws it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-04 10:42:58 +01:00
1 parent 0aa2fb8135
commit 2585b5d45f
2 files changed
+33 -4

No files matched your search

@@ -77,6 +77,24 @@ public sealed class ServerIdentityTests(TestContext context)
Assert.Equal(0, other.Authorized, "no request carried credentials");
}
[Test]
public async Task AChronosErrorFromTheInfoIsReportedAsThatError()
{
// Chronos's own error (its header and code) is read once to tell it from other services: it must still come back
// as the server's error, and an unknown certificate still asks for trust.
await using var other = await OtherService.StartAsync(context);
foreach (var (path, status, code) in new[] { ("chronos500/", HttpStatusCode.InternalServerError, "internal"), ("chronos400/", HttpStatusCode.BadRequest, "bad_request") })
{
using var plain = new ChronosClient(new Uri(other.Http, path), new CertificatePinning([]), "tests");
var error = await Assert.ThrowsAsync<ChronosApiException>(() => plain.GetInfoAsync(context.Cancellation), path);
Assert.Equal(status, error.Status, path);
Assert.Equal(code, error.Error.Code, path);
using var untrusted = new ChronosClient(new Uri(other.Https, path), new CertificatePinning([]), "tests");
await Assert.ThrowsAsync<UntrustedCertificateException>(() => untrusted.GetInfoAsync(context.Cancellation), path);
}
}
[Test]
public async Task AChronosServerBehindAnUnknownCertificateStillAsksForTrust()
{
@@ -149,6 +167,13 @@ public sealed class ServerIdentityTests(TestContext context)
// Errors in JSON with a code of their own, as many web services write them.
foreach (var (path, status) in new[] { ("json401", 401), ("json403", 403), ("json404", 404) })
app.MapGet($"/{path}/api/v1/server/info", () => Results.Content("""{"code":"denied","message":"Sign in"}""", "application/json", statusCode: status));
// Errors as Chronos writes them: its header and a code of its own.
foreach (var (path, status, code) in new[] { ("chronos500", 500, "internal"), ("chronos400", 400, "bad_request") })
app.MapGet($"/{path}/api/v1/server/info", (HttpContext http) =>
{
http.Response.Headers[ApiVersion.Header] = "1";
return Results.Content($$"""{"code":"{{code}}","message":"Failed"}""", "application/json", statusCode: status);
});
// More than a server info ever holds.
app.MapGet("/huge/api/v1/server/info", () => Results.Content("<!doctype html>" + new string('x', 2 << 20), "text/html"));
app.MapGet("/hugejson/api/v1/server/info", () => Results.Content("{\"name\":\"" + new string('x', 2 << 20) + "\"}", "application/json"));