using ZB.MOM.WW.Auth.Abstractions.ApiKeys; namespace ZB.MOM.WW.Auth.ApiKeys.SqlServer.Tests; /// /// Auth-010 (scadaproj#46), end to end through the real SQL Server store with no server: the shared /// store being unreachable (failover, lost route) must come back from VerifyAsync as a /// structured , not as a SqlException that /// surfaces as an unaudited 500. Offline: it dials a refused local port. /// public sealed class SqlServerUnreachableVerifierTests { private sealed class Pepper : IApiKeyPepperProvider { public string? GetPepper() => "0123456789abcdef"; } [Fact] public async Task VerifyAsync_AgainstAnUnreachableSqlServer_ReturnsStoreUnavailable() { var factory = new AuthSqlServerConnectionFactory(new SqlServerApiKeyOptions { // Port 1 on loopback refuses immediately; no retries, so the test stays fast. ConnectionString = "Server=tcp:127.0.0.1,1;Connect Timeout=3;ConnectRetryCount=0;TrustServerCertificate=true", }); var verifier = new ApiKeyVerifier( new ApiKeyOptions { TokenPrefix = "sbk" }, new SqlServerApiKeyStore(factory), new Pepper()); var result = await verifier.VerifyAsync("sbk_line1_supersecretvalue", CancellationToken.None); Assert.False(result.Succeeded); Assert.Equal(ApiKeyFailure.StoreUnavailable, result.Failure); } }