Exemplo n.º 1
0
    def test_user_handler(self, mock_get):
        mock_get.return_value = requests_response(self.html,
                                                  url='https://foo.com/')

        got = app.get_response('/foo.com',
                               headers={'Accept': 'application/json'})
        self.assertEquals(200, got.status_int)
        self.assertEquals('application/json; charset=utf-8',
                          got.headers['Content-Type'])
        mock_get.assert_called_once_with('http://foo.com/',
                                         headers=common.HEADERS,
                                         timeout=util.HTTP_TIMEOUT)

        self.assertEquals(self.expected_webfinger, json.loads(got.body))

        # check that magic key is persistent
        again = json.loads(
            app.get_response('/foo.com',
                             headers={
                                 'Accept': 'application/json'
                             }).body)
        self.assertEquals(self.key.href(), again['magic_keys'][0]['value'])

        links = {l['rel']: l['href'] for l in again['links']}
        self.assertEquals(self.key.href(), links['magic-public-key'])
Exemplo n.º 2
0
    def test_webfinger_handler_custom_username(self, mock_get):
        self.html = """
<body class="h-card">
<a class="u-url" rel="me" href="/about-me">
  <img class="u-photo" src="/me.jpg" />
  Mrs. ☕ Foo
</a>
<a class="u-url" href="acct:[email protected]"></a>
<a class="u-url" href="acct:[email protected]"></a>
</body>
"""
        self.expected_webfinger['subject'] = "acct:[email protected]"
        self.expected_webfinger['aliases'] = [u'https://foo.com/about-me',
            u'acct:[email protected]',
            u'acct:[email protected]',
            u'https://foo.com/']
        mock_get.return_value = requests_response(self.html, url='https://foo.com/')

        for resource in ('*****@*****.**', 'acct:[email protected]',
                         'foo.com', 'http://foo.com/', 'https://foo.com/'):
            url = '/.well-known/webfinger?%s' % urllib.urlencode(
                {'resource': resource})
            got = app.get_response(url, headers={'Accept': 'application/json'})
            self.assertEquals(200, got.status_int, got.body)
            self.assertEquals('application/json; charset=utf-8',
                              got.headers['Content-Type'])
            self.assertEquals(self.expected_webfinger, json.loads(got.body))
Exemplo n.º 3
0
    def test_webfinger_handler(self, mock_get):
        mock_get.return_value = requests_response(self.html, url='https://foo.com/')

        for resource in ('*****@*****.**', 'acct:[email protected]', '*****@*****.**',
                         'foo.com', 'http://foo.com/', 'https://foo.com/'):
            url = '/.well-known/webfinger?%s' % urllib.urlencode(
                {'resource': resource})
            got = app.get_response(url, headers={'Accept': 'application/json'})
            self.assertEquals(200, got.status_int, got.body)
            self.assertEquals('application/json; charset=utf-8',
                              got.headers['Content-Type'])
            self.assertEquals(self.expected_webfinger, json.loads(got.body))
Exemplo n.º 4
0
    def test_user_handler_no_hcard(self, mock_get):
        mock_get.return_value = requests_response("""
<body>
<div class="h-entry">
  <p class="e-content">foo bar</p>
</div>
</body>
""")
        got = app.get_response('/foo.com')
        mock_get.assert_called_once_with('http://foo.com/', headers=common.HEADERS,
                                         timeout=util.HTTP_TIMEOUT)
        self.assertEquals(400, got.status_int)
        self.assertIn('representative h-card', got.body)
Exemplo n.º 5
0
    def test_user_handler_with_push_header(self, mock_get):
        mock_get.return_value = requests_response(
            self.html, url = 'https://foo.com/', headers={
                'Link': 'badly formatted, '
                        "<xyz>; rel='foo',"
                        '<http://a.custom.hub/>; rel="hub"',
            })

        got = app.get_response('/foo.com', headers={'Accept': 'application/json'})
        self.assertEquals(200, got.status_int)
        self.assertIn({
            'rel': 'hub',
            'href': 'http://a.custom.hub/',
        }, json.loads(got.body)['links'])
Exemplo n.º 6
0
    def test_user_handler_with_atom_feed(self, mock_get):
        html = """\
<html>
<head>
<link rel="feed" href="/dont-use">
<link rel="alternate" type="application/rss+xml" href="/dont-use-either">
<link rel="alternate" type="application/atom+xml" href="/use-this">
</head>
""" + self.html
        mock_get.return_value = requests_response(html, url = 'https://foo.com/')

        got = app.get_response('/foo.com', headers={'Accept': 'application/json'})
        self.assertEquals(200, got.status_int)
        self.assertIn({
            'rel': 'http://schemas.google.com/g/2010#updates-from',
            'type': 'application/atom+xml',
            'href': 'https://foo.com/use-this',
        }, json.loads(got.body)['links'])
Exemplo n.º 7
0
 def test_host_meta_handler_jrd(self):
     got = app.get_response('/.well-known/host-meta.json')
     self.assertEquals(200, got.status_int)
     self.assertEquals('application/json; charset=utf-8',
                       got.headers['Content-Type'])
     self.assertTrue(got.body.startswith('{'), got.body)
Exemplo n.º 8
0
 def test_user_handler_bad_tld(self):
     got = app.get_response('/foo.json')
     self.assertEquals(404, got.status_int)
     self.assertIn("doesn't look like a domain", got.body)