def test02SendQuery(self): query_binding = AttributeQuerySslSOAPBinding() attribute_query = AttributeQueryFactory.create() attribute_query.subject.nameID.format = self.__class__.SUBJECT_FORMAT attribute_query.subject.nameID.value = self.__class__.SUBJECT attribute_query.issuerName = '/O=Site A/CN=Authorisation Service' attribute = Attribute() attribute.name = 'urn:ndg:saml:emailaddress' attribute.friendlyName = 'emailAddress' attribute.nameFormat = 'http://www.w3.org/2001/XMLSchema' attribute_query.attributes.append(attribute) query_binding.clockSkewTolerance = 2. query_binding.sslCACertDir = self.__class__.CLIENT_CACERT_DIR query_binding.sslCertFilePath = self.__class__.CLIENT_CERT_FILEPATH query_binding.sslPriKeyFilePath = self.__class__.CLIENT_PRIKEY_FILEPATH query_binding.sslValidDNs = self.__class__.VALID_DNS response = query_binding.send(attribute_query, uri=self.__class__.SERVICE_URI) # Convert back to ElementTree instance read for string output samlResponseElem = ResponseElementTree.toXML(response) print("SAML Response ...") print(ElementTree.tostring(samlResponseElem)) print("Pretty print SAML Response ...") print(prettyPrint(samlResponseElem)) self.assert_(response.status.statusCode.value==StatusCode.SUCCESS_URI)
def display_result(self, response): # Convert back to ElementTree instance read for string output saml_response_elem = ResponseElementTree.toXML(response) if self.pretty_print: print(prettyPrint(saml_response_elem)) else: print(ElementTree.tostring(saml_response_elem))
def send(self, soapRequest): """Make a request to the given URL with a SOAP Request object""" if not isinstance(soapRequest, UrlLib2SOAPRequest): raise TypeError('UrlLib2SOAPClient.send: expecting %r ' 'derived type for SOAP request, got %r' % (self.responseEnvelopeClass, type(soapRequest))) if not isinstance(soapRequest.envelope, self.responseEnvelopeClass): raise TypeError('UrlLib2SOAPClient.send: expecting %r ' 'derived type for SOAP envelope, got %r' % (self.responseEnvelopeClass, type(soapRequest))) if self.timeout is not None: arg = (self.timeout,) else: arg = () soapRequestStr = soapRequest.envelope.serialize() logLevel = log.getEffectiveLevel() if logLevel <= logging.DEBUG: from ndg.soap.utils.etree import prettyPrint log.debug("SOAP Request:") log.debug("_"*80) log.debug(prettyPrint(soapRequest.envelope.elem)) soapResponse = UrlLib2SOAPResponse() urllib2Request = urllib2.Request(soapRequest.url) for i in self.httpHeader.items(): urllib2Request.add_header(*i) response = self.openerDirector.open(urllib2Request, soapRequestStr, *arg) if response.code != httplib.OK: excep = HTTPException("Response for request to [%s] is: %d %s" % (soapRequest.url, response.code, response.msg)) excep.urllib2Response = response raise excep # Check for accepted response type string in response from server accepted_response_content_type = False for content_type in UrlLib2SOAPClient.RESPONSE_CONTENT_TYPES: if content_type in response.headers.typeheader: accepted_response_content_type = True if not accepted_response_content_type: responseType = ', '.join(UrlLib2SOAPClient.RESPONSE_CONTENT_TYPES) excep = SOAPResponseError("Expecting %r response type; got %r for " "request to [%s]" % (responseType, response.headers.typeheader, soapRequest.url)) excep.urllib2Response = response raise excep soapResponse.fileObject = response soapResponse.envelope = self.responseEnvelopeClass() try: soapResponse.envelope.parse(soapResponse.fileObject) except Exception, e: raise SOAPParseError("%r type error raised parsing response for " "request to [%s]: %s" % (type(e), soapRequest.url, e))