def fetch_nodeinfo_document(host): doc, status_code, error = fetch_document(host=host, path='/.well-known/nodeinfo') if not doc: return try: doc = json.loads(doc) except json.JSONDecodeError: return url, highest_version = '', 0.0 if doc.get('0'): # Buggy NodeInfo from certain old Hubzilla versions url = doc.get('0', {}).get('href') elif isinstance(doc.get('links'), dict): # Another buggy NodeInfo from certain old Hubzilla versions url = doc.get('links').get('href') else: for link in doc.get('links'): version = float(link.get('rel').split('/')[-1]) if highest_version < version <= HIGHEST_SUPPORTED_NODEINFO_VERSION: url, highest_version = link.get('href'), version if not url: return doc, status_code, error = fetch_document(url=url) if not doc: return try: doc = json.loads(doc) except json.JSONDecodeError: return return parse_nodeinfo_document(doc, host)
def test_parse_nodeinfo_21_document__invalid_usage_counts(self): result = parse_nodeinfo_document( json.loads(NODEINFO_21_DOC_INVALID_USAGE_COUNTS), 'pleroma.local') assert result == { 'organization': { 'account': '', 'contact': '', 'name': '', }, 'host': 'pleroma.local', 'name': 'pleroma.local', 'open_signups': True, 'protocols': ["activitypub"], 'relay': '', 'server_meta': {}, 'services': [], 'platform': 'pleroma', 'version': '0.7.4.0-pd0313756', 'features': {}, 'activity': { 'users': { 'total': 348, 'half_year': None, 'monthly': None, 'weekly': None, }, 'local_posts': None, 'local_comments': None, }, }
def test_parse_nodeinfo_20_document(self): result = parse_nodeinfo_document(json.loads(NODEINFO_20_DOC), 'iliketoast.net') assert result == { 'organization': { 'account': '*****@*****.**', 'contact': '', 'name': '', }, 'host': 'iliketoast.net', 'name': 'I Like Toast', 'open_signups': True, 'protocols': ["diaspora"], 'relay': '', 'server_meta': {}, 'services': ["tumblr", "twitter"], 'platform': 'diaspora', 'version': '0.7.4.0-pd0313756', 'features': { "nodeName": "I Like Toast", "xmppChat": False, "camo": { "markdown": False, "opengraph": False, "remotePods": False }, "adminAccount": "podmin", }, 'activity': { 'users': { 'total': 348, 'half_year': 123, 'monthly': 62, 'weekly': 19, }, 'local_posts': 8522, 'local_comments': 17671, }, }