fix(security): /raw credential banner keeps running findings when the ConfigDb scan fails (#847)

This commit is contained in:
Joseph Doherty
2026-11-11 03:42:01 -05:00
parent 038aa007ac
commit c6c243cc06
3 changed files with 151 additions and 35 deletions
@@ -184,4 +184,48 @@ public sealed class CredentialReferencePreflightTests
lock (Entries) Entries.Add((logLevel, formatter(state, exception)));
}
}
private static DriverHealthChanged LegacyRunning(string node) =>
new("c", "gx-old", "Healthy", null, null, 0, DateTime.UtcNow,
Diagnostics: new Dictionary<string, string>
{
[LegacyCredentialReferenceTracker.DiagnosticsKeyPrefix + "Gateway.ApiKeySecretRef"] = "deprecated",
},
ReportingNodeId: node);
[Fact]
public void Banner_keeps_running_findings_when_the_config_db_scan_failed_847()
{
// lmxopcua#847: a failed ConfigDb scan must not hide what the live health feed says is still running.
var failed = new CredentialReferencePreflightState.Snapshot([], DateTime.UtcNow, "could not read the config DB.");
var model = CredentialReferenceBannerModel.Compose(failed, [LegacyRunning("central-1")]);
model.Visible.ShouldBeTrue();
model.ScanError.ShouldNotBeNull();
model.ScanFindings.ShouldBeEmpty();
model.RunningFindings.ShouldHaveSingleItem().DriverInstanceId.ShouldBe("gx-old");
}
[Fact]
public void Banner_shows_a_scan_error_alone_and_hides_when_nothing_to_say_847()
{
CredentialReferenceBannerModel.Compose(new([], DateTime.UtcNow, "db down"), []).ShouldSatisfyAllConditions(
m => m.Visible.ShouldBeTrue(),
m => m.RunningFindings.ShouldBeEmpty());
CredentialReferenceBannerModel.Compose(new([], DateTime.UtcNow, null), []).Visible.ShouldBeFalse();
}
[Fact]
public void Banner_separates_scan_from_running_findings_and_dedups_the_redundant_pair_847()
{
var draft = new CredentialReferenceFinding(CredentialFindingSource.Draft, "Galaxy", "gx", "gx", null, "p");
var model = CredentialReferenceBannerModel.Compose(
new([draft], DateTime.UtcNow, null), [LegacyRunning("central-1"), LegacyRunning("central-2")]);
model.ScanFindings.ShouldHaveSingleItem().ShouldBe(draft);
// Both nodes run the driver and report the same thing — one line, not two.
model.RunningFindings.ShouldHaveSingleItem();
model.ScanError.ShouldBeNull();
}
}