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 _)); }