Changeset 3272 for TI12-security


Ignore:
Timestamp:
25/01/08 15:51:12 (12 years ago)
Author:
pjkersha
Message:
  • added getChildNodes() - appends to a list all descendants of a given node. Use this to pass as subset keyword to Canonicalize. This avoids an extra XPath call.
  • tested against libxml2 testC14N equivalent call and the outputs match:

./testC14N --exc-without-comments ./ChargeAmountReq_unpatched.xml test.xpath > ./output.xml

test.xpath content is:

<XPath xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
(. | @* | namespace::*)[ancestor-or-self::SOAP-ENV:Body]
</XPath>

i.e. get SOAP-ENV:Body and descendants

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/python/Tests/joachim/test.py

    r3264 r3272  
    11#!/usr/bin/env python 
     2 
     3from ZSI.wstools.Namespaces import DSIG, ENCRYPTION, OASIS, WSU, WSA200403, \ 
     4                                   SOAP, SCHEMA # last included for xsi 
    25 
    36# Canonicalization 
     
    912from xml.xpath.Context import Context 
    1013from xml import xpath 
    11   
     14#import Ft.Xml.XPath as xpath 
    1215 
    1316def test(): 
     
    2225#        'ns1':    "http://www.csapi.org/schema/parlayx/payment/amount_charging/v3_1/local", 
    2326#        'ds':     DSIG.BASE,  
    24 #        'wsu':    "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", 
     27        'wsu':    "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", 
    2528#        'wsse':   OASIS.WSSE,  
    26         'SOAP-ENV':"http://schemas.xmlsoap.org/soap/envelope/"  
     29#        'SOAP-ENV':"http://schemas.xmlsoap.org/soap/envelope/"  
    2730    } 
    2831 
    29     # Serialize and re-parse prior to reference generation - calculating 
    30     # canonicalization based on soapWriter.dom.node seems to give an 
    31     # error: the order of wsu:Id attribute is not correct 
    3232    docNode = Reader().fromString(xml) 
    3333    ctxt = Context(docNode, processorNss=processorNss) 
    34     query = '(//. | //@* | //namespace::*)[ancestor-or-self::SOAP-ENV:Body]' 
    35     refNodes = xpath.Evaluate(query,  
     34    refNodes = xpath.Evaluate('//*[@wsu:Id]',  
    3635                              contextNode=docNode,  
    3736                              context=ctxt) 
    38      
    39     refC14n = Canonicalize(docNode, None, subset=refNodes, 
    40                            unsuppressedPrefixes=[]) 
    41     print refC14n 
    42     import pdb;pdb.set_trace() 
     37    for refNode in refNodes: 
     38        # Get ref node and all it's children 
     39#        processorNss = {refNode.prefix: refNode.namespaceURI} 
     40#        refSubsetQuery='(//. | //@* | //namespace::*)[ancestor-or-self::%s]' %\ 
     41#                                                            refNode.nodeName 
     42#        refCtx = Context(docNode, processorNss=processorNss) 
     43#        refSubsetList = xpath.Evaluate(refSubsetQuery,  
     44#                                       contextNode=docNode,  
     45#                                       context=refCtx) 
     46        refSubsetList = getChildNodes(refNode, [refNode]) 
     47        refC14n = Canonicalize(docNode, None, subset=refSubsetList, 
     48                               unsuppressedPrefixes=[]) 
     49        print refC14n 
     50        import pdb;pdb.set_trace() 
     51 
     52def getChildNodes(node, nodeList=None): 
     53 
     54    if node.attributes is not None: 
     55        nodeList += node.attributes.values()  
     56    nodeList += node.childNodes 
     57    for childNode in node.childNodes: 
     58        getChildNodes(childNode, nodeList) 
     59    return nodeList 
    4360 
    4461if __name__ == "__main__": 
Note: See TracChangeset for help on using the changeset viewer.