diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_gssapi.py | 43 | ||||
-rw-r--r-- | tests/util.py | 28 |
2 files changed, 47 insertions, 24 deletions
diff --git a/tests/test_gssapi.py b/tests/test_gssapi.py index 98d4d14e..8e6ec37a 100644 --- a/tests/test_gssapi.py +++ b/tests/test_gssapi.py @@ -53,8 +53,11 @@ class GSSAPITest(KerberosTestCase): """ try: import gssapi - if (hasattr(gssapi, '__title__') and - gssapi.__title__ == 'python-gssapi'): + + if ( + hasattr(gssapi, "__title__") + and gssapi.__title__ == "python-gssapi" + ): _API = "PYTHON-GSSAPI-OLD" else: _API = "PYTHON-GSSAPI-NEW" @@ -118,28 +121,36 @@ class GSSAPITest(KerberosTestCase): self.assertEquals(0, status) elif _API == "PYTHON-GSSAPI-NEW": if self.server_mode: - gss_flags = (gssapi.RequirementFlag.protection_ready, - gssapi.RequirementFlag.integrity, - gssapi.RequirementFlag.mutual_authentication, - gssapi.RequirementFlag.delegate_to_peer) + gss_flags = ( + gssapi.RequirementFlag.protection_ready, + gssapi.RequirementFlag.integrity, + gssapi.RequirementFlag.mutual_authentication, + gssapi.RequirementFlag.delegate_to_peer, + ) else: - gss_flags = (gssapi.RequirementFlag.protection_ready, - gssapi.RequirementFlag.integrity, - gssapi.RequirementFlag.delegate_to_peer) + gss_flags = ( + gssapi.RequirementFlag.protection_ready, + gssapi.RequirementFlag.integrity, + gssapi.RequirementFlag.delegate_to_peer, + ) # Initialize a GSS-API context. krb5_oid = gssapi.MechType.kerberos - target_name = gssapi.Name("host@" + self.targ_name, - name_type=gssapi.NameType.hostbased_service) - gss_ctxt = gssapi.SecurityContext(name=target_name, - flags=gss_flags, - mech=krb5_oid, - usage='initiate') + target_name = gssapi.Name( + "host@" + self.targ_name, + name_type=gssapi.NameType.hostbased_service, + ) + gss_ctxt = gssapi.SecurityContext( + name=target_name, + flags=gss_flags, + mech=krb5_oid, + usage="initiate", + ) if self.server_mode: c_token = gss_ctxt.step(c_token) gss_ctxt_status = gss_ctxt.complete self.assertEquals(False, gss_ctxt_status) # Accept a GSS-API context. - gss_srv_ctxt = gssapi.SecurityContext(usage='accept') + gss_srv_ctxt = gssapi.SecurityContext(usage="accept") s_token = gss_srv_ctxt.step(c_token) gss_ctxt_status = gss_srv_ctxt.complete self.assertNotEquals(None, s_token) diff --git a/tests/util.py b/tests/util.py index be56b37d..cdc835c9 100644 --- a/tests/util.py +++ b/tests/util.py @@ -13,8 +13,9 @@ def _support(filename): return join(dirname(realpath(__file__)), filename) -needs_gssapi = pytest.mark.skipif(not GSS_AUTH_AVAILABLE, - reason="No GSSAPI to test") +needs_gssapi = pytest.mark.skipif( + not GSS_AUTH_AVAILABLE, reason="No GSSAPI to test" +) def needs_builtin(name): @@ -41,9 +42,11 @@ slow = pytest.mark.slow # # ToDo: add a Windows specific implementation? -if (os.environ.get("K5TEST_USER_PRINC", None) and - os.environ.get("K5TEST_HOSTNAME", None) and - os.environ.get("KRB5_KTNAME", None)): # add other vars as needed +if ( + os.environ.get("K5TEST_USER_PRINC", None) + and os.environ.get("K5TEST_HOSTNAME", None) + and os.environ.get("KRB5_KTNAME", None) +): # add other vars as needed # The environment provides the required information class DummyK5Realm(object): @@ -62,6 +65,8 @@ if (os.environ.get("K5TEST_USER_PRINC", None) and @classmethod def tearDownClass(cls): del cls.realm + + else: try: # Try to setup a kerberos environment @@ -71,22 +76,28 @@ else: class KerberosTestCase(unittest.TestCase): @classmethod def setUpClass(cls): - raise unittest.SkipTest('Missing extension package k5test. ' - 'Please run "pip install k5test" ' - 'to install it.') + raise unittest.SkipTest( + "Missing extension package k5test. " + 'Please run "pip install k5test" ' + "to install it." + ) + def update_env(testcase, mapping, env=os.environ): """Modify os.environ during a test case and restore during cleanup.""" saved_env = env.copy() + def replace(target, source): target.update(source) for k in list(target): if k not in source: target.pop(k, None) + testcase.addCleanup(replace, env, saved_env) env.update(mapping) return testcase + def k5shell(args=None): """Create a shell with an kerberos environment @@ -97,6 +108,7 @@ def k5shell(args=None): import k5test import atexit import subprocess + k5 = k5test.K5Realm() atexit.register(k5.stop) os.environ.update(k5.env) |