CI / Build and test (pull_request) Failing after 2m3s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / Docker image (pull_request) Skipped
CI / Windows tests and installer (pull_request) Skipped
CI / YAML check (pull_request) Successful in 4s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow) and pe-check. BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
113 lines
5.0 KiB
C#
113 lines
5.0 KiB
C#
using System.Buffers;
|
|
using System.Text;
|
|
using Chronos.Data.Postgres;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Data.Tests.Postgres;
|
|
|
|
/// <summary>Protocol pieces that need no server.</summary>
|
|
public sealed class PgProtocolUnitTests
|
|
{
|
|
[Test]
|
|
public void ScramMatchesTheRfc7677Example()
|
|
{
|
|
var scram = new ScramSha256("pencil", "user", "rOprNGfwEbeRWgbNEkqO");
|
|
Assert.Equal("n,,n=user,r=rOprNGfwEbeRWgbNEkqO", Encoding.UTF8.GetString(scram.ClientFirstMessage()));
|
|
var final = scram.ClientFinalMessage(Encoding.UTF8.GetBytes(
|
|
"r=rOprNGfwEbeRWgbNEkqO%hvYDpWUa2RaTCAfuxFIlj)hNlF$k0,s=W22ZaJ0SNY7soEsUEjb6gQ==,i=4096"));
|
|
Assert.Equal(
|
|
"c=biws,r=rOprNGfwEbeRWgbNEkqO%hvYDpWUa2RaTCAfuxFIlj)hNlF$k0,p=dHzbZapWIk4jUhN+Ute9ytag9zjfMHgsqmmiz7AndVQ=",
|
|
Encoding.UTF8.GetString(final));
|
|
Assert.False(scram.IsServerVerified);
|
|
Assert.Throws<System.Security.Authentication.AuthenticationException>(() => scram.VerifyServerFinal("v=AAAA"u8));
|
|
Assert.False(scram.IsServerVerified);
|
|
scram.VerifyServerFinal("v=6rriTRBi23WpRR/wtup+mMhUZUn/dB5nLTJRsjl95G4="u8);
|
|
Assert.True(scram.IsServerVerified);
|
|
}
|
|
|
|
[Test]
|
|
public void ScramRejectsANonceTheClientDidNotStart()
|
|
{
|
|
var scram = new ScramSha256("pencil", "user", "abc");
|
|
scram.ClientFirstMessage();
|
|
Assert.Throws<System.Security.Authentication.AuthenticationException>(
|
|
() => scram.ClientFinalMessage("r=xyz123,s=W22ZaJ0SNY7soEsUEjb6gQ==,i=4096"u8));
|
|
}
|
|
|
|
[Theory]
|
|
[Case("plain-ascii", "plain-ascii")]
|
|
[Case("I\u00ADX", "IX")]
|
|
[Case("a\u00A0b", "a b")]
|
|
[Case("\u2168", "IX")]
|
|
[Case("\u00AA", "a")]
|
|
[Case("bell\u0007", "bell\u0007")]
|
|
[Case("x\u00ADy\u0007", "x\u00ADy\u0007")]
|
|
public void SaslPrepMapsNormalisesAndFallsBack(string input, string expected) =>
|
|
Assert.Equal(expected, ScramSha256.SaslPrep(input));
|
|
|
|
[Test]
|
|
public void Md5ResponseMatchesPostgresFormula() =>
|
|
Assert.Equal("md5b315d1a47dc34e1aed4b36fe502f2e9c", PgMd5.Response("chronos_md5", "md5-pw", [1, 2, 3, 4]));
|
|
|
|
[Test]
|
|
public void CopyTextEscapesSpecialsAndEncodesValues()
|
|
{
|
|
var buffer = new ArrayBufferWriter<byte>();
|
|
foreach (var value in new object?[] { "a\tb\nc\rd\\e ✓", null, new byte[] { 0, 0xAB }, true, 42L, Guid.Empty, new DateTime(2020, 1, 2, 3, 4, 5), 2.5f })
|
|
{
|
|
PgTypes.WriteCopyValue(value, buffer);
|
|
buffer.Write("|"u8);
|
|
}
|
|
Assert.Equal(
|
|
"a\\tb\\nc\\rd\\\\e ✓|\\N|\\\\x00ab|t|42|00000000-0000-0000-0000-000000000000|2020-01-02T03:04:05.000000|2.5|",
|
|
Encoding.UTF8.GetString(buffer.WrittenSpan));
|
|
}
|
|
|
|
[Test]
|
|
public void DecodesHexByteaAndRejectsOtherForms()
|
|
{
|
|
Assert.BytesEqual(new byte[] { 0xDE, 0xAD, 0x01 }, (byte[])PgTypes.Decode(PgTypes.Bytea, "\\xdeAD01"u8));
|
|
Assert.Equal(0, ((byte[])PgTypes.Decode(PgTypes.Bytea, "\\x"u8)).Length);
|
|
Assert.Throws<FormatException>(() => PgTypes.Decode(PgTypes.Bytea, "a\\000"u8));
|
|
Assert.Throws<FormatException>(() => PgTypes.Decode(PgTypes.Bytea, "\\xabc"u8));
|
|
Assert.Throws<FormatException>(() => PgTypes.Decode(PgTypes.Bytea, "\\xzz"u8));
|
|
}
|
|
|
|
[Theory]
|
|
[Case("SELECT 1", true)]
|
|
[Case(" -- comment\n /* block */ select * from t", true)]
|
|
[Case("VALUES (1)", true)]
|
|
[Case("SHOW TimeZone", true)]
|
|
[Case("SELECTED", false)]
|
|
[Case("UPDATE t SET a = 1", false)]
|
|
[Case("WITH x AS (DELETE FROM t RETURNING *) SELECT * FROM x", false)]
|
|
public void RecognisesRepeatableReads(string sql, bool expected) =>
|
|
Assert.Equal(expected, PostgresSession.IsReadOnlyQuery(sql));
|
|
|
|
[Test]
|
|
public void ParsesConnectionStrings()
|
|
{
|
|
var s = PostgresSettings.Parse("Host=db.local; Port=6543; Username=me; Password='p;w''d'; SslMode=verify-full; Maximum Pool Size=7; Search Path=s1");
|
|
Assert.Equal("db.local", s.Host);
|
|
Assert.Equal(6543, s.Port);
|
|
Assert.Equal("me", s.Database);
|
|
Assert.Equal("p;w'd", s.Password);
|
|
Assert.Equal(SslMode.VerifyFull, s.SslMode);
|
|
Assert.Equal(7, s.MaxPoolSize);
|
|
Assert.Equal("s1", s.SearchPath);
|
|
Assert.Equal("chronos-server", s.ApplicationName);
|
|
Assert.Throws<FormatException>(() => PostgresSettings.Parse("Host=x;Username=u;SslMode=allowish"));
|
|
Assert.Throws<FormatException>(() => PostgresSettings.Parse("Host=x;Username=u;Pasword=typo"));
|
|
Assert.Throws<FormatException>(() => PostgresSettings.Parse("Host=x;Username=u;Minimum Pool Size=5;Maximum Pool Size=2"));
|
|
}
|
|
|
|
[Test]
|
|
public void InfersTheDialectFromTheConnectionString()
|
|
{
|
|
Assert.Equal(Dialect.Postgres, DatabaseOptions.Parse("Server=x;User Id=u").Dialect);
|
|
Assert.Equal(Dialect.Sqlite, DatabaseOptions.Parse("Data Source=/tmp/a.db").Dialect);
|
|
Assert.Equal(Dialect.Sqlite, DatabaseOptions.Parse(@"C:\Users\me\chronos.db").Dialect);
|
|
Assert.Throws<FormatException>(() => DatabaseOptions.Parse("Foo=bar"));
|
|
}
|
|
}
|