def test_all_entities_parses(self): r = requests.get("http://127.0.0.1:%s/entities" % self.port) assert (r.status_code == 200) # assert (r.encoding == 'utf8') t = parse_xml(six.BytesIO(r.content)) assert (t is not None) validate_document(t)
def publish(req, *opts): """ Publish the working document in XML form. :param req: The request :param opts: Options (unused) :return: None Publish takes one argument: path to a file where the document tree will be written. **Examples** .. code-block:: yaml - publish: /tmp/idp.xml """ if req.t is None: raise PipeException("Empty document submitted for publication") if req.args is None: raise PipeException("publish must specify output") try: validate_document(req.t) except DocumentInvalid, ex: log.error(ex.error_log) raise PipeException("XML schema validation failed")
def test_all_entities_parses(self): r = requests.get("http://127.0.0.1:8080/entities") assert (r.status_code == 200) #assert (r.encoding == 'utf8') t = parse_xml(StringIO(r.content)) assert (t is not None) validate_document(t)
def filter_or_validate( t: ElementTree, filter_invalid: bool = False, base_url: str = "", source=None, validation_errors: Optional[Dict[str, Any]] = None, ) -> ElementTree: if validation_errors is None: validation_errors = {} log.debug("Filtering invalids from {}".format(base_url)) if filter_invalid: t = filter_invalids_from_document(t, base_url=base_url, validation_errors=validation_errors) for entity_id, err in validation_errors.items(): log.error( "Validation error while parsing {} (from {}). Removed @entityID='{}': {}" .format(base_url, source, entity_id, err)) else: # all or nothing log.debug("Validating (one-shot) {}".format(base_url)) try: validate_document(t) except DocumentInvalid as ex: err = xml_error(ex.error_log, m=base_url) validation_errors[base_url] = err raise MetadataException( "Validation error while parsing {}: (from {}): {}".format( base_url, source, err)) return t
def test_alias_ndn(self): r = requests.get("http://127.0.0.1:%s/ndn.xml" % self.port) assert (r.status_code == 200) # assert (r.encoding == 'utf8') t = parse_xml(six.BytesIO(r.content)) assert (t is not None) assert (root(t).get('entityID') == 'https://idp.nordu.net/idp/shibboleth') validate_document(t)
def test_alias_ndn(self): r = requests.get("http://127.0.0.1:%s/ndn.xml" % self.port) assert r.status_code == 200 # assert (r.encoding == 'utf8') t = parse_xml(StringIO(r.content)) assert t is not None assert root(t).get("entityID") == "https://idp.nordu.net/idp/shibboleth" validate_document(t)
def test_alias_ndn(self): r = requests.get("http://127.0.0.1:8080/ndn.xml") assert (r.status_code == 200) #assert (r.encoding == 'utf8') t = parse_xml(StringIO(r.content)) assert (t is not None) assert ( root(t).get('entityID') == 'https://idp.nordu.net/idp/shibboleth') validate_document(t)
def publish(req, *opts): """ Publish the working document in XML form. :param req: The request :param opts: Options (unused) :return: None Publish takes one argument: path to a file where the document tree will be written. **Examples** .. code-block:: yaml - publish: /tmp/idp.xml """ if req.t is None: raise PipeException("Empty document submitted for publication") if req.args is None: raise PipeException("publish must specify output") try: validate_document(req.t) except DocumentInvalid as ex: log.error(ex.error_log) raise PipeException("XML schema validation failed") output_file = None if type(req.args) is dict: output_file = req.args.get("output", None) else: output_file = req.args[0] if output_file is not None: output_file = output_file.strip() log.debug("publish {}".format(output_file)) resource_name = output_file m = re.match(FILESPEC_REGEX, output_file) if m: output_file = m.group(1) resource_name = m.group(2) log.debug("output_file={}, resource_name={}".format( output_file, resource_name)) out = output_file if os.path.isdir(output_file): out = "{}.xml".format(os.path.join(output_file, req.id)) safe_write(out, dumptree(req.t)) req.md.store.update( req.t, tid=resource_name ) # TODO maybe this is not the right thing to do anymore return req.t
def validate(req, *opts): """ Validate the working document :param req: The request :param opts: Not used :return: The unmodified tree Generate an exception unless the working tree validates. Validation is done automatically during publication and loading of metadata so this call is seldom needed. """ if req.t is not None: validate_document(req.t) return req.t