def test_xml_sign(self): evt2220_not_signed = xml.load_fromfile( os.path.join(here, 'xml', 'S-2220_not_signed.xml')) xmlschema = xml.XMLValidate(evt2220_not_signed) isvalid = xmlschema.isvalid() self.assertFalse(isvalid, msg=str(xmlschema.last_error)) # Test signing cert_data = pkcs12_data(cert_file=os.path.join( there, 'certs', 'libesocial-cert-test.pfx'), password='******') evt2220_signed = xml.sign(evt2220_not_signed, cert_data) xml.XMLValidate(evt2220_signed).validate()
def test_S2220_xml(self): evt2220 = xml.load_fromfile(os.path.join(here, 'xml', 'S-2220.xml')) isvalid = True try: xml.XMLValidate(evt2220).validate() except AssertionError: isvalid = False self.assertTrue(isvalid)
def add_event(self, event): if not isinstance(event, etree._ElementTree): raise ValueError('Not an ElementTree instance!') if len(self.batch) < self.max_batch_size: # Normally, the element with Id attribute is the first one event.getroot().getchildren()[0].set('Id', self._event_id()) # Signing... event_signed = xml.sign(event, self.cert_data) # Validating xml.XMLValidate(event_signed).validate() # Adding the event to batch self.batch.append(event_signed) else: raise Exception('More than {} events per batch is not permitted!'.format(self.max_batch_size))
def validate_envelop(self, which, envelop): xmlschema = self._xsd(which) element_test = envelop if not isinstance(envelop, etree._ElementTree): element_test = etree.ElementTree(envelop) xml.XMLValidate(element_test, xsd=xmlschema).validate()