test(data): PostgreSQL MD5, cleartext, trust and TLS tests can run, and must where TLS is set up
BRIEF §6.3 requires every authentication method and TLS mode against the PostgreSQL service containers, but the MD5, cleartext and trust tests always skipped in CI (no roles) and the TLS tests skipped at run time because the official images start with TLS off. .github/scripts/postgres-ci-setup.sh prepares a server container: a role per method with its pg_hba line ahead of the image's SCRAM line (the MD5 password stored as MD5), and TLS with a self-signed certificate for localhost and 127.0.0.1, enabled with ALTER SYSTEM and a reload whose rejected lines fail the script. With TITANO_TEST_PG_TLS=1 a server that refuses TLS fails the TLS tests instead of skipping them, and a new test checks that verify-full accepts the server whose certificate chains to TITANO_TEST_PG_ROOT_CERT. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
3 files changed
+86
-3
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Security.Authentication;
|
||||
using Titano.Data.Postgres;
|
||||
using Titano.Data.Tests.Infrastructure;
|
||||
@@ -6,7 +7,11 @@ using Titano.Testing;
|
||||
|
||||
namespace Titano.Data.Tests.Postgres;
|
||||
|
||||
/// <summary>Protocol-level tests against a live server (TITANO_TEST_PG; optional TITANO_TEST_PG_MD5/_CLEARTEXT/_TRUST).</summary>
|
||||
/// <summary>
|
||||
/// Protocol-level tests against a live server (TITANO_TEST_PG). Optional: TITANO_TEST_PG_MD5/_CLEARTEXT/_TRUST (roles
|
||||
/// of the other authentication methods), TITANO_TEST_PG_TLS=1 (the server offers TLS) and TITANO_TEST_PG_ROOT_CERT (the
|
||||
/// PEM its certificate chains to). CI sets them all up (.github/scripts/postgres-ci-setup.sh).
|
||||
/// </summary>
|
||||
[RequiresEnvironment(PgTestServer.Variable)]
|
||||
public sealed class PgWireTests(TestContext context) : DatabaseTest(context)
|
||||
{
|
||||
@@ -15,6 +20,14 @@ public sealed class PgWireTests(TestContext context) : DatabaseTest(context)
|
||||
private async Task<PostgresDatabase> OpenAsync(string? extra = null) =>
|
||||
(PostgresDatabase)Own(DatabaseFactory.Open(await NewOptionsAsync(extraPostgres: extra)));
|
||||
|
||||
/// <summary>A server without TLS skips the TLS tests, unless it was set up with TLS (<see cref="PgTestServer.TlsVariable"/>).</summary>
|
||||
[DoesNotReturn]
|
||||
private static void WithoutTls(DatabaseConnectionException refusal)
|
||||
{
|
||||
if (PgTestServer.TlsExpected) Assert.Fail($"{PgTestServer.TlsVariable} says the server offers TLS, but it refused: {refusal.Message}");
|
||||
TestContext.Skip("server has no TLS");
|
||||
}
|
||||
|
||||
private async Task<string> AuthenticateAsync(string connectionString)
|
||||
{
|
||||
var database = Own(new PostgresDatabase(PostgresSettings.Parse(connectionString)));
|
||||
@@ -61,7 +74,7 @@ public sealed class PgWireTests(TestContext context) : DatabaseTest(context)
|
||||
}
|
||||
catch (DatabaseConnectionException ex) when (ex.Message.Contains("does not support TLS", StringComparison.Ordinal))
|
||||
{
|
||||
TestContext.Skip("server has no TLS");
|
||||
WithoutTls(ex);
|
||||
return;
|
||||
}
|
||||
await using var session = await database.OpenAsync(Ct);
|
||||
@@ -83,13 +96,22 @@ public sealed class PgWireTests(TestContext context) : DatabaseTest(context)
|
||||
}
|
||||
catch (DatabaseConnectionException ex) when (ex.Message.Contains("does not support TLS", StringComparison.Ordinal))
|
||||
{
|
||||
TestContext.Skip("server has no TLS");
|
||||
WithoutTls(ex);
|
||||
}
|
||||
catch (AuthenticationException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task VerifyFullAcceptsACertificateThatChainsToTheConfiguredRoot()
|
||||
{
|
||||
var root = PgTestServer.Optional("TITANO_TEST_PG_ROOT_CERT");
|
||||
var database = await OpenAsync($"SslMode=VerifyFull;Root Certificate={root}");
|
||||
await using var session = await database.OpenAsync(Ct);
|
||||
Assert.True(await session.ScalarAsync<bool>("SELECT ssl FROM pg_stat_ssl WHERE pid = pg_backend_pid()", [], Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DecodesEveryMappedResultType()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user