Changeset 7150
- Timestamp:
- 01/07/10 13:08:57 (11 years ago)
- Location:
- TI12-security/trunk/ndg_saml/ndg/saml
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/ndg_saml/ndg/saml/saml2/binding/soap/client/__init__.py
r7143 r7150 13 13 14 14 from os import path 15 from ConfigParser import ConfigParser 15 from ConfigParser import ConfigParser, SafeConfigParser 16 16 17 17 from ndg.saml.common import SAMLObject 18 18 19 from ndg.security.common.utils.factory import importModuleObject 20 from ndg.security.common.utils.configfileparsers import ( 21 CaseSensitiveConfigParser) 19 from ndg.saml.utils.factory import importModuleObject 22 20 from ndg.soap import SOAPEnvelopeBase 23 21 from ndg.soap.etree import SOAPEnvelope … … 223 221 if isinstance(cfg, basestring): 224 222 cfgFilePath = path.expandvars(cfg) 225 _cfg = CaseSensitiveConfigParser() 223 _cfg = SafeConfigParser() 224 _cfg.optionxform = str 225 226 226 _cfg.read(cfgFilePath) 227 227 -
TI12-security/trunk/ndg_saml/ndg/saml/test/binding/soap/test_samlinterface.py
r7147 r7150 1 """ Attribute Authority SAMLInterface unit test package1 """SAML Generic SOAP Binding Query/Response Interface unit test package 2 2 3 3 NERC DataGrid Project … … 11 11 import logging 12 12 logging.basicConfig(level=logging.DEBUG) 13 log = logging.getLogger(__name__) 13 14 import unittest 14 15 … … 27 28 from ndg.saml.xml import XMLConstants 28 29 from ndg.saml.xml.etree import AttributeQueryElementTree, ResponseElementTree 29 from ndg.saml.saml2.binding.soap. subjectquery import (30 from ndg.saml.saml2.binding.soap.client.subjectquery import ( 30 31 SubjectQuerySOAPBinding, ResponseIssueInstantInvalid, 31 32 AssertionIssueInstantInvalid, AssertionConditionNotBeforeInvalid, … … 38 39 39 40 class SamlSoapBindingApp(object): 41 """Simple WSGI application to handle SAML Attribute Query/Response 42 """ 43 FIRSTNAME_ATTRNAME = "urn:ndg:saml:firstname" 44 LASTNAME_ATTRNAME = "urn:ndg:saml:lastname" 45 EMAILADDRESS_ATTRNAME = "urn:ndg:saml:emailaddress" 46 NAMEID_FORMAT = "urn:ndg:saml:openid" 47 40 48 def __init__(self): 41 49 self.firstName = "Philip" … … 85 93 86 94 for attribute in attributeQuery.attributes: 87 if attribute.name == EsgSamlNamespaces.FIRSTNAME_ATTRNAME:95 if attribute.name == SamlSoapBindingApp.FIRSTNAME_ATTRNAME: 88 96 # special case handling for 'FirstName' attribute 89 97 fnAttribute = Attribute() … … 98 106 assertion.attributeStatements[0].attributes.append(fnAttribute) 99 107 100 elif attribute.name == EsgSamlNamespaces.LASTNAME_ATTRNAME:108 elif attribute.name == SamlSoapBindingApp.LASTNAME_ATTRNAME: 101 109 lnAttribute = Attribute() 102 110 lnAttribute.name = attribute.name … … 110 118 assertion.attributeStatements[0].attributes.append(lnAttribute) 111 119 112 elif attribute.name == EsgSamlNamespaces.EMAILADDRESS_ATTRNAME:120 elif attribute.name == SamlSoapBindingApp.EMAILADDRESS_ATTRNAME: 113 121 emailAddressAttribute = Attribute() 114 122 emailAddressAttribute.name = attribute.name … … 124 132 125 133 samlResponse.assertions.append(assertion) 126 127 # Add mapping for ESG Group/Role Attribute Value to enable ElementTree128 # Attribute Value factory to render the XML output129 toXMLTypeMap = {130 XSGroupRoleAttributeValue: XSGroupRoleAttributeValueElementTree131 }132 133 134 134 135 samlResponse.status = Status() … … 142 143 customToXMLTypeMap=toXMLTypeMap) 143 144 xml = ElementTree.tostring(samlResponseElem) 145 log.debug('Sending response to query:\n%s', xml) 144 146 145 147 # Create SOAP response and attach the SAML Response payload … … 156 158 157 159 158 class SamlAttribute AuthorityInterfaceTestCase(BaseTestCase):159 """T ODO: test SAML Attribute Authority interface"""160 class SamlAttributeQueryTestCase(unittest.TestCase): 161 """Test the SAML SOAP binding using an Attribute Query as an example""" 160 162 thisDir = os.path.dirname(os.path.abspath(__file__)) 161 163 RESPONSE = '''\ … … 205 207 self.app = paste.fixture.TestApp(wsgiApp) 206 208 207 BaseTestCase.__init__(self, *args, **kwargs)209 unittest.TestCase.__init__(self, *args, **kwargs) 208 210 209 211 def test01AttributeQuery(self): … … 221 223 attributeQuery.subject = Subject() 222 224 attributeQuery.subject.nameID = NameID() 223 attributeQuery.subject.nameID.format = EsgSamlNamespaces.NAMEID_FORMAT225 attributeQuery.subject.nameID.format = SamlSoapBindingApp.NAMEID_FORMAT 224 226 attributeQuery.subject.nameID.value = \ 225 227 "https://openid.localhost/philip.kershaw" … … 227 229 # special case handling for 'FirstName' attribute 228 230 fnAttribute = Attribute() 229 fnAttribute.name = EsgSamlNamespaces.FIRSTNAME_ATTRNAME231 fnAttribute.name = SamlSoapBindingApp.FIRSTNAME_ATTRNAME 230 232 fnAttribute.nameFormat = "http://www.w3.org/2001/XMLSchema#string" 231 233 fnAttribute.friendlyName = "FirstName" … … 235 237 # special case handling for 'LastName' attribute 236 238 lnAttribute = Attribute() 237 lnAttribute.name = EsgSamlNamespaces.LASTNAME_ATTRNAME239 lnAttribute.name = SamlSoapBindingApp.LASTNAME_ATTRNAME 238 240 lnAttribute.nameFormat = "http://www.w3.org/2001/XMLSchema#string" 239 241 lnAttribute.friendlyName = "LastName" … … 243 245 # special case handling for 'LastName' attribute 244 246 emailAddressAttribute = Attribute() 245 emailAddressAttribute.name = EsgSamlNamespaces.EMAILADDRESS_ATTRNAME247 emailAddressAttribute.name = SamlSoapBindingApp.EMAILADDRESS_ATTRNAME 246 248 emailAddressAttribute.nameFormat = XMLConstants.XSD_NS+"#"+\ 247 249 XSStringAttributeValue.TYPE_LOCAL_NAME … … 314 316 attributeQuery.subject = Subject() 315 317 attributeQuery.subject.nameID = NameID() 316 attributeQuery.subject.nameID.format = EsgSamlNamespaces.NAMEID_FORMAT318 attributeQuery.subject.nameID.format = SamlSoapBindingApp.NAMEID_FORMAT 317 319 attributeQuery.subject.nameID.value = \ 318 320 "https://esg.prototype.ucar.edu/myopenid/testUser" … … 320 322 # special case handling for 'FirstName' attribute 321 323 fnAttribute = Attribute() 322 fnAttribute.name = EsgSamlNamespaces.FIRSTNAME_ATTRNAME324 fnAttribute.name = SamlSoapBindingApp.FIRSTNAME_ATTRNAME 323 325 fnAttribute.nameFormat = "http://www.w3.org/2001/XMLSchema#string" 324 326 fnAttribute.friendlyName = "FirstName" … … 328 330 # special case handling for 'LastName' attribute 329 331 lnAttribute = Attribute() 330 lnAttribute.name = EsgSamlNamespaces.LASTNAME_ATTRNAME332 lnAttribute.name = SamlSoapBindingApp.LASTNAME_ATTRNAME 331 333 lnAttribute.nameFormat = "http://www.w3.org/2001/XMLSchema#string" 332 334 lnAttribute.friendlyName = "LastName" … … 336 338 # special case handling for 'LastName' attribute 337 339 emailAddressAttribute = Attribute() 338 emailAddressAttribute.name = EsgSamlNamespaces.EMAILADDRESS_ATTRNAME340 emailAddressAttribute.name = SamlSoapBindingApp.EMAILADDRESS_ATTRNAME 339 341 emailAddressAttribute.nameFormat = XMLConstants.XSD_NS+"#"+\ 340 342 XSStringAttributeValue.TYPE_LOCAL_NAME … … 365 367 self.fail('Expecting "Response" element in SOAP body') 366 368 367 toSAMLTypeMap = [XSGroupRoleAttributeValueElementTree.factoryMatchFunc] 368 response = ResponseElementTree.fromXML(response.envelope.body.elem[0], 369 customToSAMLTypeMap=toSAMLTypeMap) 370 self.assert_(response) 371 372 def test03ParseResponse(self): 373 response = \ 374 '''<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 375 <SOAP-ENV:Body> 376 <samlp:Response ID="05680cb2-4973-443d-9d31-7bc99bea87c1" InResponseTo="e3183380-ae82-4285-8827-8c40613842de" IssueInstant="2009-08-17T12:28:37.325Z" Version="2.0" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"> 377 <saml:Issuer Format="urn:esg:issuer" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">ESG-NCAR</saml:Issuer> 378 <samlp:Status> 379 <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" /> 380 </samlp:Status> 381 <saml:Assertion ID="192c67d9-f9cd-457a-9242-999e7b943166" IssueInstant="2009-08-17T12:28:37.347Z" Version="2.0" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"> 382 <saml:Issuer Format="urn:esg:issuer">ESG-NCAR</saml:Issuer> 383 <saml:Subject> 384 <saml:NameID Format="urn:esg:openid">https://esg.prototype.ucar.edu/myopenid/testUser</saml:NameID> 385 </saml:Subject> 386 <saml:Conditions NotBefore="2009-08-17T12:28:37.347Z" NotOnOrAfter="2009-08-18T12:28:37.347Z" /> 387 <saml:AttributeStatement> 388 <saml:Attribute FriendlyName="FirstName" Name="urn:esg:first:name" NameFormat="http://www.w3.org/2001/XMLSchema#string"> 389 <saml:AttributeValue xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Test</saml:AttributeValue> 390 </saml:Attribute> 391 <saml:Attribute FriendlyName="LastName" Name="urn:esg:last:name" NameFormat="http://www.w3.org/2001/XMLSchema#string"> 392 <saml:AttributeValue xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">User</saml:AttributeValue> 393 </saml:Attribute> 394 <saml:Attribute FriendlyName="EmailAddress" Name="urn:esg:first:email:address" NameFormat="http://www.w3.org/2001/XMLSchema#string"> 395 <saml:AttributeValue xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">ejn@ucar.edu</saml:AttributeValue> 396 </saml:Attribute> 397 <saml:Attribute FriendlyName="GroupRole" Name="urn:esg:group:role" NameFormat="groupRole"> 398 <saml:AttributeValue> 399 <esg:groupRole group="CCSM" role="default" xmlns:esg="http://www.esg.org" /> 400 </saml:AttributeValue> 401 <saml:AttributeValue> 402 <esg:groupRole group="Dynamical Core" role="default" xmlns:esg="http://www.esg.org" /> 403 </saml:AttributeValue> 404 <saml:AttributeValue> 405 <esg:groupRole group="NARCCAP" role="default" xmlns:esg="http://www.esg.org" /> 406 </saml:AttributeValue> 407 </saml:Attribute> 408 </saml:AttributeStatement> 409 </saml:Assertion> 410 </samlp:Response> 411 </SOAP-ENV:Body> 412 </SOAP-ENV:Envelope>''' 413 414 soapResponse = SOAPEnvelope() 415 416 responseStream = StringIO() 417 responseStream.write(response) 418 responseStream.seek(0) 419 420 soapResponse.parse(responseStream) 421 422 print("Parsed response ...") 423 print(soapResponse.serialize()) 424 425 toSAMLTypeMap = [XSGroupRoleAttributeValueElementTree.factoryMatchFunc] 426 response = ResponseElementTree.fromXML(soapResponse.body.elem[0], 427 customToSAMLTypeMap=toSAMLTypeMap) 369 response = ResponseElementTree.fromXML(response.envelope.body.elem[0]) 428 370 self.assert_(response) 429 371 … … 441 383 print(soapResponse.serialize()) 442 384 443 toSAMLTypeMap = [XSGroupRoleAttributeValueElementTree.factoryMatchFunc] 444 response = ResponseElementTree.fromXML(soapResponse.body.elem[0], 445 customToSAMLTypeMap=toSAMLTypeMap) 385 response = ResponseElementTree.fromXML(soapResponse.body.elem[0]) 446 386 return response 447 387 … … 455 395 seconds=60*60*8)) 456 396 } 457 responseStr = SamlAttributeAuthorityInterfaceTestCase.RESPONSE % \397 responseStr = self.__class__.RESPONSE % \ 458 398 respDict 459 399 response = self._parseResponse(responseStr) … … 471 411 seconds=60*60*8)) 472 412 } 473 responseStr = SamlAttributeAuthorityInterfaceTestCase.RESPONSE % \413 responseStr = self.__class__.RESPONSE % \ 474 414 respDict 475 415 response = self._parseResponse(responseStr) … … 491 431 seconds=60*60*8)) 492 432 } 493 responseStr = SamlAttributeAuthorityInterfaceTestCase.RESPONSE % \433 responseStr = self.__class__.RESPONSE % \ 494 434 respDict 495 435 response = self._parseResponse(responseStr) … … 510 450 seconds=60*60*8)) 511 451 } 512 responseStr = SamlAttributeAuthorityInterfaceTestCase.RESPONSE % \452 responseStr = self.__class__.RESPONSE % \ 513 453 respDict 514 454 response = self._parseResponse(responseStr) … … 530 470 seconds=60*60*8)) 531 471 } 532 responseStr = SamlAttributeAuthorityInterfaceTestCase.RESPONSE % \472 responseStr = self.__class__.RESPONSE % \ 533 473 respDict 534 474 response = self._parseResponse(responseStr) … … 550 490 seconds=60*60*8)) 551 491 } 552 responseStr = SamlAttributeAuthorityInterfaceTestCase.RESPONSE % \492 responseStr = self.__class__.RESPONSE % \ 553 493 respDict 554 494 response = self._parseResponse(responseStr) … … 574 514 seconds=60*60*8)) 575 515 } 576 responseStr = SamlAttributeAuthorityInterfaceTestCase.RESPONSE % \ 577 respDict 516 responseStr = self.__class__.RESPONSE % respDict 578 517 response = self._parseResponse(responseStr) 579 518 binding = SubjectQuerySOAPBinding()
Note: See TracChangeset
for help on using the changeset viewer.