Changeset 6602 for TI12-security
- Timestamp:
- 22/02/10 12:12:42 (10 years ago)
- Location:
- TI12-security/trunk/ndg_security_saml/saml
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/ndg_security_saml/saml/common/__init__.py
r6547 r6602 52 52 elementLocalName, 53 53 namespacePrefix) 54 54 55 55 @property 56 56 def qname(self): … … 78 78 raise NotImplementedError() 79 79 80 def __getstate__(self): 81 '''Enable pickling''' 82 _dict = {} 83 for attrName in SAMLObject.__slots__: 84 # Ugly hack to allow for derived classes setting private member 85 # variables 86 if attrName.startswith('__'): 87 attrName = "_SAMLObject" + attrName 88 89 try: 90 _dict[attrName] = getattr(self, attrName) 91 except: 92 pass 93 94 return _dict 95 96 def __setstate__(self, attrDict): 97 '''Enable pickling''' 98 for attrName, val in attrDict.items(): 99 setattr(self, attrName, val) 100 80 101 81 class SAMLVersion( SAMLObject):102 class SAMLVersion(object): 82 103 """Version helper class""" 83 104 … … 86 107 VERSION_20 = (2, 0) 87 108 KNOWN_VERSIONS = (VERSION_10, VERSION_11, VERSION_20) 109 110 __slots__ = ('__version', ) 88 111 89 112 def __init__(self, version): … … 95 118 raise TypeError("Expecting string, tuple or list type for SAML " 96 119 "version initialiser; got %r" % version) 120 121 def __getstate__(self): 122 '''Enable pickling''' 123 _dict = {} 124 for attrName in SAMLVersion.__slots__: 125 # Ugly hack to allow for derived classes setting private member 126 # variables 127 if attrName.startswith('__'): 128 attrName = "_SAMLVersion" + attrName 129 130 _dict[attrName] = getattr(self, attrName) 131 132 return _dict 133 134 def __setstate__(self, attrDict): 135 '''Enable pickling''' 136 for attrName, val in attrDict.items(): 137 setattr(self, attrName, val) 97 138 98 139 def __str__(self): -
TI12-security/trunk/ndg_security_saml/saml/saml2/core.py
r6579 r6602 91 91 self.__attributeValues = [] 92 92 93 def __getstate__(self): 94 '''Enable pickling''' 95 _dict = {} 96 for attrName in Attribute.__slots__: 97 # Ugly hack to allow for derived classes setting private member 98 # variables 99 if attrName.startswith('__'): 100 attrName = "_Attribute" + attrName 101 102 _dict[attrName] = getattr(self, attrName) 103 104 return _dict 105 93 106 def _get_name(self): 94 107 return self.__name … … 172 185 class AttributeStatement(Statement): 173 186 '''SAML 2.0 Core AttributeStatement''' 174 __slots__ = ('__attributes', '__encryptedAttributes') 175 176 def __init__(self, **kw): 177 super(AttributeStatement, self).__init__(**kw) 178 179 self.__attributes = TypedList(Attribute) 180 self.__encryptedAttributes = TypedList(Attribute) 181 187 182 188 # Element local name 183 189 DEFAULT_ELEMENT_LOCAL_NAME = "AttributeStatement" … … 195 201 TYPE_LOCAL_NAME, 196 202 SAMLConstants.SAML20_PREFIX) 203 204 __slots__ = ('__attributes', '__encryptedAttributes') 205 206 def __init__(self, **kw): 207 super(AttributeStatement, self).__init__(**kw) 208 209 self.__attributes = TypedList(Attribute) 210 self.__encryptedAttributes = TypedList(Attribute) 211 212 def __getstate__(self): 213 '''Enable pickling''' 214 _dict = super(AttributeStatement, self).__getstate__() 215 for attrName in AttributeStatement.__slots__: 216 # Ugly hack to allow for derived classes setting private member 217 # variables 218 if attrName.startswith('__'): 219 attrName = "_AttributeStatement" + attrName 220 221 _dict[attrName] = getattr(self, attrName) 222 223 return _dict 197 224 198 225 def _get_attributes(self): … … 240 267 # SessionNoOnOrAfter attribute name 241 268 SESSION_NOT_ON_OR_AFTER_ATTRIB_NAME = "SessionNotOnOrAfter" 242 269 270 __slots__ = () 271 243 272 def _getAuthnInstant(self): 244 273 '''Gets the time when the authentication took place. … … 343 372 self.__value = None 344 373 self.value = decisionType 374 375 def __getstate__(self): 376 '''Enable pickling''' 377 _dict = {} 378 for attrName in DecisionType.__slots__: 379 # Ugly hack to allow for derived classes setting private member 380 # variables 381 if attrName.startswith('__'): 382 attrName = "_DecisionType" + attrName 383 384 _dict[attrName] = getattr(self, attrName) 385 386 return _dict 345 387 346 388 def _setValue(self, value): … … 429 471 DECISION_ATTRIB_NAME = "Decision" 430 472 473 __slots__ = ( 474 '__resource', 475 '__decision', 476 '__actions', 477 '__evidence', 478 '__normalizeResource', 479 '__safeNormalizationChars') 480 431 481 def __init__(self, 432 482 normalizeResource=True, … … 448 498 self.safeNormalizationChars = safeNormalizationChars 449 499 500 def __getstate__(self): 501 '''Enable pickling''' 502 _dict = super(AuthzDecisionStatement, self).__getstate__() 503 for attrName in AuthzDecisionStatement.__slots__: 504 # Ugly hack to allow for derived classes setting private member 505 # variables 506 if attrName.startswith('__'): 507 attrName = "_AuthzDecisionStatement" + attrName 508 509 _dict[attrName] = getattr(self, attrName) 510 511 return _dict 512 450 513 def _getNormalizeResource(self): 451 514 return self.__normalizeResource … … 616 679 SAMLConstants.SAML20_PREFIX) 617 680 __slots__ = ( 618 '__qname',619 681 '__baseID', 620 682 '__nameID', … … 637 699 # Subject Confirmations of the Subject. 638 700 self.__subjectConfirmations = [] 701 702 def __getstate__(self): 703 '''Enable pickling''' 704 _dict = super(Subject, self).__getstate__() 705 for attrName in Subject.__slots__: 706 # Ugly hack to allow for derived classes setting private member 707 # variables 708 if attrName.startswith('__'): 709 attrName = "_Subject" + attrName 710 711 _dict[attrName] = getattr(self, attrName) 712 713 return _dict 639 714 640 715 def _getBaseID(self): … … 738 813 739 814 __slots__ = ( 740 '__qname',741 815 '__name', 742 816 '__nameQualifier', … … 747 821 ) 748 822 749 def __init__(self, namespaceURI, elementLocalName, namespacePrefix):823 def __init__(self, **kw): 750 824 '''@param namespaceURI: the namespace the element is in 751 825 @param elementLocalName: the local name of the XML element this Object … … 753 827 @param namespacePrefix: the prefix for the given namespace 754 828 ''' 755 s elf.__qname = QName(namespaceURI, elementLocalName, namespacePrefix)829 super(AbstractNameIDType, self).__init__(**kw) 756 830 757 831 # Name of the Name ID. … … 771 845 772 846 self.__value = None 773 774 def _getQName(self): 775 return self.__qname 776 777 def _setQName(self, value): 778 if not isinstance(value, QName): 779 raise TypeError("\"qname\" must be a %r derived type, " 780 "got %r" % (QName, type(value))) 781 782 self.__qname = value 783 784 qname = property(fget=_getQName, fset=_setQName, doc="qualified name") 847 848 def __getstate__(self): 849 '''Enable pickling''' 850 _dict = super(AbstractNameIDType, self).__getstate__() 851 for attrName in AbstractNameIDType.__slots__: 852 # Ugly hack to allow for derived classes setting private member 853 # variables 854 if attrName.startswith('__'): 855 attrName = "_AbstractNameIDType" + attrName 856 857 _dict[attrName] = getattr(self, attrName) 858 859 return _dict 785 860 786 861 def _getValue(self): … … 860 935 SAMLConstants.SAML20_PREFIX) 861 936 862 def __init__(self, 863 namespaceURI=SAMLConstants.SAML20_NS, 864 localPart=DEFAULT_ELEMENT_LOCAL_NAME, 865 namespacePrefix=SAMLConstants.SAML20_PREFIX): 866 super(Issuer, self).__init__(namespaceURI, 867 localPart, 868 namespacePrefix) 937 __slots__ = () 869 938 870 939 … … 889 958 __slots__ = () 890 959 891 def __init__(self,892 namespaceURI=SAMLConstants.SAML20_NS,893 localPart=DEFAULT_ELEMENT_LOCAL_NAME,894 namespacePrefix=SAMLConstants.SAML20_PREFIX):895 super(NameID, self).__init__(namespaceURI,896 localPart,897 namespacePrefix)898 899 960 900 961 class Conditions(SAMLObject): … … 929 990 ) 930 991 931 def __init__(self): 992 def __init__(self, **kw): 993 super(Conditions, self).__init__(**kw) 932 994 933 995 # A Condition. … … 940 1002 self.__notOnOrAfter = None 941 1003 1004 def __getstate__(self): 1005 '''Enable pickling''' 1006 _dict = super(Conditions, self).__getstate__() 1007 for attrName in Conditions.__slots__: 1008 # Ugly hack to allow for derived classes setting private member 1009 # variables 1010 if attrName.startswith('__'): 1011 attrName = "_Conditions" + attrName 1012 1013 _dict[attrName] = getattr(self, attrName) 1014 1015 return _dict 1016 942 1017 def _getNotBefore(self): 943 1018 '''Get the date/time before which the assertion is invalid. … … 1070 1145 """SAML 2.0 Attribute Assertion for use with NERC DataGrid 1071 1146 """ 1072 ns = "urn:oasis:names:tc:SAML:1.0:assertion"1073 nsPfx = "saml"1074 issuer = 'http:#badc.nerc.ac.uk'1075 attributeName = "urn:mace:dir:attribute-def:eduPersonAffiliation"1076 attributeNS = "urn:mace:shibboleth:1.0:attributeNamespace:uri"1077 1078 1147 # Element local name. 1079 1148 DEFAULT_ELEMENT_LOCAL_NAME = "Assertion" … … 1132 1201 self.__authzDecisionStatements = TypedList(AuthzDecisionStatement) 1133 1202 self.__attributeStatements = TypedList(AttributeStatement) 1134 1203 1204 def __getstate__(self): 1205 '''Enable pickling''' 1206 _dict = super(Assertion, self).__getstate__() 1207 for attrName in Assertion.__slots__: 1208 # Ugly hack to allow for derived classes setting private member 1209 # variables 1210 if attrName.startswith('__'): 1211 attrName = "_Assertion" + attrName 1212 1213 _dict[attrName] = getattr(self, attrName) 1214 1215 return _dict 1216 1135 1217 def _get_version(self): 1136 1218 '''@return: the SAML Version of this assertion. … … 1302 1384 __slots__ = ('__value',) 1303 1385 1304 def __init__(self): 1386 def __init__(self, **kw): 1387 super(XSStringAttributeValue, self).__init__(**kw) 1305 1388 self.__value = None 1306 1389 1390 def __getstate__(self): 1391 '''Enable pickling''' 1392 _dict = super(XSStringAttributeValue, self).__getstate__() 1393 for attrName in XSStringAttributeValue.__slots__: 1394 # Ugly hack to allow for derived classes setting private member 1395 # variables 1396 if attrName.startswith('__'): 1397 attrName = "_XSStringAttributeValue" + attrName 1398 1399 _dict[attrName] = getattr(self, attrName) 1400 1401 return _dict 1402 1307 1403 def _getValue(self): 1308 1404 return self.__value … … 1337 1433 SAMLConstants.SAML20P_PREFIX) 1338 1434 1339 __slots__ = ('__unknownChildren', '__qname') 1340 1341 def __init__(self): 1435 __slots__ = ('__unknownChildren', ) 1436 1437 def __init__(self, **kw): 1438 super(StatusDetail, self).__init__(**kw) 1439 1342 1440 # child "any" elements. 1343 1441 self.__unknownChildren = TypedList(SAMLObject) 1344 self.__qname = QName(StatusDetail.DEFAULT_ELEMENT_NAME.namespaceURI, 1345 StatusDetail.DEFAULT_ELEMENT_NAME, 1346 StatusDetail.DEFAULT_ELEMENT_NAME.prefix) 1442 1443 def __getstate__(self): 1444 '''Enable pickling''' 1445 _dict = super(StatusDetail, self).__getstate__() 1446 for attrName in StatusDetail.__slots__: 1447 # Ugly hack to allow for derived classes setting private member 1448 # variables 1449 if attrName.startswith('__'): 1450 attrName = "_StatusDetail" + attrName 1451 1452 _dict[attrName] = getattr(self, attrName) 1453 1454 return _dict 1347 1455 1348 1456 def getUnknownXMLTypes(self, qname=None): … … 1367 1475 doc="Child objects of Status Detail - may be " 1368 1476 "any type") 1369 1370 def _getQName(self):1371 return self.__qname1372 1373 def _setQName(self, value):1374 if not isinstance(value, QName):1375 raise TypeError("\"qname\" must be a %r derived type, "1376 "got %r" % (QName, type(value)))1377 1378 self.__qname = value1379 1380 qname = property(fget=_getQName, fset=_setQName, doc="qualified name")1381 1477 1382 1478 … … 1389 1485 SAMLConstants.SAML20P_PREFIX) 1390 1486 1391 __slots__ = ('__value', '__qname') 1392 1393 def __init__(self): 1487 __slots__ = ('__value', ) 1488 1489 def __init__(self, **kw): 1490 super(StatusMessage, self).__init__(**kw) 1491 1394 1492 # Value attribute URI. 1395 1493 self.__value = None 1396 self.__qname = QName(StatusMessage.DEFAULT_ELEMENT_NAME.namespaceURI, 1397 StatusMessage.DEFAULT_ELEMENT_NAME.localPart, 1398 StatusMessage.DEFAULT_ELEMENT_NAME.prefix) 1399 1494 1495 def __getstate__(self): 1496 '''Enable pickling''' 1497 _dict = super(StatusMessage, self).__getstate__() 1498 for attrName in StatusMessage.__slots__: 1499 # Ugly hack to allow for derived classes setting private member 1500 # variables 1501 if attrName.startswith('__'): 1502 attrName = "_StatusMessage" + attrName 1503 1504 _dict[attrName] = getattr(self, attrName) 1505 1506 return _dict 1507 1400 1508 def _getValue(self): 1401 1509 return self.__value … … 1408 1516 self.__value = value 1409 1517 1410 value = property(fget=_getValue, fset=_setValue, 1411 doc="Status message value") 1412 1413 def _getQName(self): 1414 return self.__qname 1415 1416 def _setQName(self, value): 1417 if not isinstance(value, QName): 1418 raise TypeError("\"qname\" must be a %r derived type, " 1419 "got %r" % (QName, type(value))) 1420 1421 self.__qname = value 1422 1423 qname = property(fget=_getQName, fset=_setQName, doc="qualified name") 1518 value = property(fget=_getValue, fset=_setValue, doc="Status message value") 1424 1519 1425 1520 … … 1526 1621 "urn:oasis:names:tc:SAML:2.0:status:UnsupportedBinding" 1527 1622 1528 __slots__ = ('__value', '__childStatusCode', '__qname') 1529 1530 def __init__(self): 1623 __slots__ = ('__value', '__childStatusCode',) 1624 1625 def __init__(self, **kw): 1626 super(StatusCode, self).__init__(**kw) 1627 1531 1628 # Value attribute URI. 1532 1629 self.__value = None … … 1534 1631 # Nested secondary StatusCode child element. 1535 1632 self.__childStatusCode = None 1536 1537 self.__qname = QName(StatusCode.DEFAULT_ELEMENT_NAME.namespaceURI, 1538 StatusCode.DEFAULT_ELEMENT_NAME.localPart, 1539 StatusCode.DEFAULT_ELEMENT_NAME.prefix) 1540 1633 1634 def __getstate__(self): 1635 '''Enable pickling''' 1636 _dict = super(StatusCode, self).__getstate__() 1637 for attrName in StatusCode.__slots__: 1638 # Ugly hack to allow for derived classes setting private member 1639 # variables 1640 if attrName.startswith('__'): 1641 attrName = "_StatusCode" + attrName 1642 1643 _dict[attrName] = getattr(self, attrName) 1644 1645 return _dict 1646 1541 1647 def _getStatusCode(self): 1542 1648 return self.__childStatusCode … … 1564 1670 1565 1671 value = property(fget=_getValue, fset=_setValue, doc="Status code value") 1566 1567 def _getQName(self):1568 return self.__qname1569 1570 def _setQName(self, value):1571 if not isinstance(value, QName):1572 raise TypeError("\"qname\" must be a %r derived type, "1573 "got %r" % (QName, type(value)))1574 1575 self.__qname = value1576 1577 qname = property(fget=_getQName, fset=_setQName, doc="qualified name")1578 1672 1579 1673 … … 1597 1691 SAMLConstants.SAML20P_PREFIX) 1598 1692 1599 __slots__ = ('__statusCode', '__statusMessage', '__statusDetail', '__qname') 1600 1601 def __init__(self): 1693 __slots__ = ('__statusCode', '__statusMessage', '__statusDetail', ) 1694 1695 def __init__(self, **kw): 1696 super(Status, self).__init__(**kw) 1697 1602 1698 # StatusCode element. 1603 1699 self.__statusCode = None … … 1609 1705 self.__statusDetail = None 1610 1706 1611 self.__qname = QName(Status.DEFAULT_ELEMENT_NAME.namespaceURI, 1612 Status.DEFAULT_ELEMENT_NAME.localPart, 1613 Status.DEFAULT_ELEMENT_NAME.prefix) 1707 def __getstate__(self): 1708 '''Enable pickling''' 1709 _dict = super(Status, self).__getstate__() 1710 for attrName in Status.__slots__: 1711 # Ugly hack to allow for derived classes setting private member 1712 # variables 1713 if attrName.startswith('__'): 1714 attrName = "_Status" + attrName 1614 1715 1615 def _getQName(self): 1616 return self.__qname 1617 1618 def _setQName(self, value): 1619 if not isinstance(value, QName): 1620 raise TypeError("\"qname\" must be a %r derived type, " 1621 "got %r" % (QName, type(value))) 1622 1623 self.__qname = value 1624 1625 qname = property(fget=_getQName, fset=_setQName, doc="qualified name") 1626 1716 _dict[attrName] = getattr(self, attrName) 1717 1718 return _dict 1719 1627 1720 def _getStatusCode(self): 1628 1721 ''' … … 1804 1897 1805 1898 self.__actionTypes = Action.ACTION_TYPES 1806 1899 1900 def __getstate__(self): 1901 '''Enable pickling''' 1902 _dict = super(Action, self).__getstate__() 1903 for attrName in Action.__slots__: 1904 # Ugly hack to allow for derived classes setting private member 1905 # variables 1906 if attrName.startswith('__'): 1907 attrName = "_Action" + attrName 1908 1909 _dict[attrName] = getattr(self, attrName) 1910 1911 return _dict 1912 1807 1913 def _getActionTypes(self): 1808 1914 return self.__actionTypes … … 1946 2052 ) 1947 2053 1948 def __init__(self): 2054 def __init__(self, **kw): 2055 '''Request abstract type 2056 @type kw: dict 2057 @param kw: see SAMLObject.__init__ 2058 ''' 2059 super(RequestAbstractType, self).__init__(**kw) 2060 1949 2061 # SAML Version of the request. 1950 2062 self.__version = None … … 1967 2079 # Extensions child element. 1968 2080 self.__extensions = None 1969 2081 2082 def __getstate__(self): 2083 '''Enable pickling''' 2084 _dict = super(RequestAbstractType, self).__getstate__() 2085 for attrName in RequestAbstractType.__slots__: 2086 # Ugly hack to allow for derived classes setting private member 2087 # variables 2088 if attrName.startswith('__'): 2089 attrName = "_RequestAbstractType" + attrName 2090 2091 _dict[attrName] = getattr(self, attrName) 2092 2093 return _dict 2094 1970 2095 def _get_version(self): 1971 2096 '''@return: the SAML Version of this assertion. … … 2113 2238 super(SubjectQuery, self).__init__() 2114 2239 self.__subject = None 2115 2240 2241 def __getstate__(self): 2242 '''Enable pickling''' 2243 _dict = super(SubjectQuery, self).__getstate__() 2244 for attrName in SubjectQuery.__slots__: 2245 # Ugly hack to allow for derived classes setting private member 2246 # variables 2247 if attrName.startswith('__'): 2248 attrName = "_SubjectQuery" + attrName 2249 2250 _dict[attrName] = getattr(self, attrName) 2251 2252 return _dict 2253 2116 2254 def _getSubject(self): 2117 2255 '''Gets the Subject of this request. … … 2157 2295 super(AttributeQuery, self).__init__() 2158 2296 self.__attributes = TypedList(Attribute) 2297 2298 def __getstate__(self): 2299 '''Enable pickling''' 2300 _dict = super(AttributeQuery, self).__getstate__() 2301 for attrName in AttributeQuery.__slots__: 2302 # Ugly hack to allow for derived classes setting private member 2303 # variables 2304 if attrName.startswith('__'): 2305 attrName = "_AttributeQuery" + attrName 2306 2307 _dict[attrName] = getattr(self, attrName) 2308 2309 return _dict 2159 2310 2160 2311 def _getAttributes(self): … … 2435 2586 self.safeNormalizationChars = safeNormalizationChars 2436 2587 2588 def __getstate__(self): 2589 '''Enable pickling''' 2590 _dict = super(AuthzDecisionQuery, self).__getstate__() 2591 for attrName in AuthzDecisionQuery.__slots__: 2592 # Ugly hack to allow for derived classes setting private member 2593 # variables 2594 if attrName.startswith('__'): 2595 attrName = "_AuthzDecisionQueryy" + attrName 2596 2597 _dict[attrName] = getattr(self, attrName) 2598 2599 return _dict 2600 2437 2601 def _getNormalizeResource(self): 2438 2602 return self.__normalizeResource … … 2613 2777 INAPPLICABLE_CONSENT = "urn:oasis:names:tc:SAML:2.0:consent:inapplicable" 2614 2778 2615 __slots__ = ( 2616 '__qname', 2779 __slots__ = ( 2617 2780 '__version', 2618 2781 '__id', … … 2626 2789 ) 2627 2790 2628 def __init__(self ):2629 s elf.__qname = None2791 def __init__(self, **kw): 2792 super(StatusResponseType, self).__init__(**kw) 2630 2793 2631 2794 self.__version = SAMLVersion(SAMLVersion.VERSION_20) … … 2638 2801 self.__status = None 2639 2802 self.__extensions = None 2640 2641 def _getQName(self): 2642 return self.__qname 2643 2644 def _setQName(self, value): 2645 if not isinstance(value, QName): 2646 raise TypeError("\"qname\" must be a %r derived type, " 2647 "got %r" % (QName, type(value))) 2648 2649 self.__qname = value 2650 2651 qname = property(fget=_getQName, fset=_setQName, doc="qualified name") 2652 2803 2804 def __getstate__(self): 2805 '''Enable pickling''' 2806 _dict = super(StatusResponseType, self).__getstate__() 2807 for attrName in StatusResponseType.__slots__: 2808 # Ugly hack to allow for derived classes setting private member 2809 # variables 2810 if attrName.startswith('__'): 2811 attrName = "_StatusResponseType" + attrName 2812 2813 _dict[attrName] = getattr(self, attrName) 2814 2815 return _dict 2816 2653 2817 def _get_version(self): 2654 2818 '''@return: the SAML Version of this response. … … 2855 3019 __slots__ = ('__indexedChildren',) 2856 3020 2857 def __init__(self ):3021 def __init__(self, **kw): 2858 3022 '''''' 2859 super(Response, self).__init__( )3023 super(Response, self).__init__(**kw) 2860 3024 2861 3025 # Assertion child elements 2862 3026 self.__indexedChildren = [] 2863 2864 def _getAssertions(self): 3027 3028 def __getstate__(self): 3029 '''Enable pickling''' 3030 _dict = super(Response, self).__getstate__() 3031 for attrName in Response.__slots__: 3032 # Ugly hack to allow for derived classes setting private member 3033 # variables 3034 if attrName.startswith('__'): 3035 attrName = "_Response" + attrName 3036 3037 _dict[attrName] = getattr(self, attrName) 3038 3039 return _dict 3040 3041 @property 3042 def assertions(self): 3043 "Assertions contained in this response" 2865 3044 return self.__indexedChildren 2866 2867 assertions = property(fget=_getAssertions,2868 doc="Assertions contained in this response") -
TI12-security/trunk/ndg_security_saml/saml/test/test_saml.py
r6559 r6602 17 17 18 18 import unittest 19 import pickle 19 20 20 21 from xml.etree.ElementTree import iselement … … 43 44 UNCORRECTED_RESOURCE_URI = "http://LOCALHOST:80/My Secured URI" 44 45 RESOURCE_URI = "http://localhost/My%20Secured%20URI" 46 XSSTRING_NS = "http://www.w3.org/2001/XMLSchema#string" 45 47 46 48 def __init__(self): … … 117 119 fnAttribute = Attribute() 118 120 fnAttribute.name = "urn:esg:first:name" 119 fnAttribute.nameFormat = "http://www.w3.org/2001/XMLSchema#string"121 fnAttribute.nameFormat = SAMLUtil.XSSTRING_NS 120 122 fnAttribute.friendlyName = "FirstName" 121 123 … … 131 133 lnAttribute = Attribute() 132 134 lnAttribute.name = "urn:esg:last:name" 133 lnAttribute.nameFormat = "http://www.w3.org/2001/XMLSchema#string"135 lnAttribute.nameFormat = SAMLUtil.XSSTRING_NS 134 136 lnAttribute.friendlyName = "LastName" 135 137 … … 158 160 attribute = Attribute() 159 161 attribute.name = name 160 attribute.nameFormat = "http://www.w3.org/2001/XMLSchema#string"162 attribute.nameFormat = SAMLUtil.XSSTRING_NS 161 163 162 164 stringAttributeValue = XSStringAttributeValue() … … 286 288 SAMLTestCase.NAMEID_VALUE) 287 289 288 elem = AttributeQueryElementTree.toXML(attributeQuery) 290 elem = AttributeQueryElementTree.toXML(attributeQuery) 289 291 xmlOutput = prettyPrint(elem) 290 292 … … 327 329 print("_"*80) 328 330 329 def test05CreateAttributeQueryResponse(self):331 def _createAttributeQueryResponse(self): 330 332 response = Response() 331 333 response.issueInstant = datetime.utcnow() … … 365 367 366 368 response.assertions.append(assertion) 369 370 return response 371 372 def test05CreateAttributeQueryResponse(self): 373 response = self._createAttributeQueryResponse() 367 374 368 375 # Create ElementTree Assertion Element … … 600 607 ].actions[-1].value == Action.HTTP_GET_ACTION) 601 608 602 609 610 def test12PickleAssertion(self): 611 # Test pickling with __slots__ 612 assertion = self._createAttributeAssertionHelper() 613 assertion.issuer = Issuer() 614 assertion.issuer.format = Issuer.X509_SUBJECT 615 assertion.issuer.value = SAMLTestCase.ISSUER_DN 616 617 jar = pickle.dumps(assertion) 618 assertion2 = pickle.loads(jar) 619 self.assert_(isinstance(assertion2, Assertion)) 620 self.assert_(assertion2.issuer.value == assertion.issuer.value) 621 self.assert_(assertion2.issuer.format == assertion.issuer.format) 622 self.assert_(len(assertion2.attributeStatements)==1) 623 self.assert_(len(assertion2.attributeStatements[0].attributes) > 0) 624 self.assert_(assertion2.attributeStatements[0].attributes[0 625 ].attributeValues[0 626 ].value == assertion.attributeStatements[0].attributes[0 627 ].attributeValues[0].value) 628 629 def test13PickleAttributeQuery(self): 630 # Test pickling with __slots__ 631 samlUtil = SAMLUtil() 632 samlUtil.firstName = '' 633 samlUtil.lastName = '' 634 samlUtil.emailAddress = '' 635 query = samlUtil.buildAttributeQuery(SAMLTestCase.ISSUER_DN, 636 SAMLTestCase.NAMEID_VALUE) 637 638 jar = pickle.dumps(query) 639 query2 = pickle.loads(jar) 640 641 self.assert_(isinstance(query2, AttributeQuery)) 642 self.assert_(query2.subject.nameID.value == query.subject.nameID.value) 643 self.assert_((query2.subject.nameID.format == 644 query.subject.nameID.format)) 645 self.assert_(query2.issuer.value == query.issuer.value) 646 self.assert_(query2.issuer.format == query.issuer.format) 647 self.assert_(query2.issueInstant == query.issueInstant) 648 self.assert_(query2.id == query.id) 649 self.assert_(len(query2.attributes) == 3) 650 self.assert_(query2.attributes[0].name == "urn:esg:first:name") 651 self.assert_(query2.attributes[1].nameFormat == SAMLUtil.XSSTRING_NS) 652 653 def test14PickleAttributeQueryResponse(self): 654 response = self._createAttributeQueryResponse() 655 656 jar = pickle.dumps(response) 657 response2 = pickle.loads(jar) 658 659 self.assert_(isinstance(response2, Response)) 660 self.assert_((response2.status.statusCode.value == 661 response.status.statusCode.value)) 662 self.assert_((response2.status.statusMessage.value == 663 response.status.statusMessage.value)) 664 self.assert_(len(response2.assertions) == 1) 665 self.assert_(response2.assertions[0].id == response.assertions[0].id) 666 self.assert_((response2.assertions[0].conditions.notBefore == 667 response.assertions[0].conditions.notBefore)) 668 self.assert_((response2.assertions[0].conditions.notOnOrAfter == 669 response.assertions[0].conditions.notOnOrAfter)) 670 self.assert_(len(response2.assertions[0].attributeStatements) == 1) 671 self.assert_(len(response2.assertions[0].attributeStatements[0 672 ].attributes) == 9) 673 self.assert_(response2.assertions[0].attributeStatements[0].attributes[1 674 ].attributeValues[0 675 ].value == response.assertions[0].attributeStatements[0 676 ].attributes[1].attributeValues[0].value) 677 678 603 679 if __name__ == "__main__": 604 680 unittest.main() -
TI12-security/trunk/ndg_security_saml/saml/xml/etree.py
r6579 r6602 1618 1618 cls.DEFAULT_ELEMENT_LOCAL_NAME) 1619 1619 1620 action = Action() 1620 1621 namespace = elem.attrib.get(cls.NAMESPACE_ATTRIB_NAME) 1621 1622 if namespace is None: 1622 raise XMLTypeParseError('No "%s" attribute found in "%s" ' 1623 'element' % 1624 (cls.NAMESPACE_ATTRIB_NAME, 1625 cls.DEFAULT_ELEMENT_LOCAL_NAME)) 1626 action = Action() 1627 action.namespace = namespace 1623 log.warning('No "%s" attribute found in "%s" element assuming ' 1624 '%r action namespace' % 1625 (cls.NAMESPACE_ATTRIB_NAME, 1626 cls.DEFAULT_ELEMENT_LOCAL_NAME, 1627 action.namespace)) 1628 else: 1629 action.namespace = namespace 1630 1628 1631 action.value = elem.text.strip() 1629 1632
Note: See TracChangeset
for help on using the changeset viewer.