fix(transport-ui): count site data-connection config in export secret banner (M8, C2-SECRET-1)

This commit is contained in:
Joseph Doherty
2026-06-18 06:37:38 -04:00
parent 50d77b07cf
commit 542a3e92eb
2 changed files with 81 additions and 0 deletions
@@ -318,6 +318,11 @@ public partial class TransportExport : ComponentBase
{
if (!string.IsNullOrEmpty(db.ConnectionString)) count++;
}
foreach (var dc in resolved.DataConnections)
{
if (!string.IsNullOrEmpty(dc.PrimaryConfiguration)) count++;
if (!string.IsNullOrEmpty(dc.BackupConfiguration)) count++;
}
return count;
}
@@ -438,4 +438,80 @@ public class TransportExportPageTests : BunitContext
var filename = TransportExportPage.BuildFilename("dev/cluster a", fixedTime);
Assert.Equal("scadabundle-dev-cluster-a-2026-05-24-134522.scadabundle", filename);
}
// ─────────────────────────────────────────────────────────────────────
// Test 7 (M8 C2-SECRET-1): CountSecrets includes site data-connection
// PrimaryConfiguration and BackupConfiguration fields in the banner total.
// ─────────────────────────────────────────────────────────────────────
[Fact]
public void CountSecrets_includes_data_connection_primary_and_backup_configurations()
{
// One data connection with both fields populated — expect 2 secrets counted.
var dcBoth = new DataConnection { Id = 1, SiteId = 10, Name = "PlcA", Protocol = "OpcUa",
PrimaryConfiguration = "{\"endpoint\":\"opc.tcp://plc-a:4840\"}", BackupConfiguration = "{\"endpoint\":\"opc.tcp://plc-a-backup:4840\"}" };
var resolved = new ResolvedExport(
TemplateFolders: Array.Empty<TemplateFolder>(),
Templates: Array.Empty<Template>(),
SharedScripts: Array.Empty<SharedScript>(),
ExternalSystems: Array.Empty<ExternalSystemDefinition>(),
ExternalSystemMethods: Array.Empty<ExternalSystemMethod>(),
DatabaseConnections: Array.Empty<DatabaseConnectionDefinition>(),
NotificationLists: Array.Empty<NotificationList>(),
SmtpConfigs: Array.Empty<SmtpConfiguration>(),
ApiMethods: Array.Empty<ApiMethod>(),
ContentManifest: Array.Empty<ManifestContentEntry>())
{
DataConnections = new List<DataConnection> { dcBoth },
};
Assert.Equal(2, TransportExportPage.CountSecrets(resolved));
}
[Fact]
public void CountSecrets_counts_only_non_empty_data_connection_configurations()
{
// Primary only — backup is null.
var dcPrimaryOnly = new DataConnection { Id = 2, SiteId = 10, Name = "PlcB", Protocol = "OpcUa",
PrimaryConfiguration = "{\"endpoint\":\"opc.tcp://plc-b:4840\"}", BackupConfiguration = null };
// Neither field set — should not contribute.
var dcEmpty = new DataConnection { Id = 3, SiteId = 10, Name = "PlcC", Protocol = "OpcUa",
PrimaryConfiguration = null, BackupConfiguration = null };
var resolved = new ResolvedExport(
TemplateFolders: Array.Empty<TemplateFolder>(),
Templates: Array.Empty<Template>(),
SharedScripts: Array.Empty<SharedScript>(),
ExternalSystems: Array.Empty<ExternalSystemDefinition>(),
ExternalSystemMethods: Array.Empty<ExternalSystemMethod>(),
DatabaseConnections: Array.Empty<DatabaseConnectionDefinition>(),
NotificationLists: Array.Empty<NotificationList>(),
SmtpConfigs: Array.Empty<SmtpConfiguration>(),
ApiMethods: Array.Empty<ApiMethod>(),
ContentManifest: Array.Empty<ManifestContentEntry>())
{
DataConnections = new List<DataConnection> { dcPrimaryOnly, dcEmpty },
};
Assert.Equal(1, TransportExportPage.CountSecrets(resolved));
}
[Fact]
public void CountSecrets_returns_zero_when_no_data_connections()
{
var resolved = new ResolvedExport(
TemplateFolders: Array.Empty<TemplateFolder>(),
Templates: Array.Empty<Template>(),
SharedScripts: Array.Empty<SharedScript>(),
ExternalSystems: Array.Empty<ExternalSystemDefinition>(),
ExternalSystemMethods: Array.Empty<ExternalSystemMethod>(),
DatabaseConnections: Array.Empty<DatabaseConnectionDefinition>(),
NotificationLists: Array.Empty<NotificationList>(),
SmtpConfigs: Array.Empty<SmtpConfiguration>(),
ApiMethods: Array.Empty<ApiMethod>(),
ContentManifest: Array.Empty<ManifestContentEntry>());
Assert.Equal(0, TransportExportPage.CountSecrets(resolved));
}
}