# coding=utf-8 """Unit tests for webfinger.py. to test: * user URL that redirects * error handling """ import html from unittest import mock import urllib.parse from oauth_dropins.webutil import util from oauth_dropins.webutil.testutil import requests_response from oauth_dropins.webutil.util import json_loads import requests import common import models from . import testutil class WebfingerTest(testutil.TestCase): def setUp(self): super().setUp() self.html = """
Mrs. ☕ Foo """ self.key = models.User.get_or_create('foo.com') self.expected_webfinger = { 'subject': 'acct:foo.com@foo.com', 'aliases': [ 'https://foo.com/about-me', 'https://foo.com/', ], 'links': [{ 'rel': 'http://webfinger.net/rel/profile-page', 'type': 'text/html', 'href': 'https://foo.com/about-me' }, { 'rel': 'http://webfinger.net/rel/profile-page', 'type': 'text/html', 'href': 'https://foo.com/' }, { 'rel': 'http://webfinger.net/rel/avatar', 'href': 'https://foo.com/me.jpg' }, { 'rel': 'canonical_uri', 'type': 'text/html', 'href': 'https://foo.com/about-me' }, { 'rel': 'self', 'type': 'application/activity+json', 'href': 'http://localhost/foo.com' }, { 'rel': 'inbox', 'type': 'application/activity+json', 'href': 'http://localhost/foo.com/inbox' }, { 'rel': 'sharedInbox', 'type': 'application/activity+json', 'href': 'http://localhost/inbox' }, { 'rel': 'http://ostatus.org/schema/1.0/subscribe', 'template': 'http://localhost/user/foo.com?url={uri}', }], } 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('foo bar