diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2011-07-30 12:57:24 +0200 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2011-08-01 09:23:16 -0400 |
commit | 1e710acc5ce225c7e6aa33bc0dfe8af65f49d182 (patch) | |
tree | 2d7214eb37f91580f397d69ab105a73f063fc1fb /src/tests | |
parent | d2d90b7195f58bd20628b1c62d1e1b01bfbb7a2b (diff) | |
download | sssd-1e710acc5ce225c7e6aa33bc0dfe8af65f49d182.tar.gz sssd-1e710acc5ce225c7e6aa33bc0dfe8af65f49d182.tar.bz2 sssd-1e710acc5ce225c7e6aa33bc0dfe8af65f49d182.zip |
HBAC rule validation Python bindings
https://fedorahosted.org/sssd/ticket/943
Diffstat (limited to 'src/tests')
-rwxr-xr-x | src/tests/pyhbac-test.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/tests/pyhbac-test.py b/src/tests/pyhbac-test.py index b19fe586..5579180b 100755 --- a/src/tests/pyhbac-test.py +++ b/src/tests/pyhbac-test.py @@ -232,6 +232,30 @@ class PyHbacRuleTest(unittest.TestCase): "srchosts <category 0 names [%s] groups []>>" % (name, service, targethost, srchost)) + def testValidate(self): + r = pyhbac.HbacRule('valid_rule') + + valid, missing = r.validate() + self.assertEqual(valid, False) + self.assertItemsEqual(missing, ( pyhbac.HBAC_RULE_ELEMENT_USERS, + pyhbac.HBAC_RULE_ELEMENT_SERVICES, + pyhbac.HBAC_RULE_ELEMENT_TARGETHOSTS, + pyhbac.HBAC_RULE_ELEMENT_SOURCEHOSTS )) + + r.users.names = [ "someuser" ] + r.services.names = [ "ssh" ] + + valid, missing = r.validate() + self.assertEqual(valid, False) + self.assertItemsEqual(missing, ( pyhbac.HBAC_RULE_ELEMENT_TARGETHOSTS, + pyhbac.HBAC_RULE_ELEMENT_SOURCEHOSTS )) + + r.srchosts.names = [ "host1" ] + r.targethosts.names = [ "host2" ] + + valid, missing = r.validate() + self.assertEqual(valid, True) + class PyHbacRequestElementTest(unittest.TestCase): def testInstantiateEmpty(self): el = pyhbac.HbacRequestElement() @@ -428,6 +452,12 @@ class PyHbacModuleTest(unittest.TestCase): assert hasattr(pyhbac, "HBAC_CATEGORY_NULL") assert hasattr(pyhbac, "HBAC_CATEGORY_ALL") + def testHasRuleElementTypes(self): + assert hasattr(pyhbac, "HBAC_RULE_ELEMENT_USERS") + assert hasattr(pyhbac, "HBAC_RULE_ELEMENT_SERVICES") + assert hasattr(pyhbac, "HBAC_RULE_ELEMENT_TARGETHOSTS") + assert hasattr(pyhbac, "HBAC_RULE_ELEMENT_SOURCEHOSTS") + def testHbacResultString(self): results = [ pyhbac.HBAC_EVAL_ALLOW, pyhbac.HBAC_EVAL_DENY, pyhbac.HBAC_EVAL_ERROR ] |