mirror of
https://github.com/samba-team/samba.git
synced 2025-03-20 22:50:26 +03:00
tests/krb5/raw_testcase.py: Allow specifying a fallback credentials function
This allows us to use other methods of obtaining credentials if getting them from the environment fails. Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> BUG: https://bugzilla.samba.org/show_bug.cgi?id=14817 (cherry picked from commit e1601f2b56f09a944c5cfb119502fdcf49a03c99)
This commit is contained in:
parent
47b6072624
commit
b423bb95af
@ -528,20 +528,47 @@ class RawKerberosTest(TestCaseInTempDir):
|
||||
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
|
||||
require_strongest_key=False,
|
||||
fallback_creds_fn=None):
|
||||
if prefix in self.creds_dict:
|
||||
return self.creds_dict[prefix]
|
||||
|
||||
# We don't have the credentials already
|
||||
creds = None
|
||||
env_err = None
|
||||
try:
|
||||
# Try to obtain them from the environment
|
||||
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)
|
||||
except Exception as err:
|
||||
# An error occurred, so save it for later
|
||||
env_err = err
|
||||
else:
|
||||
self.assertIsNotNone(creds)
|
||||
|
||||
# Save the obtained credentials
|
||||
self.creds_dict[prefix] = creds
|
||||
return creds
|
||||
|
||||
return self.creds_dict[prefix]
|
||||
if fallback_creds_fn is not None:
|
||||
try:
|
||||
# Try to use the fallback method
|
||||
creds = fallback_creds_fn()
|
||||
except Exception as err:
|
||||
print("ERROR FROM ENV: %r" % (env_err))
|
||||
print("FALLBACK-FN: %s" % (fallback_creds_fn))
|
||||
print("FALLBACK-ERROR: %r" % (err))
|
||||
else:
|
||||
self.assertIsNotNone(creds)
|
||||
# Save the obtained credentials
|
||||
self.creds_dict[prefix] = creds
|
||||
return creds
|
||||
|
||||
# Both methods failed, so raise the exception from the
|
||||
# environment method
|
||||
raise env_err
|
||||
|
||||
def get_user_creds(self,
|
||||
allow_missing_password=False,
|
||||
|
Loading…
x
Reference in New Issue
Block a user