Changeset 3580


Ignore:
Timestamp:
11/03/08 10:28:21 (11 years ago)
Author:
pjkersha
Message:

Updated and tested against 1.3a6 10 March ET release:

  • Tests 17 and 18 now work - inclusive and exclusive C14N on SOAP message subsets.
  • Added test 19 for inclusive namespace test but fails.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/python/ndg.security.test/ndg/security/test/elementTreeC14n/testC14n.py

    r3507 r3580  
    5959        ETC14N.write(elem, f) 
    6060        c14n = f.getvalue() 
    61         self.assertEqual(c14n, '<doc>#xC2#xA9</doc>') 
    62  
     61        #self.assertEqual(c14n, '<doc>#xC2#xA9</doc>') 
     62        self.assertEqual(c14n, '<doc>\xC2\xA9</doc>') 
    6363 
    6464    def test01aPIsCommentsAndOutsideOfDocElem(self): 
     
    434434         
    435435        # Extract nodes for signing 
    436         #etRefNodes = elem.findall('.//*[@wsu:Id]', namespaces=processorNss) 
    437  
    438         # Attribute based search doesn't work - search based on node name 
    439         # instead as a temporary measure 
    440         soapEnvNS = {'SOAP-ENV':"http://schemas.xmlsoap.org/soap/envelope/"} 
    441         soapBodyElem = elem.findall('.//SOAP-ENV:Body', namespaces=soapEnvNS) 
    442          
    443         wsseNS = {'wsse':\ 
    444 "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"} 
    445         binSecTokElem = elem.findall('.//wsse:BinarySecurityToken', 
    446                                      namespaces=wsseNS) 
    447  
    448         etRefNodes = binSecTokElem + soapBodyElem 
     436        etRefNodes = elem.findall('.//*[@wsu:Id]', namespaces=processorNss) 
    449437         
    450438        for zsiRefNode, etRefNode in zip(zsiRefNodes, etRefNodes): 
     
    459447                  
    460448            f = StringIO() 
    461 #            ETC14N.write(elem, f, etRefNode) 
    462             ETC14N.write(etRefNode, f) 
     449            ETC14N.write(elem, f, subset=etRefNode) 
    463450            etRefC14n = f.getvalue() 
    464451             
     
    493480         
    494481        # Extract nodes for signing 
    495         #etRefNodes = elem.findall('.//*[@wsu:Id]', namespaces=processorNss) 
    496  
    497         # Attribute based search doesn't work - search based on node name 
    498         # instead as a temporary measure 
    499         soapEnvNS = {'SOAP-ENV':"http://schemas.xmlsoap.org/soap/envelope/"} 
    500         soapBodyElem = elem.findall('.//SOAP-ENV:Body', namespaces=soapEnvNS) 
    501          
    502         wsseNS = {'wsse':\ 
    503 "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"} 
    504         binSecTokElem = elem.findall('.//wsse:BinarySecurityToken', 
    505                                      namespaces=wsseNS) 
    506  
    507         etRefNodes = binSecTokElem + soapBodyElem 
     482        etRefNodes = elem.findall('.//*[@wsu:Id]', namespaces=processorNss) 
    508483         
    509484        for zsiRefNode, etRefNode in zip(zsiRefNodes, etRefNodes): 
     
    521496            # ElementTree equivalent      
    522497            f = StringIO() 
    523             ETC14N.write(elem, f, etRefNode) 
     498            ETC14N.write(elem, f, etRefNode, exclusive=True) 
    524499            etRefC14n = f.getvalue() 
    525500             
     
    536511        # Exclusive C14N applied to portions of a SOAP message by extracting 
    537512        # using XPath 
     513        inputFile = './soapGetAttCertResponse.xml' 
     514         
    538515        from xml.xpath.Context import Context 
    539516        from xml import xpath 
    540517        from xml.dom.ext.reader import PyExpat 
    541518        reader = PyExpat.Reader() 
    542         dom = reader.fromStream(open('./soapGetAttCertResponse.xml')) 
     519        dom = reader.fromStream(open(inputFile)) 
    543520        processorNss = \ 
    544521        { 
     
    551528                                  contextNode=dom,  
    552529                                  context=ctxt) 
    553         for zsiRefNode in zsiRefNodes: 
     530 
     531        # ElementTree 
     532        elem = ETC14N.parse(inputFile) 
     533         
     534        # Extract nodes for signing 
     535        etRefNodes = elem.findall('.//*[@wsu:Id]', namespaces=processorNss) 
     536         
     537        nsPfx = ['SOAP-ENV', 'ds'] 
     538        for zsiRefNode, etRefNode in zip(zsiRefNodes, etRefNodes): 
    554539            # Get ref node and all it's children 
    555540            refSubsetList = getChildNodes(zsiRefNode) 
    556541            zsiRefC14n = Canonicalize(dom, None, subset=refSubsetList, 
    557                                    unsuppressedPrefixes=['SOAP-ENV', 'ds']) 
     542                                   unsuppressedPrefixes=nsPfx) 
    558543 
    559544#            print "_"*80 
     
    564549                 'w').write(zsiRefC14n) 
    565550         
     551            # ElementTree equivalent      
     552            f = StringIO() 
     553            ETC14N.write(elem, f, subset=etRefNode, exclusive=True, 
     554                         inclusive_namespaces=nsPfx) 
     555            etRefC14n = f.getvalue() 
     556             
     557#            print "_"*80 
     558#            print "ElementTree Exclusive C14N %s:\n" % etRefNode.tag 
     559#            print etRefC14n 
     560            open('soapGetAttCertResponse-%s-et-exclC14n.xml' % \ 
     561                 etRefNode.tag.split('}')[-1],  
     562                 'w').write(etRefC14n) 
     563 
     564            self.assertEqual(zsiRefC14n, etRefC14n) 
     565       
    566566 
    567567def getChildNodes(node, nodeList=None): 
Note: See TracChangeset for help on using the changeset viewer.