Skip to content

Commit

Permalink
[~] AZ creation test bugfix CactuseSecurity#2597
Browse files Browse the repository at this point in the history
  • Loading branch information
SolidProgramming committed Dec 3, 2024
1 parent 3fc4f4a commit 69b4d25
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
19 changes: 11 additions & 8 deletions roles/lib/files/FWO.Services/ModellingVarianceAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ private async Task AnalyseAppZone(Management mgt)

if (existingAppZone is not null)
{
WfReqTask? taskEntryNewAppZone = TaskList.FirstOrDefault(x => x.Title == userConfig.GetText("new_app_zone") + existingAppZone.IdString && x.OnManagement?.Id == mgt.Id);
WfReqTask? taskEntryUpdateAppZone = TaskList.FirstOrDefault(x => x.Title == userConfig.GetText("update_app_zone") + existingAppZone.IdString + userConfig.GetText("add_members") && x.OnManagement?.Id == mgt.Id);
WfReqTask? taskEntryDeleteAppZone = DeleteTasksList.FirstOrDefault(x => x.Title == userConfig.GetText("update_app_zone") + existingAppZone.IdString + userConfig.GetText("remove_members") && x.OnManagement?.Id == mgt.Id);
WfReqTask? taskEntryNewAppZone = TaskList.FirstOrDefault(x => x.Title == userConfig.GetText("new_app_zone") + existingAppZone.Name && x.OnManagement?.Id == mgt.Id);
WfReqTask? taskEntryUpdateAppZone = TaskList.FirstOrDefault(x => x.Title == userConfig.GetText("update_app_zone") + existingAppZone.Name + userConfig.GetText("add_members") && x.OnManagement?.Id == mgt.Id);
WfReqTask? taskEntryDeleteAppZone = DeleteTasksList.FirstOrDefault(x => x.Title == userConfig.GetText("update_app_zone") + existingAppZone.Name + userConfig.GetText("remove_members") && x.OnManagement?.Id == mgt.Id);

if (!ResolveExistingApp(existingAppZone, mgt) && taskEntryNewAppZone is null)
{
Expand Down Expand Up @@ -275,7 +275,7 @@ private bool ResolveExistingApp(ModellingNwGroup app, Management mgt)
string sanitizedARName = Sanitizer.SanitizeJsonFieldMand(app.IdString, ref shortened);
if (allExistingAppRoles.ContainsKey(mgt.Id))
{
existingApp = allExistingAppRoles[mgt.Id].FirstOrDefault(a => a.Name == app.IdString || a.Name == sanitizedARName);
existingApp = allExistingAppRoles[mgt.Id].FirstOrDefault(a => a.Name == app.IdString || a.Name == sanitizedARName || a.Name == app.Name);
}
if (existingApp != null)
{
Expand Down Expand Up @@ -405,27 +405,30 @@ private void RequestUpdateApp(ModellingNwGroup app, Management mgt)
{
string title = "";
string additionalInfoKeys = "";
string groupName = "";

if (app.GetType() == typeof(ModellingAppRole))
{
title = userConfig.GetText("update_app_role");
additionalInfoKeys = AdditionalInfoKeys.AppRoleId;
groupName = app.IdString;
}
else if (app.GetType() == typeof(ModellingAppZone))
{
title = userConfig.GetText("update_app_zone");
additionalInfoKeys = AdditionalInfoKeys.AppZoneId;
groupName = app.Name;
}

FillGroupMembers(app.IdString, mgt);
Dictionary<string, string>? addInfo = new() { { AdditionalInfoKeys.GrpName, app.IdString }, { additionalInfoKeys, app.Id.ToString() } };
FillGroupMembers(groupName, mgt);
Dictionary<string, string>? addInfo = new() { { AdditionalInfoKeys.GrpName, groupName }, { additionalInfoKeys, app.Id.ToString() } };
if (newGroupMembers.Count > 0)
{
newGroupMembers.AddRange(unchangedGroupMembers);
newGroupMembers.AddRange(unchangedGroupMembersDuringCreate); // will be deleted later
TaskList.Add(new()
{
Title = title + app.IdString + userConfig.GetText("add_members"),
Title = title + groupName + userConfig.GetText("add_members"),
TaskType = WfTaskType.group_modify.ToString(),
RequestAction = RequestAction.modify.ToString(),
ManagementId = mgt.Id,
Expand All @@ -440,7 +443,7 @@ private void RequestUpdateApp(ModellingNwGroup app, Management mgt)
deletedGroupMembers.AddRange(newCreatedGroupMembers);
DeleteTasksList.Add(new()
{
Title = title + app.IdString + userConfig.GetText("remove_members"),
Title = title + groupName + userConfig.GetText("remove_members"),
TaskType = WfTaskType.group_modify.ToString(),
RequestAction = RequestAction.modify.ToString(),
ManagementId = mgt.Id,
Expand Down
20 changes: 10 additions & 10 deletions roles/test/files/FWO.Test/ModellingVarianceAnalysisTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,19 @@ public async Task TestAnalyseModelledConnections()
ClassicAssert.AreEqual("source", TaskList[1].Elements[0].Field);
ClassicAssert.AreEqual("addAfterCreation", TaskList[1].Elements[0].RequestAction);

ClassicAssert.AreEqual(WfTaskType.group_create.ToString(), TaskList[2].TaskType);
ClassicAssert.AreEqual(WfTaskType.group_modify.ToString(), TaskList[2].TaskType);
ClassicAssert.AreEqual("{\"GrpName\":\"AZ4711\",\"AppZoneId\":\"3\"}", TaskList[2].AdditionalInfo);
ClassicAssert.AreEqual("create", TaskList[2].RequestAction);
ClassicAssert.AreEqual("modify", TaskList[2].RequestAction);
ClassicAssert.AreEqual(3, TaskList[2].TaskNumber);
ClassicAssert.AreEqual("New AppZone: AZ4711", TaskList[2].Title);
ClassicAssert.AreEqual("Update AppZone: AZ4711: Add Members", TaskList[2].Title);
ClassicAssert.AreEqual(2, TaskList[2].Elements.Count);
ClassicAssert.AreEqual("AppServer1", TaskList[2].Elements[0].Name);
ClassicAssert.AreEqual("AppServer2", TaskList[2].Elements[1].Name);
ClassicAssert.AreEqual("AppServer2", TaskList[2].Elements[0].Name);
ClassicAssert.AreEqual("AppServer1", TaskList[2].Elements[1].Name);
ClassicAssert.AreEqual("AZ4711", TaskList[2].Elements[0].GroupName);
ClassicAssert.AreEqual("1.1.1.1/32", TaskList[2].Elements[0].IpString);
ClassicAssert.AreEqual("1.1.1.1/32", TaskList[2].Elements[0].IpEnd);
ClassicAssert.AreEqual("2.2.2.2/32", TaskList[2].Elements[1].IpString);
ClassicAssert.AreEqual("2.2.2.2/32", TaskList[2].Elements[1].IpEnd);
ClassicAssert.AreEqual("1.1.1.1/32", TaskList[2].Elements[1].IpString);
ClassicAssert.AreEqual("1.1.1.1/32", TaskList[2].Elements[1].IpEnd);
ClassicAssert.AreEqual("2.2.2.2/32", TaskList[2].Elements[0].IpString);
ClassicAssert.AreEqual("2.2.2.2/32", TaskList[2].Elements[0].IpEnd);
ClassicAssert.AreEqual("source", TaskList[2].Elements[0].Field);
ClassicAssert.AreEqual("addAfterCreation", TaskList[2].Elements[0].RequestAction);

Expand Down Expand Up @@ -191,7 +191,7 @@ public async Task TestAnalyseModelledConnections()
ClassicAssert.AreEqual(WfTaskType.group_modify.ToString(), TaskList[0].TaskType);
ClassicAssert.AreEqual(WfTaskType.group_create.ToString(), TaskList[1].TaskType);
ClassicAssert.AreEqual(WfTaskType.group_create.ToString(), TaskList[2].TaskType);
ClassicAssert.AreEqual(WfTaskType.group_create.ToString(), TaskList[3].TaskType);
ClassicAssert.AreEqual(WfTaskType.group_modify.ToString(), TaskList[3].TaskType);
ClassicAssert.AreEqual(WfTaskType.access.ToString(), TaskList[4].TaskType);
ClassicAssert.AreEqual(WfTaskType.group_modify.ToString(), TaskList[5].TaskType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class ModellingVarianceAnalysisTestApiConn : SimulatedApiConnection
static readonly NetworkObject Nwgroup1 = new() { Id = 1, Name = "AR504711-001", Type = new() { Name = ObjectType.Group }, ObjectGroupFlats = [new() { Object = NwObj1 }, new() { Object = NwObj3 }] };
static readonly ModellingAppServer AppServer1 = new() { Id = 13, Name = "AppServer1", Ip = "1.1.1.1/32", IpEnd = "1.1.1.1/32" };
static readonly ModellingAppServer AppServer2 = new() { Id = 14, Name = "AppServer2", Ip = "2.2.2.2/32", IpEnd = "2.2.2.2/32" };
static readonly NetworkObject AZProd = new() { Id = 2, Name = "AZ4711", Type = new() { Name = ObjectType.Group }, ObjectGroupFlats = [new() { Object = NwObj1 }, new() { Object = NwObj2 }] };
static readonly NetworkObject AZProd = new() { Id = 2, Name = "AZ4711", Type = new() { Name = ObjectType.Group }, ObjectGroupFlats = [new() { Object = NwObj1 }] };
static readonly ModellingAppZone AZExist = new() { Id = 3, Name = "AZ4711", AppServers = new() { new() { Content = AppServer1 }, new() { Content = AppServer2 } } };

public override async Task<QueryResponseType> SendQueryAsync<QueryResponseType>(string query, object? variables = null, string? operationName = null)
Expand Down

0 comments on commit 69b4d25

Please sign in to comment.