mirror of
https://github.com/SELinuxProject/setools
synced 2025-03-31 07:46:24 +00:00
Change all unit tests for "unset" query to use full comparison.
Fully compare the lists rather than only counting objects. Also fix comparison problem in Nodecon and Genfscon. In libqpol, the all genfscons/nodecons iterators allocate new objects, so the pointer comparison in PolicySymbol fails.
This commit is contained in:
parent
9fec147c52
commit
8ba3cf16f5
@ -49,6 +49,17 @@ class Genfscon(FSContext):
|
||||
def __str__(self):
|
||||
return "genfscon {0.fs} {0.path} {0.context}".format(self)
|
||||
|
||||
def __eq__(self, other):
|
||||
# Libqpol allocates new C objects in the
|
||||
# genfscons iterator, so pointer comparison
|
||||
# in the PolicySymbol object doesn't work.
|
||||
try:
|
||||
return (self.fs == other.fs and
|
||||
self.path == other.path and
|
||||
self.context == other.context)
|
||||
except AttributeError:
|
||||
return (str(self) == str(other))
|
||||
|
||||
@property
|
||||
def filetype(self):
|
||||
"""The file type for this genfscon statement."""
|
||||
|
@ -69,6 +69,17 @@ class Nodecon(NetContext):
|
||||
def __str__(self):
|
||||
return "nodecon {0.address} {0.netmask} {0.context}".format(self)
|
||||
|
||||
def __eq__(self, other):
|
||||
# Libqpol allocates new C objects in the
|
||||
# nodecons iterator, so pointer comparison
|
||||
# in the PolicySymbol object doesn't work.
|
||||
try:
|
||||
return (self.address == other.address and
|
||||
self.netmask == other.netmask and
|
||||
self.context == other.context)
|
||||
except AttributeError:
|
||||
return (str(self) == str(other))
|
||||
|
||||
@property
|
||||
def ip_version(self):
|
||||
"""
|
||||
|
@ -29,14 +29,12 @@ class CommonQueryTest(unittest.TestCase):
|
||||
def test_000_unset(self):
|
||||
"""Common query with no criteria."""
|
||||
# query with no parameters gets all types.
|
||||
for numcommons, c in enumerate(self.p.commons(), start=1):
|
||||
pass
|
||||
commons = sorted(self.p.commons())
|
||||
|
||||
q = CommonQuery(self.p)
|
||||
for q_numcommons, u in enumerate(q.results(), start=1):
|
||||
pass
|
||||
q_commons = sorted(q.results())
|
||||
|
||||
self.assertEqual(numcommons, q_numcommons)
|
||||
self.assertListEqual(commons, q_commons)
|
||||
|
||||
def test_001_name_exact(self):
|
||||
"""Common query with exact name match."""
|
||||
|
@ -29,14 +29,12 @@ class FSUseQueryTest(unittest.TestCase):
|
||||
def test_000_unset(self):
|
||||
"""fs_use_* query with no criteria"""
|
||||
# query with no parameters gets all fs_use_*.
|
||||
for numrules, s in enumerate(self.p.fs_uses(), start=1):
|
||||
pass
|
||||
fsu = sorted(self.p.fs_uses())
|
||||
|
||||
q = FSUseQuery(self.p)
|
||||
for q_numrules, s in enumerate(q.results(), start=1):
|
||||
pass
|
||||
q_fsu = sorted(q.results())
|
||||
|
||||
self.assertEqual(numrules, q_numrules)
|
||||
self.assertListEqual(fsu, q_fsu)
|
||||
|
||||
def test_001_fs_exact(self):
|
||||
"""fs_use_* query with exact fs match"""
|
||||
|
@ -29,14 +29,12 @@ class GenfsconQueryTest(unittest.TestCase):
|
||||
def test_000_unset(self):
|
||||
"""Genfscon query with no criteria"""
|
||||
# query with no parameters gets all genfs.
|
||||
for numrules, s in enumerate(self.p.genfscons(), start=1):
|
||||
pass
|
||||
genfs = sorted(self.p.genfscons())
|
||||
|
||||
q = GenfsconQuery(self.p)
|
||||
for q_numrules, s in enumerate(q.results(), start=1):
|
||||
pass
|
||||
q_genfs = sorted(q.results())
|
||||
|
||||
self.assertEqual(numrules, q_numrules)
|
||||
self.assertListEqual(genfs, q_genfs)
|
||||
|
||||
def test_001_fs_exact(self):
|
||||
"""Genfscon query with exact fs match"""
|
||||
|
@ -29,14 +29,12 @@ class InitialSIDQueryTest(unittest.TestCase):
|
||||
def test_000_unset(self):
|
||||
"""Initial SID query with no criteria"""
|
||||
# query with no parameters gets all SIDs.
|
||||
for numrules, s in enumerate(self.p.initialsids(), start=1):
|
||||
pass
|
||||
sids = sorted(self.p.initialsids())
|
||||
|
||||
q = InitialSIDQuery(self.p)
|
||||
for q_numrules, s in enumerate(q.results(), start=1):
|
||||
pass
|
||||
q_sids = sorted(q.results())
|
||||
|
||||
self.assertEqual(numrules, q_numrules)
|
||||
self.assertListEqual(sids, q_sids)
|
||||
|
||||
def test_001_name_exact(self):
|
||||
"""Initial SID query with exact match"""
|
||||
|
@ -36,14 +36,12 @@ class MLSRuleQueryTest(unittest.TestCase):
|
||||
def test_000_unset(self):
|
||||
"""MLS rule query with no criteria."""
|
||||
# query with no parameters gets all MLS rules.
|
||||
for numrules, r in enumerate(self.p.mlsrules(), start=1):
|
||||
pass
|
||||
rules = sorted(self.p.mlsrules())
|
||||
|
||||
q = MLSRuleQuery(self.p)
|
||||
for q_numrules, r in enumerate(q.results(), start=1):
|
||||
pass
|
||||
q_rules = sorted(q.results())
|
||||
|
||||
self.assertEqual(numrules, q_numrules)
|
||||
self.assertListEqual(rules, q_rules)
|
||||
|
||||
def test_001_source_direct(self):
|
||||
"""MLS rule query with exact, direct, source match."""
|
||||
|
@ -29,14 +29,12 @@ class NetifconQueryTest(unittest.TestCase):
|
||||
def test_000_unset(self):
|
||||
"""Netifcon query with no criteria"""
|
||||
# query with no parameters gets all netifs.
|
||||
for numrules, s in enumerate(self.p.netifcons(), start=1):
|
||||
pass
|
||||
netifs = sorted(self.p.netifcons())
|
||||
|
||||
q = NetifconQuery(self.p)
|
||||
for q_numrules, s in enumerate(q.results(), start=1):
|
||||
pass
|
||||
q_netifs = sorted(q.results())
|
||||
|
||||
self.assertEqual(numrules, q_numrules)
|
||||
self.assertListEqual(netifs, q_netifs)
|
||||
|
||||
def test_001_name_exact(self):
|
||||
"""Netifcon query with exact match"""
|
||||
|
@ -31,14 +31,12 @@ class NodeconQueryTest(unittest.TestCase):
|
||||
def test_000_unset(self):
|
||||
"""Nodecon query with no criteria"""
|
||||
# query with no parameters gets all nodecons.
|
||||
for numrules, s in enumerate(self.p.nodecons(), start=1):
|
||||
pass
|
||||
nodecons = sorted(self.p.nodecons())
|
||||
|
||||
q = NodeconQuery(self.p)
|
||||
for q_numrules, s in enumerate(q.results(), start=1):
|
||||
pass
|
||||
q_nodecons = sorted(q.results())
|
||||
|
||||
self.assertEqual(numrules, q_numrules)
|
||||
self.assertListEqual(nodecons, q_nodecons)
|
||||
|
||||
def test_001_ip_version(self):
|
||||
"""Nodecon query with IP version match."""
|
||||
|
@ -29,14 +29,12 @@ class ObjClassQueryTest(unittest.TestCase):
|
||||
def test_000_unset(self):
|
||||
"""Class query with no criteria."""
|
||||
# query with no parameters gets all types.
|
||||
for numclasses, c in enumerate(self.p.classes(), start=1):
|
||||
pass
|
||||
classes = sorted(self.p.classes())
|
||||
|
||||
q = ObjClassQuery(self.p)
|
||||
for q_numclasses, u in enumerate(q.results(), start=1):
|
||||
pass
|
||||
q_classes = sorted(q.results())
|
||||
|
||||
self.assertEqual(numclasses, q_numclasses)
|
||||
self.assertListEqual(classes, q_classes)
|
||||
|
||||
def test_001_name_exact(self):
|
||||
"""Class query with exact name match."""
|
||||
|
@ -29,14 +29,12 @@ class PolCapQueryTest(unittest.TestCase):
|
||||
def test_000_unset(self):
|
||||
"""Policy capability query with no criteria"""
|
||||
# query with no parameters gets all permissives
|
||||
for numtypes, t in enumerate(self.p.permissives(), start=1):
|
||||
pass
|
||||
types = sorted(self.p.permissives())
|
||||
|
||||
q = PermissiveQuery(self.p)
|
||||
for q_numtypes, t in enumerate(q.results(), start=1):
|
||||
pass
|
||||
q_types = sorted(q.results())
|
||||
|
||||
self.assertEqual(numtypes, q_numtypes)
|
||||
self.assertListEqual(types, q_types)
|
||||
|
||||
def test_001_name_exact(self):
|
||||
"""Permissive query with exact match"""
|
||||
|
@ -29,10 +29,10 @@ class PolCapQueryTest(unittest.TestCase):
|
||||
def test_000_unset(self):
|
||||
"""Policy capability query with no criteria"""
|
||||
# query with no parameters gets all capabilities.
|
||||
allcaps = sorted(str(c) for c in self.p.polcaps())
|
||||
allcaps = sorted(self.p.polcaps())
|
||||
|
||||
q = PolCapQuery(self.p)
|
||||
qcaps = sorted(str(c) for c in q.results())
|
||||
qcaps = sorted(q.results())
|
||||
|
||||
self.assertListEqual(allcaps, qcaps)
|
||||
|
||||
|
@ -30,14 +30,12 @@ class RBACRuleQueryTest(unittest.TestCase):
|
||||
def test_000_unset(self):
|
||||
"""RBAC rule query with no criteria."""
|
||||
# query with no parameters gets all RBAC rules.
|
||||
for numrules, r in enumerate(self.p.rbacrules(), start=1):
|
||||
pass
|
||||
rules = sorted(self.p.rbacrules())
|
||||
|
||||
q = RBACRuleQuery(self.p)
|
||||
for q_numrules, r in enumerate(q.results(), start=1):
|
||||
pass
|
||||
q_rules = sorted(q.results())
|
||||
|
||||
self.assertEqual(numrules, q_numrules)
|
||||
self.assertListEqual(rules, q_rules)
|
||||
|
||||
def test_001_source_direct(self):
|
||||
"""RBAC rule query with exact, direct, source match."""
|
||||
|
@ -29,15 +29,14 @@ class RoleQueryTest(unittest.TestCase):
|
||||
def test_000_unset(self):
|
||||
"""Role query with no criteria."""
|
||||
# query with no parameters gets all types.
|
||||
for numroles, r in enumerate(self.p.roles(), start=1):
|
||||
pass
|
||||
roles = sorted(self.p.roles())
|
||||
# remove object_r, as it is skipped from the role query
|
||||
roles.remove("object_r")
|
||||
|
||||
q = RoleQuery(self.p)
|
||||
for q_numroles, t in enumerate(q.results(), start=1):
|
||||
pass
|
||||
q_roles = sorted(q.results())
|
||||
|
||||
# numroles-1 as object_r is skipped from the role query
|
||||
self.assertEqual(numroles - 1, q_numroles)
|
||||
self.assertListEqual(roles, q_roles)
|
||||
|
||||
def test_001_name_exact(self):
|
||||
"""Role query with exact name match."""
|
||||
|
@ -30,14 +30,12 @@ class TERuleQueryTest(unittest.TestCase):
|
||||
def test_000_unset(self):
|
||||
"""TE rule query with no criteria."""
|
||||
# query with no parameters gets all TE rules.
|
||||
for numrules, r in enumerate(self.p.terules(), start=1):
|
||||
pass
|
||||
rules = sorted(self.p.terules())
|
||||
|
||||
q = TERuleQuery(self.p)
|
||||
for q_numrules, r in enumerate(q.results(), start=1):
|
||||
pass
|
||||
q_rules = sorted(q.results())
|
||||
|
||||
self.assertEqual(numrules, q_numrules)
|
||||
self.assertListEqual(rules, q_rules)
|
||||
|
||||
def test_001_source_direct(self):
|
||||
"""TE rule query with exact, direct, source match."""
|
||||
|
@ -29,10 +29,10 @@ class TypeQueryTest(unittest.TestCase):
|
||||
def test_000_unset(self):
|
||||
"""Type query with no criteria."""
|
||||
# query with no parameters gets all types.
|
||||
alltypes = sorted(str(t) for t in self.p.types())
|
||||
alltypes = sorted(self.p.types())
|
||||
|
||||
q = TypeQuery(self.p)
|
||||
qtypes = sorted(str(t) for t in q.results())
|
||||
qtypes = sorted(q.results())
|
||||
|
||||
self.assertListEqual(alltypes, qtypes)
|
||||
|
||||
|
@ -29,10 +29,10 @@ class UserQueryTest(unittest.TestCase):
|
||||
def test_000_unset(self):
|
||||
"""User query with no criteria."""
|
||||
# query with no parameters gets all types.
|
||||
allusers = sorted(str(u) for u in self.p.users())
|
||||
allusers = sorted(self.p.users())
|
||||
|
||||
q = UserQuery(self.p)
|
||||
qusers = sorted(str(u) for u in q.results())
|
||||
qusers = sorted(q.results())
|
||||
|
||||
self.assertListEqual(allusers, qusers)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user