using System.Security.Cryptography.X509Certificates; using Chronos.Testing; using Chronos.Tools.Commands; namespace Chronos.Tools.Tests; /// postgres-ci prepares the CI server for the wire tests without docker (BRIEF ยง6.3, amended 2026-10-23, R3). public sealed class PostgresCiCommandTests { [Test] public void TheTestRolesGoAheadOfTheImagesRulesOnceOnly() { const string image = "local all all trust\nhost all all all scram-sha-256\n"; var once = PostgresCiCommand.PrependRules(image); Assert.Equal( "host all chronos_md5 all md5\nhost all chronos_clear all password\nhost all chronos_trust all trust\n" + image, once); Assert.Equal(once, PostgresCiCommand.PrependRules(once)); } [Test] public void TheCertificateNamesTheServiceHostAndLoopback() { var (pem, key) = PostgresCiCommand.CreateCertificate("postgres"); using var certificate = X509Certificate2.CreateFromPem(pem, key); Assert.True(certificate.HasPrivateKey); Assert.Equal("CN=postgres", certificate.Subject); Assert.True(certificate.MatchesHostname("postgres")); Assert.True(certificate.MatchesHostname("localhost")); Assert.True(certificate.MatchesHostname("127.0.0.1")); Assert.False(certificate.MatchesHostname("example.org")); Assert.Less((certificate.NotAfter - DateTime.Now).TotalDays, 3); } [Test] public void LiteralsDoubleTheirQuotes() => Assert.Equal("'/var/lib/postgresql/data/it''s'", PostgresCiCommand.Literal("/var/lib/postgresql/data/it's")); }