def test_local_serialize_schema(self): from ZSI import SoapWriter from ZSI import _child_elements from xml.dom.ext.reader import PyExpat msg = self.client_module.DSQueryRegistrySoapOut() msg.DSQueryRegistryResult = msg.new_DSQueryRegistryResult() msg.DSQueryRegistryResult.Any = 'hi' input = open('wsdl/nvo-admin.wsdl').read() reader = PyExpat.Reader() dom = reader.fromString(input) dnode = _child_elements(dom)[0] tnode = _child_elements(dnode)[0] snode = _child_elements(tnode)[0] msg.DSQueryRegistryResult.Schema = snode sw = SoapWriter() sw.serialize(msg) soap = str(sw) print soap ps = ParsedSoap(soap) pyobj = ps.Parse(msg.typecode) self.failUnlessEqual(pyobj.DSQueryRegistryResult.Any, msg.DSQueryRegistryResult.Any) self.failUnless(_is_element(pyobj.DSQueryRegistryResult.Schema)) print _get_element_nsuri_name(pyobj.DSQueryRegistryResult.Schema) self.failUnlessEqual(_get_element_nsuri_name(pyobj.DSQueryRegistryResult.Schema), (u'http://www.w3.org/2001/XMLSchema', u'schema'))
def test_local_serialize_schema(self): from ZSI import SoapWriter from ZSI import _child_elements from xml.dom.ext.reader import PyExpat msg = self.client_module.DSQueryRegistrySoapOut() msg.DSQueryRegistryResult = msg.new_DSQueryRegistryResult() msg.DSQueryRegistryResult.Any = 'hi' input = open('wsdl/nvo-admin.wsdl').read() reader = PyExpat.Reader() dom = reader.fromString(input) dnode = _child_elements(dom)[0] tnode = _child_elements(dnode)[0] snode = _child_elements(tnode)[0] msg.DSQueryRegistryResult.Schema = snode sw = SoapWriter() sw.serialize(msg) soap = str(sw) print(soap) ps = ParsedSoap(soap) pyobj = ps.Parse(msg.typecode) self.assertEqual(pyobj.DSQueryRegistryResult.Any, msg.DSQueryRegistryResult.Any) self.assertTrue(_is_element(pyobj.DSQueryRegistryResult.Schema)) print(_get_element_nsuri_name(pyobj.DSQueryRegistryResult.Schema)) self.assertEqual( _get_element_nsuri_name(pyobj.DSQueryRegistryResult.Schema), ('http://www.w3.org/2001/XMLSchema', 'schema'))
def getOperationName(self, ps, action): '''Returns operation name. action -- soapAction value ''' method = self.root.get(_get_element_nsuri_name(ps.body_root)) or \ self.soapAction.get(action) if method is None: raise UnknownRequestException, \ 'failed to map request to a method: action(%s), root%s' %(action,_get_element_nsuri_name(ps.body_root)) return method
def getOperationName(self, ps, action): '''Returns operation name. action -- soapAction value ''' method = self.soapAction.get(action) or \ self.root.get(_get_element_nsuri_name(ps.body_root)) if method is None: raise UnknownRequestException, \ 'failed to map request to a method: action(%s), root%s' %(action,_get_element_nsuri_name(ps.body_root)) return method
def processRequest(cls, ps, **kw): """invokes callback that should return a (request,response) tuple. representing the SOAP request and response respectively. ps -- ParsedSoap instance representing HTTP Body. request -- twisted.web.server.Request """ resource = kw['resource'] request = kw['request'] method = getattr(resource, 'wsa_%s' % _get_element_nsuri_name(ps.body_root)[-1]) # TODO: grab ps.address, clean this up. try: req_pyobj,rsp_pyobj = method(ps, ps.address, request=request) except TypeError as ex: log.err( 'ERROR: service %s is broken, method MUST return request, response'\ %self.__class__.__name__ ) raise except Exception as ex: log.err('failure when calling bound method') raise return rsp_pyobj
def processRequest(self, ps, **kw): # TODO: Clean this up resource = kw['resource'] d = getattr(resource, 'root', None) key = _get_element_nsuri_name(ps.body_root) if d is None or d.has_key(key) is False: raise RuntimeError,\ 'Error looking for key(%s) in root dictionary(%s)' %(key, str(d)) self.op_name = d[key] self.address = address = Address() address.parse(ps) action = address.getAction() if not action: raise WSActionException('No WS-Action specified in Request') request = kw['request'] http_headers = request.getAllHeaders() soap_action = http_headers.get('soapaction') if soap_action and soap_action.strip('\'"') != action: raise WSActionException(\ 'SOAP Action("%s") must match WS-Action("%s") if specified.'\ %(soap_action,action) ) # Save WS-Address in ParsedSoap instance. ps.address = address return ps
def processRequest(cls, ps, **kw): """invokes callback that should return a (request,response) tuple. representing the SOAP request and response respectively. ps -- ParsedSoap instance representing HTTP Body. request -- twisted.web.server.Request """ resource = kw['resource'] request = kw['request'] method = getattr(resource, 'wsa_%s' % _get_element_nsuri_name(ps.body_root)[-1]) # TODO: grab ps.address, clean this up. try: req_pyobj, rsp_pyobj = method(ps, ps.address, request=request) except TypeError as ex: log.err( 'ERROR: service %s is broken, method MUST return request, response'\ %self.__class__.__name__ ) raise except Exception as ex: log.err('failure when calling bound method') raise return rsp_pyobj
def processRequest(cls, ps, **kw): """invokes callback that should return a (request,response) tuple. representing the SOAP request and response respectively. ps -- ParsedSoap instance representing HTTP Body. request -- twisted.web.server.Request """ resource = kw['resource'] request = kw['request'] root = _get_element_nsuri_name(ps.body_root) for key, method in inspect.getmembers(resource, inspect.ismethod): if (getattr(method, 'soapmethod', False) and method.root == root): break else: raise RuntimeError('Missing soap callback method for root "%s"' % root) try: req = ps.Parse(method.requesttypecode) except Exception as ex: raise try: rsp = method.responsetypecode.pyclass() except Exception as ex: raise try: req, rsp = method(req, rsp) except Exception as ex: raise return rsp
def processRequest(cls, ps, **kw): """invokes callback that should return a (request,response) tuple. representing the SOAP request and response respectively. ps -- ParsedSoap instance representing HTTP Body. request -- twisted.web.server.Request """ resource = kw['resource'] request = kw['request'] method = getattr(resource, 'soap_%s' % _get_element_nsuri_name(ps.body_root)[-1]) try: req,rsp = method(ps, request=request) except Exception, ex: raise
def processRequest(cls, ps, **kw): """invokes callback that should return a (request,response) tuple. representing the SOAP request and response respectively. ps -- ParsedSoap instance representing HTTP Body. request -- twisted.web.server.Request """ resource = kw["resource"] request = kw["request"] method = getattr(resource, "soap_%s" % _get_element_nsuri_name(ps.body_root)[-1]) try: req_pyobj, rsp_pyobj = method(ps, request=request) except TypeError, ex: log.err("ERROR: service %s is broken, method MUST return request, response" % cls.__name__) raise
def processRequest(cls, ps, **kw): """invokes callback that should return a (request,response) tuple. representing the SOAP request and response respectively. ps -- ParsedSoap instance representing HTTP Body. request -- twisted.web.server.Request """ resource = kw['resource'] request = kw['request'] method = getattr(resource, 'soap_%s' % _get_element_nsuri_name(ps.body_root)[-1]) try: req, rsp = method(ps, request=request) except Exception, ex: raise
def processRequest(cls, ps, **kw): """invokes callback that should return a (request,response) tuple. representing the SOAP request and response respectively. ps -- ParsedSoap instance representing HTTP Body. request -- twisted.web.server.Request """ resource = kw['resource'] request = kw['request'] method = getattr(resource, 'soap_%s' % _get_element_nsuri_name(ps.body_root)[-1]) try: req_pyobj,rsp_pyobj = method(ps, request=request) except TypeError, ex: log.err( 'ERROR: service %s is broken, method MUST return request, response'\ % cls.__name__ ) raise
def processRequest(cls, ps, **kw): """invokes callback that should return a (request,response) tuple. representing the SOAP request and response respectively. ps -- ParsedSoap instance representing HTTP Body. request -- twisted.web.server.Request """ resource = kw['resource'] request = kw['request'] root = _get_element_nsuri_name(ps.body_root) for key,method in inspect.getmembers(resource, inspect.ismethod): if (getattr(method, 'soapmethod', False) and method.root == root): break else: raise RuntimeError, 'Missing soap callback method for root "%s"' %root try: req = ps.Parse(method.requesttypecode) except Exception, ex: raise
def xcheck_c14n_exc4(self): RCVDIGEST = "jhTbi7gWlY9oLqsRr+EZ0bokRFA=" CALDIGEST = "IkMyI4zCDlK41qE7sZxvkFHJioU=" d1 = base64.encodestring(local_sha(WRONG).digest()).strip() d2 = base64.encodestring(local_sha(CORRECT).digest()).strip() ps = ParsedSoap(XML_INST4) el = filter(lambda el: _get_element_nsuri_name(el) == (WSA200403.ADDRESS, "MessageID"), ps.header_elements)[0] s = StringIO() Canonicalize(el, s, unsuppressedPrefixes=[]) cxml = s.getvalue() # print "-- "*20 # print cxml # print "-- "*20 d3 = base64.encodestring(local_sha(cxml).digest()).strip() self.assertEqual(d1, RCVDIGEST) self.assertEqual(d2, CALDIGEST) self.assertEqual(d3, CALDIGEST)
def xcheck_c14n_exc4(self): RCVDIGEST = "jhTbi7gWlY9oLqsRr+EZ0bokRFA=" CALDIGEST = "IkMyI4zCDlK41qE7sZxvkFHJioU=" d1 = base64.encodestring(sha.sha(WRONG).digest()).strip() d2 = base64.encodestring(sha.sha(CORRECT).digest()).strip() ps = ParsedSoap(XML_INST4) el = filter(lambda el: _get_element_nsuri_name(el) == (WSA200403.ADDRESS, "MessageID"), ps.header_elements)[0] s = StringIO() Canonicalize(el, s, unsuppressedPrefixes=[]) cxml = s.getvalue() print "-- "*20 print cxml print "-- "*20 d3 = base64.encodestring(sha.sha(cxml).digest()).strip() self.assertEqual(d1, RCVDIGEST) self.assertEqual(d2, CALDIGEST) self.assertEqual(d3, CALDIGEST)
def getSubstitutionElement(self, elt, ps): """if elt matches a member of the head substitutionGroup, return the GED typecode representation of the member. head -- ElementDeclaration typecode, elt -- the DOM element being parsed ps -- ParsedSoap instance """ nsuri, ncname = _get_element_nsuri_name(elt) typecode = GED(nsuri, ncname) if typecode is None: return try: nsuri, ncname = typecode.substitutionGroup except (AttributeError, TypeError): return if (ncname == self.pname) and (nsuri == self.nspname or (not nsuri and not self.nspname)): return typecode return
def getSubstitutionElement(self, elt, ps): '''if elt matches a member of the head substitutionGroup, return the GED typecode representation of the member. head -- ElementDeclaration typecode, elt -- the DOM element being parsed ps -- ParsedSoap instance ''' nsuri,ncname = _get_element_nsuri_name(elt) typecode = GED(nsuri,ncname) if typecode is None: return try: nsuri,ncname = typecode.substitutionGroup except (AttributeError, TypeError): return if (ncname == self.pname) and (nsuri == self.nspname or (not nsuri and not self.nspname)): return typecode return
def setUp(self): self.ps = ParsedSoap(XML_INST1) self.el = filter( lambda el: _get_element_nsuri_name(el) == (WSA200403.ADDRESS, "From"), self.ps.header_elements)[0]
def setUp(self): self.ps = ParsedSoap(XML_INST1) self.el = filter(lambda el: _get_element_nsuri_name(el) == (WSA200403.ADDRESS, "From"), self.ps.header_elements)[0]
def setUp(self): self.ps = ParsedSoap(XML_INST1) self.el = [ el for el in self.ps.header_elements if _get_element_nsuri_name(el) == (WSA200403.ADDRESS, "From") ][0]