aboutsummaryrefslogtreecommitdiff
path: root/rpkid/xml-parse-test.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2008-02-27 19:02:11 +0000
committerRob Austein <sra@hactrn.net>2008-02-27 19:02:11 +0000
commite1bc9584d821857a9a1869f38b934812ff60f7fb (patch)
treec9c1f45818ab9f4e6dacefc1428c9a9dcb67c0fd /rpkid/xml-parse-test.py
parenta9ecdddda7c364cd62dbd1c16fc0f19615fe288e (diff)
Filename cleanup
svn path=/rpkid/Makefile; revision=1531
Diffstat (limited to 'rpkid/xml-parse-test.py')
-rwxr-xr-xrpkid/xml-parse-test.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/rpkid/xml-parse-test.py b/rpkid/xml-parse-test.py
new file mode 100755
index 00000000..bde7d167
--- /dev/null
+++ b/rpkid/xml-parse-test.py
@@ -0,0 +1,67 @@
+# $Id$
+
+# Copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND ARIN DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS. IN NO EVENT SHALL ARIN BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+
+import glob, rpki.up_down, rpki.left_right, rpki.relaxng, xml.sax, lxml.etree, lxml.sax, POW, POW.pkix
+
+verbose = True
+
+def test(fileglob, rng, sax_handler, encoding, tester=None):
+ files = glob.glob(fileglob)
+ files.sort()
+ for f in files:
+ print "\n<!--", f, "-->"
+ handler = sax_handler()
+ elt_in = lxml.etree.parse(f).getroot()
+ rng.assertValid(elt_in)
+ lxml.sax.saxify(elt_in, handler)
+ elt_out = handler.result.toXML()
+ rng.assertValid(elt_out)
+ if (tester):
+ tester(elt_in, elt_out, handler.result)
+ print lxml.etree.tostring(elt_out, pretty_print=True, encoding=encoding, xml_declaration=True)
+
+def pprint_cert(cert):
+ print cert.get_POW().pprint()
+
+def ud_tester(elt_in, elt_out, msg):
+ assert isinstance(msg, rpki.up_down.message_pdu)
+ if verbose:
+ if isinstance(msg.payload, rpki.up_down.list_response_pdu):
+ for c in msg.payload.classes:
+ for i in range(len(c.certs)):
+ print "[Certificate #%d]" % i
+ pprint_cert(c.certs[i].cert)
+ print "[Issuer]"
+ pprint_cert(c.issuer)
+
+def lr_tester(elt_in, elt_out, msg):
+ assert isinstance(msg, rpki.left_right.msg)
+ if verbose:
+ for bsc in [x for x in msg if isinstance(x, rpki.left_right.bsc_elt)]:
+ for cert in bsc.signing_cert:
+ pprint_cert(cert)
+
+test(fileglob="up-down-protocol-samples/*.xml",
+ rng=rpki.relaxng.up_down,
+ sax_handler=rpki.up_down.sax_handler,
+ encoding="utf-8",
+ tester=ud_tester)
+
+test(fileglob="left-right-protocol-samples/*.xml",
+ rng=rpki.relaxng.left_right,
+ sax_handler=rpki.left_right.sax_handler,
+ encoding="us-ascii",
+ tester=lr_tester)