fix error messages
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Thu, 17 Jan 2013 21:45:08 +0000 (16:45 -0500)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Thu, 17 Jan 2013 21:45:08 +0000 (16:45 -0500)
sfa/trust/credential.py
sfa/util/faults.py

index d9d3972..cdc632a 100644 (file)
@@ -696,6 +696,12 @@ class Credential(object):
     def decode(self):
         if not self.xml:
             return
+
+        doc = None
+        try:
+            doc = parseString(self.xml)
+        except ExpatError,e:
+            raise CredentialNotVerifiable("Malformed credential")
         doc = parseString(self.xml)
         sigs = []
         signed_cred = doc.getElementsByTagName("signed-credential")
index 1a4e92e..f1d5cfd 100644 (file)
@@ -329,7 +329,7 @@ class InvalidXML(SfaFault):
     def __init__(self, value, extra = None):
         self.value = value
         faultString = "Invalid XML Document: %(value)s" % locals()
-        SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
+        SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
     def __str__(self):
         return repr(self.value)
 
@@ -341,10 +341,13 @@ class AccountNotEnabled(SfaFault):
         return repr(self.value)
 
 class CredentialNotVerifiable(SfaFault):
-    def __init__(self, value, extra = None):
+    def __init__(self, value=None, extra = None):
         self.value = value
-        faultString = "Unable to verify credential: %(value)s, " %locals()
-        SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
+        faultString = "Unable to verify credential" %locals()
+        if value:
+            faultString += ": %s" % value
+        faultString += ", " 
+        SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
     def __str__(self):
         return repr(self.value)