forked from cybrespace/mastodon
Fix an error when actor json couldn't be fetched in ResolveRemoteAccountService (#4979)
* Fix an error when actor json couldn't be fetched in ResolveRemoteAccountService * Add specs
This commit is contained in:
parent
7be3131240
commit
1eab53ee10
|
@ -80,6 +80,7 @@ class ResolveRemoteAccountService < BaseService
|
|||
def activitypub_ready?
|
||||
!@webfinger.link('self').nil? &&
|
||||
['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].include?(@webfinger.link('self').type) &&
|
||||
!actor_json.nil? &&
|
||||
actor_json['inbox'].present?
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
HTTP/1.1 200 OK
|
||||
Date: Sun, 17 Sep 2017 06:51:23 GMT
|
||||
Content-Type: application/json; charset=utf-8
|
||||
X-XSS-Protection: 1; mode=block
|
||||
Link: <https://ap.example.com/.well-known/webfinger?resource=acct%3Afoo%40ap.example.com>; rel="lrdd"; type="application/xrd+xml", <https://ap.example.com/users/foo.atom>; rel="alternate"; type="application/atom+xml"
|
||||
Vary: Accept-Encoding
|
||||
Cache-Control: max-age=0, private, must-revalidate
|
||||
|
||||
{"@context":"https://www.w3.org/ns/activitystreams","id":"https://ap.example.com/users/foo","type":"Person","following":"https://ap.example.com/users/foo/following","followers":"https://ap.example.com/users/foo/followers","inbox":null,"outbox":"https://ap.example.com/users/foo/outbox","preferredUsername":"foo","name":"","summary":"\u003cp\u003etest\u003c/p\u003e","icon":"https://quitter.no/avatar/7477-300-20160211190340.png","image":"/headers/original/missing.png","publicKey":{"id":"https://ap.example.com/users/foo#main-key","owner":"https://ap.example.com/users/foo","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu3L4vnpNLzVH31MeWI39\n4F0wKeJFsLDAsNXGeOu0QF2x+h1zLWZw/agqD2R3JPU9/kaDJGPIV2Sn5zLyUA9S\n6swCCMOtn7BBR9g9sucgXJmUFB0tACH2QSgHywMAybGfmSb3LsEMNKsGJ9VsvYoh\n8lDET6X4Pyw+ZJU0/OLo/41q9w+OrGtlsTm/PuPIeXnxa6BLqnDaxC+4IcjG/FiP\nahNCTINl/1F/TgSSDZ4Taf4U9XFEIFw8wmgploELozzIzKq+t8nhQYkgAkt64euW\npva3qL5KD1mTIZQEP+LZvh3s2WHrLi3fhbdRuwQ2c0KkJA2oSTFPDpqqbPGZ3Qvu\nHQIDAQAB\n-----END PUBLIC KEY-----\n"}}
|
|
@ -0,0 +1,9 @@
|
|||
HTTP/1.1 200 OK
|
||||
Cache-Control: max-age=0, private, must-revalidate
|
||||
Content-Type: application/activity+json; charset=utf-8
|
||||
Link: <https://ap.example.com/.well-known/webfinger?resource=acct%3Afoo%40ap.example.com>; rel="lrdd"; type="application/xrd+xml", <https://ap.example.com/users/foo.atom>; rel="alternate"; type="application/atom+xml", <https://ap.example.com/users/foo>; rel="alternate"; type="application/activity+json"
|
||||
Vary: Accept-Encoding
|
||||
X-Content-Type-Options: nosniff
|
||||
X-Xss-Protection: 1; mode=block
|
||||
|
||||
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation"}],"id":"https://ap.example.com/users/foo","type":"Person","following":"https://ap.example.com/users/foo/following","followers":"https://ap.example.com/users/foo/followers","inbox":"https://ap.example.com/users/foo/inbox","outbox":"https://ap.example.com/users/foo/outbox","preferredUsername":"foo","name":"","summary":"\u003cp\u003etest\u003c/p\u003e","url":"https://ap.example.com/@foo","manuallyApprovesFollowers":false,"publicKey":{"id":"https://ap.example.com/users/foo#main-key","owner":"https://ap.example.com/users/foo","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu3L4vnpNLzVH31MeWI39\n4F0wKeJFsLDAsNXGeOu0QF2x+h1zLWZw/agqD2R3JPU9/kaDJGPIV2Sn5zLyUA9S\n6swCCMOtn7BBR9g9sucgXJmUFB0tACH2QSgHywMAybGfmSb3LsEMNKsGJ9VsvYoh\n8lDET6X4Pyw+ZJU0/OLo/41q9w+OrGtlsTm/PuPIeXnxa6BLqnDaxC+4IcjG/FiP\nahNCTINl/1F/TgSSDZ4Taf4U9XFEIFw8wmgploELozzIzKq+t8nhQYkgAkt64euW\npva3qL5KD1mTIZQEP+LZvh3s2WHrLi3fhbdRuwQ2c0KkJA2oSTFPDpqqbPGZ3Qvu\nHQIDAQAB\n-----END PUBLIC KEY-----\n"},"endpoints":{"sharedInbox":"https://ap.example.com/inbox"},"icon":{"type":"Image","url":"https://quitter.no/avatar/7477-300-20160211190340.png"}}
|
|
@ -0,0 +1,47 @@
|
|||
HTTP/1.1 200 OK
|
||||
Cache-Control: max-age=0, private, must-revalidate
|
||||
Content-Type: application/atom+xml; charset=utf-8
|
||||
Link: <https://ap.example.com/.well-known/webfinger?resource=acct%3Afoo%40ap.example.com>; rel="lrdd"; type="application/xrd+xml", <https://ap.example.com/users/foo.atom>; rel="alternate"; type="application/atom+xml", <https://ap.example.com/users/foo>; rel="alternate"; type="application/activity+json"
|
||||
Vary: Accept-Encoding
|
||||
Date: Sun, 17 Sep 2017 06:33:53 GMT
|
||||
|
||||
<?xml version="1.0"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:media="http://purl.org/syndication/atommedia" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:mastodon="http://mastodon.social/schema/1.0">
|
||||
<id>https://ap.example.com/users/foo.atom</id>
|
||||
<title>foo</title>
|
||||
<subtitle>test</subtitle>
|
||||
<updated>2017-09-16T18:50:09Z</updated>
|
||||
<logo>https://ap.example.com/system/accounts/avatars/000/000/001/original/141ee5846d159cba.png?1505587809</logo>
|
||||
<author>
|
||||
<id>https://ap.example.com/users/foo</id>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
|
||||
<uri>https://ap.example.com/users/foo</uri>
|
||||
<name>foo</name>
|
||||
<email>foo@ap.example.com</email>
|
||||
<summary type="html"><p>test</p></summary>
|
||||
<link rel="alternate" type="text/html" href="https://ap.example.com/@foo"/>
|
||||
<link rel="avatar" type="image/jpeg" media:width="120" media:height="120" href="https://quitter.no/avatar/7477-300-20160211190340.png"/>
|
||||
<poco:preferredUsername>foo</poco:preferredUsername>
|
||||
<poco:note>test</poco:note>
|
||||
<mastodon:scope>public</mastodon:scope>
|
||||
</author>
|
||||
<link rel="alternate" type="text/html" href="https://ap.example.com/@foo"/>
|
||||
<link rel="self" type="application/atom+xml" href="https://ap.example.com/users/foo.atom"/>
|
||||
<link rel="hub" href="https://ap.example.com/api/push"/>
|
||||
<link rel="salmon" href="https://ap.example.com/api/salmon/1"/>
|
||||
<entry>
|
||||
<id>https://ap.example.com/users/foo/statuses/11076</id>
|
||||
<published>2017-09-13T01:23:19Z</published>
|
||||
<updated>2017-09-13T01:23:19Z</updated>
|
||||
<title>New status by foo</title>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
|
||||
<link rel="alternate" type="application/activity+json" href="https://ap.example.com/users/foo/statuses/11076"/>
|
||||
<content type="html" xml:lang="ja"><p>test</p></content>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
|
||||
<mastodon:scope>public</mastodon:scope>
|
||||
<link rel="alternate" type="text/html" href="https://ap.example.com/@foo/11076"/>
|
||||
<link rel="self" type="application/atom+xml" href="https://ap.example.com/users/foo/updates/11015.atom"/>
|
||||
<ostatus:conversation ref="tag:ap.example.com,2017-09-13:objectId=7412:objectType=Conversation"/>
|
||||
</entry>
|
||||
</feed>
|
|
@ -0,0 +1,7 @@
|
|||
HTTP/1.1 200 OK
|
||||
Cache-Control: max-age=0, private, must-revalidate
|
||||
Content-Type: application/jrd+json; charset=utf-8
|
||||
X-Content-Type-Options: nosniff
|
||||
Date: Sun, 17 Sep 2017 06:22:50 GMT
|
||||
|
||||
{"subject":"acct:foo@ap.example.com","aliases":["https://ap.example.com/@foo","https://ap.example.com/users/foo"],"links":[{"rel":"http://webfinger.net/rel/profile-page","type":"text/html","href":"https://ap.example.com/@foo"},{"rel":"http://schemas.google.com/g/2010#updates-from","type":"application/atom+xml","href":"https://ap.example.com/users/foo.atom"},{"rel":"self","type":"application/activity+json","href":"https://ap.example.com/users/foo"},{"rel":"salmon","href":"https://ap.example.com/api/salmon/1"},{"rel":"magic-public-key","href":"data:application/magic-public-key,RSA.u3L4vnpNLzVH31MeWI394F0wKeJFsLDAsNXGeOu0QF2x-h1zLWZw_agqD2R3JPU9_kaDJGPIV2Sn5zLyUA9S6swCCMOtn7BBR9g9sucgXJmUFB0tACH2QSgHywMAybGfmSb3LsEMNKsGJ9VsvYoh8lDET6X4Pyw-ZJU0_OLo_41q9w-OrGtlsTm_PuPIeXnxa6BLqnDaxC-4IcjG_FiPahNCTINl_1F_TgSSDZ4Taf4U9XFEIFw8wmgploELozzIzKq-t8nhQYkgAkt64euWpva3qL5KD1mTIZQEP-LZvh3s2WHrLi3fhbdRuwQ2c0KkJA2oSTFPDpqqbPGZ3QvuHQ==.AQAB"},{"rel":"http://ostatus.org/schema/1.0/subscribe","template":"https://ap.example.com/authorize_follow?acct={uri}"}]}
|
|
@ -72,6 +72,39 @@ RSpec.describe ResolveRemoteAccountService do
|
|||
end
|
||||
|
||||
context 'with an ActivityPub account' do
|
||||
before do
|
||||
stub_request(:get, "https://ap.example.com/.well-known/webfinger?resource=acct:foo@ap.example.com").to_return(request_fixture('activitypub-webfinger.txt'))
|
||||
stub_request(:get, "https://ap.example.com/users/foo").to_return(request_fixture('activitypub-actor.txt'))
|
||||
stub_request(:get, "https://ap.example.com/users/foo.atom").to_return(request_fixture('activitypub-feed.txt'))
|
||||
stub_request(:get, %r{https://ap.example.com/users/foo/\w+}).to_return(status: 404)
|
||||
end
|
||||
|
||||
it 'fallback to OStatus if actor json could not be fetched' do
|
||||
stub_request(:get, "https://ap.example.com/users/foo").to_return(status: 404)
|
||||
|
||||
account = subject.call('foo@ap.example.com')
|
||||
|
||||
expect(account.ostatus?).to eq true
|
||||
expect(account.remote_url).to eq 'https://ap.example.com/users/foo.atom'
|
||||
end
|
||||
|
||||
it 'fallback to OStatus if actor json did not have inbox_url' do
|
||||
stub_request(:get, "https://ap.example.com/users/foo").to_return(request_fixture('activitypub-actor-noinbox.txt'))
|
||||
|
||||
account = subject.call('foo@ap.example.com')
|
||||
|
||||
expect(account.ostatus?).to eq true
|
||||
expect(account.remote_url).to eq 'https://ap.example.com/users/foo.atom'
|
||||
end
|
||||
|
||||
it 'returns new remote account' do
|
||||
account = subject.call('foo@ap.example.com')
|
||||
|
||||
expect(account.activitypub?).to eq true
|
||||
expect(account.domain).to eq 'ap.example.com'
|
||||
expect(account.inbox_url).to eq 'https://ap.example.com/users/foo/inbox'
|
||||
end
|
||||
|
||||
pending
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue