Files
Chronos/tests/Chronos.App.Tests/Uploader/ServerAddressTests.cs
T
Alby96andClaude Opus 5.5 0aa2fb8135 fix(server): client address from the page's port, stricter Chronos identity, Host networking notes
Review fixes on top of the public ports change (owner review 3):

- Settings > Network and TLS: opened over HTTPS, the client address uses the port
  the page came through (a container's 8443 published as 8444 with Public HTTPS
  port still empty showed the wrong 8443), and a "Use <port>" button fills that
  port in. Saving a Public HTTPS port other than the page's asks first, since the
  HTTPS redirect follows it at once and a typo would lock the panel's link out.
- GetInfoAsync tells Chronos from other services by stricter rules on both the
  trusted and the untrusted-certificate path: any redirect, any answer that is not
  JSON, more than 1 MB, or an error without the X-Chronos-Api header is not
  Chronos. Another service's certificate is no longer offered for trust after a
  cross-scheme redirect, an error page or a JSON 401/403/404, and a JSON 401 over
  HTTP no longer reads as a wrong password.
- The HTTP port typed without a scheme (TLS to a plain HTTP port) now gives the
  not-Chronos error instead of "the server did not answer".
- The Uploader's certificate question names the address with its port.
- A link-local IPv6 address with a zone index is refused instead of losing it.
- In a container, the first save of the settings removes HttpPort/HttpsPort from
  server.json, so the start-up warning stops; the warning says so.
- Guide, README, compose and template: with network type Host the mappings do
  nothing and CHRONOS_HTTP_PORT / CHRONOS_HTTPS_PORT move the listening ports off
  ones another service uses; the template overview is back to two sentences.
- BRIEF, DECISIONS and CHANGELOG updated; en/it strings added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 10:28:08 +01:00

42 lines
1.7 KiB
C#

using Chronos.Testing;
using Chronos.Uploader.Server;
namespace Chronos.App.Tests.Uploader;
public sealed class ServerAddressTests
{
[Theory]
[Case("nas.local:8443", "https://nas.local:8443/")]
[Case("https://nas.local:8443", "https://nas.local:8443/")]
[Case(" http://192.168.1.20:8080/chronos ", "http://192.168.1.20:8080/chronos/")]
[Case("https://nas.local/?x=1#y", "https://nas.local/")]
// Owner review 3: no scheme and no port is Chronos's HTTPS port, as the placeholder shows.
[Case("192.168.30.23", "https://192.168.30.23:8443/")]
[Case("nas.local", "https://nas.local:8443/")]
[Case("nas.local/chronos", "https://nas.local:8443/chronos/")]
[Case("192.168.30.23:8444", "https://192.168.30.23:8444/")]
[Case("nas.local:443", "https://nas.local/")]
[Case("https://chronos.example.com", "https://chronos.example.com/")]
[Case("http://nas.local", "http://nas.local/")]
[Case("fd00::5", "https://[fd00::5]:8443/")]
[Case("[fd00::5]", "https://[fd00::5]:8443/")]
[Case("[fd00::5]:9443", "https://[fd00::5]:9443/")]
[Case("https://[fd00::5]", "https://[fd00::5]/")]
public void ServerAddressesBecomeApiBases(string typed, string expected)
{
Assert.True(ServerAddress.TryParse(typed, out var uri));
Assert.Equal(expected, uri.ToString());
}
[Theory]
[Case("")]
[Case(" ")]
[Case("ftp://nas.local")]
[Case("https://")]
// A zone index cannot reach the request: refused rather than dropped.
[Case("fe80::1%12")]
[Case("[fe80::1%12]:8443")]
[Case("https://[fe80::1%2512]")]
public void InvalidServerAddressesAreRejected(string typed) => Assert.False(ServerAddress.TryParse(typed, out _));
}