mirror of
https://github.com/SELinuxProject/setools
synced 2025-04-01 22:58:12 +00:00
parent
904a83b27e
commit
bfa50a42f8
@ -16,10 +16,7 @@
|
|||||||
# License along with SETools. If not, see
|
# License along with SETools. If not, see
|
||||||
# <http://www.gnu.org/licenses/>.
|
# <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
try:
|
import ipaddress
|
||||||
import ipaddress
|
|
||||||
except ImportError: # pragma: no cover
|
|
||||||
pass
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from socket import AF_INET, AF_INET6
|
from socket import AF_INET, AF_INET6
|
||||||
@ -87,10 +84,7 @@ class NodeconQuery(MatchContext, PolicyQuery):
|
|||||||
@network.setter
|
@network.setter
|
||||||
def network(self, value):
|
def network(self, value):
|
||||||
if value:
|
if value:
|
||||||
try:
|
|
||||||
self._network = ipaddress.ip_network(value)
|
self._network = ipaddress.ip_network(value)
|
||||||
except NameError: # pragma: no cover
|
|
||||||
raise RuntimeError("Nodecon IP address/network functions require Python 3.3+.")
|
|
||||||
else:
|
else:
|
||||||
self._network = None
|
self._network = None
|
||||||
|
|
||||||
@ -108,14 +102,9 @@ class NodeconQuery(MatchContext, PolicyQuery):
|
|||||||
for nodecon in self.policy.nodecons():
|
for nodecon in self.policy.nodecons():
|
||||||
|
|
||||||
if self.network:
|
if self.network:
|
||||||
try:
|
|
||||||
netmask = ipaddress.ip_address(nodecon.netmask)
|
netmask = ipaddress.ip_address(nodecon.netmask)
|
||||||
except NameError: # pragma: no cover
|
|
||||||
# Should never actually hit this since the self.network
|
|
||||||
# setter raises the same exception.
|
|
||||||
raise RuntimeError("Nodecon IP address/network functions require Python 3.3+.")
|
|
||||||
|
|
||||||
# Python 3.3's IPv6Network constructor does not support
|
# Python 3.4's IPv6Network constructor does not support
|
||||||
# expanded netmasks, only CIDR numbers. Convert netmask
|
# expanded netmasks, only CIDR numbers. Convert netmask
|
||||||
# into CIDR.
|
# into CIDR.
|
||||||
# This is Brian Kernighan's method for counting set bits.
|
# This is Brian Kernighan's method for counting set bits.
|
||||||
|
@ -126,14 +126,6 @@ class NodeconQueryTab(AnalysisTab):
|
|||||||
self.criteria_frame.setHidden(not self.criteria_expander.isChecked())
|
self.criteria_frame.setHidden(not self.criteria_expander.isChecked())
|
||||||
self.notes.setHidden(not self.notes_expander.isChecked())
|
self.notes.setHidden(not self.notes_expander.isChecked())
|
||||||
|
|
||||||
# Network criteria is available only on Python 3.3+
|
|
||||||
if sys.version_info < (3, 3):
|
|
||||||
self.network_criteria.setEnabled(False)
|
|
||||||
self.network_criteria.setToolTip("This feature requires Python 3.3 or newer.")
|
|
||||||
self.network.setToolTip("This feature requires Python 3.3 or newer.")
|
|
||||||
self.network_exact.setToolTip("This feature requires Python 3.3 or newer.")
|
|
||||||
self.network_overlap.setToolTip("This feature requires Python 3.3 or newer.")
|
|
||||||
|
|
||||||
# Range criteria is available only if policy is MLS
|
# Range criteria is available only if policy is MLS
|
||||||
if not self.policy.mls:
|
if not self.policy.mls:
|
||||||
self.range_criteria.setEnabled(False)
|
self.range_criteria.setEnabled(False)
|
||||||
|
@ -213,7 +213,6 @@ class NodeconQueryTest(unittest.TestCase):
|
|||||||
nodecons = sorted(n.address for n in q.results())
|
nodecons = sorted(n.address for n in q.results())
|
||||||
self.assertListEqual(["10.1.55.1"], nodecons)
|
self.assertListEqual(["10.1.55.1"], nodecons)
|
||||||
|
|
||||||
@unittest.skipIf(sys.version_info < (3, 3), "Requires Python 3.3+.")
|
|
||||||
def test_100_v4network_equal(self):
|
def test_100_v4network_equal(self):
|
||||||
"""Nodecon query with IPv4 equal network"""
|
"""Nodecon query with IPv4 equal network"""
|
||||||
q = NodeconQuery(self.p, network="10.1.100.0/24", network_overlap=False)
|
q = NodeconQuery(self.p, network="10.1.100.0/24", network_overlap=False)
|
||||||
@ -221,7 +220,6 @@ class NodeconQueryTest(unittest.TestCase):
|
|||||||
nodecons = sorted(n.address for n in q.results())
|
nodecons = sorted(n.address for n in q.results())
|
||||||
self.assertListEqual(["10.1.100.0"], nodecons)
|
self.assertListEqual(["10.1.100.0"], nodecons)
|
||||||
|
|
||||||
@unittest.skipIf(sys.version_info < (3, 3), "Requires Python 3.3+.")
|
|
||||||
def test_101_v4network_overlap(self):
|
def test_101_v4network_overlap(self):
|
||||||
"""Nodecon query with IPv4 network overlap"""
|
"""Nodecon query with IPv4 network overlap"""
|
||||||
q = NodeconQuery(self.p, network="10.1.101.128/25", network_overlap=True)
|
q = NodeconQuery(self.p, network="10.1.101.128/25", network_overlap=True)
|
||||||
@ -229,7 +227,6 @@ class NodeconQueryTest(unittest.TestCase):
|
|||||||
nodecons = sorted(n.address for n in q.results())
|
nodecons = sorted(n.address for n in q.results())
|
||||||
self.assertListEqual(["10.1.101.0"], nodecons)
|
self.assertListEqual(["10.1.101.0"], nodecons)
|
||||||
|
|
||||||
@unittest.skipIf(sys.version_info < (3, 3), "Requires Python 3.3+.")
|
|
||||||
def test_110_v6network_equal(self):
|
def test_110_v6network_equal(self):
|
||||||
"""Nodecon query with IPv6 equal network"""
|
"""Nodecon query with IPv6 equal network"""
|
||||||
q = NodeconQuery(self.p, network="1100::/16", network_overlap=False)
|
q = NodeconQuery(self.p, network="1100::/16", network_overlap=False)
|
||||||
@ -237,7 +234,6 @@ class NodeconQueryTest(unittest.TestCase):
|
|||||||
nodecons = sorted(n.address for n in q.results())
|
nodecons = sorted(n.address for n in q.results())
|
||||||
self.assertListEqual(["1100::"], nodecons)
|
self.assertListEqual(["1100::"], nodecons)
|
||||||
|
|
||||||
@unittest.skipIf(sys.version_info < (3, 3), "Requires Python 3.3+.")
|
|
||||||
def test_111_v6network_overlap(self):
|
def test_111_v6network_overlap(self):
|
||||||
"""Nodecon query with IPv6 network overlap"""
|
"""Nodecon query with IPv6 network overlap"""
|
||||||
q = NodeconQuery(self.p, network="1110:8000::/17", network_overlap=True)
|
q = NodeconQuery(self.p, network="1110:8000::/17", network_overlap=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user