a little more robust against odd conditions
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 3 Jun 2014 15:03:43 +0000 (17:03 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 3 Jun 2014 15:03:43 +0000 (17:03 +0200)
sfa/trust/auth.py
sfa/trust/credential.py

index 0b9f081..59ca4c2 100644 (file)
@@ -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
index 775cde9..c1e55ee 100644 (file)
@@ -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: