-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make remote follow handle non-web users
- Loading branch information
Showing
4 changed files
with
31 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,11 @@ | |
<div class="row"> | ||
<form method="post" action="/remote-follow"> | ||
<nobr> | ||
<label for="follow-address">Follow @{{ id }} with your fediverse address:</label> | ||
<label for="follow-address">Follow @{{ handle }} with your fediverse address:</label> | ||
<input id="follow-address" name="address" type="text" required | ||
placeholder="@[email protected]" alt="fediverse address" | ||
value="{{ follow_url or '' }}"></input> | ||
<input name="domain" type="hidden" value="{{ id }}"></input> | ||
<input name="id" type="hidden" value="{{ id }}"></input> | ||
<input name="protocol" type="hidden" value="{{ user.LABEL }}"></input> | ||
<button type="submit" class="btn btn-default">Follow</button> | ||
</nobr> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,29 +70,29 @@ def setUp(self): | |
super().setUp() | ||
self.make_user('user.com', cls=Web, has_redirects=True) | ||
|
||
def test_no_domain(self, _): | ||
def test_no_id(self, _): | ||
got = self.client.post('/remote-follow?address=@[email protected]&protocol=web') | ||
self.assertEqual(400, got.status_code) | ||
|
||
def test_no_address(self, _): | ||
got = self.client.post('/remote-follow?domain=baz.com&protocol=web') | ||
got = self.client.post('/remote-follow?id=baz.com&protocol=web') | ||
self.assertEqual(400, got.status_code) | ||
|
||
def test_no_protocol(self, _): | ||
got = self.client.post('/remote-follow?address=@[email protected]&domain=user.com') | ||
got = self.client.post('/remote-follow?address=@[email protected]&id=user.com') | ||
self.assertEqual(400, got.status_code) | ||
|
||
def test_unknown_protocol(self, _): | ||
got = self.client.post('/remote-follow?address=@[email protected]&domain=user.com&protocol=foo') | ||
got = self.client.post('/remote-follow?address=@[email protected]&id=user.com&protocol=foo') | ||
self.assertEqual(400, got.status_code) | ||
|
||
def test_no_user(self, _): | ||
got = self.client.post('/remote-follow?address=@[email protected]&domain=baz.com') | ||
got = self.client.post('/remote-follow?address=@[email protected]&id=baz.com') | ||
self.assertEqual(400, got.status_code) | ||
|
||
def test_addr(self, mock_get): | ||
mock_get.return_value = WEBFINGER | ||
got = self.client.post('/remote-follow?address=@[email protected]&domain=user.com&protocol=web') | ||
got = self.client.post('/remote-follow?address=@[email protected]&id=user.com&protocol=web') | ||
self.assertEqual(302, got.status_code) | ||
self.assertEqual('https://ba.r/[email protected]@user.com', | ||
got.headers['Location']) | ||
|
@@ -103,35 +103,48 @@ def test_addr(self, mock_get): | |
|
||
def test_url(self, mock_get): | ||
mock_get.return_value = WEBFINGER | ||
got = self.client.post('/remote-follow?address=https://ba.r/foo&domain=user.com&protocol=web') | ||
got = self.client.post('/remote-follow?address=https://ba.r/foo&id=user.com&protocol=web') | ||
self.assertEqual(302, got.status_code) | ||
self.assertEqual('https://ba.r/[email protected]@user.com', got.headers['Location']) | ||
|
||
mock_get.assert_has_calls(( | ||
self.req('https://ba.r/.well-known/webfinger?resource=https://ba.r/foo'), | ||
)) | ||
|
||
def test_non_web_user(self, mock_get): | ||
user = self.make_user('fake:user', cls=Fake) | ||
|
||
mock_get.return_value = WEBFINGER | ||
got = self.client.post('/remote-follow?address=@[email protected]&id=fake:user&protocol=fake') | ||
self.assertEqual(302, got.status_code) | ||
self.assertEqual('https://ba.r/follow?uri=@fake:handle:[email protected]', | ||
got.headers['Location']) | ||
|
||
mock_get.assert_has_calls(( | ||
self.req('https://ba.r/.well-known/webfinger?resource=acct:[email protected]'), | ||
)) | ||
|
||
def test_no_webfinger_subscribe_link(self, mock_get): | ||
mock_get.return_value = requests_response({ | ||
'subject': 'acct:[email protected]', | ||
'links': [{'rel': 'other', 'template': 'meh'}], | ||
}) | ||
|
||
got = self.client.post('/remote-follow?address=https://ba.r/foo&domain=user.com&protocol=web') | ||
got = self.client.post('/remote-follow?address=https://ba.r/foo&id=user.com&protocol=web') | ||
self.assertEqual(302, got.status_code) | ||
self.assertEqual('/web/user.com', got.headers['Location']) | ||
|
||
def test_webfinger_error(self, mock_get): | ||
mock_get.return_value = requests_response(status=500) | ||
|
||
got = self.client.post('/remote-follow?address=https://ba.r/foo&domain=user.com&protocol=web') | ||
got = self.client.post('/remote-follow?address=https://ba.r/foo&id=user.com&protocol=web') | ||
self.assertEqual(302, got.status_code) | ||
self.assertEqual('/web/user.com', got.headers['Location']) | ||
|
||
def test_webfinger_returns_not_json(self, mock_get): | ||
mock_get.return_value = requests_response('<html>not json</html>') | ||
|
||
got = self.client.post('/remote-follow?address=https://ba.r/foo&domain=user.com&protocol=web') | ||
got = self.client.post('/remote-follow?address=https://ba.r/foo&id=user.com&protocol=web') | ||
self.assertEqual(302, got.status_code) | ||
self.assertEqual('/web/user.com', got.headers['Location']) | ||
|
||
|