From bd2ce9f178dc6c03a06e95fa04a8b13844d3c3f6 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 3 Jun 2014 17:03:43 +0200 Subject: [PATCH] a little more robust against odd conditions --- sfa/trust/auth.py | 11 ++++++++--- sfa/trust/credential.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sfa/trust/auth.py b/sfa/trust/auth.py index 0b9f0812..59ca4c27 100644 --- a/sfa/trust/auth.py +++ b/sfa/trust/auth.py @@ -2,6 +2,7 @@ # SfaAPI authentication # import sys +from types import StringTypes from sfa.util.faults import InsufficientRights, MissingCallerGID, MissingTrustedRoots, PermissionError, \ BadRequestHash, ConnectionKeyGIDMismatch, SfaPermissionDenied, CredentialNotVerifiable, Forbidden, \ @@ -56,9 +57,13 @@ class Auth: speaking_for_xrn=None): if xrns is None: xrns=[] def log_invalid_cred(cred): - cred_obj=Credential(string=cred) - logger.debug("failed to validate credential - dump=%s"%cred_obj.dump_string(dump_parents=True)) - error = sys.exc_info()[:2] + if not isinstance (cred, StringTypes): + logger.info("cannot validate credential %s - expecting a string"%cred) + error="checkCredentials: expected a string, received %s"%(type(cred)) + else: + cred_obj=Credential(string=cred) + logger.info("failed to validate credential - dump=%s"%cred_obj.dump_string(dump_parents=True)) + error = sys.exc_info()[:2] return error # if xrns are specified they cannot be None or empty string diff --git a/sfa/trust/credential.py b/sfa/trust/credential.py index 775cde96..c1e55ee0 100644 --- a/sfa/trust/credential.py +++ b/sfa/trust/credential.py @@ -268,7 +268,7 @@ class Credential(object): str = file(filename).read() # if this is a legacy credential, write error and bail out - if str.strip().startswith("-----"): + if isinstance (str, StringTypes) and str.strip().startswith("-----"): logger.error("Legacy credentials not supported any more - giving up with %s..."%str[:10]) return else: -- 2.43.0