# coding=utf-8 """Unit tests for webfinger.py.""" import copy import html from unittest.mock import patch import urllib.parse from oauth_dropins.webutil.testutil import requests_response # import first so that Fake is defined before URL routes are registered from . import testutil import common from web import Web from .test_web import ACTOR_HTML WEBFINGER = { 'subject': 'acct:user.com@user.com', 'aliases': [ 'https://user.com/about-me', 'https://user.com/', ], 'links': [{ 'rel': 'http://webfinger.net/rel/profile-page', 'type': 'text/html', 'href': 'https://user.com/about-me', }, { 'rel': 'http://webfinger.net/rel/profile-page', 'type': 'text/html', 'href': 'https://user.com/', }, { 'rel': 'http://webfinger.net/rel/avatar', 'href': 'https://user.com/me.jpg', }, { 'rel': 'canonical_uri', 'type': 'text/html', 'href': 'https://user.com/about-me', }, { 'rel': 'self', 'type': 'application/activity+json', 'href': 'http://localhost/user.com', }, { 'rel': 'inbox', 'type': 'application/activity+json', 'href': 'http://localhost/user.com/inbox' }, { 'rel': 'sharedInbox', 'type': 'application/activity+json', 'href': 'http://localhost/ap/sharedInbox', }, { 'rel': 'http://ostatus.org/schema/1.0/subscribe', 'template': 'http://localhost/web/user.com?url={uri}', }], } WEBFINGER_NO_HCARD = { 'subject': 'acct:user.com@user.com', 'aliases': ['https://user.com/'], 'links': [{ 'rel': 'http://webfinger.net/rel/profile-page', 'type': 'text/html', 'href': 'https://user.com/', }, { 'rel': 'canonical_uri', 'type': 'text/html', 'href': 'https://user.com/', }, { 'rel': 'self', 'type': 'application/activity+json', 'href': 'http://localhost/user.com', }, { 'rel': 'inbox', 'type': 'application/activity+json', 'href': 'http://localhost/user.com/inbox', }, { 'rel': 'sharedInbox', 'type': 'application/activity+json', 'href': 'http://localhost/ap/sharedInbox', }, { 'rel': 'http://ostatus.org/schema/1.0/subscribe', 'template': 'http://localhost/web/user.com?url={uri}', }], } class HostMetaTest(testutil.TestCase): def test_host_meta_xrd(self): got = self.client.get('/.well-known/host-meta') self.assertEqual(200, got.status_code) self.assertEqual('application/xrd+xml; charset=utf-8', got.headers['Content-Type']) body = got.get_data(as_text=True) self.assertTrue(body.startswith('