diff --git a/nca/CoreDS/CanonicalHyperCubeSet.py b/nca/CoreDS/CanonicalHyperCubeSet.py index ad556817..227c1f22 100644 --- a/nca/CoreDS/CanonicalHyperCubeSet.py +++ b/nca/CoreDS/CanonicalHyperCubeSet.py @@ -544,6 +544,9 @@ def _contained_in_aux(self, other, all_active_dims): # noqa: C901 if not self._is_last_dimension() and not other._is_last_dimension() and \ not (self.layers[layer])._contained_in_aux(other_sub_elem, all_active_dims[1:]): return False + if self._is_last_dimension() and not other._is_last_dimension() and \ + not other_sub_elem._is_sub_elem_entire_sub_space(): + return False remaining = current_layer_0 - common_part if remaining: # continue exploring other's cubes for containment of the remaining part from self diff --git a/tests/classes_unit_tests/testCanonicalHyperCubeSetNew.py b/tests/classes_unit_tests/testCanonicalHyperCubeSetNew.py index c9f6ce38..2927d6cf 100644 --- a/tests/classes_unit_tests/testCanonicalHyperCubeSetNew.py +++ b/tests/classes_unit_tests/testCanonicalHyperCubeSetNew.py @@ -4,6 +4,8 @@ from nca.CoreDS.MinDFA import MinDFA from nca.CoreDS.CanonicalHyperCubeSet import CanonicalHyperCubeSet from nca.CoreDS.DimensionsManager import DimensionsManager +from nca.CoreDS.Peer import BasePeerSet, IpBlock +from nca.CoreDS.ProtocolSet import ProtocolSet dimensions = ["src_ports", "ports", "methods", "paths"] dimensions2 = ["ports", "src_ports", "methods", "paths"] @@ -971,6 +973,33 @@ def test_contained_in_new(self): d = CanonicalHyperCubeSet.create_from_cube(dimensions, [get_str_dfa("x|y|z")], ["paths"]) self.assertTrue(c.contained_in(d)) + def test_bug_in_contained(self): + BasePeerSet.reset() + BasePeerSet().add_peer("A") + BasePeerSet().add_peer("B") + BasePeerSet().add_peer("C") + ipv4_block = IpBlock.get_all_ips_block(True) + my_dimensions1 = ["src_peers", "dst_peers"] + my_dimensions2 = ["src_peers", "dst_peers", "protocols"] + conns1 = CanonicalHyperCubeSet.create_from_cube(my_dimensions1, + [BasePeerSet().get_peer_interval_of({"B"}), + BasePeerSet().get_peer_interval_of({"A", "B", "C", ipv4_block})], + my_dimensions1) + conns1.add_cube([BasePeerSet().get_peer_interval_of({"C"}), + BasePeerSet().get_peer_interval_of({"A", ipv4_block})], my_dimensions1) + + conns2 = CanonicalHyperCubeSet.create_from_cube(my_dimensions2, + [BasePeerSet().get_peer_interval_of({"B"}), + BasePeerSet().get_peer_interval_of({"B", "C"}), + ProtocolSet.get_non_tcp_protocols()], + my_dimensions2) + conns2.add_cube([BasePeerSet().get_peer_interval_of({"B"}), + BasePeerSet().get_peer_interval_of({"A", ipv4_block})], my_dimensions1) + conns2.add_cube([BasePeerSet().get_peer_interval_of({"C"}), + BasePeerSet().get_peer_interval_of({"A", ipv4_block})], my_dimensions1) + self.assertFalse(conns1.contained_in(conns2)) + self.assertTrue(conns2.contained_in(conns1)) + def test_subtract_basic(self): x = CanonicalHyperCubeSet(dimensions) y = CanonicalHyperCubeSet(dimensions)