def test_utils(self): entity_id = root(self.t).get('entityID') self.md.store.update(root(self.t), entity_id) e = self.md.lookup(entity_id)[0] assert (is_idp(e)) assert (not is_sp(e)) icon = entity_icon_url(e) assert ('url' in icon) assert ('https://www.example.com/static/images/umu_logo.jpg' in icon['url']) assert ('width' in icon) assert ('358' == icon['width']) assert ('height' in icon) assert ('63' == icon['height']) assert ('62' != icon['height']) domains = entity_domains(e) assert ('example.com' in domains) assert ('example.net' in domains) assert ('idp.example.com' not in domains) assert ('foo.com' not in domains) edup = deepcopy(e) name, desc = entity_extended_display(e) assert(name == 'Example University') assert(desc == 'Identity Provider for Example University') disp = entity_display_name(e) assert (disp == 'Example University') for elt in e.findall(".//{%s}DisplayName" % NS['mdui']): elt.getparent().remove(elt) disp = entity_display_name(e) assert (disp == 'The Example University') for elt in e.findall(".//{%s}OrganizationDisplayName" % NS['md']): elt.getparent().remove(elt) disp = entity_display_name(e) assert (disp == 'ExampleU') for elt in e.findall(".//{%s}OrganizationName" % NS['md']): elt.getparent().remove(elt) disp = entity_display_name(e) assert (disp == entity_id) e = edup subs = entity_domains(e) assert ('example.com' in subs) assert ('example.net' in subs) assert ('idp.example.com' not in subs) summary = entity_simple_summary(e) assert (summary['title'] == 'Example University') assert (summary['descr'] == 'Identity Provider for Example University') assert (summary['entityID'] == entity_id) assert ('domains' in summary) assert ('id' in summary) empty = entity_simple_summary(None) assert (not empty)
def test_utils(self): entity_id = root(self.t).get('entityID') self.md.store.update(root(self.t), entity_id) e = self.md.lookup(entity_id)[0] assert (is_idp(e)) assert (not is_sp(e)) icon = entity_icon_url(e) assert ('url' in icon) assert ('https://www.example.com/static/images/umu_logo.jpg' in icon['url']) assert ('width' in icon) assert ('358' == icon['width']) assert ('height' in icon) assert ('63' == icon['height']) assert ('62' != icon['height']) domains = entity_domains(e) assert ('example.com' in domains) assert ('example.net' in domains) assert ('idp.example.com' not in domains) assert ('foo.com' not in domains) edup = deepcopy(e) name, desc = entity_extended_display(e) assert(name == 'Example University') assert(desc == 'Identity Provider for Example University') disp = entity_display_name(e) assert (disp == 'Example University') for elt in e.findall(".//{%s}DisplayName" % NS['mdui']): elt.getparent().remove(elt) disp = entity_display_name(e) assert (disp == 'The Example University') for elt in e.findall(".//{%s}OrganizationDisplayName" % NS['md']): elt.getparent().remove(elt) disp = entity_display_name(e) assert (disp == 'ExampleU') for elt in e.findall(".//{%s}OrganizationName" % NS['md']): elt.getparent().remove(elt) disp = entity_display_name(e) assert (disp == entity_id) e = edup subs = entity_domains(e) assert ('example.com' in subs) assert ('example.net' in subs) assert ('idp.example.com' not in subs) summary = entity_simple_summary(e) assert (summary['title'] == 'Example University') assert (summary['descr'] == 'Identity Provider for Example University') assert (summary['entityID'] == entity_id) assert ('domains' in summary) assert ('id' in summary) empty = entity_simple_summary(None) assert (not empty)
def webfinger_handler(request: Request) -> Response: """An implementation the webfinger protocol (http://tools.ietf.org/html/draft-ietf-appsawg-webfinger-12) in order to provide information about up and downstream metadata available at this pyFF instance. Example: .. code-block:: bash # curl http://my.org/.well-known/webfinger?resource=http://my.org This should result in a JSON structure that looks something like this: .. code-block:: json { "expires": "2013-04-13T17:40:42.188549", "links": [ { "href": "http://reep.refeds.org:8080/role/sp.xml", "rel": "urn:oasis:names:tc:SAML:2.0:metadata" }, { "href": "http://reep.refeds.org:8080/role/sp.json", "rel": "disco-json" } ], "subject": "http://reep.refeds.org:8080" } Depending on which version of pyFF you're running and the configuration you may also see downstream metadata listed using the 'role' attribute to the link elements. """ resource = request.params.get('resource', None) rel = request.params.get('rel', None) if resource is None: resource = request.host_url jrd: Dict[str, Any] = dict() dt = datetime.now() + timedelta(hours=1) jrd['expires'] = dt.isoformat() jrd['subject'] = request.host_url links: List[Dict[str, Any]] = list() jrd['links'] = links _dflt_rels = { 'urn:oasis:names:tc:SAML:2.0:metadata': ['.xml', 'application/xml'], 'disco-json': ['.json', 'application/json'], } if rel is None or len(rel) == 0: rel = _dflt_rels.keys() else: rel = [rel] def _links(url: str, title: Any = None) -> None: if url.startswith('/'): url = url.lstrip('/') for r in rel: suffix = "" if not url.endswith('/'): suffix = _dflt_rels[r][0] links.append( dict(rel=r, type=_dflt_rels[r][1], href='%s/%s%s' % (request.host_url, url, suffix))) _links('/entities/') for a in request.registry.md.store.collections(): if a is not None and '://' not in a: _links(a) for entity in request.registry.md.store.lookup('entities'): entity_display = entity_display_name(entity) _links("/entities/%s" % hash_id(entity.get('entityID')), title=entity_display) aliases = request.registry.aliases for a in aliases.keys(): for v in request.registry.md.store.attribute(aliases[a]): _links('%s/%s' % (a, quote_plus(v))) response = Response(dumps(jrd, default=json_serializer)) response.headers['Content-Type'] = 'application/json' return response