fix(host): resolve Host-003,004 — replace plaintext secrets with env placeholders, validate site seed-node ports; re-triage Host-002
This commit is contained in:
41
tests/ScadaLink.Host.Tests/CentralDbTestEnvironment.cs
Normal file
41
tests/ScadaLink.Host.Tests/CentralDbTestEnvironment.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
namespace ScadaLink.Host.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Host-003: <c>appsettings.Central.json</c> no longer commits database connection
|
||||
/// strings — they are externalised to environment variables. Tests that exercise the
|
||||
/// full <c>Program</c> startup pipeline against the real SQL provider must therefore
|
||||
/// supply the local dev connection strings the way a deployment would: via
|
||||
/// environment variables (<c>Program</c>'s configuration builder calls
|
||||
/// <c>AddEnvironmentVariables()</c>).
|
||||
///
|
||||
/// Dispose restores the previous values so tests stay isolated.
|
||||
/// </summary>
|
||||
internal sealed class CentralDbTestEnvironment : IDisposable
|
||||
{
|
||||
// Local dev/test database — same credentials the infra docker-compose stack uses.
|
||||
// This is a test fixture value, not a committed production secret.
|
||||
private const string ConfigurationDb =
|
||||
"Server=localhost,1433;Database=ScadaLinkConfig;User Id=scadalink_app;Password=ScadaLink_Dev1#;TrustServerCertificate=true";
|
||||
private const string MachineDataDb =
|
||||
"Server=localhost,1433;Database=ScadaLinkMachineData;User Id=scadalink_app;Password=ScadaLink_Dev1#;TrustServerCertificate=true";
|
||||
|
||||
private const string ConfigKey = "ScadaLink__Database__ConfigurationDb";
|
||||
private const string MachineKey = "ScadaLink__Database__MachineDataDb";
|
||||
|
||||
private readonly string? _previousConfig;
|
||||
private readonly string? _previousMachine;
|
||||
|
||||
public CentralDbTestEnvironment()
|
||||
{
|
||||
_previousConfig = Environment.GetEnvironmentVariable(ConfigKey);
|
||||
_previousMachine = Environment.GetEnvironmentVariable(MachineKey);
|
||||
Environment.SetEnvironmentVariable(ConfigKey, ConfigurationDb);
|
||||
Environment.SetEnvironmentVariable(MachineKey, MachineDataDb);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Environment.SetEnvironmentVariable(ConfigKey, _previousConfig);
|
||||
Environment.SetEnvironmentVariable(MachineKey, _previousMachine);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user