fix(secrets): SqlServer/Akka extensions take contentRootPath; last explicit root wins (scadaproj#31)
The SQL-Server extensions called the 3-arg AddZbSecrets, and the store-path validator captured the content root of whichever call registered it first. In hub mode no registration order applied the pre-host under-content-root guard: extension-first dropped the app's 4-arg root, core-first lost the replicator (#30). That is the 0.6.0 store-path hole, reopened. - AddZbSecretsSqlServerStore / AddZbSecretsSqlServerReplication / AddZbSecretsAkkaReplication gain a trailing optional contentRootPath, forwarded to the 4-arg AddZbSecrets - the root now lives in one SecretsContentRoot instance holder per service collection; the last explicit root wins, null never erases one; the IHostEnvironment fallback is unchanged - tests: ContentRootTests (hub mode, three compositions, artifact asserted before the throw, positive control), last-explicit-wins theory in SecretsStorePathRulesTests, Akka forwarding test - code-reviews: Secrets-002 Resolved; README regenerated Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
+47
@@ -313,6 +313,53 @@ public sealed class SecretsStorePathRulesTests
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public async Task The_last_explicit_content_root_wins_whichever_call_registered_the_validator(
|
||||
bool threeArgCallFirst)
|
||||
{
|
||||
// REGRESSION (scadaproj#31). The validator used to capture the content root of whichever
|
||||
// AddZbSecrets call registered it FIRST. A replication package calls the 3-arg overload
|
||||
// internally; when that ran before the application's 4-arg call, the explicit root was
|
||||
// discarded and the pre-host guard silently skipped — the 0.6.0 hole, reopened. A null root
|
||||
// must also never erase an explicit one supplied earlier.
|
||||
string contentRoot = Path.Combine(Path.GetTempPath(), $"zb-prehost-order-{Guid.NewGuid():N}");
|
||||
Directory.CreateDirectory(contentRoot);
|
||||
string dbPath = Path.Combine(contentRoot, "store.db");
|
||||
|
||||
try
|
||||
{
|
||||
IConfiguration config = new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(new Dictionary<string, string?> { ["Secrets:SqlitePath"] = dbPath })
|
||||
.Build();
|
||||
|
||||
var services = new ServiceCollection();
|
||||
if (threeArgCallFirst)
|
||||
{
|
||||
services.AddZbSecrets(config, "Secrets");
|
||||
services.AddZbSecrets(config, "Secrets", contentRoot);
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddZbSecrets(config, "Secrets", contentRoot);
|
||||
services.AddZbSecrets(config, "Secrets");
|
||||
}
|
||||
|
||||
using ServiceProvider provider = services.BuildServiceProvider();
|
||||
Exception? thrown = await Record.ExceptionAsync(
|
||||
() => provider.GetRequiredService<SqliteSecretsStoreMigrator>().MigrateAsync(default));
|
||||
|
||||
Assert.False(File.Exists(dbPath), "a rejected path must not be left holding a store file");
|
||||
Assert.IsType<OptionsValidationException>(thrown);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Microsoft.Data.Sqlite.SqliteConnection.ClearAllPools();
|
||||
Directory.Delete(contentRoot, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Without_a_content_root_the_pre_host_container_still_cannot_be_told_it_is_fine()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user