コード例 #1
0
ファイル: test_t9.py プロジェクト: 0z-cloud/ZSI-Py3
 def check_c14n_exc(self):
     """http://www.w3.org/TR/xml-exc-c14n/
     """
     s = StringIO()
     Canonicalize(self.el, s, unsuppressedPrefixes=[])
     cxml = s.getvalue()
     d1 = base64.encodestring(sha.sha(C14N_EXCL1).digest()).strip()
     d2 = base64.encodestring(sha.sha(cxml).digest()).strip()
     self.assertEqual(d1, C14N_EXCL1_DIGEST)
     self.assertEqual(d1, d2)
コード例 #2
0
ファイル: test_t9.py プロジェクト: acigna/pywez
 def check_c14n(self):
     """http://www.w3.org/TR/xml-c14n
     """
     s = StringIO()
     Canonicalize(self.el, s, unsuppressedPrefixes=None)
     cxml = s.getvalue()
     d1 = base64.encodestring(local_sha(C14N_INC1).digest()).strip()
     d2 = base64.encodestring(local_sha(cxml).digest()).strip()
     self.assertEqual(d1, d2)
     self.assertEqual(d1, C14N_INC1_DIGEST)
コード例 #3
0
ファイル: test_t9.py プロジェクト: 0z-cloud/ZSI-Py3
 def check_c14n_exc2_unsuppressed(self):
     """http://www.w3.org/TR/xml-exc-c14n/
     The method of canonicalization described in this specification receives 
     an InclusiveNamespaces PrefixList parameter, which lists namespace prefixes 
     that are handled in the manner described by the Canonical XML Recommendation 
     """
     s = StringIO()
     Canonicalize(self.el, s, unsuppressedPrefixes=['xsi', 'xsd'])
     cxml = s.getvalue()
     d1 = base64.encodestring(sha.sha(C14N_EXCL2).digest()).strip()
     d2 = base64.encodestring(sha.sha(cxml).digest()).strip()
     self.assertEqual(d1, C14N_EXCL2_DIGEST)
     self.assertEqual(d1, d2)
コード例 #4
0
ファイル: test_t9.py プロジェクト: 0z-cloud/ZSI-Py3
    def check_c14n_exc3(self):
        """http://www.w3.org/TR/xml-exc-c14n/
        tests if a namespace defined in a parent node to the top node 
        to be canonicalized is added when discovered that this namespace
        is used.
        """
        self.ps = ParsedSoap(XML_INST2)
        self.el = self.ps.body

        s = StringIO()
        Canonicalize(self.el, s, unsuppressedPrefixes=[])
        cxml = s.getvalue()
        print(cxml)
        d1 = base64.encodestring(sha.sha(C14N_EXCL3).digest()).strip()
        d2 = base64.encodestring(sha.sha(cxml).digest()).strip()
        self.assertEqual(d1, C14N_EXCL3_DIGEST)
        self.assertEqual(d1, d2)
コード例 #5
0
    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)
コード例 #6
0
    def checkt6(self):
        try:
            istr = io.StringIO(intext)
            m = mimetools.Message(istr)
            cid = resolvers.MIMEResolver(m['content-type'], istr)
            xml = cid.GetSOAPPart()
            ps = ParsedSoap(xml, resolver=cid.Resolve)
        except ParseException as e:
            print(FaultFromZSIException(e).AsSOAP(), file=OUT)
            self.fail()
        except Exception as e:
            # Faulted while processing; assume it's in the header.
            print(FaultFromException(e, 1,
                                     sys.exc_info()[2]).AsSOAP(),
                  file=OUT)
            self.fail()

        try:
            dict = ps.Parse(typecode)
        except Exception as e:
            # Faulted while processing; now it's the body
            print(FaultFromException(e, 0,
                                     sys.exc_info()[2]).AsSOAP(),
                  file=OUT)
            self.fail()

        self.assertEqual(dict['stringtest'], strExtTest,
                         "Failed to extract stringtest correctly")
        print(base64.encodestring(cid['*****@*****.**'].read()))
        v = dict['b64']
        print(type(v), 'is type(v)')
        self.assertEqual(cid['*****@*****.**'].getvalue(), v, "mismatch")
        print(base64.encodestring(v))
        from ZSI.wstools.c14n import Canonicalize
        z = dict['xmltest']
        print(type(z), z)
        print(Canonicalize(z))
コード例 #7
0
ファイル: Utility.py プロジェクト: 0z-cloud/ZSI-Py3
 def canonicalize(self):
     return Canonicalize(self.node)
コード例 #8
0
            # Faulted while processing; now it's the body
            print >> OUT, FaultFromException(e, 0, sys.exc_info()[2]).AsSOAP()
            self.fail()

        self.failUnlessEqual(dict['stringtest'], strExtTest,
                             "Failed to extract stringtest correctly")
        print base64.encodestring(cid['*****@*****.**'].read())
        v = dict['b64']
        print type(v), 'is type(v)'
        self.failUnlessEqual(cid['*****@*****.**'].getvalue(), v,
                             "mismatch")
        print base64.encodestring(v)
        from ZSI.wstools.c14n import Canonicalize
        z = dict['xmltest']
        print type(z), z
        print Canonicalize(z)


def makeTestSuite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(t6TestCase, "check"))
    return suite


def main():
    unittest.main(defaultTest="makeTestSuite")


OUT = sys.stdout
typecode = TC.Struct(None, [
    TC.String('b64'),