Skip to content

Commit f99c38b

Browse files
committed
comparer fix + metadata
1 parent 9ab74ed commit f99c38b

File tree

3 files changed

+111
-10
lines changed

3 files changed

+111
-10
lines changed

roles/api/files/replace_metadata.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10480,6 +10480,17 @@
1048010480
}
1048110481
],
1048210482
"select_permissions": [
10483+
{
10484+
"role": "approver",
10485+
"permission": {
10486+
"columns": [
10487+
"ticket_id",
10488+
"owner_id"
10489+
],
10490+
"filter": {}
10491+
},
10492+
"comment": ""
10493+
},
1048310494
{
1048410495
"role": "auditor",
1048510496
"permission": {
@@ -10491,6 +10502,28 @@
1049110502
},
1049210503
"comment": ""
1049310504
},
10505+
{
10506+
"role": "fw-admin",
10507+
"permission": {
10508+
"columns": [
10509+
"ticket_id",
10510+
"owner_id"
10511+
],
10512+
"filter": {}
10513+
},
10514+
"comment": ""
10515+
},
10516+
{
10517+
"role": "implementer",
10518+
"permission": {
10519+
"columns": [
10520+
"ticket_id",
10521+
"owner_id"
10522+
],
10523+
"filter": {}
10524+
},
10525+
"comment": ""
10526+
},
1049410527
{
1049510528
"role": "modeller",
1049610529
"permission": {
@@ -10501,6 +10534,39 @@
1050110534
"filter": {}
1050210535
},
1050310536
"comment": ""
10537+
},
10538+
{
10539+
"role": "planner",
10540+
"permission": {
10541+
"columns": [
10542+
"ticket_id",
10543+
"owner_id"
10544+
],
10545+
"filter": {}
10546+
},
10547+
"comment": ""
10548+
},
10549+
{
10550+
"role": "requester",
10551+
"permission": {
10552+
"columns": [
10553+
"ticket_id",
10554+
"owner_id"
10555+
],
10556+
"filter": {}
10557+
},
10558+
"comment": ""
10559+
},
10560+
{
10561+
"role": "reviewer",
10562+
"permission": {
10563+
"columns": [
10564+
"ticket_id",
10565+
"owner_id"
10566+
],
10567+
"filter": {}
10568+
},
10569+
"comment": ""
1050410570
}
1050510571
]
1050610572
},

roles/lib/files/FWO.Services/NetworkServiceComparer.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,39 @@ public bool Equals(NetworkService? service1, NetworkService? service2)
1818
return false;
1919
}
2020

21+
if (CompareProtTypes(service1, service2))
22+
{
23+
return true;
24+
}
25+
2126
int destPortEnd1 = service1.DestinationPortEnd ?? service1.DestinationPort ?? 0;
2227
int destPortEnd2 = service2.DestinationPortEnd ?? service2.DestinationPort ?? 0;
2328

24-
return (!option.SvcRegardPortAndProt || service1.ProtoId == service2.ProtoId
25-
&& service1.DestinationPort == service2.DestinationPort
26-
&& destPortEnd1 == destPortEnd2)
27-
&& (!option.SvcRegardName || service1.Name == service2.Name || CompareProtTypes(service1, service2));
29+
return (!option.SvcRegardPortAndProt || (service1.ProtoId == service2.ProtoId &&
30+
service1.DestinationPort == service2.DestinationPort && destPortEnd1 == destPortEnd2))
31+
&& (!option.SvcRegardName || service1.Name == service2.Name);
2832
}
2933

3034
public int GetHashCode(NetworkService service)
3135
{
36+
if (IsProtType(service.ProtoId))
37+
{
38+
return (option.SvcRegardPortAndProt ? HashCode.Combine(service.ProtoId) : 0)
39+
^ (option.SvcRegardName ? HashCode.Combine(service.Name) : 0);
40+
}
3241
int destPortEnd = service.DestinationPortEnd ?? service.DestinationPort ?? 0;
33-
string relevantName = IsProtType(service.ProtoId) ? service.Protocol.Name : service.Name;
3442
return (option.SvcRegardPortAndProt ? HashCode.Combine(service.ProtoId, service.DestinationPort, destPortEnd) : 0)
35-
^ (option.SvcRegardName ? HashCode.Combine(relevantName) : 0);
43+
^ (option.SvcRegardName ? HashCode.Combine(service.Name) : 0);
3644
}
3745

3846
private static bool IsProtType(int? protoId)
3947
{
40-
return protoId != 1 && protoId != 6 && protoId != 17;
48+
return protoId != null && protoId != 1 && protoId != 6 && protoId != 17;
4149
}
4250

4351
private static bool CompareProtTypes(NetworkService service1, NetworkService service2)
4452
{
45-
return IsProtType(service1.Protocol.Id) && IsProtType(service2.Protocol.Id) && service1.Protocol.Name == service2.Protocol.Name;
53+
return IsProtType(service1.ProtoId) && IsProtType(service2.ProtoId) && service1.ProtoId == service2.ProtoId;
4654
}
4755
}
4856

roles/tests-unit/files/FWO.Test/ComparerTest.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ internal class ComparerTest
4646
static readonly NetworkService Svc4 = new() { Name = "Svc4", DestinationPort = 1235, DestinationPortEnd = 1235, ProtoId = 6, Protocol = new() { Id = 6, Name = "TCP"} };
4747
static readonly NetworkService Svc5 = new() { Name = "Svc5", DestinationPort = 1234, DestinationPortEnd = 1235, ProtoId = 12, Protocol = new() { Id = 12, Name = "PUP"} };
4848
static readonly NetworkService Svc6 = new() { Name = "Svc1", DestinationPort = 1, DestinationPortEnd = 1, ProtoId = 1, Protocol = new() { Id = 1, Name = "ICMP"} };
49-
static readonly NetworkService Svc7 = new() { Name = "Svc7", DestinationPort = 1235, DestinationPortEnd = null, ProtoId = 6, Protocol = new() { Id = 6, Name = "TCP"} };
49+
static readonly NetworkService Svc7 = new() { Name = "Svc7", DestinationPort = 1235, DestinationPortEnd = null, ProtoId = 6, Protocol = new() { Id = 6, Name = "TCP"} };
50+
static readonly NetworkService Svc8 = new() { Name = "", DestinationPort = null, DestinationPortEnd = null, ProtoId = 50 };
51+
static readonly NetworkService Svc9 = new() { Name = "", DestinationPort = null, DestinationPortEnd = null, ProtoId = 50, Protocol = new() { Id = 50, Name = "ESP"} };
52+
static readonly NetworkService Svc10 = new() { Name = "", DestinationPort = null, DestinationPortEnd = null };
5053

51-
static readonly NetworkService SvcGrp1 = new() { Name = "SvcGrp1", ServiceGroupFlats = [ new GroupFlat<NetworkService>(){ Object = Svc1 }]};
54+
static readonly NetworkService SvcGrp1 = new() { Name = "SvcGrp1", ServiceGroupFlats = [new GroupFlat<NetworkService>() { Object = Svc1 }] };
5255
static readonly NetworkService SvcGrp2 = new() { Name = "SvcGrp2", ServiceGroupFlats = [ new GroupFlat<NetworkService>(){ Object = Svc1 }]};
5356
static readonly NetworkService SvcGrp3 = new() { Name = "SvcGrp3", ServiceGroupFlats = [ new GroupFlat<NetworkService>(){ Object = Svc2 }]};
5457
static readonly NetworkService SvcGrp4 = new() { Name = "SvcGrp4", ServiceGroupFlats = [ new GroupFlat<NetworkService>(){ Object = Svc1 }, new GroupFlat<NetworkService>(){ Object = Svc2 }]};
@@ -338,13 +341,21 @@ public void TestNetworkServiceComparer()
338341
ClassicAssert.AreEqual(false, networkServiceComparer.Equals(Svc1,Svc5));
339342
ClassicAssert.AreEqual(false, networkServiceComparer.Equals(Svc1,Svc6));
340343
ClassicAssert.AreEqual(true, networkServiceComparer.Equals(Svc4,Svc7));
344+
ClassicAssert.AreEqual(false, networkServiceComparer.Equals(Svc1,Svc9));
345+
ClassicAssert.AreEqual(false, networkServiceComparer.Equals(Svc5,Svc9));
346+
ClassicAssert.AreEqual(true, networkServiceComparer.Equals(Svc8,Svc9));
347+
ClassicAssert.AreEqual(false, networkServiceComparer.Equals(Svc8,Svc10));
341348
ClassicAssert.AreEqual(true, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc1));
342349
ClassicAssert.AreEqual(true, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc2));
343350
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc3));
344351
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc4));
345352
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc5));
346353
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc6));
347354
ClassicAssert.AreEqual(true, networkServiceComparer.GetHashCode(Svc4) == networkServiceComparer.GetHashCode(Svc7));
355+
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc9));
356+
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc5) == networkServiceComparer.GetHashCode(Svc9));
357+
ClassicAssert.AreEqual(true, networkServiceComparer.GetHashCode(Svc8) == networkServiceComparer.GetHashCode(Svc9));
358+
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc8) == networkServiceComparer.GetHashCode(Svc10));
348359

349360
ruleRecognitionOption.SvcRegardName = true;
350361
networkServiceComparer = new(ruleRecognitionOption);
@@ -355,12 +366,20 @@ public void TestNetworkServiceComparer()
355366
ClassicAssert.AreEqual(false, networkServiceComparer.Equals(Svc1,Svc4));
356367
ClassicAssert.AreEqual(false, networkServiceComparer.Equals(Svc1,Svc5));
357368
ClassicAssert.AreEqual(false, networkServiceComparer.Equals(Svc1,Svc6));
369+
ClassicAssert.AreEqual(false, networkServiceComparer.Equals(Svc1,Svc9));
370+
ClassicAssert.AreEqual(false, networkServiceComparer.Equals(Svc5,Svc9));
371+
ClassicAssert.AreEqual(true, networkServiceComparer.Equals(Svc8,Svc9));
372+
ClassicAssert.AreEqual(false, networkServiceComparer.Equals(Svc8,Svc10));
358373
ClassicAssert.AreEqual(true, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc1));
359374
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc2));
360375
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc3));
361376
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc4));
362377
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc5));
363378
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc6));
379+
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc9));
380+
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc5) == networkServiceComparer.GetHashCode(Svc9));
381+
ClassicAssert.AreEqual(true, networkServiceComparer.GetHashCode(Svc8) == networkServiceComparer.GetHashCode(Svc9));
382+
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc8) == networkServiceComparer.GetHashCode(Svc10));
364383

365384
ruleRecognitionOption.SvcRegardPortAndProt = false;
366385
networkServiceComparer = new(ruleRecognitionOption);
@@ -371,12 +390,20 @@ public void TestNetworkServiceComparer()
371390
ClassicAssert.AreEqual(false, networkServiceComparer.Equals(Svc1,Svc4));
372391
ClassicAssert.AreEqual(false, networkServiceComparer.Equals(Svc1,Svc5));
373392
ClassicAssert.AreEqual(true, networkServiceComparer.Equals(Svc1,Svc6));
393+
ClassicAssert.AreEqual(false, networkServiceComparer.Equals(Svc1,Svc9));
394+
ClassicAssert.AreEqual(false, networkServiceComparer.Equals(Svc5,Svc9));
395+
ClassicAssert.AreEqual(true, networkServiceComparer.Equals(Svc8,Svc9));
396+
ClassicAssert.AreEqual(true, networkServiceComparer.Equals(Svc8,Svc10));
374397
ClassicAssert.AreEqual(true, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc1));
375398
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc2));
376399
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc3));
377400
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc4));
378401
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc5));
379402
ClassicAssert.AreEqual(true, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc6));
403+
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc1) == networkServiceComparer.GetHashCode(Svc9));
404+
ClassicAssert.AreEqual(false, networkServiceComparer.GetHashCode(Svc5) == networkServiceComparer.GetHashCode(Svc9));
405+
ClassicAssert.AreEqual(true, networkServiceComparer.GetHashCode(Svc8) == networkServiceComparer.GetHashCode(Svc9));
406+
ClassicAssert.AreEqual(true, networkServiceComparer.GetHashCode(Svc8) == networkServiceComparer.GetHashCode(Svc10));
380407
}
381408

382409
[Test]

0 commit comments

Comments
 (0)