1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-21 20:23:50 +03:00

tests/krb5/raw_testcase.py: Cache obtained credentials

If credentials are used more than once, we can now use the credentials
that we already obtained and so avoid fetching them again.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
This commit is contained in:
Joseph Sutton
2021-06-15 17:10:44 +12:00
committed by Stefan Metzmacher
parent 6a77c2b933
commit 22a90aea82
2 changed files with 34 additions and 5 deletions

View File

@@ -371,6 +371,14 @@ class RawKerberosTest(TestCaseInTempDir):
e = self.etype_test_permutations[idx]
return (e['name'], e['etypes'])
@classmethod
def setUpClass(cls):
super().setUpClass()
# A dictionary containing credentials that have already been
# obtained.
cls.creds_dict = {}
def setUp(self):
super().setUp()
self.do_asn1_print = False
@@ -441,11 +449,11 @@ class RawKerberosTest(TestCaseInTempDir):
allow_missing=allow_missing)
return val
def _get_krb5_creds(self, prefix,
default_username=None,
allow_missing_password=False,
allow_missing_keys=True,
require_strongest_key=False):
def _get_krb5_creds_from_env(self, prefix,
default_username=None,
allow_missing_password=False,
allow_missing_keys=True,
require_strongest_key=False):
c = KerberosCredentials()
c.guess()
@@ -515,6 +523,26 @@ class RawKerberosTest(TestCaseInTempDir):
return c
def _get_krb5_creds(self,
prefix,
default_username=None,
allow_missing_password=False,
allow_missing_keys=True,
require_strongest_key=False):
if prefix not in self.creds_dict:
# We don't have the credentials already
creds = self._get_krb5_creds_from_env(prefix,
default_username=default_username,
allow_missing_password=allow_missing_password,
allow_missing_keys=allow_missing_keys,
require_strongest_key=require_strongest_key)
self.assertIsNotNone(creds)
# Save the obtained credentials
self.creds_dict[prefix] = creds
return self.creds_dict[prefix]
def get_user_creds(self,
allow_missing_password=False,
allow_missing_keys=True):